Приложение для заметок, с целями и с ии чатом · VibeGit
Приложение для заметок, с целями и с ии чатом Это приложение для заметок с ии(свои ключи), есть поддерживание целей, их отслеживание по %
prilozhenie-dlya-zametok-s-tselyami-i-s-ii-chato / src / components / screens / ai-chat.tsx 702 строк · изменён 5 нояб., 15:46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
"use client" ;
import { useEffect, useRef, useState } from "react" ;
import {
AlertTriangle ,
Flag ,
History ,
ImagePlus ,
KeyRound ,
NotebookPen ,
Paperclip ,
Plus ,
SendHorizonal ,
Sparkles ,
Trash2 ,
X ,
} from "lucide-react" ;
import { useStore } from "@/lib/store" ;
import {
AI_PROVIDERS ,
aiOnline,
callModel,
generateReply,
open
onClose
onPick
open
ref
state
notes state n n
notes n
n
notes state g
g
state
open onClose open
state dispatch
fmt day month hour minute
state d
d fmt d d
open onClose open
state dispatch
ai state
p ai
type settings ai p
provider p p ai
p
p
provider m
state
state dispatch
input setInput
context setContext
images setImages
pickerOpen setPickerOpen
historyOpen setHistoryOpen
settingsOpen setSettingsOpen
typing setTyping
scrollRef
imageInputRef
dialog
state d d state state
online state
slashQuery input input
slashNotes
slashQuery
state
n n n
n n slashQuery
el scrollRef
el el el
dialog messages typing dialog id
root
tallest
h
h tallest tallest h
keyboard h tallest
keyboard root
root
sync
sync
sync
sync
root
messages
dialog type dialogId dialog messages
noteId title
prev
prev p p noteId p
prev
prev type id noteId title
files
files
f files
url f
prev prev url
imageInputRef imageInputRef
raw
text raw input
text images typing dialog
refs context
imgs images
userMsg
id
role
text text
context refs
images imgs
ts
userMsg
online
reply state dialog userMsg userMsg refs imgs
id role text reply context refs images ts
e
id
role
text
context
images
ts
error
r r
id
role
text userMsg refs state imgs
context refs
images
ts
messages dialog messages
online messages
s
s
messages m
m
m
online
m
m
m
m url i
m
m c
c
c
typing
i
slashQuery
slashNotes
slashNotes n
n
images
images url i
context
context c
c
online
SUGGESTIONS
,
}
from
"@/lib/ai"
;
import
{ imageToDataUrl }
from
"@/lib/files"
;
import
{ Markdown }
from
"@/lib/markdown"
;
import
type
{
AiProvider
,
ChatContextRef
,
ChatMessage
}
from
"@/lib/types"
;
import
{ cn, uid }
from
"@/lib/utils"
;
import
{ Chip , Sheet }
from
"../ui"
;
function
ContextPicker
(
{
,
,
,
}
:
{
:
boolean
;
onClose
:
(
)
=>
void
;
onPick
:
(
:
ChatContextRef
)
=>
void
;
}
)
{
const
{
}
=
useStore
(
)
;
const
=
.
notes
.
filter
(
(
)
=>
!
.
deletedAt
)
;
return
(
< Sheet open = { open} onClose = { onClose} title = " Привязать контекст" >
< p className = " mb-2 text-xs font-bold uppercase tracking-wider text-faint" >
Заметки
</ p>
< ul className = " mb-4 flex flex-col gap-1.5" >
{
.
slice
(
0
,
6
)
.
map
(
(
)
=>
(
< li key = { n. id } >
< button
onClick = { ( ) => {
onPick ( { type: "note" , id: n. id , title: n. title || "Без названия" } ) ;
onClose ( ) ;
} }
className = " flex w-full items-center gap-2.5 rounded-xl border border-line bg-card px-3.5 py-2.5 text-left text-sm font-semibold text-body transition-all hover:border-accent/50 active:scale-[0.98]"
>
< NotebookPen className = " h-4 w-4 shrink-0 text-accent" />
< span className = " truncate" >
{
.
title
||
"Без названия"
}
</ span>
</ button>
</ li>
)
)
}
{
.
length
===
0
&&
< li className = " text-sm text-faint" >
Заметок пока нет.
</ li>
}
</ ul>
< p className = " mb-2 text-xs font-bold uppercase tracking-wider text-faint" >
Цели
</ p>
< ul className = " flex flex-col gap-1.5" >
{
.
goals
.
map
(
(
)
=>
(
< li key = { g. id } >
< button
onClick = { ( ) => {
onPick ( { type: "goal" , id: g. id , title: g. title } ) ;
onClose ( ) ;
} }
className = " flex w-full items-center gap-2.5 rounded-xl border border-line bg-card px-3.5 py-2.5 text-left text-sm font-semibold text-body transition-all hover:border-accent/50 active:scale-[0.98]"
>
< Flag className = " h-4 w-4 shrink-0 text-accent" />
< span className = " truncate" >
{
.
title
}
</ span>
</ button>
</ li>
)
)
}
{
.
goals
.
length
===
0
&&
< li className = " text-sm text-faint" >
Целей пока нет.
</ li>
}
</ ul>
</ Sheet >
)
;
}
function
HistorySheet
(
{
,
}
:
{
:
boolean
;
onClose
:
(
)
=>
void
}
)
{
const
{
,
}
=
useStore
(
)
;
const
=
new
Intl
.
DateTimeFormat
(
"ru-RU"
,
{
:
"numeric"
,
:
"short"
,
:
"2-digit"
,
:
"2-digit"
}
)
;
return
(
< Sheet open = { open} onClose = { onClose} title = " История диалогов" >
< button
onClick = { ( ) => {
dispatch ( { type: "dialog/new" } ) ;
onClose ( ) ;
} }
className = " mb-3 flex w-full items-center justify-center gap-1.5 rounded-2xl bg-accent py-3 text-sm font-bold text-white transition-all hover:brightness-110 active:scale-[0.98]"
>
< Plus className = " h-4 w-4" />
Новый диалог
</ button>
< ul className = " flex flex-col gap-1.5" >
{
.
dialogs
.
map
(
(
)
=>
(
< li key = { d. id } className = " flex items-center gap-2" >
< button
onClick = { ( ) => {
dispatch ( { type: "dialog/select" , id: d. id } ) ;
onClose ( ) ;
} }
aria-current = { d. id === state. activeDialogId }
className = { cn (
"flex min-w-0 flex-1 flex-col rounded-xl border px-3.5 py-2.5 text-left transition-all active:scale-[0.98]" ,
d. id === state. activeDialogId
? "border-accent bg-accent-soft"
: "border-line bg-card hover:border-accent/50"
) }
>
< span className = " truncate text-sm font-semibold text-body" >
{
.
title
}
</ span>
< span className = " num text-[11px] text-faint" >
{
.
format
(
.
updatedAt
)
}
·
{
.
messages
.
length
}
сообщ.
</ span>
</ button>
< button
onClick = { ( ) => dispatch ( { type: "dialog/delete" , id: d. id } ) }
aria-label = { ` Удалить диалог « ${ d. title} » ` }
className = " flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-faint transition-all hover:bg-danger/10 hover:text-danger active:scale-90"
>
< Trash2 className = " h-4 w-4" />
</ button>
</ li>
)
)
}
</ ul>
</ Sheet >
)
;
}
function
AiSettingsSheet
(
{
,
}
:
{
:
boolean
;
onClose
:
(
)
=>
void
}
)
{
const
{
,
}
=
useStore
(
)
;
const
=
.
ai
;
const
patch
=
(
:
Partial
<
typeof
>
)
=>
dispatch
(
{
:
"ai/settings"
,
:
{
...
,
...
}
}
)
;
const
=
AI_PROVIDERS
.
find
(
(
)
=>
.
id
===
.
provider
)
??
AI_PROVIDERS
[
0
]
;
return
(
< Sheet open = { open} onClose = { onClose} title = " Настройки ассистента" >
< div className = " flex flex-col gap-4" >
< div>
< p className = " mb-2 text-xs font-bold uppercase tracking-wider text-faint" >
Провайдер
</ p>
< div className = " grid grid-cols-4 gap-1.5" >
{
AI_PROVIDERS
.
map
(
(
)
=>
(
< button
key = { p. id }
onClick = { ( ) =>
patch ( {
provider: p. id as AiProvider ,
baseUrl: p. baseUrl || ai. baseUrl ,
model: p. models [ 0 ] ?? ai. model ,
} )
}
aria-pressed = { ai. provider === p. id }
className = { cn (
"rounded-xl border px-1 py-2 text-[11px] font-bold transition-all active:scale-95" ,
ai. provider === p. id
? "border-accent bg-accent-soft text-accent-strong"
: "border-line text-faint hover:text-body"
) }
>
{
.
label
}
</ button>
)
)
}
</ div>
</ div>
< label className = " block" >
< span className = " mb-1.5 block text-xs font-bold uppercase tracking-wider text-faint" >
Эндпоинт (OpenAI-совместимый)
</ span>
< input
value = { ai. baseUrl }
onChange = { ( e) => patch ( { baseUrl: e. target . value } ) }
placeholder = " https://api.example.com/v1"
spellCheck = { false }
className = " num h-11 w-full rounded-xl border border-line bg-card px-3.5 text-sm text-body placeholder:text-faint/50 focus:border-accent focus:outline-none"
/>
</ label>
< label className = " block" >
< span className = " mb-1.5 flex items-center gap-1.5 text-xs font-bold uppercase tracking-wider text-faint" >
< KeyRound className = " h-3 w-3" />
API-ключ
</ span>
< input
type = " password"
value = { ai. apiKey }
onChange = { ( e) => patch ( { apiKey: e. target . value } ) }
placeholder = " sk-…"
spellCheck = { false }
autoComplete = " off"
className = " num h-11 w-full rounded-xl border border-line bg-card px-3.5 text-sm text-body placeholder:text-faint/50 focus:border-accent focus:outline-none"
/>
< span className = " mt-1 block text-[11px] leading-relaxed text-faint" >
Хранится только в localStorage этого браузера. Без ключа чат работает в локальном демо-режиме.
</ span>
</ label>
< label className = " block" >
< span className = " mb-1.5 block text-xs font-bold uppercase tracking-wider text-faint" >
Модель
</ span>
< input
value = { ai. model }
onChange = { ( e) => patch ( { model: e. target . value } ) }
list = " margin-models"
placeholder = " gpt-4o-mini"
spellCheck = { false }
className = " num h-11 w-full rounded-xl border border-line bg-card px-3.5 text-sm text-body placeholder:text-faint/50 focus:border-accent focus:outline-none"
/>
< datalist id = " margin-models" >
{
.
models
.
map
(
(
)
=>
(
< option key = { m} value = { m} />
)
)
}
</ datalist>
</ label>
< label className = " block" >
< span className = " mb-1.5 block text-xs font-bold uppercase tracking-wider text-faint" >
Инструкции ассистенту (ваш AGENTS.md)
</ span>
< textarea
value = { ai. instructions }
onChange = { ( e) => patch ( { instructions: e. target . value } ) }
placeholder = { "Как отвечать, на что опираться.\nНапример: «Отвечай коротко, предлагай шаги только по моим целям, по утрам напоминай про пробежку»." }
rows = { 4 }
className = " w-full resize-none rounded-xl border border-line bg-card p-3.5 text-sm leading-relaxed text-body placeholder:text-faint/50 focus:border-accent focus:outline-none"
/>
</ label>
< p
className = { cn (
"rounded-xl px-3.5 py-2.5 text-xs font-semibold" ,
aiOnline ( state)
? "bg-success/10 text-success"
: "bg-card-2 text-faint"
) }
>
{
aiOnline
(
)
?
` Онлайн: ответы идут через ${ provider. label} · ${ ai. model} `
:
"Демо-режим: ответы собираются локально из ваших данных"
}
</ p>
</ div>
</ Sheet >
)
;
}
export
function
AiScreen
(
)
{
const
{
,
}
=
useStore
(
)
;
const
[
,
]
=
useState
(
""
)
;
const
[
,
]
=
useState < ChatContextRef[ ] >
(
[
]
)
;
const
[
,
]
=
useState < string [ ] >
(
[
]
)
;
const
[
,
]
=
useState
(
false
)
;
const
[
,
]
=
useState
(
false
)
;
const
[
,
]
=
useState
(
false
)
;
const
[
,
]
=
useState
(
false
)
;
const
=
useRef < HTMLDivElement>
(
null
)
;
const
=
useRef < HTMLInputElement>
(
null
)
;
const
=
.
dialogs
.
find
(
(
)
=>
.
id
===
.
activeDialogId
)
??
.
dialogs
[
0
]
;
const
=
aiOnline
(
)
;
const
=
.
startsWith
(
"/"
)
?
.
slice
(
1
)
.
toLowerCase
(
)
:
null
;
const
=
!==
null
?
.
notes
.
filter
(
(
)
=>
!
.
deletedAt
&&
.
kind
!==
"list"
)
.
filter
(
(
)
=>
.
title
.
toLowerCase
(
)
.
includes
(
)
)
.
slice
(
0
,
6
)
:
[
]
;
useEffect
(
(
)
=>
{
const
=
.
current
;
if
(
)
.
scrollTop
=
.
scrollHeight
;
}
,
[
?.
.
length
,
,
?.
]
)
;
useEffect
(
(
)
=>
{
const
=
document
.
documentElement
;
let
=
window
.
innerHeight
;
const
sync
=
(
)
=>
{
const
=
window
.
innerHeight
;
if
(
>
)
=
;
const
=
<
-
120
&&
window
.
matchMedia
(
"(pointer: coarse)"
)
.
matches
;
if
(
)
.
setAttribute
(
"data-keyboard"
,
"1"
)
;
else
.
removeAttribute
(
"data-keyboard"
)
;
}
;
sync
(
)
;
window
.
addEventListener
(
"resize"
,
)
;
window
.
visualViewport
?.
addEventListener
(
"resize"
,
)
;
return
(
)
=>
{
window
.
removeEventListener
(
"resize"
,
)
;
window
.
visualViewport
?.
removeEventListener
(
"resize"
,
)
;
.
removeAttribute
(
"data-keyboard"
)
;
}
;
}
,
[
]
)
;
const
push
=
(
:
ChatMessage
[
]
)
=>
{
if
(
)
dispatch
(
{
:
"dialog/push"
,
:
.
id
,
}
)
;
}
;
const
pickSlashNote
=
(
:
string
,
:
string
)
=>
{
setContext
(
(
)
=>
.
some
(
(
)
=>
.
id
===
&&
.
type
===
"note"
)
?
:
[
...
,
{
:
"note"
,
:
,
}
]
)
;
setInput
(
""
)
;
}
;
const
addImages
=
async
(
:
FileList
|
null
)
=>
{
if
(
!
)
return
;
for
(
const
of
Array
.
from
(
)
.
slice
(
0
,
4
)
)
{
try
{
const
=
await
imageToDataUrl
(
)
;
setImages
(
(
)
=>
[
...
,
]
)
;
}
catch
{
}
}
if
(
.
current
)
.
current
.
value
=
""
;
}
;
const
send
=
async
(
?
:
string
)
=>
{
const
=
(
??
)
.
trim
(
)
;
if
(
(
!
&&
!
.
length
)
||
||
!
)
return
;
const
=
;
const
=
;
const
:
ChatMessage
=
{
:
uid
(
"m"
)
,
:
"user"
,
:
||
"Что на изображении?"
,
:
,
:
,
:
Date
.
now
(
)
,
}
;
push
(
[
]
)
;
setInput
(
""
)
;
setContext
(
[
]
)
;
setImages
(
[
]
)
;
setTyping
(
true
)
;
if
(
)
{
try
{
const
=
await
callModel
(
,
[
...
.
messages
,
]
,
.
text
,
,
)
;
push
(
[
{
:
uid
(
"m"
)
,
:
"assistant"
,
:
,
:
,
:
[
]
,
:
Date
.
now
(
)
}
]
)
;
}
catch
(
)
{
push
(
[
{
:
uid
(
"m"
)
,
:
"assistant"
,
:
` Не удалось достучаться до модели: ${ e instanceof Error ? e. message : "неизвестная ошибка" } . Проверьте ключ и эндпоинт в настройках — или продолжим в демо-режиме. `
,
:
[
]
,
:
[
]
,
:
Date
.
now
(
)
,
:
true
,
}
,
]
)
;
}
}
else
{
await
new
Promise
(
(
)
=>
setTimeout
(
,
700
)
)
;
push
(
[
{
:
uid
(
"m"
)
,
:
"assistant"
,
:
generateReply
(
.
text
,
,
,
)
,
:
,
:
[
]
,
:
Date
.
now
(
)
,
}
,
]
)
;
}
setTyping
(
false
)
;
}
;
const
=
?.
??
[
]
;
return
(
< div className = " flex min-h-0 flex-1 flex-col" >
{
}
< div className = " flex shrink-0 items-center gap-2 px-5 pt-3" >
< button
onClick = { ( ) => setHistoryOpen ( true ) }
className = " flex items-center gap-1.5 rounded-full border border-line bg-card px-3 py-1.5 text-xs font-bold text-faint transition-all hover:text-body active:scale-95"
>
< History className = " h-3.5 w-3.5" />
История
</ button>
< button
onClick = { ( ) => dispatch ( { type: "dialog/new" } ) }
className = " flex items-center gap-1.5 rounded-full border border-line bg-card px-3 py-1.5 text-xs font-bold text-faint transition-all hover:text-body active:scale-95"
>
< Plus className = " h-3.5 w-3.5" />
Новый
</ button>
< div className = " flex-1" />
< button
onClick = { ( ) => setSettingsOpen ( true ) }
className = { cn (
"flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-xs font-bold transition-all active:scale-95" ,
online
? "border-success/40 bg-success/10 text-success"
: "border-line bg-card text-faint hover:text-body"
) }
>
< KeyRound className = " h-3.5 w-3.5" />
{
?
"Онлайн"
:
"Демо"
}
</ button>
</ div>
{
}
< div ref = { scrollRef} className = " flex-1 overflow-y-auto px-5 pt-3 scrollbar-none" >
{
.
length
===
0
?
(
< div className = " flex h-full flex-col items-center justify-center gap-4 text-center animate-rise" >
< div className = " flex h-14 w-14 items-center justify-center rounded-3xl bg-accent-soft" >
< Sparkles className = " h-6 w-6 text-accent-strong" />
</ div>
< div>
< p className = " font-bold text-body" >
Чем помочь, сэр?
</ p>
< p className = " mt-1 max-w-[30ch] text-sm leading-relaxed text-faint" >
Я вижу ваши заметки, цели, задачи на сегодня и календарь. Спросите — или
привяжите контекст скрепкой.
</ p>
</ div>
< div className = " flex max-w-full flex-wrap justify-center gap-2" >
{
SUGGESTIONS
.
map
(
(
)
=>
(
< button
key = { s}
onClick = { ( ) => send ( s) }
className = " rounded-full border border-line bg-card px-3.5 py-2 text-xs font-semibold text-faint transition-all hover:border-accent hover:text-accent active:scale-95"
>
{
}
</ button>
)
)
}
</ div>
</ div>
)
:
(
< ul className = " flex flex-col gap-3 pb-3" >
{
.
map
(
(
)
=>
(
< li
key = { m. id }
className = { cn ( "flex animate-rise" , m. role === "user" ? "justify-end" : "justify-start" ) }
>
< div
className = { cn (
"max-w-[85%] rounded-3xl px-4 py-3 text-[15px] leading-relaxed" ,
m. role === "user"
? "rounded-br-lg bg-accent text-white"
: m. error
? "rounded-bl-lg border border-danger/40 bg-danger/5 text-body"
: "rounded-bl-lg border border-line bg-card text-body"
) }
>
{
.
role
===
"assistant"
&&
(
< p
className = { cn (
"mb-1 flex items-center gap-1 text-[10px] font-bold uppercase tracking-wider" ,
m. error ? "text-danger" : "text-accent"
) }
>
{
.
error
?
(
< >
< AlertTriangle className = " h-3 w-3" />
Ошибка API
</ >
)
:
(
< >
< Sparkles className = " h-3 w-3" />
Margin AI ·
{
?
"онлайн"
:
"демо"
}
</ >
)
}
</ p>
)
}
{
.
role
===
"assistant"
?
(
< Markdown text = { m. text } />
)
:
(
< p className = " whitespace-pre-wrap" >
{
.
text
}
</ p>
)
}
{
.
images
.
length
>
0
&&
(
< div className = " mt-2 flex flex-wrap gap-2" >
{
.
images
.
map
(
(
,
)
=>
(
< img
key = { i}
src = { url}
alt = { ` Прикреплённое изображение ${ i + 1 } ` }
className = " max-h-40 rounded-xl border border-white/20 object-cover"
/>
)
)
}
</ div>
)
}
{
.
context
.
length
>
0
&&
(
< div className = " mt-2 flex flex-wrap gap-1.5" >
{
.
context
.
map
(
(
)
=>
(
< span
key = { ` ${ c. type } - ${ c. id} ` }
className = { cn (
"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[11px] font-semibold" ,
m. role === "user"
? "bg-white/20 text-white"
: "bg-accent-soft text-accent-strong"
) }
>
{
.
type
===
"note"
?
(
< NotebookPen className = " h-3 w-3" />
)
:
(
< Flag className = " h-3 w-3" />
)
}
< span className = " max-w-[14ch] truncate" >
{
.
title
}
</ span>
</ span>
)
)
}
</ div>
)
}
</ div>
</ li>
)
)
}
{
&&
(
< li className = " flex justify-start animate-fade" >
< div className = " flex items-center gap-1.5 rounded-3xl rounded-bl-lg border border-line bg-card px-4 py-3.5" >
{
[
0
,
1
,
2
]
.
map
(
(
)
=>
(
< span
key = { i}
className = " h-1.5 w-1.5 animate-bounce rounded-full bg-faint"
style = { { animationDelay: ` ${ i * 120 } ms ` } }
/>
)
)
}
</ div>
</ li>
)
}
</ ul>
)
}
</ div>
{
}
< div className = " relative shrink-0 border-t border-line/60 bg-canvas/80 px-4 pt-2.5 pb-3 backdrop-blur-xl" >
{
}
{
!==
null
&&
(
< div className = " absolute bottom-full left-4 right-4 mb-2 animate-pop rounded-2xl border border-line bg-card p-2 shadow-xl" >
< p className = " px-2 pb-1.5 pt-1 text-[10px] font-bold uppercase tracking-wider text-faint" >
Привязать текстовую заметку
</ p>
{
.
length
===
0
?
(
< p className = " px-2 pb-1 text-sm text-faint" >
Нет подходящих заметок.
</ p>
)
:
(
< ul className = " flex flex-col" >
{
.
map
(
(
)
=>
(
< li key = { n. id } >
< button
onClick = { ( ) => pickSlashNote ( n. id , n. title || "Без названия" ) }
className = " flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-left text-sm font-semibold text-body transition-colors hover:bg-accent-soft active:scale-[0.98]"
>
< NotebookPen className = " h-4 w-4 shrink-0 text-accent" />
< span className = " truncate" >
{
.
title
||
"Без названия"
}
</ span>
</ button>
</ li>
)
)
}
</ ul>
)
}
</ div>
)
}
{
.
length
>
0
&&
(
< div className = " mb-2 flex flex-wrap gap-2" >
{
.
map
(
(
,
)
=>
(
< span key = { i} className = " relative animate-pop" >
{
}
< img
src = { url}
alt = { ` Фото ${ i + 1 } ` }
className = " h-16 w-16 rounded-xl border border-line object-cover"
/>
< button
onClick = { ( ) => setImages ( ( prev) => prev. filter ( ( _, j) => j !== i) ) }
aria-label = { ` Убрать фото ${ i + 1 } ` }
className = " absolute -right-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-full bg-foreground text-canvas shadow transition-transform active:scale-90"
>
< X className = " h-3 w-3" />
</ button>
</ span>
)
)
}
</ div>
)
}
{
.
length
>
0
&&
(
< div className = " mb-2 flex flex-wrap gap-1.5" >
{
.
map
(
(
)
=>
(
< Chip
key = { ` ${ c. type } - ${ c. id} ` }
icon = {
c. type === "note" ? (
< NotebookPen className = " h-3 w-3" />
) : (
< Flag className = " h-3 w-3" />
)
}
onRemove = { ( ) =>
setContext ( ( prev) => prev. filter ( ( p) => ! ( p. id === c. id && p. type === c. type ) ) )
}
>
{
.
title
}
</ Chip >
)
)
}
</ div>
)
}
< div className = " flex items-end gap-2" >
< button
onClick = { ( ) => setPickerOpen ( true ) }
onPointerDown = { ( e) => e. preventDefault ( ) }
aria-label = " Привязать заметку или цель"
className = " flex h-11 w-11 shrink-0 items-center justify-center rounded-full border border-line bg-card text-faint transition-all hover:text-accent active:scale-90"
>
< Paperclip className = " h-4.5 w-4.5" />
</ button>
< button
onClick = { ( ) => imageInputRef. current ?. click ( ) }
onPointerDown = { ( e) => e. preventDefault ( ) }
aria-label = " Прикрепить фото (например, задачи)"
className = " flex h-11 w-11 shrink-0 items-center justify-center rounded-full border border-line bg-card text-faint transition-all hover:text-accent active:scale-90"
>
< ImagePlus className = " h-4.5 w-4.5" />
</ button>
< label className = " flex-1" >
< span className = " sr-only" >
Сообщение ассистенту
</ span>
< textarea
value = { input}
onChange = { ( e) => setInput ( e. target . value ) }
onKeyDown = { ( e) => {
if ( e. nativeEvent . isComposing ) return ;
if ( slashQuery !== null && e. key === "Escape" ) {
setInput ( "" ) ;
return ;
}
if ( slashQuery !== null && e. key === "Enter" && slashNotes. length > 0 ) {
e. preventDefault ( ) ;
pickSlashNote ( slashNotes[ 0 ] . id , slashNotes[ 0 ] . title || "Без названия" ) ;
return ;
}
if ( e. key === "Enter" && ! e. shiftKey ) {
e. preventDefault ( ) ;
void send ( ) ;
}
} }
placeholder = " Вопрос… или «/»"
rows = { 1 }
className = " max-h-32 min-h-11 w-full resize-none rounded-3xl border border-line bg-card px-4 py-3 text-[15px] text-body placeholder:text-faint/70 focus:border-accent focus:outline-none"
/>
</ label>
< button
onClick = { ( ) => void send ( ) }
onPointerDown = { ( e) => e. preventDefault ( ) }
disabled = { ( ! input. trim ( ) && ! images. length ) || typing}
aria-label = " Отправить сообщение"
className = " flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-accent text-white transition-all hover:brightness-110 active:scale-90 disabled:opacity-40"
>
< SendHorizonal className = " h-4.5 w-4.5" />
</ button>
</ div>
< p className = " mt-1.5 text-[10px] font-medium text-faint/80" >
{
?
` Онлайн · ${ state. ai. model} · «/» — привязать заметку, скрепка — цель `
:
"Демо-режим: ответы собираются локально. Подключите API в настройках"
}
</ p>
< input
ref = { imageInputRef}
type = " file"
accept = " image/*"
multiple
className = " hidden"
aria-hidden
tabIndex = { - 1 }
onChange = { ( e) => void addImages ( e. target . files ) }
/>
</ div>
< ContextPicker
open = { pickerOpen}
onClose = { ( ) => setPickerOpen ( false ) }
onPick = { ( ref) =>
setContext ( ( prev) =>
prev. some ( ( p) => p. id === ref. id && p. type === ref. type ) ? prev : [ ... prev, ref]
)
}
/>
< HistorySheet open = { historyOpen} onClose = { ( ) => setHistoryOpen ( false ) } />
< AiSettingsSheet open = { settingsOpen} onClose = { ( ) => setSettingsOpen ( false ) } />
</ div>
)
;
}