feat: KI-Funktionalität per .env-Schalter AI_ENABLED abschaltbar (Standard: aus)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,7 @@ import java.util.List;
|
||||
public class WorkflowAssistantService {
|
||||
|
||||
private final BlockTypeRegistry registry;
|
||||
private final boolean aiEnabled;
|
||||
private final String apiKey;
|
||||
private final String model;
|
||||
private final ObjectMapper lenientMapper;
|
||||
@@ -38,9 +39,11 @@ public class WorkflowAssistantService {
|
||||
private volatile AnthropicClient client;
|
||||
|
||||
public WorkflowAssistantService(BlockTypeRegistry registry,
|
||||
@Value("${tasklist.ai-enabled:false}") boolean aiEnabled,
|
||||
@Value("${tasklist.anthropic-api-key:}") String apiKey,
|
||||
@Value("${tasklist.anthropic-model:claude-opus-4-8}") String model) {
|
||||
this.registry = registry;
|
||||
this.aiEnabled = aiEnabled;
|
||||
this.apiKey = apiKey == null ? "" : apiKey.trim();
|
||||
this.model = model;
|
||||
this.lenientMapper = new ObjectMapper()
|
||||
@@ -51,9 +54,9 @@ public class WorkflowAssistantService {
|
||||
public record WorkflowDraft(String name, List<TaskDto> tasks) {
|
||||
}
|
||||
|
||||
/** Ob der Assistent nutzbar ist (API-Key in der .env hinterlegt). */
|
||||
/** Ob der Assistent nutzbar ist (AI_ENABLED=true und API-Key in der .env). */
|
||||
public boolean isEnabled() {
|
||||
return !apiKey.isBlank();
|
||||
return aiEnabled && !apiKey.isBlank();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +87,8 @@ public class WorkflowAssistantService {
|
||||
public WorkflowDraft generateWorkflow(String wish, String currentName, String currentTasksJson) {
|
||||
if (!isEnabled()) {
|
||||
throw new IllegalStateException(
|
||||
"Kein Claude-API-Key konfiguriert (ANTHROPIC_API_KEY in der .env-Datei).");
|
||||
"KI-Assistent deaktiviert: AI_ENABLED=true und ANTHROPIC_API_KEY "
|
||||
+ "in der .env-Datei setzen.");
|
||||
}
|
||||
if (wish == null || wish.isBlank()) {
|
||||
throw new IllegalStateException("Bitte einen Workflow-Wunsch eingeben.");
|
||||
|
||||
@@ -229,6 +229,8 @@ public class MainView extends VerticalLayout implements BeforeEnterObserver {
|
||||
assistant.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
|
||||
assistant.setTooltipText("Workflow aus einer Beschreibung erzeugen oder ändern (Claude)");
|
||||
assistant.addClickListener(e -> openAssistantDialog());
|
||||
// KI-Funktionalität per .env (AI_ENABLED) abschaltbar.
|
||||
assistant.setVisible(workflowAssistantService.isEnabled());
|
||||
|
||||
Button undo = new Button("Rückgängig", new Icon(VaadinIcon.ARROW_BACKWARD));
|
||||
undo.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
|
||||
@@ -1033,8 +1035,9 @@ public class MainView extends VerticalLayout implements BeforeEnterObserver {
|
||||
*/
|
||||
private void openAssistantDialog() {
|
||||
if (!workflowAssistantService.isEnabled()) {
|
||||
Notification.show("KI-Assistent nicht verfügbar: Bitte ANTHROPIC_API_KEY "
|
||||
+ "in der .env-Datei hinterlegen und die Anwendung neu starten.");
|
||||
Notification.show("KI-Assistent nicht verfügbar: Bitte AI_ENABLED=true und "
|
||||
+ "ANTHROPIC_API_KEY in der .env-Datei hinterlegen und die "
|
||||
+ "Anwendung neu starten.");
|
||||
return;
|
||||
}
|
||||
boolean modifying = !instances.isEmpty();
|
||||
|
||||
@@ -31,8 +31,10 @@ management.health.mongo.enabled=false
|
||||
tasklist.hide-script-block=${HIDE_SCRIPT_BLOCK:false}
|
||||
|
||||
# --- KI-Workflow-Assistent (Claude API) --------------------------------------
|
||||
# API-Key und Modell kommen aus der .env-Datei (ANTHROPIC_API_KEY,
|
||||
# ANTHROPIC_MODEL). Ohne Key ist der Assistent im Editor deaktiviert.
|
||||
# Ein-/Ausschalter, API-Key und Modell kommen aus der .env-Datei (AI_ENABLED,
|
||||
# ANTHROPIC_API_KEY, ANTHROPIC_MODEL). Der Assistent ist nur verfügbar, wenn
|
||||
# AI_ENABLED=true gesetzt UND ein Key hinterlegt ist (Standard: aus).
|
||||
tasklist.ai-enabled=${AI_ENABLED:false}
|
||||
tasklist.anthropic-api-key=${ANTHROPIC_API_KEY:}
|
||||
tasklist.anthropic-model=${ANTHROPIC_MODEL:claude-opus-4-8}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user