Spaces:
Sleeping
Sleeping
axeronis commited on
Commit ·
b9f9102
1
Parent(s): a9615a7
feat: Add text_content to knowledge files for direct text paste
Browse files
backend/alembic/versions/2025_12_30_text_content.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add text_content to knowledge_files
|
| 2 |
+
|
| 3 |
+
Revision ID: 2025_12_30_text_content
|
| 4 |
+
Revises: 2025_12_30_content_delivery
|
| 5 |
+
Create Date: 2025-12-30 16:00:00.000000
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
from alembic import op
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# revision identifiers, used by Alembic.
|
| 13 |
+
revision = '2025_12_30_text_content'
|
| 14 |
+
down_revision = '2025_12_30_content_delivery'
|
| 15 |
+
branch_labels = None
|
| 16 |
+
depends_on = None
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def upgrade() -> None:
|
| 20 |
+
# Add text_content column to knowledge_files
|
| 21 |
+
op.add_column('knowledge_files', sa.Column('text_content', sa.TEXT(), nullable=True))
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def downgrade() -> None:
|
| 25 |
+
op.drop_column('knowledge_files', 'text_content')
|
backend/app/models/knowledge.py
CHANGED
|
@@ -137,6 +137,7 @@ class KnowledgeFile(SQLModel, table=True):
|
|
| 137 |
external_link: Optional[str] = None # YouTube, Google Drive, etc.
|
| 138 |
thumbnail_url: Optional[str] = None # Preview image
|
| 139 |
description: Optional[str] = Field(default=None, sa_column=Column(TEXT))
|
|
|
|
| 140 |
|
| 141 |
# ===== FLEXIBLE SEND CONDITIONS =====
|
| 142 |
# on_request: when client asks
|
|
|
|
| 137 |
external_link: Optional[str] = None # YouTube, Google Drive, etc.
|
| 138 |
thumbnail_url: Optional[str] = None # Preview image
|
| 139 |
description: Optional[str] = Field(default=None, sa_column=Column(TEXT))
|
| 140 |
+
text_content: Optional[str] = Field(default=None, sa_column=Column(TEXT)) # Direct text paste
|
| 141 |
|
| 142 |
# ===== FLEXIBLE SEND CONDITIONS =====
|
| 143 |
# on_request: when client asks
|
frontend/components/knowledge/KnowledgeFilesManager.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { useState } from 'react'
|
|
| 4 |
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
| 5 |
import { knowledgeApi, uploadApi } from '@/lib/api'
|
| 6 |
import { useToast } from '@/contexts/ToastContext'
|
| 7 |
-
import { Plus, Trash2, Edit2, FileText, Image as ImageIcon, Video, Link as LinkIcon, Loader2, Save, X, Tag, Calendar, GitBranch, Sparkles, Upload } from 'lucide-react'
|
| 8 |
import { motion, AnimatePresence } from 'framer-motion'
|
| 9 |
|
| 10 |
interface KnowledgeFile {
|
|
@@ -26,10 +26,11 @@ interface KnowledgeFile {
|
|
| 26 |
}
|
| 27 |
|
| 28 |
const FILE_TYPES = [
|
| 29 |
-
{ value: '
|
| 30 |
-
{ value: '
|
| 31 |
-
{ value: '
|
| 32 |
-
{ value: '
|
|
|
|
| 33 |
]
|
| 34 |
|
| 35 |
const SEND_CONDITIONS = [
|
|
@@ -50,11 +51,12 @@ export function KnowledgeFilesManager() {
|
|
| 50 |
const [uploading, setUploading] = useState(false)
|
| 51 |
const [formData, setFormData] = useState({
|
| 52 |
name: '',
|
| 53 |
-
file_type: '
|
| 54 |
file_url: '',
|
| 55 |
external_link: '',
|
| 56 |
thumbnail_url: '',
|
| 57 |
description: '',
|
|
|
|
| 58 |
send_condition: 'on_request',
|
| 59 |
trigger_day: undefined as number | undefined,
|
| 60 |
trigger_stage_id: '',
|
|
@@ -102,11 +104,12 @@ export function KnowledgeFilesManager() {
|
|
| 102 |
const resetForm = () => {
|
| 103 |
setFormData({
|
| 104 |
name: '',
|
| 105 |
-
file_type: '
|
| 106 |
file_url: '',
|
| 107 |
external_link: '',
|
| 108 |
thumbnail_url: '',
|
| 109 |
description: '',
|
|
|
|
| 110 |
send_condition: 'on_request',
|
| 111 |
trigger_day: undefined,
|
| 112 |
trigger_stage_id: '',
|
|
@@ -128,6 +131,7 @@ export function KnowledgeFilesManager() {
|
|
| 128 |
external_link: file.external_link || '',
|
| 129 |
thumbnail_url: file.thumbnail_url || '',
|
| 130 |
description: file.description || '',
|
|
|
|
| 131 |
send_condition: file.send_condition,
|
| 132 |
trigger_day: file.trigger_day,
|
| 133 |
trigger_stage_id: file.trigger_stage_id || '',
|
|
@@ -289,6 +293,29 @@ export function KnowledgeFilesManager() {
|
|
| 289 |
</div>
|
| 290 |
</div>
|
| 291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
{/* Document - Upload or URL */}
|
| 293 |
{formData.file_type === 'document' && (
|
| 294 |
<div>
|
|
|
|
| 4 |
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
| 5 |
import { knowledgeApi, uploadApi } from '@/lib/api'
|
| 6 |
import { useToast } from '@/contexts/ToastContext'
|
| 7 |
+
import { Plus, Trash2, Edit2, FileText, Image as ImageIcon, Video, Link as LinkIcon, Loader2, Save, X, Tag, Calendar, GitBranch, Sparkles, Upload, Type } from 'lucide-react'
|
| 8 |
import { motion, AnimatePresence } from 'framer-motion'
|
| 9 |
|
| 10 |
interface KnowledgeFile {
|
|
|
|
| 26 |
}
|
| 27 |
|
| 28 |
const FILE_TYPES = [
|
| 29 |
+
{ value: 'text', label: 'Текст', icon: Type, desc: 'Вставьте текст напрямую' },
|
| 30 |
+
{ value: 'document', label: 'Документ', icon: FileText, desc: 'PDF, TXT, DOCX' },
|
| 31 |
+
{ value: 'image', label: 'Изображение', icon: ImageIcon, desc: 'Фото, схемы' },
|
| 32 |
+
{ value: 'video', label: 'Видео', icon: Video, desc: 'YouTube, Vimeo' },
|
| 33 |
+
{ value: 'link', label: 'Ссылка', icon: LinkIcon, desc: 'Внешняя ссылка' }
|
| 34 |
]
|
| 35 |
|
| 36 |
const SEND_CONDITIONS = [
|
|
|
|
| 51 |
const [uploading, setUploading] = useState(false)
|
| 52 |
const [formData, setFormData] = useState({
|
| 53 |
name: '',
|
| 54 |
+
file_type: 'text',
|
| 55 |
file_url: '',
|
| 56 |
external_link: '',
|
| 57 |
thumbnail_url: '',
|
| 58 |
description: '',
|
| 59 |
+
text_content: '',
|
| 60 |
send_condition: 'on_request',
|
| 61 |
trigger_day: undefined as number | undefined,
|
| 62 |
trigger_stage_id: '',
|
|
|
|
| 104 |
const resetForm = () => {
|
| 105 |
setFormData({
|
| 106 |
name: '',
|
| 107 |
+
file_type: 'text',
|
| 108 |
file_url: '',
|
| 109 |
external_link: '',
|
| 110 |
thumbnail_url: '',
|
| 111 |
description: '',
|
| 112 |
+
text_content: '',
|
| 113 |
send_condition: 'on_request',
|
| 114 |
trigger_day: undefined,
|
| 115 |
trigger_stage_id: '',
|
|
|
|
| 131 |
external_link: file.external_link || '',
|
| 132 |
thumbnail_url: file.thumbnail_url || '',
|
| 133 |
description: file.description || '',
|
| 134 |
+
text_content: (file as any).text_content || '',
|
| 135 |
send_condition: file.send_condition,
|
| 136 |
trigger_day: file.trigger_day,
|
| 137 |
trigger_stage_id: file.trigger_stage_id || '',
|
|
|
|
| 293 |
</div>
|
| 294 |
</div>
|
| 295 |
|
| 296 |
+
{/* Text - Direct paste */}
|
| 297 |
+
{formData.file_type === 'text' && (
|
| 298 |
+
<div>
|
| 299 |
+
<label className="text-sm font-medium text-slate-400 mb-2 block">Вставьте текст</label>
|
| 300 |
+
<textarea
|
| 301 |
+
value={formData.text_content}
|
| 302 |
+
onChange={e => setFormData({ ...formData, text_content: e.target.value })}
|
| 303 |
+
placeholder="Скопируйте и вставьте текст сюда...
|
| 304 |
+
|
| 305 |
+
Поддерживаются:
|
| 306 |
+
• FAQ и ответы на вопросы
|
| 307 |
+
• Описания услуг/продуктов
|
| 308 |
+
• Инструкции для клиентов
|
| 309 |
+
• Любая текстовая информация"
|
| 310 |
+
rows={8}
|
| 311 |
+
className="w-full px-3 py-2 bg-white/5 border border-white/10 rounded-lg text-white resize-none text-sm"
|
| 312 |
+
/>
|
| 313 |
+
<p className="text-[11px] text-slate-500 mt-1">
|
| 314 |
+
AI будет использовать этот текст для ответов клиентам
|
| 315 |
+
</p>
|
| 316 |
+
</div>
|
| 317 |
+
)}
|
| 318 |
+
|
| 319 |
{/* Document - Upload or URL */}
|
| 320 |
{formData.file_type === 'document' && (
|
| 321 |
<div>
|