Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: AI chat #5383

Merged
merged 49 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c59508d
chore: ai type
appflowy May 9, 2024
25e0a4e
chore: use patch to fix version issue
appflowy May 9, 2024
544646e
Merge branch 'chore/use_patch_to_fix_client_api' into ai_chat
appflowy May 9, 2024
8bb4fd2
chore: update
appflowy May 16, 2024
4b07de0
Merge branch 'main' into ai_chat
appflowy May 16, 2024
7945acb
chore: update
appflowy May 16, 2024
ac2b6cc
Merge branch 'main' into ai_chat
appflowy May 21, 2024
5f7d6ab
chore: integrate client api
appflowy May 21, 2024
d091002
chore: add schema
appflowy May 23, 2024
06f0405
chore: setup event
appflowy May 23, 2024
e06ac37
chore: add event test
appflowy May 23, 2024
65438a0
chore: add test
appflowy May 23, 2024
cc45118
chore: update test
appflowy May 23, 2024
98e2ad9
chore: load chat message
appflowy May 25, 2024
1362483
chore: load chat message
appflowy May 25, 2024
6032fba
chore: chat ui
appflowy May 26, 2024
2d3ac9d
chore: disable create chat
appflowy May 26, 2024
7e7cba6
chore: update client api
appflowy May 26, 2024
6a82740
Merge branch 'main' into ai_chat
appflowy May 26, 2024
760be42
chore: disable chat
appflowy May 28, 2024
7851e19
Merge branch 'main' into ai_chat
appflowy May 28, 2024
9d081a3
chore: ui theme
appflowy May 30, 2024
5518073
chore: ui theme
appflowy May 30, 2024
f7216f9
chore: copy message
appflowy May 30, 2024
f2f7fd6
chore: fix test
appflowy May 30, 2024
c3f43a3
chore: show error
appflowy May 30, 2024
7524df6
chore: update bloc
appflowy May 30, 2024
a77804e
chore: update test
appflowy May 30, 2024
f7880de
chore: lint
appflowy May 30, 2024
83efb5c
chore: icon
appflowy May 30, 2024
3eb75c9
chore: hover
appflowy May 30, 2024
200b520
Merge branch 'main' into ai_chat
appflowy May 30, 2024
593b0b5
chore: show unsupported page
appflowy May 31, 2024
9f89f0c
chore: adjust mobile ui
appflowy May 31, 2024
e0b1a94
chore: adjust view title bar
appflowy May 31, 2024
2926fc0
chore: return related question
appflowy Jun 2, 2024
2dab75c
chore: error page
appflowy Jun 2, 2024
7e778d6
chore: error page
appflowy Jun 2, 2024
85453f8
chore: code format
appflowy Jun 3, 2024
bb9aa00
Merge branch 'main' into ai_chat
appflowy Jun 3, 2024
5e70142
chore: prompt
appflowy Jun 3, 2024
53b2732
chore: fix test
appflowy Jun 3, 2024
b4c3c59
chore: ui adjust
appflowy Jun 3, 2024
8a97b01
Merge branch 'main' into ai_chat
appflowy Jun 3, 2024
ad0f8bc
chore: disable create chat
appflowy Jun 3, 2024
4164113
chore: add loading page
appflowy Jun 3, 2024
9a85045
chore: fix test
appflowy Jun 3, 2024
dcab8f8
chore: disable chat action
appflowy Jun 3, 2024
e7be0ef
chore: add maximum text limit
appflowy Jun 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/flutter_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
with:
os: ${{ matrix.os }}
flutter_version: ${{ env.FLUTTER_VERSION }}
DISABLE_CI_TEST_LOG: "true"
rust_toolchain: ${{ env.RUST_TOOLCHAIN }}
cargo_make_version: ${{ env.CARGO_MAKE_VERSION }}
rust_target: ${{ matrix.target }}
Expand Down Expand Up @@ -202,6 +203,7 @@ jobs:
- name: Run Flutter unit tests
env:
DISABLE_EVENT_LOG: true
DISABLE_CI_TEST_LOG: "true"
working-directory: frontend
run: |
if [ "$RUNNER_OS" == "macOS" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ void main() {

// create document, board, grid and calendar views
for (final value in ViewLayoutPB.values) {
if (value == ViewLayoutPB.Chat) {
continue;
}
await tester.createNewPageWithNameUnderParent(
name: value.name,
parentName: gettingStarted,
Expand Down Expand Up @@ -46,6 +49,9 @@ void main() {

// create document, board, grid and calendar views
for (final value in ViewLayoutPB.values) {
if (value == ViewLayoutPB.Chat) {
continue;
}
await tester.createNewPageWithNameUnderParent(
name: value.name,
parentName: gettingStarted,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ void main() {
await tester.tapAnonymousSignInButton();

for (final layout in ViewLayoutPB.values) {
if (layout == ViewLayoutPB.Chat) {
continue;
}
// create a new page
final name = 'AppFlowy_$layout';
await tester.createNewPageWithNameUnderParent(
Expand Down Expand Up @@ -66,6 +69,8 @@ void main() {
case ViewLayoutPB.Calendar:
expect(find.byType(CalendarPage), findsOneWidget);
break;
case ViewLayoutPB.Chat:
break;
}

await tester.openPage(gettingStarted);
Expand Down
4 changes: 2 additions & 2 deletions frontend/appflowy_flutter/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ SPEC CHECKSUMS:
file_picker: 09aa5ec1ab24135ccd7a1621c46c84134bfd6655
flowy_infra_ui: 0455e1fa8c51885aa1437848e361e99419f34ebc
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
fluttertoast: 31b00dabfa7fb7bacd9e7dbee580d7a2ff4bf265
fluttertoast: fafc4fa4d01a6a9e4f772ecd190ffa525e9e2d9c
image_gallery_saver: cb43cc43141711190510e92c460eb1655cd343cb
image_picker_ios: 99dfe1854b4fa34d0364e74a78448a0151025425
integration_test: ce0a3ffa1de96d1a89ca0ac26fca7ea18a749ef4
Expand All @@ -227,4 +227,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: d0d9b4ff572d8695c38eb3f9b490f55cdfc57eca

COCOAPODS: 1.15.2
COCOAPODS: 1.11.3
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import 'dart:async';
import 'dart:convert';

import 'package:appflowy/mobile/presentation/chat/mobile_chat_screen.dart';
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
import 'package:flutter/material.dart';

import 'package:appflowy/mobile/presentation/database/board/mobile_board_screen.dart';
import 'package:appflowy/mobile/presentation/database/mobile_calendar_screen.dart';
import 'package:appflowy/mobile/presentation/database/mobile_grid_screen.dart';
import 'package:appflowy/mobile/presentation/presentation.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/recent/cached_recent_service.dart';
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

extension MobileRouter on BuildContext {
Expand Down Expand Up @@ -37,6 +39,9 @@ extension on ViewPB {
return MobileCalendarScreen.routeName;
case ViewLayoutPB.Board:
return MobileBoardScreen.routeName;
case ViewLayoutPB.Chat:
return MobileChatScreen.routeName;

default:
throw UnimplementedError('routeName for $this is not implemented');
}
Expand Down Expand Up @@ -65,6 +70,11 @@ extension on ViewPB {
MobileBoardScreen.viewId: id,
MobileBoardScreen.viewTitle: name,
};
case ViewLayoutPB.Chat:
return {
MobileChatScreen.viewId: id,
MobileChatScreen.viewTitle: name,
};
default:
throw UnimplementedError(
'queryParameters for $this is not implemented',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:appflowy/plugins/base/emoji/emoji_text.dart';
import 'package:appflowy/plugins/document/presentation/document_collaborators.dart';
import 'package:appflowy/plugins/shared/sync_indicator.dart';
import 'package:appflowy/shared/feature_flags.dart';
import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/reminder/reminder_bloc.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
Expand Down Expand Up @@ -154,7 +155,10 @@ class _MobileViewPageState extends State<MobileViewPage> {
(view) {
final plugin = view.plugin(arguments: widget.arguments ?? const {})
..init();
return plugin.widgetBuilder.buildWidget(shrinkWrap: false);
return plugin.widgetBuilder.buildWidget(
shrinkWrap: false,
context: PluginContext(userProfile: state.userProfilePB),
);
},
(error) {
return FlowyMobileStateContainer.error(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:appflowy/mobile/presentation/base/mobile_view_page.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:flutter/material.dart';

class MobileChatScreen extends StatelessWidget {
const MobileChatScreen({
super.key,
required this.id,
this.title,
});

/// view id
final String id;
final String? title;

static const routeName = '/chat';
static const viewId = 'id';
static const viewTitle = 'title';

@override
Widget build(BuildContext context) {
return MobileViewPage(
id: id,
title: title,
viewLayout: ViewLayoutPB.Chat,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:appflowy_backend/protobuf/flowy-document/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_chat_types/flutter_chat_types.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'chat_ai_message_bloc.freezed.dart';

class ChatAIMessageBloc extends Bloc<ChatAIMessageEvent, ChatAIMessageState> {
ChatAIMessageBloc({
required Message message,
}) : super(ChatAIMessageState.initial(message)) {
on<ChatAIMessageEvent>(
(event, emit) async {
await event.when(
initial: () async {},
update: (userProfile, deviceId, states) {},
);
},
);
}
}

@freezed
class ChatAIMessageEvent with _$ChatAIMessageEvent {
const factory ChatAIMessageEvent.initial() = Initial;
const factory ChatAIMessageEvent.update(
UserProfilePB userProfile,
String deviceId,
DocumentAwarenessStatesPB states,
) = Update;
}

@freezed
class ChatAIMessageState with _$ChatAIMessageState {
const factory ChatAIMessageState({
required Message message,
}) = _ChatAIMessageState;

factory ChatAIMessageState.initial(Message message) =>
ChatAIMessageState(message: message);
}
Loading
Loading