@@ -41,12 +41,13 @@ import {
41
41
useVoice
42
42
} from '@deep-foundation/deepmemo-imports/imports/voice' ;
43
43
import { useLocalStore } from '@deep-foundation/store/local' ;
44
- import React , { useEffect , useRef , useState } from 'react' ;
44
+ import React , { useEffect , useMemo , useRef , useState } from 'react' ;
45
45
import { Connection } from '../src/connection' ;
46
46
import { i18nGetStaticProps } from '../src/i18n' ;
47
47
import useAxios from 'axios-hooks' ;
48
48
import { EditorTextArea } from '@deep-foundation/deepcase/imports/editor/editor-textarea' ;
49
- import times from 'lodash/times' ;
49
+ import sortBy from 'lodash/sortBy' ;
50
+ import reverse from 'lodash/reverse' ;
50
51
import { deepEqual } from 'assert' ;
51
52
52
53
const { version } = require ( '../package.json' ) ;
@@ -106,12 +107,17 @@ const InstallerView = React.memo(function InstallerView({}: {}) {
106
107
const installer = useInstaller ( ) ;
107
108
const deep = useDeep ( ) ;
108
109
const [ apiKey , setApiKey ] = useState ( '' ) ;
110
+ const [ telegramToken , setTelegramToken ] = useState ( '' ) ;
109
111
const [ containerId , setContainerId ] = useLocalStore ( 'deepmemo-app-containerId' , null ) ;
110
112
111
113
useEffect ( ( ) => {
112
114
if ( installer ?. [ 'ApiKey' ] ?. [ 0 ] ?. value ?. value ) setApiKey ( installer ?. [ 'ApiKey' ] ?. [ 0 ] ?. value ?. value ) ;
113
115
} , [ installer ?. [ 'ApiKey' ] ?. [ 0 ] ?. value ?. value ] ) ;
114
116
117
+ useEffect ( ( ) => {
118
+ if ( installer ?. [ 'TelegramToken' ] ?. [ 0 ] ?. value ?. value ) setTelegramToken ( installer ?. [ 'TelegramToken' ] ?. [ 0 ] ?. value ?. value ) ;
119
+ } , [ installer ?. [ 'TelegramToken' ] ?. [ 0 ] ?. value ?. value ] ) ;
120
+
115
121
useEffect ( ( ) => {
116
122
if ( installer ?. [ 'space' ] ?. id ) setContainerId ( installer ?. [ 'space' ] ?. id ) ;
117
123
} , [ installer ?. [ 'space' ] ?. id ] ) ;
@@ -149,6 +155,10 @@ const InstallerView = React.memo(function InstallerView({}: {}) {
149
155
< ListIcon as = { installer ?. [ '@deep-foundation/chatgpt-azure-deep' ] ?. length ? CheckCircleIcon : WarningIcon } color = { installer ?. [ '@deep-foundation/chatgpt-azure-deep' ] ?. length ? 'green.500' : 'red.500' } />
150
156
@deep-foundation/chatgpt-azure-deep
151
157
</ ListItem >
158
+ < ListItem >
159
+ < ListIcon as = { installer ?. [ '@deep-foundation/voice-to-sync-text-file' ] ?. length ? CheckCircleIcon : WarningIcon } color = { installer ?. [ '@deep-foundation/voice-to-sync-text-file' ] ?. length ? 'green.500' : 'red.500' } />
160
+ @deep-foundation/voice-to-sync-text-file
161
+ </ ListItem >
152
162
< ListItem >
153
163
< ListIcon as = { installer ?. [ '@deep-foundation/chatgpt-azure-templates' ] ?. length ? CheckCircleIcon : WarningIcon } color = { installer ?. [ '@deep-foundation/chatgpt-azure-templates' ] ?. length ? 'green.500' : 'red.500' } />
154
164
@deep-foundation/chatgpt-azure-templates
@@ -188,13 +198,37 @@ const InstallerView = React.memo(function InstallerView({}: {}) {
188
198
{ installer ?. [ 'Model' ] ?. map ( l => < option value = { String ( l . id ) } > { l ?. value ?. value } </ option > ) }
189
199
</ Select >
190
200
</ ListItem >
201
+ < ListItem >
202
+ < ListIcon as = { installer ?. [ 'TelegramToken' ] ?. [ 0 ] ?. value ?. value ? CheckCircleIcon : WarningIcon } color = { installer ?. [ 'TelegramToken' ] ?. [ 0 ] ?. value ?. value ? 'green.500' : 'red.500' } />
203
+ TelegramToken ({ installer ?. [ 'TelegramToken' ] ?. [ 0 ] ?. value ?. value || '' } )
204
+ < InputGroup size = 'md' >
205
+ < Input placeholder = 'Enter Telegram Token for Deep.Memory chat bot' value = { telegramToken } onChange = { ( e ) => setTelegramToken ( e . target . value ) } />
206
+ < InputRightElement >
207
+ < Button size = 'sm' onClick = { async ( ) => {
208
+ await installer . saveDeepmemoryTelegramToken ( telegramToken ) ;
209
+ } } > save</ Button >
210
+ </ InputRightElement >
211
+ </ InputGroup >
212
+ </ ListItem >
213
+ < ListItem >
214
+ < ListIcon as = { installer ?. [ 'TelegramActive' ] ?. length ? CheckCircleIcon : WarningIcon } color = { installer ?. [ 'TelegramActive' ] ?. length ? 'green.500' : 'red.500' } />
215
+ Telegram bot for Deep.Memory ({ installer ?. [ 'TelegramActive' ] ?. [ 0 ] ?. id || '' } )
216
+ < Button disabled = { ! ! installer ?. [ 'TelegramActive' ] ?. length } variant = { ! ! installer ?. [ 'TelegramActive' ] ?. length ? 'outline' : 'solid' } colorScheme = { 'blue' } onClick = { ( ) => installer . telegramDeepmemoryBotStatus ( true ) } > enable</ Button >
217
+ < Button disabled = { ! installer ?. [ 'TelegramActive' ] ?. length } variant = { ! installer ?. [ 'TelegramActive' ] ?. length ? 'outline' : 'solid' } colorScheme = { 'blue' } onClick = { ( ) => installer . telegramDeepmemoryBotStatus ( false ) } > disable</ Button >
218
+ </ ListItem >
219
+ < ListItem >
220
+ < ListIcon as = { installer ?. [ 'DeepmemoryActive' ] ?. length ? CheckCircleIcon : WarningIcon } color = { installer ?. [ 'DeepmemoryActive' ] ?. length ? 'green.500' : 'red.500' } />
221
+ Deep.Memory ({ installer ?. [ 'DeepmemoryActive' ] ?. [ 0 ] ?. id || '' } )
222
+ < Button disabled = { ! ! installer ?. [ 'DeepmemoryActive' ] ?. length } variant = { ! ! installer ?. [ 'DeepmemoryActive' ] ?. length ? 'outline' : 'solid' } colorScheme = { 'blue' } onClick = { ( ) => installer . deepmemoryBotStatus ( true ) } > enable</ Button >
223
+ < Button disabled = { ! installer ?. [ 'DeepmemoryActive' ] ?. length } variant = { ! installer ?. [ 'DeepmemoryActive' ] ?. length ? 'outline' : 'solid' } colorScheme = { 'blue' } onClick = { ( ) => installer . deepmemoryBotStatus ( false ) } > disable</ Button >
224
+ </ ListItem >
191
225
< ListItem >
192
226
< ListIcon as = { installer ?. [ 'space' ] ? CheckCircleIcon : WarningIcon } color = { installer ?. [ 'space' ] ? 'green.500' : 'red.500' } />
193
227
space ({ installer ?. [ 'space' ] ?. id || '' } ) < Button disabled = { ! installer ?. space } variant = { ! ! installer ?. space ? 'outline' : 'solid' } colorScheme = { 'blue' } onClick = { ( ) => installer . defineSpace ( ) } > define</ Button >
194
228
</ ListItem >
195
229
</ List >
196
230
</ Box >
197
- { deep ?. linkId && < Graph linkId = { deep . linkId } /> }
231
+ { false && deep ?. linkId && < Graph linkId = { deep . linkId } query = { { } } /> }
198
232
</ SimpleGrid >
199
233
</ CardBody >
200
234
</ Card >
@@ -247,7 +281,23 @@ const TemplateView = React.memo(function TemplateView({ template }: { template:
247
281
} ,
248
282
} ) ;
249
283
250
- const rejectsAndResolves = deep . useMinilinksSubscription ( {
284
+ const { data : messages } = deep . useDeepSubscription ( {
285
+ type_id : { _id : [ '@deep-foundation/messaging' , 'Message' ] } ,
286
+ up : {
287
+ tree_id : { _id : [ '@deep-foundation/messaging' , 'messagingTree' ] } ,
288
+ parent : {
289
+ in : {
290
+ type_id : { _id : [ '@deep-foundation/chatgpt-azure-templates' , 'Result' ] } ,
291
+ from : {
292
+ type_id : { _id : [ '@deep-foundation/chatgpt-azure-templates' , 'Apply' ] } ,
293
+ from_id : template . id
294
+ }
295
+ }
296
+ } ,
297
+ } ,
298
+ } ) ;
299
+
300
+ const resolvesAndRejects = deep . useMinilinksSubscription ( {
251
301
type_id : { _in : [ deep . idLocal ( '@deep-foundation/core' , 'Resolved' ) , deep . idLocal ( '@deep-foundation/core' , 'Rejected' ) ] } ,
252
302
from : {
253
303
type_id : deep . idLocal ( '@deep-foundation/core' , 'Promise' ) ,
@@ -257,9 +307,14 @@ const TemplateView = React.memo(function TemplateView({ template }: { template:
257
307
from_id : template . id ,
258
308
}
259
309
} ,
260
- }
310
+ } ,
261
311
} ) ;
262
312
313
+ const results = useMemo (
314
+ ( ) => reverse ( sortBy ( [ ...resolvesAndRejects , ...messages ] , [ 'id' ] ) ) ,
315
+ [ resolvesAndRejects , messages ] ,
316
+ ) ;
317
+
263
318
return < Box borderBottom = { '1px' } borderColor = { 'gray.300' } >
264
319
< SimpleGrid columns = { { sm : 1 , md : 2 } } >
265
320
< Box >
@@ -280,7 +335,7 @@ const TemplateView = React.memo(function TemplateView({ template }: { template:
280
335
</ Box >
281
336
< HStack p = { 2 } pt = { 0 } spacing = { 2 } >
282
337
< Button
283
- colorScheme = { savedValue === value || saving ? 'grey ' : 'blue' } disabled = { savedValue === value || saving } variant = { 'solid' } size = "sm"
338
+ colorScheme = { savedValue === value || saving ? 'gray ' : 'blue' } disabled = { savedValue === value || saving } variant = { 'solid' } size = "sm"
284
339
onClick = { ( ) => save ( value ) }
285
340
>
286
341
{ saving ? < SpinnerIcon /> : savedValue === value ? < CheckIcon /> : < TriangleDownIcon /> }
@@ -306,13 +361,20 @@ const TemplateView = React.memo(function TemplateView({ template }: { template:
306
361
> x</ Button >
307
362
</ HStack >
308
363
</ Box >
309
- < Box p = { 2 } h = { '11em' } overflowY = { 'scroll' } >
310
- { rejectsAndResolves . map ( n => < Box
364
+ < Box p = { 2 } h = { '11em' } overflowY = { 'scroll' } overflowX = { 'hidden' } >
365
+ { results . map ( n => < Box
311
366
borderBottom = { '1px' } borderColor = { 'gray.300' } p = { 2 }
312
- color = { n . type_id === deep . idLocal ( '@deep-foundation/core' , 'Rejected' ) ? 'red.500' : 'green.500' }
367
+ color = {
368
+ n . type_id === deep . idLocal ( '@deep-foundation/core' , 'Rejected' ) ? 'red.500' :
369
+ n . type_id === deep . idLocal ( '@deep-foundation/core' , 'Resolved' ) ? 'green.500' :
370
+ 'black'
371
+ }
313
372
>
314
- { n . type_id === deep . idLocal ( '@deep-foundation/core' , 'Rejected' ) && < pre > < code > { JSON . stringify ( n ?. to ?. value ?. value , null , 2 ) } </ code > </ pre > }
315
- { n . type_id === deep . idLocal ( '@deep-foundation/core' , 'Resolved' ) && < pre > < code > { n ?. id } </ code > </ pre > }
373
+ < Text fontSize = 'xs' as = 'pre' sx = { { textWrap : 'wrap' } } > { n . type_id === deep . idLocal ( '@deep-foundation/core' , 'Rejected' ) ? (
374
+ < code > { JSON . stringify ( n ?. to ?. value ?. value , null , 2 ) } </ code >
375
+ ) : n . type_id === deep . idLocal ( '@deep-foundation/core' , 'Resolved' ) ? (
376
+ < code > { n ?. id } </ code >
377
+ ) : n ?. value ?. value } </ Text >
316
378
</ Box > ) }
317
379
</ Box >
318
380
</ SimpleGrid >
@@ -322,18 +384,15 @@ const TemplateView = React.memo(function TemplateView({ template }: { template:
322
384
const TemplatesViewCore = React . memo ( function TemplatesView ( { } : { } ) {
323
385
const deep = useDeep ( ) ;
324
386
const device = useDevice ( ) ;
325
- deep . useDeepSubscription ( {
387
+ const { data : templates } = deep . useDeepSubscription ( {
326
388
type_id : { _id : [ '@deep-foundation/chatgpt-azure-templates' , 'Template' ] } ,
327
389
in : {
328
390
type_id : deep . idLocal ( '@deep-foundation/core' , 'Contain' ) , from_id : deep ?. linkId ,
329
391
}
330
392
} ) ;
331
- const templates = deep . useMinilinksSubscription ( {
332
- type_id : { _id : [ '@deep-foundation/chatgpt-azure-templates' , 'Template' ] } ,
333
- } ) ;
334
393
return < >
335
394
< Box borderTop = { '1px' } borderColor = { 'gray.300' } >
336
- { templates . map ( t => ( < TemplateView template = { t } /> ) ) }
395
+ { templates . map ( t => ( < TemplateView key = { t . id } template = { t } /> ) ) }
337
396
</ Box >
338
397
</ > ;
339
398
} ) ;
0 commit comments