mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-24 22:57:12 -04:00
* chore: ai type * chore: use patch to fix version issue * chore: update * chore: update * chore: integrate client api * chore: add schema * chore: setup event * chore: add event test * chore: add test * chore: update test * chore: load chat message * chore: load chat message * chore: chat ui * chore: disable create chat * chore: update client api * chore: disable chat * chore: ui theme * chore: ui theme * chore: copy message * chore: fix test * chore: show error * chore: update bloc * chore: update test * chore: lint * chore: icon * chore: hover * chore: show unsupported page * chore: adjust mobile ui * chore: adjust view title bar * chore: return related question * chore: error page * chore: error page * chore: code format * chore: prompt * chore: fix test * chore: ui adjust * chore: disable create chat * chore: add loading page * chore: fix test * chore: disable chat action * chore: add maximum text limit
114 lines
3 KiB
Dart
114 lines
3 KiB
Dart
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
|
import 'package:appflowy/plugins/ai_chat/chat_page.dart';
|
|
import 'package:appflowy/plugins/util.dart';
|
|
import 'package:appflowy/startup/plugin/plugin.dart';
|
|
import 'package:appflowy/workspace/application/view_info/view_info_bloc.dart';
|
|
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
|
|
import 'package:appflowy/workspace/presentation/widgets/tab_bar_item.dart';
|
|
import 'package:appflowy/workspace/presentation/widgets/view_title_bar.dart';
|
|
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
class AIChatPluginBuilder extends PluginBuilder {
|
|
@override
|
|
Plugin build(dynamic data) {
|
|
if (data is ViewPB) {
|
|
return AIChatPagePlugin(view: data);
|
|
}
|
|
|
|
throw FlowyPluginException.invalidData;
|
|
}
|
|
|
|
@override
|
|
String get menuName => "AIChat";
|
|
|
|
@override
|
|
FlowySvgData get icon => FlowySvgs.chat_ai_page_s;
|
|
|
|
@override
|
|
PluginType get pluginType => PluginType.chat;
|
|
|
|
@override
|
|
ViewLayoutPB get layoutType => ViewLayoutPB.Chat;
|
|
}
|
|
|
|
class AIChatPluginConfig implements PluginConfig {
|
|
@override
|
|
bool get creatable => false;
|
|
}
|
|
|
|
class AIChatPagePlugin extends Plugin {
|
|
AIChatPagePlugin({
|
|
required ViewPB view,
|
|
}) : notifier = ViewPluginNotifier(view: view);
|
|
|
|
late final ViewInfoBloc _viewInfoBloc;
|
|
|
|
@override
|
|
final ViewPluginNotifier notifier;
|
|
|
|
@override
|
|
PluginWidgetBuilder get widgetBuilder => AIChatPagePluginWidgetBuilder(
|
|
bloc: _viewInfoBloc,
|
|
notifier: notifier,
|
|
);
|
|
|
|
@override
|
|
PluginId get id => notifier.view.id;
|
|
|
|
@override
|
|
PluginType get pluginType => PluginType.chat;
|
|
|
|
@override
|
|
void init() {
|
|
_viewInfoBloc = ViewInfoBloc(view: notifier.view)
|
|
..add(const ViewInfoEvent.started());
|
|
}
|
|
}
|
|
|
|
class AIChatPagePluginWidgetBuilder extends PluginWidgetBuilder
|
|
with NavigationItem {
|
|
AIChatPagePluginWidgetBuilder({
|
|
required this.bloc,
|
|
required this.notifier,
|
|
});
|
|
|
|
final ViewInfoBloc bloc;
|
|
final ViewPluginNotifier notifier;
|
|
int? deletedViewIndex;
|
|
|
|
@override
|
|
Widget get leftBarItem =>
|
|
ViewTitleBar(key: ValueKey(notifier.view.id), view: notifier.view);
|
|
|
|
@override
|
|
Widget tabBarItem(String pluginId) => ViewTabBarItem(view: notifier.view);
|
|
|
|
@override
|
|
Widget buildWidget({
|
|
required PluginContext context,
|
|
required bool shrinkWrap,
|
|
}) {
|
|
notifier.isDeleted.addListener(() {
|
|
final deletedView = notifier.isDeleted.value;
|
|
if (deletedView != null && deletedView.hasIndex()) {
|
|
deletedViewIndex = deletedView.index;
|
|
}
|
|
});
|
|
|
|
return BlocProvider<ViewInfoBloc>.value(
|
|
value: bloc,
|
|
child: AIChatPage(
|
|
userProfile: context.userProfile!,
|
|
key: ValueKey(notifier.view.id),
|
|
view: notifier.view,
|
|
onDeleted: () =>
|
|
context.onDeleted?.call(notifier.view, deletedViewIndex),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
List<NavigationItem> get navigationItems => [this];
|
|
}
|