class Prompt { final String id; final String text; final String title; final int order; Prompt({ required this.id, required this.text, required this.title, required this.order, }); factory Prompt.fromJson(Map json) { return Prompt( id: json['id'] as String? ?? '', text: json['text'] as String? ?? '', title: json['title'] as String? ?? '', order: json['order'] as int? ?? 0, ); } Map toJson() { return {'id': id, 'text': text, 'title': title, 'order': order}; } Prompt copyWith({String? id, String? text, String? title, int? order}) { return Prompt( id: id ?? this.id, text: text ?? this.text, title: title ?? this.title, order: order ?? this.order, ); } } class Pipeline { final String id; final String name; final List prompts; final String workingDir; final String createdAt; final String updatedAt; Pipeline({ required this.id, required this.name, required this.prompts, required this.workingDir, required this.createdAt, required this.updatedAt, }); factory Pipeline.fromJson(Map json) { return Pipeline( id: json['id'] as String? ?? '', name: json['name'] as String? ?? '', prompts: (json['prompts'] as List?) ?.map((p) => Prompt.fromJson(p as Map)) .toList() ?? [], workingDir: json['working_dir'] as String? ?? '', createdAt: json['created_at'] as String? ?? '', updatedAt: json['updated_at'] as String? ?? '', ); } Map toJson() { return { 'id': id, 'name': name, 'prompts': prompts.map((p) => p.toJson()).toList(), 'working_dir': workingDir, 'created_at': createdAt, 'updated_at': updatedAt, }; } } enum RunStatus { pending, running, completed, error } RunStatus parseRunStatus(String s) { switch (s) { case 'pending': return RunStatus.pending; case 'running': return RunStatus.running; case 'completed': return RunStatus.completed; case 'error': return RunStatus.error; default: return RunStatus.pending; } } class StepResult { final int stepIndex; final String title; final RunStatus status; final int returnCode; final String output; final String error; StepResult({ required this.stepIndex, required this.title, required this.status, required this.returnCode, required this.output, required this.error, }); factory StepResult.fromJson(Map json) { return StepResult( stepIndex: json['step_index'] as int? ?? 0, title: json['title'] as String? ?? '', status: parseRunStatus(json['status'] as String? ?? 'pending'), returnCode: json['returncode'] as int? ?? 0, output: json['output'] as String? ?? '', error: json['error'] as String? ?? '', ); } } class RunState { final String runId; final String pipelineId; final RunStatus status; final int currentStep; final List steps; RunState({ required this.runId, required this.pipelineId, required this.status, required this.currentStep, required this.steps, }); factory RunState.fromJson(Map json) { return RunState( runId: json['run_id'] as String? ?? '', pipelineId: json['pipeline_id'] as String? ?? '', status: parseRunStatus(json['status'] as String? ?? 'pending'), currentStep: json['current_step'] as int? ?? -1, steps: (json['steps'] as List?) ?.map((s) => StepResult.fromJson(s as Map)) .toList() ?? [], ); } bool get isFinished => status == RunStatus.completed || status == RunStatus.error; }