Skip to content

Commit 1b04e56

Browse files
authored
chore: remove google language manager (#10639)
1 parent 107ad45 commit 1b04e56

39 files changed

+253
-899
lines changed

codegen.json

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"DomainJoinRequest": "../../database/types/DomainJoinRequest#default as DomainJoinRequestDB",
8686
"EndTeamPromptSuccess": "./types/EndTeamPromptSuccess#EndTeamPromptSuccessSource",
8787
"File": "./types/File#TFile",
88+
"GetDemoGroupTitleSuccess": "./types/GetDemoGroupTitleSuccess#GetDemoGroupTitleSuccessSource",
8889
"GcalIntegration": "./types/GcalIntegration#GcalIntegrationSource",
8990
"GenerateGroupsSuccess": "./types/GenerateGroupsSuccess#GenerateGroupsSuccessSource",
9091
"GenerateInsightSuccess": "./types/GenerateInsightSuccess#GenerateInsightSuccessSource",

packages/client/modules/demo/ClientGraphQLServer.ts

+88-62
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import {parse, stringify} from 'flatted'
44
import ms from 'ms'
55
import {Variables} from 'relay-runtime'
66
import StrictEventEmitter from 'strict-event-emitter-types'
7-
import stringSimilarity from 'string-similarity'
87
import {ReactableEnum} from '~/__generated__/AddReactjiToReactableMutation.graphql'
98
import {DragReflectionDropTargetTypeEnum} from '~/__generated__/EndDraggingReflectionMutation.graphql'
109
import {PALETTE} from '~/styles/paletteV3'
11-
import GoogleAnalyzedEntity from '../../../server/database/types/GoogleAnalyzedEntity'
1210
import ReflectPhase from '../../../server/database/types/ReflectPhase'
1311
import {NewMeetingStage} from '../../../server/graphql/private/resolverTypes'
1412
import {
@@ -28,15 +26,14 @@ import {
2826
} from '../../types/constEnums'
2927
import {DISCUSS, GROUP, REFLECT, VOTE} from '../../utils/constants'
3028
import dndNoise from '../../utils/dndNoise'
29+
import {getSimpleGroupTitle} from '../../utils/getSimpleGroupTitle'
3130
import findStageById from '../../utils/meetings/findStageById'
3231
import sleep from '../../utils/sleep'
33-
import getGroupSmartTitle from '../../utils/smartGroup/getGroupSmartTitle'
3432
import startStage_ from '../../utils/startStage_'
3533
import unlockAllStagesForPhase from '../../utils/unlockAllStagesForPhase'
3634
import unlockNextStages from '../../utils/unlockNextStages'
3735
import LocalAtmosphere from './LocalAtmosphere'
38-
import entityLookup from './entityLookup'
39-
import getDemoEntities from './getDemoEntities'
36+
import getDemoTitles from './getDemoTitles'
4037
import handleCompletedDemoStage from './handleCompletedDemoStage'
4138
import initBotScript from './initBotScript'
4239
import initDB, {
@@ -54,7 +51,6 @@ export type DemoReflection = {
5451
createdAt: string | Date
5552
dragContext: any
5653
editorIds: any
57-
entities: any
5854
groupColor: string
5955
isEditing: any
6056
isHumanTouched: boolean
@@ -194,6 +190,36 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
194190
return validDB
195191
}
196192

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+
197223
startDemo() {
198224
this.startBot()
199225
this.db._started = true
@@ -551,12 +577,6 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
551577
const reflectionId = id || this.getTempId('ref')
552578
const normalizedContent = JSON.parse(content) as JSONContent
553579
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-
}
560580

561581
const reflection = {
562582
__typename: 'RetroReflection',
@@ -574,7 +594,6 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
574594
isActive: true,
575595
isEditing: null,
576596
isViewerCreator: userId === demoViewerId,
577-
entities,
578597
meetingId: RetroDemo.MEETING_ID,
579598
meeting: this.db.newMeeting,
580599
prompt,
@@ -586,15 +605,15 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
586605
retroReflectionGroup: undefined as any
587606
} as DemoReflection
588607

589-
const smartTitle = getGroupSmartTitle([reflection])
608+
const smartTitle = getSimpleGroupTitle([{plaintextContent}])
590609

591610
const reflectionGroup = {
592611
__typename: 'RetroReflectionGroup',
593-
commentors: null,
594612
id: reflectionGroupId,
595613
reflectionGroupId,
596614
smartTitle,
597615
title: smartTitle,
616+
commentors: null,
598617
voteCount: 0,
599618
viewerVoteCount: 0,
600619
createdAt: now,
@@ -742,28 +761,43 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
742761
reflection.content = content
743762
reflection.updatedAt = new Date().toJSON()
744763
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
750764
reflection.plaintextContent = plaintextContent
751-
reflection.entities = entities as any
752765

753766
const reflectionsInGroup = this.db.reflections.filter(
754767
({reflectionGroupId}) => reflectionGroupId === reflection.reflectionGroupId
755768
)
756-
const newTitle = getGroupSmartTitle(reflectionsInGroup)
757769
const reflectionGroup = this.db.reflectionGroups.find(
758770
(group) => group.id === reflection.reflectionGroupId
759771
)
772+
760773
if (reflectionGroup) {
761774
const titleIsUserDefined = reflectionGroup.smartTitle !== reflectionGroup.title
762-
reflectionGroup.smartTitle = newTitle
763775
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+
})
765798
}
766799
}
800+
767801
const data = {
768802
error: null,
769803
meeting: this.db.newMeeting,
@@ -1009,7 +1043,12 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
10091043
dropTargetType,
10101044
dropTargetId,
10111045
dragId
1012-
}: {reflectionId: string; dropTargetType: any; dropTargetId: string; dragId: string},
1046+
}: {
1047+
reflectionId: string
1048+
dropTargetType: any
1049+
dropTargetId: string
1050+
dragId: string
1051+
},
10131052
userId: string
10141053
) => {
10151054
const now = new Date().toJSON()
@@ -1024,6 +1063,7 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
10241063
)!
10251064
const oldReflections = oldReflectionGroup.reflections!
10261065
let failedDrop = false
1066+
10271067
if ((dropTargetType as DragReflectionDropTargetTypeEnum) === 'REFLECTION_GRID') {
10281068
const {promptId} = reflection
10291069
newReflectionGroupId = this.getTempId('group')
@@ -1050,36 +1090,23 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
10501090

10511091
this.db.reflectionGroups.push(newReflectionGroup)
10521092
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+
)
10541097

10551098
Object.assign(reflection, {
10561099
sortOrder: 0,
10571100
reflectionGroupId: newReflectionGroupId,
10581101
updatedAt: now
10591102
})
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])
10781106
} else if (
10791107
(dropTargetType as DragReflectionDropTargetTypeEnum) === 'REFLECTION_GROUP' &&
10801108
dropTargetId
10811109
) {
1082-
// group
10831110
const reflectionGroup = this.db.reflectionGroups.find((group) => group.id === dropTargetId)!
10841111
if (reflectionGroup) {
10851112
newReflectionGroupId = dropTargetId
@@ -1096,33 +1123,32 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
10961123
reflectionGroup.reflections.push(reflection as any)
10971124
reflectionGroup.reflections.sort((a, b) => (a.sortOrder < b.sortOrder ? 1 : -1))
10981125
oldReflections.splice(
1099-
oldReflections.findIndex((reflection) => reflection === reflection),
1126+
oldReflections.findIndex((r) => r.id === reflection.id),
11001127
1
11011128
)
11021129
if (oldReflectionGroupId !== newReflectionGroupId) {
11031130
const reflections = this.db.reflections
11041131
const nextReflections = reflections.filter(
11051132
(reflection) => reflection.reflectionGroupId === newReflectionGroupId
11061133
)
1107-
const oldReflections = reflections.filter(
1134+
const oldReflectionsForGroup = reflections.filter(
11081135
(reflection) => reflection.reflectionGroupId === oldReflectionGroupId
11091136
)
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+
)
11151143
}
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) {
11211146
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+
)
11261152
} else {
11271153
const meetingGroups = (this.db.newMeeting as any).reflectionGroups
11281154
meetingGroups.splice(meetingGroups.indexOf(oldReflectionGroup as any), 1)
@@ -1348,7 +1374,7 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
13481374
// To reproduce, get to the discuss phase & quickly add a task before the bots do
13491375
// the result is tasks == [undefined]
13501376
// 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 its unused, TA)
1377+
// (I removed MeetingAgendaCards, mentioned in the comment line above, as it's unused, TA)
13521378
// Safe to test removing this now that MeetingAgendaCards is gone MK
13531379
// honestly, no good idea what is going on here. don't even know if it's relay or react (or me)
13541380
await sleep(100)

packages/client/modules/demo/entityLookup.ts

-47
This file was deleted.

packages/client/modules/demo/getDemoEntities.ts

-49
This file was deleted.

0 commit comments

Comments
 (0)