nextjs-chatbot-ui 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -2
- package/components/AdminSetup.tsx +714 -650
- package/package.json +2 -1
- package/types/admin.ts +6 -0
- package/utils/connectionHelpers.ts +40 -0
|
@@ -1,650 +1,714 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import React, { useState } from 'react';
|
|
4
|
-
import { DatabaseType, DatabaseConnection, ColumnSelection, DatabaseConfig, AdminSetupProps } from '../types/admin';
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const [
|
|
14
|
-
const [
|
|
15
|
-
const [
|
|
16
|
-
const [
|
|
17
|
-
const [
|
|
18
|
-
const [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const [
|
|
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
|
-
<div>
|
|
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
|
-
<div>
|
|
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
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { useState } from 'react';
|
|
4
|
+
import { DatabaseType, DatabaseConnection, ColumnSelection, DatabaseConfig, AdminSetupProps } from '../types/admin';
|
|
5
|
+
import { normalizeConnection, transformConnectionForBackend } from '../utils/connectionHelpers';
|
|
6
|
+
import clsx from 'clsx';
|
|
7
|
+
|
|
8
|
+
const AdminSetup: React.FC<AdminSetupProps> = ({
|
|
9
|
+
onSave,
|
|
10
|
+
onTestConnection,
|
|
11
|
+
onFetchColumns,
|
|
12
|
+
}) => {
|
|
13
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
14
|
+
const [currentStep, setCurrentStep] = useState<'connection' | 'columns'>('connection');
|
|
15
|
+
const [isConnecting, setIsConnecting] = useState(false);
|
|
16
|
+
const [connectionError, setConnectionError] = useState<string | null>(null);
|
|
17
|
+
const [connectionSuccess, setConnectionSuccess] = useState(false);
|
|
18
|
+
const [availableColumns, setAvailableColumns] = useState<string[]>([]);
|
|
19
|
+
const [isLoadingColumns, setIsLoadingColumns] = useState(false);
|
|
20
|
+
|
|
21
|
+
const [dbType, setDbType] = useState<DatabaseType>('mongodb');
|
|
22
|
+
const [connection, setConnection] = useState<DatabaseConnection>({
|
|
23
|
+
type: 'mongodb',
|
|
24
|
+
host: '',
|
|
25
|
+
port: 27017,
|
|
26
|
+
database: '',
|
|
27
|
+
username: '',
|
|
28
|
+
password: '',
|
|
29
|
+
connectionString: '',
|
|
30
|
+
ssl: false,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const [columnSelection, setColumnSelection] = useState<ColumnSelection>({
|
|
34
|
+
embeddingColumns: [],
|
|
35
|
+
llmColumns: [],
|
|
36
|
+
chromaColumns: [],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const handleDbTypeChange = (type: DatabaseType) => {
|
|
40
|
+
setDbType(type);
|
|
41
|
+
setConnection({
|
|
42
|
+
...connection,
|
|
43
|
+
type,
|
|
44
|
+
port: type === 'mongodb' ? 27017 : 5432,
|
|
45
|
+
});
|
|
46
|
+
setConnectionError(null);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const handleConnectionChange = (field: keyof DatabaseConnection, value: any) => {
|
|
50
|
+
setConnection({
|
|
51
|
+
...connection,
|
|
52
|
+
[field]: value,
|
|
53
|
+
});
|
|
54
|
+
setConnectionError(null);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const handleTestConnection = async (): Promise<boolean> => {
|
|
58
|
+
setIsConnecting(true);
|
|
59
|
+
setConnectionError(null);
|
|
60
|
+
setConnectionSuccess(false);
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
// Ensure default ports are set
|
|
64
|
+
const normalizedConnection = normalizeConnection(connection, dbType);
|
|
65
|
+
|
|
66
|
+
// Transform to backend format
|
|
67
|
+
const backendRequest = transformConnectionForBackend(connection, dbType);
|
|
68
|
+
|
|
69
|
+
let isValid: boolean;
|
|
70
|
+
|
|
71
|
+
if (onTestConnection) {
|
|
72
|
+
// Use provided handler - send normalized connection
|
|
73
|
+
isValid = await onTestConnection(normalizedConnection);
|
|
74
|
+
} else {
|
|
75
|
+
// Default: Try to call backend API
|
|
76
|
+
try {
|
|
77
|
+
const response = await fetch('/api/database/test', {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
headers: {
|
|
80
|
+
'Content-Type': 'application/json',
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify(backendRequest), // Send transformed format
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
const errorData = await response.json().catch(() => ({}));
|
|
87
|
+
throw new Error(errorData.message || `HTTP ${response.status}: ${response.statusText}`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const data = await response.json();
|
|
91
|
+
isValid = data.success === true || response.ok;
|
|
92
|
+
} catch (fetchError: any) {
|
|
93
|
+
// If API endpoint doesn't exist, show helpful error
|
|
94
|
+
if (fetchError.message?.includes('Failed to fetch') || fetchError.message?.includes('404')) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
'Backend API endpoint not found. Please implement POST /api/database/test endpoint or provide onTestConnection handler.'
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
throw fetchError;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (isValid) {
|
|
104
|
+
setConnectionError(null);
|
|
105
|
+
setConnectionSuccess(true);
|
|
106
|
+
return true;
|
|
107
|
+
} else {
|
|
108
|
+
setConnectionError('Connection failed. Please check your credentials and try again.');
|
|
109
|
+
setConnectionSuccess(false);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
} catch (error: any) {
|
|
113
|
+
const errorMessage = error.message || 'Connection failed. Please try again.';
|
|
114
|
+
setConnectionError(errorMessage);
|
|
115
|
+
setConnectionSuccess(false);
|
|
116
|
+
console.error('Database connection error:', error);
|
|
117
|
+
return false;
|
|
118
|
+
} finally {
|
|
119
|
+
setIsConnecting(false);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const handleFetchColumns = async (): Promise<string[]> => {
|
|
124
|
+
setIsLoadingColumns(true);
|
|
125
|
+
setConnectionError(null);
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
// Ensure default ports are set
|
|
129
|
+
const normalizedConnection = normalizeConnection(connection, dbType);
|
|
130
|
+
|
|
131
|
+
// Transform to backend format
|
|
132
|
+
const backendRequest = transformConnectionForBackend(connection, dbType);
|
|
133
|
+
|
|
134
|
+
let columns: string[];
|
|
135
|
+
|
|
136
|
+
if (onFetchColumns) {
|
|
137
|
+
// Use provided handler
|
|
138
|
+
columns = await onFetchColumns(normalizedConnection);
|
|
139
|
+
} else {
|
|
140
|
+
// Default: Try to call backend API
|
|
141
|
+
try {
|
|
142
|
+
const response = await fetch('/api/database/columns', {
|
|
143
|
+
method: 'POST',
|
|
144
|
+
headers: {
|
|
145
|
+
'Content-Type': 'application/json',
|
|
146
|
+
},
|
|
147
|
+
body: JSON.stringify(backendRequest), // Send transformed format
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
if (!response.ok) {
|
|
151
|
+
const errorData = await response.json().catch(() => ({}));
|
|
152
|
+
throw new Error(errorData.message || `HTTP ${response.status}: ${response.statusText}`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const data = await response.json();
|
|
156
|
+
columns = data.columns || data.columnNames || [];
|
|
157
|
+
} catch (fetchError: any) {
|
|
158
|
+
// If API endpoint doesn't exist, show helpful error
|
|
159
|
+
if (fetchError.message?.includes('Failed to fetch') || fetchError.message?.includes('404')) {
|
|
160
|
+
throw new Error(
|
|
161
|
+
'Backend API endpoint not found. Please implement POST /api/database/columns endpoint or provide onFetchColumns handler.'
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
throw fetchError;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (columns && columns.length > 0) {
|
|
169
|
+
setAvailableColumns(columns);
|
|
170
|
+
setIsLoadingColumns(false);
|
|
171
|
+
return columns;
|
|
172
|
+
} else {
|
|
173
|
+
setConnectionError('No columns found in the database. Please check your database connection and table selection.');
|
|
174
|
+
setIsLoadingColumns(false);
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
} catch (error: any) {
|
|
178
|
+
const errorMessage = error.message || 'Failed to fetch columns. Please try again.';
|
|
179
|
+
setConnectionError(errorMessage);
|
|
180
|
+
setIsLoadingColumns(false);
|
|
181
|
+
console.error('Fetch columns error:', error);
|
|
182
|
+
return [];
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const handleConnectAndNext = async () => {
|
|
187
|
+
// Validate connection fields
|
|
188
|
+
if (dbType === 'mongodb') {
|
|
189
|
+
if (!connection.connectionString && (!connection.host || !connection.database)) {
|
|
190
|
+
setConnectionError('Please provide connection string or host and database');
|
|
191
|
+
setConnectionSuccess(false);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
if (!connection.host || !connection.database || !connection.username || !connection.password) {
|
|
196
|
+
setConnectionError('Please fill in all required fields');
|
|
197
|
+
setConnectionSuccess(false);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Clear previous errors
|
|
203
|
+
setConnectionError(null);
|
|
204
|
+
setConnectionSuccess(false);
|
|
205
|
+
|
|
206
|
+
// Test connection first
|
|
207
|
+
const connectionSuccess = await handleTestConnection();
|
|
208
|
+
|
|
209
|
+
if (!connectionSuccess) {
|
|
210
|
+
// Connection failed, don't proceed
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// If connection successful, fetch columns
|
|
215
|
+
const fetchedColumns = await handleFetchColumns();
|
|
216
|
+
|
|
217
|
+
if (fetchedColumns && fetchedColumns.length > 0) {
|
|
218
|
+
// Successfully fetched columns, move to next step
|
|
219
|
+
setCurrentStep('columns');
|
|
220
|
+
setConnectionError(null);
|
|
221
|
+
} else {
|
|
222
|
+
// Column fetching failed, show error but keep connection success
|
|
223
|
+
// Error is already set in handleFetchColumns
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const handleColumnToggle = (column: string, category: keyof ColumnSelection) => {
|
|
228
|
+
setColumnSelection((prev) => {
|
|
229
|
+
const currentColumns = prev[category];
|
|
230
|
+
const isSelected = currentColumns.includes(column);
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
...prev,
|
|
234
|
+
[category]: isSelected
|
|
235
|
+
? currentColumns.filter((c) => c !== column)
|
|
236
|
+
: [...currentColumns, column],
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const handleSave = () => {
|
|
242
|
+
const config: DatabaseConfig = {
|
|
243
|
+
connection,
|
|
244
|
+
columnSelection,
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
if (onSave) {
|
|
248
|
+
onSave(config);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Close modal and reset
|
|
252
|
+
setIsModalOpen(false);
|
|
253
|
+
setCurrentStep('connection');
|
|
254
|
+
setConnectionError(null);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const handleClose = () => {
|
|
258
|
+
setIsModalOpen(false);
|
|
259
|
+
setCurrentStep('connection');
|
|
260
|
+
setConnectionError(null);
|
|
261
|
+
setConnectionSuccess(false);
|
|
262
|
+
setAvailableColumns([]);
|
|
263
|
+
setColumnSelection({
|
|
264
|
+
embeddingColumns: [],
|
|
265
|
+
llmColumns: [],
|
|
266
|
+
chromaColumns: [],
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
return (
|
|
271
|
+
<>
|
|
272
|
+
{/* Sidebar Button/Item - This can be integrated into admin sidebar */}
|
|
273
|
+
<button
|
|
274
|
+
onClick={() => setIsModalOpen(true)}
|
|
275
|
+
className="w-full flex items-center gap-3 px-4 py-2.5 text-left hover:bg-gray-100 rounded-lg transition-colors"
|
|
276
|
+
>
|
|
277
|
+
<svg
|
|
278
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
279
|
+
className="h-5 w-5 text-gray-600"
|
|
280
|
+
fill="none"
|
|
281
|
+
viewBox="0 0 24 24"
|
|
282
|
+
stroke="currentColor"
|
|
283
|
+
>
|
|
284
|
+
<path
|
|
285
|
+
strokeLinecap="round"
|
|
286
|
+
strokeLinejoin="round"
|
|
287
|
+
strokeWidth={2}
|
|
288
|
+
d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4"
|
|
289
|
+
/>
|
|
290
|
+
</svg>
|
|
291
|
+
<span className="text-sm font-medium text-gray-700">Database Setup</span>
|
|
292
|
+
</button>
|
|
293
|
+
|
|
294
|
+
{/* Modal */}
|
|
295
|
+
{isModalOpen && (
|
|
296
|
+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50">
|
|
297
|
+
<div className="bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-hidden flex flex-col">
|
|
298
|
+
{/* Modal Header */}
|
|
299
|
+
<div className="px-6 py-4 border-b border-gray-200 flex items-center justify-between">
|
|
300
|
+
<h2 className="text-xl font-semibold text-gray-900">
|
|
301
|
+
{currentStep === 'connection' ? 'Database Connection' : 'Select Columns'}
|
|
302
|
+
</h2>
|
|
303
|
+
<button
|
|
304
|
+
onClick={handleClose}
|
|
305
|
+
className="text-gray-400 hover:text-gray-600 transition-colors"
|
|
306
|
+
>
|
|
307
|
+
<svg
|
|
308
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
309
|
+
className="h-6 w-6"
|
|
310
|
+
fill="none"
|
|
311
|
+
viewBox="0 0 24 24"
|
|
312
|
+
stroke="currentColor"
|
|
313
|
+
>
|
|
314
|
+
<path
|
|
315
|
+
strokeLinecap="round"
|
|
316
|
+
strokeLinejoin="round"
|
|
317
|
+
strokeWidth={2}
|
|
318
|
+
d="M6 18L18 6M6 6l12 12"
|
|
319
|
+
/>
|
|
320
|
+
</svg>
|
|
321
|
+
</button>
|
|
322
|
+
</div>
|
|
323
|
+
|
|
324
|
+
{/* Modal Content */}
|
|
325
|
+
<div className="flex-1 overflow-y-auto px-6 py-4">
|
|
326
|
+
{currentStep === 'connection' ? (
|
|
327
|
+
<div className="space-y-6">
|
|
328
|
+
{/* Database Type Selection */}
|
|
329
|
+
<div>
|
|
330
|
+
<label className="block text-sm font-medium text-gray-700 mb-3">
|
|
331
|
+
Database Type
|
|
332
|
+
</label>
|
|
333
|
+
<div className="grid grid-cols-2 gap-4">
|
|
334
|
+
<button
|
|
335
|
+
onClick={() => handleDbTypeChange('mongodb')}
|
|
336
|
+
className={clsx(
|
|
337
|
+
'p-4 border-2 rounded-lg transition-all text-left',
|
|
338
|
+
dbType === 'mongodb'
|
|
339
|
+
? 'border-blue-500 bg-blue-50'
|
|
340
|
+
: 'border-gray-200 hover:border-gray-300'
|
|
341
|
+
)}
|
|
342
|
+
>
|
|
343
|
+
<div className="flex items-center gap-3">
|
|
344
|
+
<div className={clsx(
|
|
345
|
+
'w-5 h-5 rounded-full border-2 flex items-center justify-center',
|
|
346
|
+
dbType === 'mongodb' ? 'border-blue-500' : 'border-gray-300'
|
|
347
|
+
)}>
|
|
348
|
+
{dbType === 'mongodb' && (
|
|
349
|
+
<div className="w-3 h-3 rounded-full bg-blue-500" />
|
|
350
|
+
)}
|
|
351
|
+
</div>
|
|
352
|
+
<div>
|
|
353
|
+
<div className="font-semibold text-gray-900">MongoDB</div>
|
|
354
|
+
<div className="text-xs text-gray-500">NoSQL Database</div>
|
|
355
|
+
</div>
|
|
356
|
+
</div>
|
|
357
|
+
</button>
|
|
358
|
+
<button
|
|
359
|
+
onClick={() => handleDbTypeChange('postgres')}
|
|
360
|
+
className={clsx(
|
|
361
|
+
'p-4 border-2 rounded-lg transition-all text-left',
|
|
362
|
+
dbType === 'postgres'
|
|
363
|
+
? 'border-blue-500 bg-blue-50'
|
|
364
|
+
: 'border-gray-200 hover:border-gray-300'
|
|
365
|
+
)}
|
|
366
|
+
>
|
|
367
|
+
<div className="flex items-center gap-3">
|
|
368
|
+
<div className={clsx(
|
|
369
|
+
'w-5 h-5 rounded-full border-2 flex items-center justify-center',
|
|
370
|
+
dbType === 'postgres' ? 'border-blue-500' : 'border-gray-300'
|
|
371
|
+
)}>
|
|
372
|
+
{dbType === 'postgres' && (
|
|
373
|
+
<div className="w-3 h-3 rounded-full bg-blue-500" />
|
|
374
|
+
)}
|
|
375
|
+
</div>
|
|
376
|
+
<div>
|
|
377
|
+
<div className="font-semibold text-gray-900">PostgreSQL</div>
|
|
378
|
+
<div className="text-xs text-gray-500">SQL Database</div>
|
|
379
|
+
</div>
|
|
380
|
+
</div>
|
|
381
|
+
</button>
|
|
382
|
+
</div>
|
|
383
|
+
</div>
|
|
384
|
+
|
|
385
|
+
{/* Connection Fields */}
|
|
386
|
+
{dbType === 'mongodb' ? (
|
|
387
|
+
<div className="space-y-4">
|
|
388
|
+
<div>
|
|
389
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
390
|
+
Connection String (Recommended)
|
|
391
|
+
</label>
|
|
392
|
+
<input
|
|
393
|
+
type="text"
|
|
394
|
+
value={connection.connectionString || ''}
|
|
395
|
+
onChange={(e) => handleConnectionChange('connectionString', e.target.value)}
|
|
396
|
+
placeholder="mongodb://username:password@host:port/database"
|
|
397
|
+
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
398
|
+
/>
|
|
399
|
+
<p className="mt-1 text-xs text-gray-500">
|
|
400
|
+
Or fill individual fields below
|
|
401
|
+
</p>
|
|
402
|
+
</div>
|
|
403
|
+
<div className="border-t border-gray-200 pt-4">
|
|
404
|
+
<div className="grid grid-cols-2 gap-4">
|
|
405
|
+
<div>
|
|
406
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
407
|
+
Host *
|
|
408
|
+
</label>
|
|
409
|
+
<input
|
|
410
|
+
type="text"
|
|
411
|
+
value={connection.host}
|
|
412
|
+
onChange={(e) => handleConnectionChange('host', e.target.value)}
|
|
413
|
+
placeholder="localhost"
|
|
414
|
+
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
415
|
+
/>
|
|
416
|
+
</div>
|
|
417
|
+
<div>
|
|
418
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
419
|
+
Port *
|
|
420
|
+
</label>
|
|
421
|
+
<input
|
|
422
|
+
type="number"
|
|
423
|
+
value={connection.port}
|
|
424
|
+
onChange={(e) => handleConnectionChange('port', parseInt(e.target.value) || 27017)}
|
|
425
|
+
placeholder="27017"
|
|
426
|
+
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
427
|
+
/>
|
|
428
|
+
</div>
|
|
429
|
+
</div>
|
|
430
|
+
<div className="mt-4">
|
|
431
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
432
|
+
Database Name *
|
|
433
|
+
</label>
|
|
434
|
+
<input
|
|
435
|
+
type="text"
|
|
436
|
+
value={connection.database}
|
|
437
|
+
onChange={(e) => handleConnectionChange('database', e.target.value)}
|
|
438
|
+
placeholder="my_database"
|
|
439
|
+
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
440
|
+
/>
|
|
441
|
+
</div>
|
|
442
|
+
<div className="mt-4">
|
|
443
|
+
<label className="flex items-center gap-2">
|
|
444
|
+
<input
|
|
445
|
+
type="checkbox"
|
|
446
|
+
checked={connection.ssl || false}
|
|
447
|
+
onChange={(e) => handleConnectionChange('ssl', e.target.checked)}
|
|
448
|
+
className="rounded border-gray-300 text-blue-600 focus:ring-blue-500"
|
|
449
|
+
/>
|
|
450
|
+
<span className="text-sm text-gray-700">Enable SSL</span>
|
|
451
|
+
</label>
|
|
452
|
+
</div>
|
|
453
|
+
</div>
|
|
454
|
+
</div>
|
|
455
|
+
) : (
|
|
456
|
+
<div className="space-y-4">
|
|
457
|
+
<div className="grid grid-cols-2 gap-4">
|
|
458
|
+
<div>
|
|
459
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
460
|
+
Host *
|
|
461
|
+
</label>
|
|
462
|
+
<input
|
|
463
|
+
type="text"
|
|
464
|
+
value={connection.host}
|
|
465
|
+
onChange={(e) => handleConnectionChange('host', e.target.value)}
|
|
466
|
+
placeholder="localhost"
|
|
467
|
+
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
468
|
+
/>
|
|
469
|
+
</div>
|
|
470
|
+
<div>
|
|
471
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
472
|
+
Port *
|
|
473
|
+
</label>
|
|
474
|
+
<input
|
|
475
|
+
type="number"
|
|
476
|
+
value={connection.port}
|
|
477
|
+
onChange={(e) => handleConnectionChange('port', parseInt(e.target.value) || 5432)}
|
|
478
|
+
placeholder="5432"
|
|
479
|
+
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
480
|
+
/>
|
|
481
|
+
</div>
|
|
482
|
+
</div>
|
|
483
|
+
<div>
|
|
484
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
485
|
+
Database Name *
|
|
486
|
+
</label>
|
|
487
|
+
<input
|
|
488
|
+
type="text"
|
|
489
|
+
value={connection.database}
|
|
490
|
+
onChange={(e) => handleConnectionChange('database', e.target.value)}
|
|
491
|
+
placeholder="my_database"
|
|
492
|
+
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
493
|
+
/>
|
|
494
|
+
</div>
|
|
495
|
+
<div className="grid grid-cols-2 gap-4">
|
|
496
|
+
<div>
|
|
497
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
498
|
+
Username *
|
|
499
|
+
</label>
|
|
500
|
+
<input
|
|
501
|
+
type="text"
|
|
502
|
+
value={connection.username || ''}
|
|
503
|
+
onChange={(e) => handleConnectionChange('username', e.target.value)}
|
|
504
|
+
placeholder="postgres"
|
|
505
|
+
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
506
|
+
/>
|
|
507
|
+
</div>
|
|
508
|
+
<div>
|
|
509
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
510
|
+
Password *
|
|
511
|
+
</label>
|
|
512
|
+
<input
|
|
513
|
+
type="password"
|
|
514
|
+
value={connection.password || ''}
|
|
515
|
+
onChange={(e) => handleConnectionChange('password', e.target.value)}
|
|
516
|
+
placeholder="••••••••"
|
|
517
|
+
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
518
|
+
/>
|
|
519
|
+
</div>
|
|
520
|
+
</div>
|
|
521
|
+
<div>
|
|
522
|
+
<label className="flex items-center gap-2">
|
|
523
|
+
<input
|
|
524
|
+
type="checkbox"
|
|
525
|
+
checked={connection.ssl || false}
|
|
526
|
+
onChange={(e) => handleConnectionChange('ssl', e.target.checked)}
|
|
527
|
+
className="rounded border-gray-300 text-blue-600 focus:ring-blue-500"
|
|
528
|
+
/>
|
|
529
|
+
<span className="text-sm text-gray-700">Enable SSL</span>
|
|
530
|
+
</label>
|
|
531
|
+
</div>
|
|
532
|
+
</div>
|
|
533
|
+
)}
|
|
534
|
+
|
|
535
|
+
{connectionError && (
|
|
536
|
+
<div className="bg-red-50 border border-red-200 rounded-lg p-4">
|
|
537
|
+
<p className="text-sm text-red-800">{connectionError}</p>
|
|
538
|
+
</div>
|
|
539
|
+
)}
|
|
540
|
+
{connectionSuccess && !connectionError && !isConnecting && (
|
|
541
|
+
<div className="bg-green-50 border border-green-200 rounded-lg p-4">
|
|
542
|
+
<p className="text-sm text-green-800">✓ Connection successful!</p>
|
|
543
|
+
</div>
|
|
544
|
+
)}
|
|
545
|
+
</div>
|
|
546
|
+
) : (
|
|
547
|
+
<div className="space-y-6">
|
|
548
|
+
{isLoadingColumns ? (
|
|
549
|
+
<div className="flex flex-col items-center justify-center py-8">
|
|
550
|
+
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mb-3"></div>
|
|
551
|
+
<p className="text-sm text-gray-600">Loading columns...</p>
|
|
552
|
+
</div>
|
|
553
|
+
) : availableColumns.length === 0 ? (
|
|
554
|
+
<div className="bg-yellow-50 border border-yellow-200 rounded-lg p-4">
|
|
555
|
+
<p className="text-sm text-yellow-800">No columns available. Please go back and check your connection.</p>
|
|
556
|
+
</div>
|
|
557
|
+
) : (
|
|
558
|
+
<>
|
|
559
|
+
<div>
|
|
560
|
+
<p className="text-sm text-gray-600 mb-2">
|
|
561
|
+
Select which columns to use for <strong>Embeddings</strong>, <strong>LLM processing</strong>, and <strong>ChromaDB storage</strong>.
|
|
562
|
+
</p>
|
|
563
|
+
<p className="text-xs text-gray-500 mb-4">
|
|
564
|
+
Found {availableColumns.length} column{availableColumns.length !== 1 ? 's' : ''} in your database.
|
|
565
|
+
</p>
|
|
566
|
+
</div>
|
|
567
|
+
|
|
568
|
+
{/* Embedding Columns */}
|
|
569
|
+
<div>
|
|
570
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
571
|
+
Works with Embeddings
|
|
572
|
+
</label>
|
|
573
|
+
<p className="text-xs text-gray-500 mb-3">Select columns that will be used for embedding generation</p>
|
|
574
|
+
<div className="grid grid-cols-2 gap-2 max-h-40 overflow-y-auto border border-gray-200 rounded-lg p-3 bg-gray-50">
|
|
575
|
+
{availableColumns.length === 0 ? (
|
|
576
|
+
<p className="text-sm text-gray-500 col-span-2 text-center py-2">No columns available</p>
|
|
577
|
+
) : (
|
|
578
|
+
availableColumns.map((column) => (
|
|
579
|
+
<label
|
|
580
|
+
key={`embedding-${column}`}
|
|
581
|
+
className="flex items-center gap-2 cursor-pointer hover:bg-white p-2 rounded transition-colors"
|
|
582
|
+
>
|
|
583
|
+
<input
|
|
584
|
+
type="checkbox"
|
|
585
|
+
checked={columnSelection.embeddingColumns.includes(column)}
|
|
586
|
+
onChange={() => handleColumnToggle(column, 'embeddingColumns')}
|
|
587
|
+
className="rounded border-gray-300 text-blue-600 focus:ring-blue-500"
|
|
588
|
+
/>
|
|
589
|
+
<span className="text-sm text-gray-700">{column}</span>
|
|
590
|
+
</label>
|
|
591
|
+
))
|
|
592
|
+
)}
|
|
593
|
+
</div>
|
|
594
|
+
{columnSelection.embeddingColumns.length > 0 && (
|
|
595
|
+
<p className="text-xs text-green-600 mt-1">
|
|
596
|
+
{columnSelection.embeddingColumns.length} column{columnSelection.embeddingColumns.length !== 1 ? 's' : ''} selected
|
|
597
|
+
</p>
|
|
598
|
+
)}
|
|
599
|
+
</div>
|
|
600
|
+
|
|
601
|
+
{/* LLM Columns */}
|
|
602
|
+
<div>
|
|
603
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
604
|
+
Works with LLM
|
|
605
|
+
</label>
|
|
606
|
+
<p className="text-xs text-gray-500 mb-3">Select columns that will be processed by the LLM</p>
|
|
607
|
+
<div className="grid grid-cols-2 gap-2 max-h-40 overflow-y-auto border border-gray-200 rounded-lg p-3 bg-gray-50">
|
|
608
|
+
{availableColumns.length === 0 ? (
|
|
609
|
+
<p className="text-sm text-gray-500 col-span-2 text-center py-2">No columns available</p>
|
|
610
|
+
) : (
|
|
611
|
+
availableColumns.map((column) => (
|
|
612
|
+
<label
|
|
613
|
+
key={`llm-${column}`}
|
|
614
|
+
className="flex items-center gap-2 cursor-pointer hover:bg-white p-2 rounded transition-colors"
|
|
615
|
+
>
|
|
616
|
+
<input
|
|
617
|
+
type="checkbox"
|
|
618
|
+
checked={columnSelection.llmColumns.includes(column)}
|
|
619
|
+
onChange={() => handleColumnToggle(column, 'llmColumns')}
|
|
620
|
+
className="rounded border-gray-300 text-blue-600 focus:ring-blue-500"
|
|
621
|
+
/>
|
|
622
|
+
<span className="text-sm text-gray-700">{column}</span>
|
|
623
|
+
</label>
|
|
624
|
+
))
|
|
625
|
+
)}
|
|
626
|
+
</div>
|
|
627
|
+
{columnSelection.llmColumns.length > 0 && (
|
|
628
|
+
<p className="text-xs text-green-600 mt-1">
|
|
629
|
+
{columnSelection.llmColumns.length} column{columnSelection.llmColumns.length !== 1 ? 's' : ''} selected
|
|
630
|
+
</p>
|
|
631
|
+
)}
|
|
632
|
+
</div>
|
|
633
|
+
|
|
634
|
+
{/* ChromaDB Columns */}
|
|
635
|
+
<div>
|
|
636
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
637
|
+
Works with ChromaDB
|
|
638
|
+
</label>
|
|
639
|
+
<p className="text-xs text-gray-500 mb-3">Select columns that will be stored in ChromaDB</p>
|
|
640
|
+
<div className="grid grid-cols-2 gap-2 max-h-40 overflow-y-auto border border-gray-200 rounded-lg p-3 bg-gray-50">
|
|
641
|
+
{availableColumns.length === 0 ? (
|
|
642
|
+
<p className="text-sm text-gray-500 col-span-2 text-center py-2">No columns available</p>
|
|
643
|
+
) : (
|
|
644
|
+
availableColumns.map((column) => (
|
|
645
|
+
<label
|
|
646
|
+
key={`chroma-${column}`}
|
|
647
|
+
className="flex items-center gap-2 cursor-pointer hover:bg-white p-2 rounded transition-colors"
|
|
648
|
+
>
|
|
649
|
+
<input
|
|
650
|
+
type="checkbox"
|
|
651
|
+
checked={columnSelection.chromaColumns.includes(column)}
|
|
652
|
+
onChange={() => handleColumnToggle(column, 'chromaColumns')}
|
|
653
|
+
className="rounded border-gray-300 text-blue-600 focus:ring-blue-500"
|
|
654
|
+
/>
|
|
655
|
+
<span className="text-sm text-gray-700">{column}</span>
|
|
656
|
+
</label>
|
|
657
|
+
))
|
|
658
|
+
)}
|
|
659
|
+
</div>
|
|
660
|
+
{columnSelection.chromaColumns.length > 0 && (
|
|
661
|
+
<p className="text-xs text-green-600 mt-1">
|
|
662
|
+
{columnSelection.chromaColumns.length} column{columnSelection.chromaColumns.length !== 1 ? 's' : ''} selected
|
|
663
|
+
</p>
|
|
664
|
+
)}
|
|
665
|
+
</div>
|
|
666
|
+
</>
|
|
667
|
+
)}
|
|
668
|
+
</div>
|
|
669
|
+
)}
|
|
670
|
+
</div>
|
|
671
|
+
|
|
672
|
+
{/* Modal Footer */}
|
|
673
|
+
<div className="px-6 py-4 border-t border-gray-200 flex items-center justify-between">
|
|
674
|
+
<button
|
|
675
|
+
onClick={currentStep === 'columns' ? () => setCurrentStep('connection') : handleClose}
|
|
676
|
+
className="px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-100 rounded-lg transition-colors"
|
|
677
|
+
>
|
|
678
|
+
{currentStep === 'columns' ? 'Back' : 'Cancel'}
|
|
679
|
+
</button>
|
|
680
|
+
<div className="flex gap-3">
|
|
681
|
+
{currentStep === 'connection' ? (
|
|
682
|
+
<button
|
|
683
|
+
onClick={handleConnectAndNext}
|
|
684
|
+
disabled={isConnecting || isLoadingColumns}
|
|
685
|
+
className="px-6 py-2 bg-blue-600 text-white text-sm font-medium rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center gap-2"
|
|
686
|
+
>
|
|
687
|
+
{isConnecting && (
|
|
688
|
+
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
|
|
689
|
+
)}
|
|
690
|
+
{isLoadingColumns ? 'Loading Columns...' : isConnecting ? 'Connecting...' : 'Connect & Next'}
|
|
691
|
+
</button>
|
|
692
|
+
) : (
|
|
693
|
+
<button
|
|
694
|
+
onClick={handleSave}
|
|
695
|
+
disabled={
|
|
696
|
+
columnSelection.embeddingColumns.length === 0 &&
|
|
697
|
+
columnSelection.llmColumns.length === 0 &&
|
|
698
|
+
columnSelection.chromaColumns.length === 0
|
|
699
|
+
}
|
|
700
|
+
className="px-6 py-2 bg-blue-600 text-white text-sm font-medium rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
|
|
701
|
+
>
|
|
702
|
+
Save Configuration
|
|
703
|
+
</button>
|
|
704
|
+
)}
|
|
705
|
+
</div>
|
|
706
|
+
</div>
|
|
707
|
+
</div>
|
|
708
|
+
</div>
|
|
709
|
+
)}
|
|
710
|
+
</>
|
|
711
|
+
);
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
export default AdminSetup;
|