mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 15:54:35 +01:00
feat: ask ai (#936)
* feat: ask ai in ssh terminal Fixes #934 * new(ask_ai): settings * fix: app hot reload * new: l10n * chore: deps. * opt.
This commit is contained in:
74
lib/data/model/ai/ask_ai_models.dart
Normal file
74
lib/data/model/ai/ask_ai_models.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// Chat message exchanged with the Ask AI service.
|
||||
enum AskAiMessageRole { user, assistant }
|
||||
|
||||
@immutable
|
||||
class AskAiMessage {
|
||||
const AskAiMessage({
|
||||
required this.role,
|
||||
required this.content,
|
||||
});
|
||||
|
||||
final AskAiMessageRole role;
|
||||
final String content;
|
||||
|
||||
String get apiRole {
|
||||
switch (role) {
|
||||
case AskAiMessageRole.user:
|
||||
return 'user';
|
||||
case AskAiMessageRole.assistant:
|
||||
return 'assistant';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Recommended command returned by the AI tool call.
|
||||
@immutable
|
||||
class AskAiCommand {
|
||||
const AskAiCommand({
|
||||
required this.command,
|
||||
this.description = '',
|
||||
this.toolName,
|
||||
});
|
||||
|
||||
final String command;
|
||||
final String description;
|
||||
final String? toolName;
|
||||
}
|
||||
|
||||
@immutable
|
||||
sealed class AskAiEvent {
|
||||
const AskAiEvent();
|
||||
}
|
||||
|
||||
/// Incremental text delta emitted while streaming the AI response.
|
||||
class AskAiContentDelta extends AskAiEvent {
|
||||
const AskAiContentDelta(this.delta);
|
||||
final String delta;
|
||||
}
|
||||
|
||||
/// Emits when a tool call returns a runnable command suggestion.
|
||||
class AskAiToolSuggestion extends AskAiEvent {
|
||||
const AskAiToolSuggestion(this.command);
|
||||
final AskAiCommand command;
|
||||
}
|
||||
|
||||
/// Signals that the stream finished successfully.
|
||||
class AskAiCompleted extends AskAiEvent {
|
||||
const AskAiCompleted({
|
||||
required this.fullText,
|
||||
required this.commands,
|
||||
});
|
||||
|
||||
final String fullText;
|
||||
final List<AskAiCommand> commands;
|
||||
}
|
||||
|
||||
/// Signals that the stream terminated with an error before completion.
|
||||
class AskAiStreamError extends AskAiEvent {
|
||||
const AskAiStreamError(this.error, this.stackTrace);
|
||||
|
||||
final Object error;
|
||||
final StackTrace? stackTrace;
|
||||
}
|
||||
Reference in New Issue
Block a user