mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 18:57:05 +08:00
- Add actions list to chat messages Introduce - ChatActionType/ChatActionTarget enums and mapping helpers - Refactor viewmodel to parse actions and apply fixes via enums - Implement DashbotActionWidgetFactory and action widgets (auto-fix, add-tests, language, code, upload) - Integrate upload attachments provider and map upload_asset action - Update prompt schema docs to prefer actions array and include upload_asset - Update chat bubble to render multiple actions
58 lines
1.4 KiB
Dart
58 lines
1.4 KiB
Dart
import 'dart:typed_data';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:nanoid/nanoid.dart';
|
|
|
|
class ChatAttachment {
|
|
final String id;
|
|
final String name;
|
|
final String mimeType;
|
|
final int sizeBytes;
|
|
final Uint8List data;
|
|
final DateTime createdAt;
|
|
|
|
ChatAttachment({
|
|
required this.id,
|
|
required this.name,
|
|
required this.mimeType,
|
|
required this.sizeBytes,
|
|
required this.data,
|
|
required this.createdAt,
|
|
});
|
|
}
|
|
|
|
class AttachmentsState {
|
|
final List<ChatAttachment> items;
|
|
const AttachmentsState({this.items = const []});
|
|
|
|
AttachmentsState copyWith({List<ChatAttachment>? items}) =>
|
|
AttachmentsState(items: items ?? this.items);
|
|
}
|
|
|
|
class AttachmentsNotifier extends StateNotifier<AttachmentsState> {
|
|
AttachmentsNotifier() : super(const AttachmentsState());
|
|
|
|
ChatAttachment add({
|
|
required String name,
|
|
required String mimeType,
|
|
required Uint8List data,
|
|
}) {
|
|
final att = ChatAttachment(
|
|
id: nanoid(),
|
|
name: name,
|
|
mimeType: mimeType,
|
|
sizeBytes: data.length,
|
|
data: data,
|
|
createdAt: DateTime.now(),
|
|
);
|
|
state = state.copyWith(items: [...state.items, att]);
|
|
debugPrint('[Attachments] Added ${att.name} (${att.sizeBytes} bytes)');
|
|
return att;
|
|
}
|
|
}
|
|
|
|
final attachmentsProvider =
|
|
StateNotifierProvider<AttachmentsNotifier, AttachmentsState>((ref) {
|
|
return AttachmentsNotifier();
|
|
});
|