@@ -4,11 +4,9 @@ import {parse, stringify} from 'flatted'
4
4
import ms from 'ms'
5
5
import { Variables } from 'relay-runtime'
6
6
import StrictEventEmitter from 'strict-event-emitter-types'
7
- import stringSimilarity from 'string-similarity'
8
7
import { ReactableEnum } from '~/__generated__/AddReactjiToReactableMutation.graphql'
9
8
import { DragReflectionDropTargetTypeEnum } from '~/__generated__/EndDraggingReflectionMutation.graphql'
10
9
import { PALETTE } from '~/styles/paletteV3'
11
- import GoogleAnalyzedEntity from '../../../server/database/types/GoogleAnalyzedEntity'
12
10
import ReflectPhase from '../../../server/database/types/ReflectPhase'
13
11
import { NewMeetingStage } from '../../../server/graphql/private/resolverTypes'
14
12
import {
@@ -28,15 +26,14 @@ import {
28
26
} from '../../types/constEnums'
29
27
import { DISCUSS , GROUP , REFLECT , VOTE } from '../../utils/constants'
30
28
import dndNoise from '../../utils/dndNoise'
29
+ import { getSimpleGroupTitle } from '../../utils/getSimpleGroupTitle'
31
30
import findStageById from '../../utils/meetings/findStageById'
32
31
import sleep from '../../utils/sleep'
33
- import getGroupSmartTitle from '../../utils/smartGroup/getGroupSmartTitle'
34
32
import startStage_ from '../../utils/startStage_'
35
33
import unlockAllStagesForPhase from '../../utils/unlockAllStagesForPhase'
36
34
import unlockNextStages from '../../utils/unlockNextStages'
37
35
import LocalAtmosphere from './LocalAtmosphere'
38
- import entityLookup from './entityLookup'
39
- import getDemoEntities from './getDemoEntities'
36
+ import getDemoTitles from './getDemoTitles'
40
37
import handleCompletedDemoStage from './handleCompletedDemoStage'
41
38
import initBotScript from './initBotScript'
42
39
import initDB , {
@@ -54,7 +51,6 @@ export type DemoReflection = {
54
51
createdAt : string | Date
55
52
dragContext : any
56
53
editorIds : any
57
- entities : any
58
54
groupColor : string
59
55
isEditing : any
60
56
isHumanTouched : boolean
@@ -194,6 +190,36 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
194
190
return validDB
195
191
}
196
192
193
+ private async updateReflectionGroupTitle (
194
+ reflectionGroup : DemoReflectionGroup ,
195
+ reflectionsContent : string [ ] ,
196
+ titleIsUserDefined = false
197
+ ) {
198
+ const loadingTitle = ''
199
+ reflectionGroup . smartTitle = loadingTitle
200
+ if ( ! titleIsUserDefined ) {
201
+ reflectionGroup . title = loadingTitle
202
+ }
203
+
204
+ try {
205
+ const aiTitle = await getDemoTitles ( reflectionsContent )
206
+ if ( aiTitle && aiTitle !== loadingTitle ) {
207
+ reflectionGroup . smartTitle = aiTitle
208
+ if ( ! titleIsUserDefined ) {
209
+ reflectionGroup . title = aiTitle
210
+ }
211
+ this . emit ( SubscriptionChannel . MEETING , {
212
+ __typename : 'UpdateReflectionGroupTitlePayload' ,
213
+ meetingId : RetroDemo . MEETING_ID ,
214
+ reflectionGroupId : reflectionGroup . id ,
215
+ reflectionGroup : reflectionGroup
216
+ } )
217
+ }
218
+ } catch ( err ) {
219
+ console . error ( 'Error generating AI title:' , err )
220
+ }
221
+ }
222
+
197
223
startDemo ( ) {
198
224
this . startBot ( )
199
225
this . db . _started = true
@@ -551,12 +577,6 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
551
577
const reflectionId = id || this . getTempId ( 'ref' )
552
578
const normalizedContent = JSON . parse ( content ) as JSONContent
553
579
const plaintextContent = generateText ( normalizedContent , serverTipTapExtensions )
554
- let entities = [ ] as GoogleAnalyzedEntity [ ]
555
- if ( userId !== demoViewerId ) {
556
- entities = entityLookup [ reflectionId as keyof typeof entityLookup ] . entities
557
- } else {
558
- entities = ( await getDemoEntities ( plaintextContent ) ) as any
559
- }
560
580
561
581
const reflection = {
562
582
__typename : 'RetroReflection' ,
@@ -574,7 +594,6 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
574
594
isActive : true ,
575
595
isEditing : null ,
576
596
isViewerCreator : userId === demoViewerId ,
577
- entities,
578
597
meetingId : RetroDemo . MEETING_ID ,
579
598
meeting : this . db . newMeeting ,
580
599
prompt,
@@ -586,15 +605,15 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
586
605
retroReflectionGroup : undefined as any
587
606
} as DemoReflection
588
607
589
- const smartTitle = getGroupSmartTitle ( [ reflection ] )
608
+ const smartTitle = getSimpleGroupTitle ( [ { plaintextContent } ] )
590
609
591
610
const reflectionGroup = {
592
611
__typename : 'RetroReflectionGroup' ,
593
- commentors : null ,
594
612
id : reflectionGroupId ,
595
613
reflectionGroupId,
596
614
smartTitle,
597
615
title : smartTitle ,
616
+ commentors : null ,
598
617
voteCount : 0 ,
599
618
viewerVoteCount : 0 ,
600
619
createdAt : now ,
@@ -742,28 +761,43 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
742
761
reflection . content = content
743
762
reflection . updatedAt = new Date ( ) . toJSON ( )
744
763
const plaintextContent = generateText ( JSON . parse ( content ) , serverTipTapExtensions )
745
- const isVeryDifferent =
746
- stringSimilarity . compareTwoStrings ( plaintextContent , reflection . plaintextContent ) < 0.9
747
- const entities = isVeryDifferent
748
- ? await getDemoEntities ( plaintextContent )
749
- : reflection . entities
750
764
reflection . plaintextContent = plaintextContent
751
- reflection . entities = entities as any
752
765
753
766
const reflectionsInGroup = this . db . reflections . filter (
754
767
( { reflectionGroupId} ) => reflectionGroupId === reflection . reflectionGroupId
755
768
)
756
- const newTitle = getGroupSmartTitle ( reflectionsInGroup )
757
769
const reflectionGroup = this . db . reflectionGroups . find (
758
770
( group ) => group . id === reflection . reflectionGroupId
759
771
)
772
+
760
773
if ( reflectionGroup ) {
761
774
const titleIsUserDefined = reflectionGroup . smartTitle !== reflectionGroup . title
762
- reflectionGroup . smartTitle = newTitle
763
775
if ( ! titleIsUserDefined ) {
764
- reflectionGroup . title = newTitle
776
+ const reflectionsContent = reflectionsInGroup . map ( ( r ) => r . content )
777
+ // Set loading state
778
+ const loadingTitle = ''
779
+ reflectionGroup . smartTitle = loadingTitle
780
+ reflectionGroup . title = loadingTitle
781
+
782
+ getDemoTitles ( reflectionsContent )
783
+ . then ( ( aiTitle ) => {
784
+ if ( aiTitle && aiTitle !== loadingTitle ) {
785
+ reflectionGroup . smartTitle = aiTitle
786
+ reflectionGroup . title = aiTitle
787
+ this . emit ( SubscriptionChannel . MEETING , {
788
+ __typename : 'UpdateReflectionGroupTitlePayload' ,
789
+ meetingId : RetroDemo . MEETING_ID ,
790
+ reflectionGroupId : reflectionGroup . id ,
791
+ reflectionGroup : reflectionGroup
792
+ } )
793
+ }
794
+ } )
795
+ . catch ( ( err ) => {
796
+ console . error ( 'Error generating AI title:' , err )
797
+ } )
765
798
}
766
799
}
800
+
767
801
const data = {
768
802
error : null ,
769
803
meeting : this . db . newMeeting ,
@@ -1009,7 +1043,12 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
1009
1043
dropTargetType,
1010
1044
dropTargetId,
1011
1045
dragId
1012
- } : { reflectionId : string ; dropTargetType : any ; dropTargetId : string ; dragId : string } ,
1046
+ } : {
1047
+ reflectionId : string
1048
+ dropTargetType : any
1049
+ dropTargetId : string
1050
+ dragId : string
1051
+ } ,
1013
1052
userId : string
1014
1053
) => {
1015
1054
const now = new Date ( ) . toJSON ( )
@@ -1024,6 +1063,7 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
1024
1063
) !
1025
1064
const oldReflections = oldReflectionGroup . reflections !
1026
1065
let failedDrop = false
1066
+
1027
1067
if ( ( dropTargetType as DragReflectionDropTargetTypeEnum ) === 'REFLECTION_GRID' ) {
1028
1068
const { promptId} = reflection
1029
1069
newReflectionGroupId = this . getTempId ( 'group' )
@@ -1050,36 +1090,23 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
1050
1090
1051
1091
this . db . reflectionGroups . push ( newReflectionGroup )
1052
1092
this . db . discussions . push ( new DemoDiscussion ( newReflectionGroupId ) )
1053
- oldReflections . splice ( oldReflections . indexOf ( reflection as any ) , 1 )
1093
+ oldReflections . splice (
1094
+ oldReflections . findIndex ( ( r ) => r . id === reflection . id ) ,
1095
+ 1
1096
+ )
1054
1097
1055
1098
Object . assign ( reflection , {
1056
1099
sortOrder : 0 ,
1057
1100
reflectionGroupId : newReflectionGroupId ,
1058
1101
updatedAt : now
1059
1102
} )
1060
- const nextTitle = getGroupSmartTitle ( [ reflection as DemoReflection ] )
1061
- newReflectionGroup . smartTitle = nextTitle
1062
- newReflectionGroup . title = nextTitle
1063
- if ( oldReflections . length > 0 ) {
1064
- const oldTitle = getGroupSmartTitle ( oldReflections )
1065
- const titleIsUserDefined = oldReflectionGroup . smartTitle !== oldReflectionGroup . title
1066
- oldReflectionGroup . smartTitle = oldTitle
1067
- if ( ! titleIsUserDefined ) {
1068
- oldReflectionGroup . title = oldTitle
1069
- }
1070
- } else {
1071
- const meetingGroups = ( this . db . newMeeting as any ) . reflectionGroups
1072
- meetingGroups . splice ( meetingGroups . indexOf ( oldReflectionGroup as any ) , 1 )
1073
- Object . assign ( oldReflectionGroup , {
1074
- isActive : false ,
1075
- updatedAt : now
1076
- } )
1077
- }
1103
+ const reflectionContent = ( reflection as DemoReflection ) . content
1104
+
1105
+ this . updateReflectionGroupTitle ( newReflectionGroup , [ reflectionContent ] )
1078
1106
} else if (
1079
1107
( dropTargetType as DragReflectionDropTargetTypeEnum ) === 'REFLECTION_GROUP' &&
1080
1108
dropTargetId
1081
1109
) {
1082
- // group
1083
1110
const reflectionGroup = this . db . reflectionGroups . find ( ( group ) => group . id === dropTargetId ) !
1084
1111
if ( reflectionGroup ) {
1085
1112
newReflectionGroupId = dropTargetId
@@ -1096,33 +1123,32 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
1096
1123
reflectionGroup . reflections . push ( reflection as any )
1097
1124
reflectionGroup . reflections . sort ( ( a , b ) => ( a . sortOrder < b . sortOrder ? 1 : - 1 ) )
1098
1125
oldReflections . splice (
1099
- oldReflections . findIndex ( ( reflection ) => reflection === reflection ) ,
1126
+ oldReflections . findIndex ( ( r ) => r . id === reflection . id ) ,
1100
1127
1
1101
1128
)
1102
1129
if ( oldReflectionGroupId !== newReflectionGroupId ) {
1103
1130
const reflections = this . db . reflections
1104
1131
const nextReflections = reflections . filter (
1105
1132
( reflection ) => reflection . reflectionGroupId === newReflectionGroupId
1106
1133
)
1107
- const oldReflections = reflections . filter (
1134
+ const oldReflectionsForGroup = reflections . filter (
1108
1135
( reflection ) => reflection . reflectionGroupId === oldReflectionGroupId
1109
1136
)
1110
- const nextTitle = getGroupSmartTitle ( nextReflections )
1111
- const titleIsUserDefined = reflectionGroup . smartTitle !== reflectionGroup . title
1112
- reflectionGroup . smartTitle = nextTitle
1113
- if ( ! titleIsUserDefined ) {
1114
- reflectionGroup . title = nextTitle
1137
+
1138
+ if ( nextReflections . length > 0 ) {
1139
+ this . updateReflectionGroupTitle (
1140
+ reflectionGroup ,
1141
+ nextReflections . map ( ( r ) => r . content )
1142
+ )
1115
1143
}
1116
- const oldReflectionGroup = this . db . reflectionGroups . find (
1117
- ( group ) => group . id === oldReflectionGroupId
1118
- ) !
1119
- if ( oldReflections . length > 0 ) {
1120
- const oldTitle = getGroupSmartTitle ( oldReflections )
1144
+
1145
+ if ( oldReflectionsForGroup . length > 0 ) {
1121
1146
const titleIsUserDefined = oldReflectionGroup . smartTitle !== oldReflectionGroup . title
1122
- oldReflectionGroup . smartTitle = oldTitle
1123
- if ( ! titleIsUserDefined ) {
1124
- oldReflectionGroup . title = oldTitle
1125
- }
1147
+ this . updateReflectionGroupTitle (
1148
+ oldReflectionGroup ,
1149
+ oldReflectionsForGroup . map ( ( r ) => r . content ) ,
1150
+ titleIsUserDefined
1151
+ )
1126
1152
} else {
1127
1153
const meetingGroups = ( this . db . newMeeting as any ) . reflectionGroups
1128
1154
meetingGroups . splice ( meetingGroups . indexOf ( oldReflectionGroup as any ) , 1 )
@@ -1348,7 +1374,7 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
1348
1374
// To reproduce, get to the discuss phase & quickly add a task before the bots do
1349
1375
// the result is tasks == [undefined]
1350
1376
// if a sleep is added, RetroDiscussPhase component is notified, but without, only MeetingAgendaCards is notified
1351
- // (I removed MeetingAgendaCards, mentioned in the comment line above, as it’ s unused, TA)
1377
+ // (I removed MeetingAgendaCards, mentioned in the comment line above, as it' s unused, TA)
1352
1378
// Safe to test removing this now that MeetingAgendaCards is gone MK
1353
1379
// honestly, no good idea what is going on here. don't even know if it's relay or react (or me)
1354
1380
await sleep ( 100 )
0 commit comments