@nextsparkjs/theme-default 0.1.0-beta.1
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/about/business.md +49 -0
- package/about/features.json +302 -0
- package/about/team.md +79 -0
- package/api/ai/chat/stream/route.ts +212 -0
- package/api/ai/orchestrator/route.ts +226 -0
- package/api/ai/single-agent/route.ts +291 -0
- package/api/ai/usage/route.ts +122 -0
- package/blocks/benefits/component.tsx +100 -0
- package/blocks/benefits/config.ts +11 -0
- package/blocks/benefits/examples.ts +85 -0
- package/blocks/benefits/fields.ts +156 -0
- package/blocks/benefits/schema.ts +33 -0
- package/blocks/cta-section/component.tsx +100 -0
- package/blocks/cta-section/config.ts +11 -0
- package/blocks/cta-section/examples.ts +41 -0
- package/blocks/cta-section/fields.ts +89 -0
- package/blocks/cta-section/index.ts +6 -0
- package/blocks/cta-section/schema.ts +32 -0
- package/blocks/cta-section/thumbnail.png +1 -0
- package/blocks/faq-accordion/component.tsx +156 -0
- package/blocks/faq-accordion/config.ts +11 -0
- package/blocks/faq-accordion/examples.ts +77 -0
- package/blocks/faq-accordion/fields.ts +119 -0
- package/blocks/faq-accordion/index.ts +6 -0
- package/blocks/faq-accordion/schema.ts +45 -0
- package/blocks/features-grid/component.tsx +112 -0
- package/blocks/features-grid/config.ts +11 -0
- package/blocks/features-grid/examples.ts +63 -0
- package/blocks/features-grid/fields.ts +97 -0
- package/blocks/features-grid/index.ts +6 -0
- package/blocks/features-grid/schema.ts +40 -0
- package/blocks/features-grid/thumbnail.png +1 -0
- package/blocks/hero/component.tsx +100 -0
- package/blocks/hero/config.ts +11 -0
- package/blocks/hero/examples.ts +35 -0
- package/blocks/hero/fields.ts +60 -0
- package/blocks/hero/index.ts +6 -0
- package/blocks/hero/schema.ts +32 -0
- package/blocks/hero/thumbnail.png +1 -0
- package/blocks/hero/thumbnail.png.txt +6 -0
- package/blocks/hero-with-form/component.tsx +232 -0
- package/blocks/hero-with-form/config.ts +11 -0
- package/blocks/hero-with-form/examples.ts +16 -0
- package/blocks/hero-with-form/fields.ts +207 -0
- package/blocks/hero-with-form/index.ts +6 -0
- package/blocks/hero-with-form/schema.ts +54 -0
- package/blocks/jumbotron/component.tsx +136 -0
- package/blocks/jumbotron/config.ts +11 -0
- package/blocks/jumbotron/examples.ts +36 -0
- package/blocks/jumbotron/fields.ts +202 -0
- package/blocks/jumbotron/index.ts +6 -0
- package/blocks/jumbotron/schema.ts +55 -0
- package/blocks/logo-cloud/component.tsx +154 -0
- package/blocks/logo-cloud/config.ts +11 -0
- package/blocks/logo-cloud/examples.ts +34 -0
- package/blocks/logo-cloud/fields.ts +133 -0
- package/blocks/logo-cloud/index.ts +6 -0
- package/blocks/logo-cloud/schema.ts +46 -0
- package/blocks/post-content/component.tsx +197 -0
- package/blocks/post-content/config.ts +11 -0
- package/blocks/post-content/examples.ts +33 -0
- package/blocks/post-content/fields.ts +165 -0
- package/blocks/post-content/index.ts +4 -0
- package/blocks/post-content/schema.ts +46 -0
- package/blocks/pricing-table/component.tsx +154 -0
- package/blocks/pricing-table/config.ts +11 -0
- package/blocks/pricing-table/examples.ts +96 -0
- package/blocks/pricing-table/fields.ts +161 -0
- package/blocks/pricing-table/index.ts +4 -0
- package/blocks/pricing-table/schema.ts +50 -0
- package/blocks/split-content/component.tsx +135 -0
- package/blocks/split-content/config.ts +11 -0
- package/blocks/split-content/examples.ts +38 -0
- package/blocks/split-content/fields.ts +198 -0
- package/blocks/split-content/index.ts +6 -0
- package/blocks/split-content/schema.ts +67 -0
- package/blocks/stats-counter/component.tsx +124 -0
- package/blocks/stats-counter/config.ts +11 -0
- package/blocks/stats-counter/examples.ts +61 -0
- package/blocks/stats-counter/fields.ts +134 -0
- package/blocks/stats-counter/index.ts +6 -0
- package/blocks/stats-counter/schema.ts +47 -0
- package/blocks/testimonials/component.tsx +114 -0
- package/blocks/testimonials/config.ts +11 -0
- package/blocks/testimonials/examples.ts +65 -0
- package/blocks/testimonials/fields.ts +105 -0
- package/blocks/testimonials/index.ts +6 -0
- package/blocks/testimonials/schema.ts +41 -0
- package/blocks/testimonials/thumbnail.png +1 -0
- package/blocks/text-content/component.tsx +97 -0
- package/blocks/text-content/config.ts +11 -0
- package/blocks/text-content/examples.ts +30 -0
- package/blocks/text-content/fields.ts +88 -0
- package/blocks/text-content/index.ts +6 -0
- package/blocks/text-content/schema.ts +30 -0
- package/blocks/text-content/thumbnail.png +1 -0
- package/blocks/timeline/component.tsx +267 -0
- package/blocks/timeline/config.ts +11 -0
- package/blocks/timeline/examples.ts +68 -0
- package/blocks/timeline/fields.ts +147 -0
- package/blocks/timeline/index.ts +6 -0
- package/blocks/timeline/schema.ts +49 -0
- package/blocks/video-hero/component.tsx +270 -0
- package/blocks/video-hero/config.ts +11 -0
- package/blocks/video-hero/examples.ts +24 -0
- package/blocks/video-hero/fields.ts +98 -0
- package/blocks/video-hero/index.ts +6 -0
- package/blocks/video-hero/schema.ts +39 -0
- package/components/ai-chat/ChatPanel.tsx +575 -0
- package/components/ai-chat/ConversationItem.tsx +266 -0
- package/components/ai-chat/ConversationSidebar.tsx +99 -0
- package/components/ai-chat/MarkdownRenderer.tsx +15 -0
- package/components/ai-chat/Message.tsx +42 -0
- package/components/ai-chat/MessageInput.tsx +49 -0
- package/components/ai-chat/MessageList.tsx +46 -0
- package/components/ai-chat/TypingIndicator.tsx +11 -0
- package/config/app.config.ts +367 -0
- package/config/billing.config.ts +349 -0
- package/config/dashboard.config.ts +506 -0
- package/config/dev.config.ts +104 -0
- package/config/features.config.ts +203 -0
- package/config/flows.config.ts +129 -0
- package/config/permissions.config.ts +245 -0
- package/config/theme.config.ts +74 -0
- package/docs/01-overview/01-introduction.md +335 -0
- package/docs/01-overview/02-customization.md +671 -0
- package/docs/02-features/01-components.md +155 -0
- package/docs/02-features/02-styling.md +139 -0
- package/docs/02-features/03-tasks-entity.md +407 -0
- package/docs/03-ai/01-overview.md +211 -0
- package/docs/03-ai/02-customization.md +436 -0
- package/entities/customers/customers.config.ts +75 -0
- package/entities/customers/customers.fields.ts +165 -0
- package/entities/customers/customers.service.ts +516 -0
- package/entities/customers/customers.types.ts +83 -0
- package/entities/customers/messages/en.json +66 -0
- package/entities/customers/messages/es.json +66 -0
- package/entities/customers/migrations/001_customers_table.sql +102 -0
- package/entities/customers/migrations/002_customers_metas.sql +92 -0
- package/entities/pages/messages/en.json +41 -0
- package/entities/pages/messages/es.json +41 -0
- package/entities/pages/migrations/001_pages_table.sql +112 -0
- package/entities/pages/migrations/002_pages_metas.sql +56 -0
- package/entities/pages/migrations/003_add_status.sql +50 -0
- package/entities/pages/pages-management.service.ts +610 -0
- package/entities/pages/pages.config.ts +94 -0
- package/entities/pages/pages.fields.ts +101 -0
- package/entities/pages/pages.service.ts +290 -0
- package/entities/pages/pages.types.ts +124 -0
- package/entities/posts/components/post-header.tsx +97 -0
- package/entities/posts/messages/en.json +55 -0
- package/entities/posts/messages/es.json +55 -0
- package/entities/posts/migrations/001_posts_table.sql +115 -0
- package/entities/posts/migrations/003_add_status.sql +44 -0
- package/entities/posts/migrations/004_entity_taxonomy_relations.sql +129 -0
- package/entities/posts/migrations/006_posts_metas.sql +56 -0
- package/entities/posts/posts.config.ts +101 -0
- package/entities/posts/posts.fields.ts +116 -0
- package/entities/posts/posts.service.ts +376 -0
- package/entities/posts/posts.types.ts +74 -0
- package/entities/tasks/messages/en.json +204 -0
- package/entities/tasks/messages/es.json +204 -0
- package/entities/tasks/migrations/001_tasks_table.sql +105 -0
- package/entities/tasks/migrations/002_task_metas.sql +85 -0
- package/entities/tasks/migrations/sample_data.json +77 -0
- package/entities/tasks/tasks.config.ts +79 -0
- package/entities/tasks/tasks.fields.ts +196 -0
- package/entities/tasks/tasks.service.ts +541 -0
- package/entities/tasks/tasks.types.ts +56 -0
- package/lib/hooks/useAiChat.ts +114 -0
- package/lib/hooks/useConversations.ts +376 -0
- package/lib/hooks/useOrchestratorChat.ts +122 -0
- package/lib/hooks/usePersistentChat.ts +315 -0
- package/lib/hooks/useStreamingChat.ts +127 -0
- package/lib/hooks/useTokenUsage.ts +63 -0
- package/lib/langchain/agents/customer-assistant.md +69 -0
- package/lib/langchain/agents/index.ts +61 -0
- package/lib/langchain/agents/orchestrator.md +59 -0
- package/lib/langchain/agents/page-assistant.md +85 -0
- package/lib/langchain/agents/single-agent.md +46 -0
- package/lib/langchain/agents/task-assistant.md +55 -0
- package/lib/langchain/config.ts +45 -0
- package/lib/langchain/handlers/customer-handler.ts +338 -0
- package/lib/langchain/handlers/page-handler.ts +232 -0
- package/lib/langchain/handlers/task-handler.ts +323 -0
- package/lib/langchain/langchain.config.ts +223 -0
- package/lib/langchain/observability.config.ts +30 -0
- package/lib/langchain/orchestrator.ts +562 -0
- package/lib/langchain/tools/customers.ts +176 -0
- package/lib/langchain/tools/index.ts +10 -0
- package/lib/langchain/tools/orchestrator.ts +92 -0
- package/lib/langchain/tools/pages.ts +289 -0
- package/lib/langchain/tools/tasks.ts +167 -0
- package/lib/scheduled-actions/billing.ts +149 -0
- package/lib/scheduled-actions/index.ts +170 -0
- package/lib/scheduled-actions/webhook.ts +231 -0
- package/lib/selectors.ts +197 -0
- package/messages/de/admin.json +219 -0
- package/messages/de/aiUsage.json +36 -0
- package/messages/de/buttons.json +19 -0
- package/messages/de/categories.json +35 -0
- package/messages/de/common.json +16 -0
- package/messages/de/dev.json +101 -0
- package/messages/de/docs.json +27 -0
- package/messages/de/entities.json +7 -0
- package/messages/de/features.json +119 -0
- package/messages/de/footer.json +22 -0
- package/messages/de/home.json +57 -0
- package/messages/de/index.ts +39 -0
- package/messages/de/mobileNav.json +13 -0
- package/messages/de/navigation.json +8 -0
- package/messages/de/observability.json +74 -0
- package/messages/de/posts.json +54 -0
- package/messages/de/pricing.json +102 -0
- package/messages/de/support.json +9 -0
- package/messages/de/teams.json +8 -0
- package/messages/en/admin.json +219 -0
- package/messages/en/aiUsage.json +36 -0
- package/messages/en/buttons.json +19 -0
- package/messages/en/categories.json +35 -0
- package/messages/en/common.json +16 -0
- package/messages/en/dev.json +106 -0
- package/messages/en/docs.json +27 -0
- package/messages/en/entities.json +7 -0
- package/messages/en/features.json +119 -0
- package/messages/en/footer.json +22 -0
- package/messages/en/home.json +57 -0
- package/messages/en/index.ts +39 -0
- package/messages/en/mobileNav.json +13 -0
- package/messages/en/navigation.json +8 -0
- package/messages/en/observability.json +74 -0
- package/messages/en/posts.json +54 -0
- package/messages/en/pricing.json +102 -0
- package/messages/en/support.json +9 -0
- package/messages/en/teams.json +8 -0
- package/messages/es/admin.json +219 -0
- package/messages/es/aiUsage.json +36 -0
- package/messages/es/buttons.json +19 -0
- package/messages/es/categories.json +35 -0
- package/messages/es/common.json +16 -0
- package/messages/es/dev.json +101 -0
- package/messages/es/docs.json +27 -0
- package/messages/es/entities.json +7 -0
- package/messages/es/features.json +119 -0
- package/messages/es/footer.json +22 -0
- package/messages/es/home.json +57 -0
- package/messages/es/index.ts +39 -0
- package/messages/es/mobileNav.json +13 -0
- package/messages/es/navigation.json +8 -0
- package/messages/es/observability.json +74 -0
- package/messages/es/posts.json +54 -0
- package/messages/es/pricing.json +102 -0
- package/messages/es/support.json +9 -0
- package/messages/es/teams.json +8 -0
- package/messages/fr/admin.json +219 -0
- package/messages/fr/aiUsage.json +36 -0
- package/messages/fr/buttons.json +19 -0
- package/messages/fr/categories.json +35 -0
- package/messages/fr/common.json +16 -0
- package/messages/fr/dev.json +101 -0
- package/messages/fr/docs.json +27 -0
- package/messages/fr/entities.json +7 -0
- package/messages/fr/features.json +119 -0
- package/messages/fr/footer.json +22 -0
- package/messages/fr/home.json +57 -0
- package/messages/fr/index.ts +39 -0
- package/messages/fr/mobileNav.json +13 -0
- package/messages/fr/navigation.json +8 -0
- package/messages/fr/observability.json +74 -0
- package/messages/fr/posts.json +54 -0
- package/messages/fr/pricing.json +102 -0
- package/messages/fr/support.json +9 -0
- package/messages/fr/teams.json +8 -0
- package/messages/it/admin.json +219 -0
- package/messages/it/aiUsage.json +36 -0
- package/messages/it/buttons.json +19 -0
- package/messages/it/categories.json +35 -0
- package/messages/it/common.json +16 -0
- package/messages/it/dev.json +101 -0
- package/messages/it/docs.json +27 -0
- package/messages/it/entities.json +7 -0
- package/messages/it/features.json +119 -0
- package/messages/it/footer.json +22 -0
- package/messages/it/home.json +57 -0
- package/messages/it/index.ts +39 -0
- package/messages/it/mobileNav.json +13 -0
- package/messages/it/navigation.json +8 -0
- package/messages/it/observability.json +74 -0
- package/messages/it/posts.json +54 -0
- package/messages/it/pricing.json +102 -0
- package/messages/it/support.json +9 -0
- package/messages/it/teams.json +8 -0
- package/messages/pt/admin.json +219 -0
- package/messages/pt/aiUsage.json +36 -0
- package/messages/pt/buttons.json +19 -0
- package/messages/pt/categories.json +35 -0
- package/messages/pt/common.json +16 -0
- package/messages/pt/dev.json +101 -0
- package/messages/pt/docs.json +27 -0
- package/messages/pt/entities.json +7 -0
- package/messages/pt/features.json +119 -0
- package/messages/pt/footer.json +22 -0
- package/messages/pt/home.json +57 -0
- package/messages/pt/index.ts +39 -0
- package/messages/pt/mobileNav.json +13 -0
- package/messages/pt/navigation.json +8 -0
- package/messages/pt/observability.json +74 -0
- package/messages/pt/posts.json +54 -0
- package/messages/pt/pricing.json +102 -0
- package/messages/pt/support.json +9 -0
- package/messages/pt/teams.json +8 -0
- package/migrations/089_add_editor_team_role.sql +39 -0
- package/migrations/090_demo_users_teams.sql +540 -0
- package/migrations/091_greek_teams_billing.sql +523 -0
- package/migrations/092_billing_sample_data.sql +774 -0
- package/migrations/093_pages_sample_data.sql +1158 -0
- package/migrations/094_posts_sample_data.sql +278 -0
- package/migrations/095_tasks_sample_data.sql +440 -0
- package/migrations/096_customers_sample_data.sql +358 -0
- package/migrations/097_scheduled_actions_sample_data.sql +111 -0
- package/package.json +22 -0
- package/public/docs/desktop-layout-example.png +0 -0
- package/styles/components.css +11 -0
- package/styles/globals.css +179 -0
- package/templates/(public)/blog/[slug]/page.tsx +65 -0
- package/templates/(public)/layout.tsx +25 -0
- package/templates/(public)/page.tsx +200 -0
- package/templates/(public)/support/page.tsx +321 -0
- package/templates/dashboard/(main)/agent-multi/page.tsx +63 -0
- package/templates/dashboard/(main)/agent-single/page.tsx +142 -0
- package/templates/dashboard/(main)/settings/ai-usage/page.tsx +157 -0
- package/templates/superadmin/ai-observability/[traceId]/page.tsx +27 -0
- package/templates/superadmin/ai-observability/page.tsx +17 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react'
|
|
4
|
+
import { MessageSquare, Pin, MoreVertical, Pencil, Trash2, PinOff } from 'lucide-react'
|
|
5
|
+
import { cn } from '@nextsparkjs/core/lib/utils'
|
|
6
|
+
import { Button } from '@nextsparkjs/core/components/ui/button'
|
|
7
|
+
import {
|
|
8
|
+
DropdownMenu,
|
|
9
|
+
DropdownMenuContent,
|
|
10
|
+
DropdownMenuItem,
|
|
11
|
+
DropdownMenuSeparator,
|
|
12
|
+
DropdownMenuTrigger,
|
|
13
|
+
} from '@nextsparkjs/core/components/ui/dropdown-menu'
|
|
14
|
+
import {
|
|
15
|
+
Dialog,
|
|
16
|
+
DialogContent,
|
|
17
|
+
DialogDescription,
|
|
18
|
+
DialogFooter,
|
|
19
|
+
DialogHeader,
|
|
20
|
+
DialogTitle,
|
|
21
|
+
} from '@nextsparkjs/core/components/ui/dialog'
|
|
22
|
+
import { Input } from '@nextsparkjs/core/components/ui/input'
|
|
23
|
+
import type { ConversationInfo } from '../../lib/hooks/useConversations'
|
|
24
|
+
|
|
25
|
+
interface ConversationItemProps {
|
|
26
|
+
conversation: ConversationInfo
|
|
27
|
+
isActive: boolean
|
|
28
|
+
onClick: () => void
|
|
29
|
+
onRename: (name: string) => Promise<void>
|
|
30
|
+
onDelete: () => Promise<void>
|
|
31
|
+
onTogglePin: () => Promise<void>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Format relative time (e.g., "2h ago", "3d ago")
|
|
36
|
+
*/
|
|
37
|
+
function formatRelativeTime(dateString: string): string {
|
|
38
|
+
const date = new Date(dateString)
|
|
39
|
+
const now = new Date()
|
|
40
|
+
const diffMs = now.getTime() - date.getTime()
|
|
41
|
+
const diffSecs = Math.floor(diffMs / 1000)
|
|
42
|
+
const diffMins = Math.floor(diffSecs / 60)
|
|
43
|
+
const diffHours = Math.floor(diffMins / 60)
|
|
44
|
+
const diffDays = Math.floor(diffHours / 24)
|
|
45
|
+
|
|
46
|
+
if (diffDays > 0) return `${diffDays}d ago`
|
|
47
|
+
if (diffHours > 0) return `${diffHours}h ago`
|
|
48
|
+
if (diffMins > 0) return `${diffMins}m ago`
|
|
49
|
+
return 'Just now'
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get display name for a conversation
|
|
54
|
+
*/
|
|
55
|
+
function getDisplayName(conversation: ConversationInfo): string {
|
|
56
|
+
if (conversation.name) return conversation.name
|
|
57
|
+
if (conversation.firstMessage) {
|
|
58
|
+
return conversation.firstMessage.slice(0, 40) + (conversation.firstMessage.length > 40 ? '...' : '')
|
|
59
|
+
}
|
|
60
|
+
return 'New conversation'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function ConversationItem({
|
|
64
|
+
conversation,
|
|
65
|
+
isActive,
|
|
66
|
+
onClick,
|
|
67
|
+
onRename,
|
|
68
|
+
onDelete,
|
|
69
|
+
onTogglePin,
|
|
70
|
+
}: ConversationItemProps) {
|
|
71
|
+
const [isRenameDialogOpen, setIsRenameDialogOpen] = useState(false)
|
|
72
|
+
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false)
|
|
73
|
+
const [newName, setNewName] = useState(conversation.name || '')
|
|
74
|
+
const [isLoading, setIsLoading] = useState(false)
|
|
75
|
+
|
|
76
|
+
const displayName = getDisplayName(conversation)
|
|
77
|
+
|
|
78
|
+
const handleRename = async () => {
|
|
79
|
+
if (!newName.trim()) return
|
|
80
|
+
setIsLoading(true)
|
|
81
|
+
try {
|
|
82
|
+
await onRename(newName.trim())
|
|
83
|
+
setIsRenameDialogOpen(false)
|
|
84
|
+
} finally {
|
|
85
|
+
setIsLoading(false)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const handleDelete = async () => {
|
|
90
|
+
setIsLoading(true)
|
|
91
|
+
try {
|
|
92
|
+
await onDelete()
|
|
93
|
+
setIsDeleteDialogOpen(false)
|
|
94
|
+
} finally {
|
|
95
|
+
setIsLoading(false)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const handleTogglePin = async () => {
|
|
100
|
+
setIsLoading(true)
|
|
101
|
+
try {
|
|
102
|
+
await onTogglePin()
|
|
103
|
+
} finally {
|
|
104
|
+
setIsLoading(false)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<>
|
|
110
|
+
<div
|
|
111
|
+
data-cy="conversation-item"
|
|
112
|
+
className={cn(
|
|
113
|
+
'group flex items-center gap-2 px-3 py-2 rounded-md cursor-pointer transition-colors',
|
|
114
|
+
isActive
|
|
115
|
+
? 'bg-accent text-accent-foreground'
|
|
116
|
+
: 'hover:bg-muted/50'
|
|
117
|
+
)}
|
|
118
|
+
onClick={onClick}
|
|
119
|
+
>
|
|
120
|
+
{/* Pin indicator */}
|
|
121
|
+
{conversation.isPinned && (
|
|
122
|
+
<Pin className="h-3 w-3 text-muted-foreground flex-shrink-0" />
|
|
123
|
+
)}
|
|
124
|
+
|
|
125
|
+
{/* Icon */}
|
|
126
|
+
<MessageSquare className="h-4 w-4 text-muted-foreground flex-shrink-0" />
|
|
127
|
+
|
|
128
|
+
{/* Content */}
|
|
129
|
+
<div className="flex-1 min-w-0">
|
|
130
|
+
<p className="text-sm font-medium truncate">{displayName}</p>
|
|
131
|
+
<p className="text-xs text-muted-foreground">
|
|
132
|
+
{formatRelativeTime(conversation.updatedAt)}
|
|
133
|
+
{conversation.messageCount > 0 && (
|
|
134
|
+
<span> · {conversation.messageCount} msgs</span>
|
|
135
|
+
)}
|
|
136
|
+
</p>
|
|
137
|
+
</div>
|
|
138
|
+
|
|
139
|
+
{/* Actions dropdown */}
|
|
140
|
+
<DropdownMenu>
|
|
141
|
+
<DropdownMenuTrigger asChild>
|
|
142
|
+
<Button
|
|
143
|
+
variant="ghost"
|
|
144
|
+
size="icon"
|
|
145
|
+
className="h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity"
|
|
146
|
+
onClick={(e) => e.stopPropagation()}
|
|
147
|
+
data-cy="conversation-menu"
|
|
148
|
+
>
|
|
149
|
+
<MoreVertical className="h-4 w-4" />
|
|
150
|
+
</Button>
|
|
151
|
+
</DropdownMenuTrigger>
|
|
152
|
+
<DropdownMenuContent align="end">
|
|
153
|
+
<DropdownMenuItem
|
|
154
|
+
onClick={(e: React.MouseEvent) => {
|
|
155
|
+
e.stopPropagation()
|
|
156
|
+
setNewName(conversation.name || displayName)
|
|
157
|
+
setIsRenameDialogOpen(true)
|
|
158
|
+
}}
|
|
159
|
+
data-cy="rename-conversation"
|
|
160
|
+
>
|
|
161
|
+
<Pencil className="h-4 w-4 mr-2" />
|
|
162
|
+
Rename
|
|
163
|
+
</DropdownMenuItem>
|
|
164
|
+
<DropdownMenuItem
|
|
165
|
+
onClick={(e: React.MouseEvent) => {
|
|
166
|
+
e.stopPropagation()
|
|
167
|
+
handleTogglePin()
|
|
168
|
+
}}
|
|
169
|
+
data-cy="toggle-pin-conversation"
|
|
170
|
+
>
|
|
171
|
+
{conversation.isPinned ? (
|
|
172
|
+
<>
|
|
173
|
+
<PinOff className="h-4 w-4 mr-2" />
|
|
174
|
+
Unpin
|
|
175
|
+
</>
|
|
176
|
+
) : (
|
|
177
|
+
<>
|
|
178
|
+
<Pin className="h-4 w-4 mr-2" />
|
|
179
|
+
Pin
|
|
180
|
+
</>
|
|
181
|
+
)}
|
|
182
|
+
</DropdownMenuItem>
|
|
183
|
+
<DropdownMenuSeparator />
|
|
184
|
+
<DropdownMenuItem
|
|
185
|
+
onClick={(e: React.MouseEvent) => {
|
|
186
|
+
e.stopPropagation()
|
|
187
|
+
setIsDeleteDialogOpen(true)
|
|
188
|
+
}}
|
|
189
|
+
className="text-destructive"
|
|
190
|
+
data-cy="delete-conversation"
|
|
191
|
+
>
|
|
192
|
+
<Trash2 className="h-4 w-4 mr-2" />
|
|
193
|
+
Delete
|
|
194
|
+
</DropdownMenuItem>
|
|
195
|
+
</DropdownMenuContent>
|
|
196
|
+
</DropdownMenu>
|
|
197
|
+
</div>
|
|
198
|
+
|
|
199
|
+
{/* Rename Dialog */}
|
|
200
|
+
<Dialog open={isRenameDialogOpen} onOpenChange={setIsRenameDialogOpen}>
|
|
201
|
+
<DialogContent>
|
|
202
|
+
<DialogHeader>
|
|
203
|
+
<DialogTitle>Rename conversation</DialogTitle>
|
|
204
|
+
<DialogDescription>
|
|
205
|
+
Enter a new name for this conversation.
|
|
206
|
+
</DialogDescription>
|
|
207
|
+
</DialogHeader>
|
|
208
|
+
<Input
|
|
209
|
+
value={newName}
|
|
210
|
+
onChange={(e) => setNewName(e.target.value)}
|
|
211
|
+
placeholder="Conversation name"
|
|
212
|
+
onKeyDown={(e) => {
|
|
213
|
+
if (e.key === 'Enter') {
|
|
214
|
+
handleRename()
|
|
215
|
+
}
|
|
216
|
+
}}
|
|
217
|
+
data-cy="rename-input"
|
|
218
|
+
/>
|
|
219
|
+
<DialogFooter>
|
|
220
|
+
<Button
|
|
221
|
+
variant="outline"
|
|
222
|
+
onClick={() => setIsRenameDialogOpen(false)}
|
|
223
|
+
>
|
|
224
|
+
Cancel
|
|
225
|
+
</Button>
|
|
226
|
+
<Button
|
|
227
|
+
onClick={handleRename}
|
|
228
|
+
disabled={!newName.trim() || isLoading}
|
|
229
|
+
data-cy="confirm-rename"
|
|
230
|
+
>
|
|
231
|
+
{isLoading ? 'Saving...' : 'Save'}
|
|
232
|
+
</Button>
|
|
233
|
+
</DialogFooter>
|
|
234
|
+
</DialogContent>
|
|
235
|
+
</Dialog>
|
|
236
|
+
|
|
237
|
+
{/* Delete Confirmation Dialog */}
|
|
238
|
+
<Dialog open={isDeleteDialogOpen} onOpenChange={setIsDeleteDialogOpen}>
|
|
239
|
+
<DialogContent>
|
|
240
|
+
<DialogHeader>
|
|
241
|
+
<DialogTitle>Delete conversation</DialogTitle>
|
|
242
|
+
<DialogDescription>
|
|
243
|
+
Are you sure you want to delete this conversation? This action cannot be undone.
|
|
244
|
+
</DialogDescription>
|
|
245
|
+
</DialogHeader>
|
|
246
|
+
<DialogFooter>
|
|
247
|
+
<Button
|
|
248
|
+
variant="outline"
|
|
249
|
+
onClick={() => setIsDeleteDialogOpen(false)}
|
|
250
|
+
>
|
|
251
|
+
Cancel
|
|
252
|
+
</Button>
|
|
253
|
+
<Button
|
|
254
|
+
variant="destructive"
|
|
255
|
+
onClick={handleDelete}
|
|
256
|
+
disabled={isLoading}
|
|
257
|
+
data-cy="confirm-delete"
|
|
258
|
+
>
|
|
259
|
+
{isLoading ? 'Deleting...' : 'Delete'}
|
|
260
|
+
</Button>
|
|
261
|
+
</DialogFooter>
|
|
262
|
+
</DialogContent>
|
|
263
|
+
</Dialog>
|
|
264
|
+
</>
|
|
265
|
+
)
|
|
266
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Plus, MessageSquarePlus, Loader2 } from 'lucide-react'
|
|
4
|
+
import { Button } from '@nextsparkjs/core/components/ui/button'
|
|
5
|
+
import { ScrollArea } from '@nextsparkjs/core/components/ui/scroll-area'
|
|
6
|
+
import { ConversationItem } from './ConversationItem'
|
|
7
|
+
import type { ConversationInfo } from '../../lib/hooks/useConversations'
|
|
8
|
+
|
|
9
|
+
interface ConversationSidebarProps {
|
|
10
|
+
conversations: ConversationInfo[]
|
|
11
|
+
activeSessionId: string | null
|
|
12
|
+
onSelect: (sessionId: string) => void
|
|
13
|
+
onNew: () => Promise<void>
|
|
14
|
+
onRename: (sessionId: string, name: string) => Promise<void>
|
|
15
|
+
onDelete: (sessionId: string) => Promise<void>
|
|
16
|
+
onTogglePin: (sessionId: string) => Promise<void>
|
|
17
|
+
isLoading: boolean
|
|
18
|
+
isCreating: boolean
|
|
19
|
+
canCreateNew: boolean
|
|
20
|
+
conversationCount: number
|
|
21
|
+
maxConversations: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function ConversationSidebar({
|
|
25
|
+
conversations,
|
|
26
|
+
activeSessionId,
|
|
27
|
+
onSelect,
|
|
28
|
+
onNew,
|
|
29
|
+
onRename,
|
|
30
|
+
onDelete,
|
|
31
|
+
onTogglePin,
|
|
32
|
+
isLoading,
|
|
33
|
+
isCreating,
|
|
34
|
+
canCreateNew,
|
|
35
|
+
conversationCount,
|
|
36
|
+
maxConversations,
|
|
37
|
+
}: ConversationSidebarProps) {
|
|
38
|
+
return (
|
|
39
|
+
<div
|
|
40
|
+
className="flex flex-col h-full border-r bg-muted/30"
|
|
41
|
+
data-cy="conversation-sidebar"
|
|
42
|
+
>
|
|
43
|
+
{/* Header */}
|
|
44
|
+
<div className="p-4 border-b">
|
|
45
|
+
<Button
|
|
46
|
+
onClick={onNew}
|
|
47
|
+
disabled={!canCreateNew || isCreating}
|
|
48
|
+
className="w-full"
|
|
49
|
+
data-cy="new-conversation-button"
|
|
50
|
+
>
|
|
51
|
+
{isCreating ? (
|
|
52
|
+
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
|
53
|
+
) : (
|
|
54
|
+
<Plus className="h-4 w-4 mr-2" />
|
|
55
|
+
)}
|
|
56
|
+
New conversation
|
|
57
|
+
</Button>
|
|
58
|
+
|
|
59
|
+
{/* Count indicator */}
|
|
60
|
+
<p className="text-xs text-muted-foreground text-center mt-2">
|
|
61
|
+
{conversationCount} / {maxConversations} conversations
|
|
62
|
+
</p>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
{/* Conversations List */}
|
|
66
|
+
<ScrollArea className="flex-1">
|
|
67
|
+
<div className="p-2 space-y-1">
|
|
68
|
+
{isLoading ? (
|
|
69
|
+
<div className="flex items-center justify-center py-8">
|
|
70
|
+
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
|
71
|
+
</div>
|
|
72
|
+
) : conversations.length === 0 ? (
|
|
73
|
+
<div className="text-center py-8 px-4">
|
|
74
|
+
<MessageSquarePlus className="h-8 w-8 mx-auto text-muted-foreground mb-2" />
|
|
75
|
+
<p className="text-sm text-muted-foreground">
|
|
76
|
+
No conversations yet.
|
|
77
|
+
</p>
|
|
78
|
+
<p className="text-xs text-muted-foreground mt-1">
|
|
79
|
+
Start a new conversation to begin.
|
|
80
|
+
</p>
|
|
81
|
+
</div>
|
|
82
|
+
) : (
|
|
83
|
+
conversations.map((conversation) => (
|
|
84
|
+
<ConversationItem
|
|
85
|
+
key={conversation.sessionId}
|
|
86
|
+
conversation={conversation}
|
|
87
|
+
isActive={conversation.sessionId === activeSessionId}
|
|
88
|
+
onClick={() => onSelect(conversation.sessionId)}
|
|
89
|
+
onRename={(name) => onRename(conversation.sessionId, name)}
|
|
90
|
+
onDelete={() => onDelete(conversation.sessionId)}
|
|
91
|
+
onTogglePin={() => onTogglePin(conversation.sessionId)}
|
|
92
|
+
/>
|
|
93
|
+
))
|
|
94
|
+
)}
|
|
95
|
+
</div>
|
|
96
|
+
</ScrollArea>
|
|
97
|
+
</div>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import ReactMarkdown from 'react-markdown'
|
|
2
|
+
import { cn } from '@nextsparkjs/core/lib/utils'
|
|
3
|
+
|
|
4
|
+
interface MarkdownRendererProps {
|
|
5
|
+
content: string
|
|
6
|
+
className?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function MarkdownRenderer({ content, className }: MarkdownRendererProps) {
|
|
10
|
+
return (
|
|
11
|
+
<div className={cn('prose prose-sm dark:prose-invert max-w-none', className)}>
|
|
12
|
+
<ReactMarkdown>{content}</ReactMarkdown>
|
|
13
|
+
</div>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { cn } from '@nextsparkjs/core/lib/utils'
|
|
2
|
+
import { Message as MessageType } from '../../lib/hooks/useAiChat'
|
|
3
|
+
import { MarkdownRenderer } from './MarkdownRenderer'
|
|
4
|
+
import { User, Bot } from 'lucide-react'
|
|
5
|
+
import { createCyId } from '@nextsparkjs/core/lib/testing-utils'
|
|
6
|
+
|
|
7
|
+
interface MessageProps {
|
|
8
|
+
message: MessageType
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function Message({ message }: MessageProps) {
|
|
12
|
+
const isUser = message.role === 'user'
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<div
|
|
16
|
+
data-cy={createCyId('ai-chat', `message-${message.role}`)}
|
|
17
|
+
className={cn(
|
|
18
|
+
'flex w-full gap-3 p-4',
|
|
19
|
+
isUser ? 'flex-row-reverse' : 'flex-row'
|
|
20
|
+
)}
|
|
21
|
+
>
|
|
22
|
+
<div
|
|
23
|
+
className={cn(
|
|
24
|
+
'flex h-8 w-8 shrink-0 items-center justify-center rounded-full border',
|
|
25
|
+
isUser ? 'bg-primary text-primary-foreground' : 'bg-muted'
|
|
26
|
+
)}
|
|
27
|
+
>
|
|
28
|
+
{isUser ? <User className="h-4 w-4" /> : <Bot className="h-4 w-4" />}
|
|
29
|
+
</div>
|
|
30
|
+
<div
|
|
31
|
+
className={cn(
|
|
32
|
+
'flex max-w-[80%] flex-col gap-1 rounded-lg px-4 py-2 text-sm',
|
|
33
|
+
isUser
|
|
34
|
+
? 'bg-primary text-primary-foreground'
|
|
35
|
+
: 'bg-muted'
|
|
36
|
+
)}
|
|
37
|
+
>
|
|
38
|
+
<MarkdownRenderer content={message.content} />
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { KeyboardEvent } from 'react'
|
|
2
|
+
import { Button } from '@nextsparkjs/core/components/ui/button'
|
|
3
|
+
import { Textarea } from '@nextsparkjs/core/components/ui/textarea'
|
|
4
|
+
import { Send } from 'lucide-react'
|
|
5
|
+
import { createCyId } from '@nextsparkjs/core/lib/testing-utils'
|
|
6
|
+
|
|
7
|
+
interface MessageInputProps {
|
|
8
|
+
value: string
|
|
9
|
+
onChange: (value: string) => void
|
|
10
|
+
onSend: () => void
|
|
11
|
+
isLoading: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function MessageInput({ value, onChange, onSend, isLoading }: MessageInputProps) {
|
|
15
|
+
const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
16
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
17
|
+
e.preventDefault()
|
|
18
|
+
onSend()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<div className="p-4 border-t bg-background">
|
|
24
|
+
<div className="flex gap-2">
|
|
25
|
+
<Textarea
|
|
26
|
+
data-cy={createCyId('ai-chat', 'message-input')}
|
|
27
|
+
value={value}
|
|
28
|
+
onChange={(e) => onChange(e.target.value)}
|
|
29
|
+
onKeyDown={handleKeyDown}
|
|
30
|
+
placeholder="Type a message..."
|
|
31
|
+
className="min-h-[60px] resize-none"
|
|
32
|
+
disabled={isLoading}
|
|
33
|
+
/>
|
|
34
|
+
<Button
|
|
35
|
+
data-cy={createCyId('ai-chat', 'send-btn')}
|
|
36
|
+
size="icon"
|
|
37
|
+
onClick={onSend}
|
|
38
|
+
disabled={!value.trim() || isLoading}
|
|
39
|
+
className="h-[60px] w-[60px]"
|
|
40
|
+
>
|
|
41
|
+
<Send className="h-5 w-5" />
|
|
42
|
+
</Button>
|
|
43
|
+
</div>
|
|
44
|
+
<div className="text-xs text-muted-foreground mt-2 text-center">
|
|
45
|
+
Press Enter to send, Shift + Enter for new line
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react'
|
|
2
|
+
import { ScrollArea } from '@nextsparkjs/core/components/ui/scroll-area'
|
|
3
|
+
import { Message as MessageType } from '../../lib/hooks/useAiChat'
|
|
4
|
+
import { Message } from './Message'
|
|
5
|
+
import { TypingIndicator } from './TypingIndicator'
|
|
6
|
+
import { createCyId } from '@nextsparkjs/core/lib/testing-utils'
|
|
7
|
+
|
|
8
|
+
interface MessageListProps {
|
|
9
|
+
messages: MessageType[]
|
|
10
|
+
isLoading: boolean
|
|
11
|
+
error?: string | null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function MessageList({ messages, isLoading, error }: MessageListProps) {
|
|
15
|
+
const scrollRef = useRef<HTMLDivElement>(null)
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (scrollRef.current) {
|
|
19
|
+
scrollRef.current.scrollIntoView({ behavior: 'smooth' })
|
|
20
|
+
}
|
|
21
|
+
}, [messages, isLoading])
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<ScrollArea data-cy={createCyId('ai-chat', 'message-list')} className="flex-1 p-4">
|
|
25
|
+
<div className="flex flex-col gap-4">
|
|
26
|
+
{error && (
|
|
27
|
+
<div
|
|
28
|
+
data-cy={createCyId('ai-chat', 'error-message')}
|
|
29
|
+
className="p-4 mb-2 text-sm text-red-600 bg-red-50 dark:bg-red-900/20 dark:text-red-400 rounded-lg"
|
|
30
|
+
>
|
|
31
|
+
{error}
|
|
32
|
+
</div>
|
|
33
|
+
)}
|
|
34
|
+
{messages.map((message) => (
|
|
35
|
+
<Message key={message.id} message={message} />
|
|
36
|
+
))}
|
|
37
|
+
{isLoading && (
|
|
38
|
+
<div className="flex items-center gap-2 p-4">
|
|
39
|
+
<TypingIndicator />
|
|
40
|
+
</div>
|
|
41
|
+
)}
|
|
42
|
+
<div ref={scrollRef} />
|
|
43
|
+
</div>
|
|
44
|
+
</ScrollArea>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createCyId } from '@nextsparkjs/core/lib/testing-utils'
|
|
2
|
+
|
|
3
|
+
export function TypingIndicator() {
|
|
4
|
+
return (
|
|
5
|
+
<div data-cy={createCyId('ai-chat', 'typing-indicator')} className="flex items-center gap-1 p-2">
|
|
6
|
+
<div className="w-2 h-2 bg-muted-foreground/40 rounded-full animate-bounce [animation-delay:-0.3s]" />
|
|
7
|
+
<div className="w-2 h-2 bg-muted-foreground/40 rounded-full animate-bounce [animation-delay:-0.15s]" />
|
|
8
|
+
<div className="w-2 h-2 bg-muted-foreground/40 rounded-full animate-bounce" />
|
|
9
|
+
</div>
|
|
10
|
+
)
|
|
11
|
+
}
|