@@ -14,6 +14,8 @@ import { useConfigValue } from "~/shared/config";
1414import * as main from "~/store/tinybase/store/main" ;
1515import { normalizeKeywordList } from "~/stt/keywords" ;
1616
17+ const MAX_TRANSCRIPTION_HINTS = 50 ;
18+
1719export function useKeywords ( sessionId : string ) {
1820 const rawMd = main . UI . useCell ( "sessions" , sessionId , "raw_md" , main . STORE_ID ) ;
1921 const title = main . UI . useCell ( "sessions" , sessionId , "title" , main . STORE_ID ) ;
@@ -35,12 +37,9 @@ export function useKeywords(sessionId: string) {
3537 } , [ dictionaryTerms , eventJson , rawMd , title ] ) ;
3638}
3739
38- type KeywordStore = {
39- getCell : (
40- tableId : "sessions" ,
41- rowId : string ,
42- cellId : "raw_md" | "title" | "event_json" ,
43- ) => unknown ;
40+ export type KeywordStore = {
41+ getCell : main . Store [ "getCell" ] ;
42+ forEachRow ?: main . Store [ "forEachRow" ] ;
4443} ;
4544
4645export function getSessionKeywords ( {
@@ -52,10 +51,30 @@ export function getSessionKeywords({
5251 sessionId : string ;
5352 dictionaryTerms : string [ ] ;
5453} ) {
54+ return getSessionTranscriptionHints ( {
55+ store,
56+ sessionId,
57+ dictionaryTerms,
58+ } ) ;
59+ }
60+
61+ export function getSessionTranscriptionHints ( {
62+ store,
63+ sessionId,
64+ dictionaryTerms,
65+ } : {
66+ store : KeywordStore ;
67+ sessionId : string ;
68+ dictionaryTerms : string [ ] ;
69+ } ) {
70+ const eventJson = store . getCell ( "sessions" , sessionId , "event_json" ) ;
71+
5572 return buildKeywords ( {
5673 rawMd : store . getCell ( "sessions" , sessionId , "raw_md" ) ,
5774 title : store . getCell ( "sessions" , sessionId , "title" ) ,
58- eventJson : store . getCell ( "sessions" , sessionId , "event_json" ) ,
75+ eventJson,
76+ sessionParticipantTerms : getSessionParticipantNames ( store , sessionId ) ,
77+ eventParticipantTerms : getAttachedEventParticipantNames ( store , eventJson ) ,
5978 dictionaryTerms,
6079 } ) ;
6180}
@@ -64,11 +83,15 @@ export function buildKeywords({
6483 rawMd,
6584 title,
6685 eventJson,
86+ sessionParticipantTerms = [ ] ,
87+ eventParticipantTerms = [ ] ,
6788 dictionaryTerms,
6889} : {
6990 rawMd : unknown ;
7091 title : unknown ;
7192 eventJson : unknown ;
93+ sessionParticipantTerms ?: string [ ] ;
94+ eventParticipantTerms ?: string [ ] ;
7295 dictionaryTerms : string [ ] ;
7396} ) {
7497 const sourceText = buildKeywordSourceText ( {
@@ -81,7 +104,13 @@ export function buildKeywords({
81104 ? extractKeywordsFromMarkdown ( sourceText )
82105 : { keywords : [ ] , keyphrases : [ ] } ;
83106
84- return normalizeKeywordList ( [ ...dictionaryTerms , ...keywords , ...keyphrases ] ) ;
107+ return normalizeKeywordList ( [
108+ ...sessionParticipantTerms ,
109+ ...eventParticipantTerms ,
110+ ...dictionaryTerms ,
111+ ...keywords ,
112+ ...keyphrases ,
113+ ] ) . slice ( 0 , MAX_TRANSCRIPTION_HINTS ) ;
85114}
86115
87116export function buildKeywordSourceText ( {
@@ -198,6 +227,114 @@ const eventKeywordFields = (eventJson: unknown): string[] => {
198227 }
199228} ;
200229
230+ const getSessionParticipantNames = (
231+ store : KeywordStore ,
232+ sessionId : string ,
233+ ) : string [ ] => {
234+ if ( ! store . forEachRow ) {
235+ return [ ] ;
236+ }
237+
238+ const names : string [ ] = [ ] ;
239+ store . forEachRow ( "mapping_session_participant" , ( mappingId , _forEachCell ) => {
240+ const mappedSessionId = store . getCell (
241+ "mapping_session_participant" ,
242+ mappingId ,
243+ "session_id" ,
244+ ) ;
245+ if ( mappedSessionId !== sessionId ) {
246+ return ;
247+ }
248+
249+ const humanId = stringValue (
250+ store . getCell ( "mapping_session_participant" , mappingId , "human_id" ) ,
251+ ) ;
252+ if ( ! humanId ) {
253+ return ;
254+ }
255+
256+ const name = stringValue ( store . getCell ( "humans" , humanId , "name" ) ) ;
257+ if ( name ) {
258+ names . push ( name ) ;
259+ }
260+ } ) ;
261+
262+ return names ;
263+ } ;
264+
265+ const getAttachedEventParticipantNames = (
266+ store : KeywordStore ,
267+ eventJson : unknown ,
268+ ) : string [ ] => {
269+ if ( ! store . forEachRow ) {
270+ return [ ] ;
271+ }
272+
273+ const sessionEvent = parseSessionEvent ( eventJson ) ;
274+ if ( ! sessionEvent ) {
275+ return [ ] ;
276+ }
277+
278+ let participantsJson : unknown ;
279+ store . forEachRow ( "events" , ( eventId , _forEachCell ) => {
280+ if ( participantsJson !== undefined ) {
281+ return ;
282+ }
283+
284+ const trackingId = store . getCell ( "events" , eventId , "tracking_id_event" ) ;
285+ const calendarId = store . getCell ( "events" , eventId , "calendar_id" ) ;
286+ if (
287+ trackingId === sessionEvent . trackingId &&
288+ calendarId === sessionEvent . calendarId
289+ ) {
290+ participantsJson = store . getCell ( "events" , eventId , "participants_json" ) ;
291+ }
292+ } ) ;
293+
294+ return parseEventParticipantNames ( participantsJson ) ;
295+ } ;
296+
297+ const parseSessionEvent = (
298+ eventJson : unknown ,
299+ ) : { trackingId : string ; calendarId : string } | null => {
300+ if ( typeof eventJson !== "string" || ! eventJson ) {
301+ return null ;
302+ }
303+
304+ try {
305+ const event = JSON . parse ( eventJson ) ;
306+ const trackingId = stringValue ( event ?. tracking_id ) ;
307+ const calendarId = stringValue ( event ?. calendar_id ) ;
308+ return trackingId && calendarId ? { trackingId, calendarId } : null ;
309+ } catch {
310+ return null ;
311+ }
312+ } ;
313+
314+ const parseEventParticipantNames = ( participantsJson : unknown ) : string [ ] => {
315+ if ( typeof participantsJson !== "string" || ! participantsJson ) {
316+ return [ ] ;
317+ }
318+
319+ try {
320+ const participants = JSON . parse ( participantsJson ) ;
321+ if ( ! Array . isArray ( participants ) ) {
322+ return [ ] ;
323+ }
324+
325+ return participants . flatMap ( ( participant ) => {
326+ if ( participant ?. is_current_user === true ) {
327+ return [ ] ;
328+ }
329+
330+ const name = stringValue ( participant ?. name ) ;
331+ return name ? [ name ] : [ ] ;
332+ } ) ;
333+ } catch {
334+ return [ ] ;
335+ }
336+ } ;
337+
201338const removeCodeBlocks = ( text : string ) : string =>
202339 text . replace ( / ` ` ` [ \s \S ] * ?` ` ` / g, "" ) . replace ( / ` [ ^ ` ] + ` / g, "" ) ;
203340
0 commit comments