Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
feat: create default project getting started and a couple dafault thread
Faisal Amir3265f6b709b3
diff --git a/web-app/src/containers/SetupScreen.tsx b/web-app/src/containers/SetupScreen.tsxindex b43d7a9eb..18dd585a4 100644--- a/web-app/src/containers/SetupScreen.tsx+++ b/web-app/src/containers/SetupScreen.tsx@@ -6,6 +6,8 @@ import { localStorageKey, CACHE_EXPIRY_MS } from '@/constants/localStorage'import { useDownloadStore } from '@/hooks/useDownloadStore'import { useServiceHub } from '@/hooks/useServiceHub'import { useEffect, useMemo, useCallback, useState, useRef } from 'react'+import { ulid } from 'ulidx'+import { ChatCompletionRole, ContentType, MessageStatus } from '@janhq/core'import type { CatalogModel } from '@/services/models/types'import {NEW_JAN_MODEL_HF_REPO,@@ -17,11 +19,12 @@ import { IconEye, IconSquareCheck } from '@tabler/icons-react'import { cn } from '@/lib/utils'import { useGeneralSetting } from '@/hooks/useGeneralSetting'import HeaderPage from './HeaderPage'-import { DownloadIcon, FolderIcon, FolderPlusIcon, MessageCircle, PanelLeft, Search } from 'lucide-react'-import { NavMain } from '@/components/left-sidebar/NavMain'+import { DownloadIcon, PanelLeft} from 'lucide-react'import { ThemeSwitcher } from './ThemeSwitcher'+import { FontSizeSwitcher } from './FontSizeSwitcher'import { AccentColorPicker } from './AccentColorPicker'import { Skeleton } from '@/components/ui/skeleton'+import { useThreads } from '@/hooks/useThreads'type CacheEntry = {status: 'RED' | 'YELLOW' | 'GREEN' | 'GREY'@@ -104,6 +107,231 @@ function SetupScreen() {const checkedModelId = useRef<string | null>(null)const [isSupportCheckComplete, setIsSupportCheckComplete] = useState(false)const huggingfaceToken = useGeneralSetting((state) => state.huggingfaceToken)+ const { createThread } = useThreads()+ const threadCheckedRef = useRef(false)++ // Create default thread and project for new user (only once)+ useEffect(() => {+ if (threadCheckedRef.current) return+ threadCheckedRef.current = true++ const setupDefaults = async () => {+ try {+ // Create default project "Getting started"+ const existingProjects = await serviceHub.projects().getProjects()+ const hasDefaultProject = existingProjects.some(+ (p) => p.name === 'Getting started'+ )+ let defaultProjectId: string | undefined+ if (!hasDefaultProject) {+ const project = await serviceHub.projects().addProject('Getting started')+ defaultProjectId = project.id+ } else {+ defaultProjectId = existingProjects.find((p) => p.name === 'Getting started')?.id+ }++ // Create default thread (outside of project)+ const existingThreads = await serviceHub.threads().fetchThreads()+ const hasDefaultThread = existingThreads.some(+ (t) => t.title === 'What is Jan?'+ )+ if (!hasDefaultThread) {+ const thread = await createThread(+ { id: '', provider: '' },+ 'What is Jan?'+ )++ // Add dummy messages+ const now = Date.now()+ const messages = [+ {+ id: ulid(),+ object: 'message',+ thread_id: thread.id,+ role: ChatCompletionRole.User,+ content: [+ {+ type: ContentType.Text,+ text: { value: 'Hey, so what is Jan?', annotations: [] },+ },+ ],+ status: MessageStatus.Ready,+ created_at: now,+ completed_at: now,+ },+ {+ id: ulid(),+ object: 'message',+ thread_id: thread.id,+ role: ChatCompletionRole.Assistant,+ content: [+ {+ type: ContentType.Text,+ text: {+ value:+ "Hello, I'm Jan! I'm an open-source AI assistant built by the team at Menlo Research.\n\nI can help you answer questions, think through complex ideas, and solve problems, big or small, by using tools to complete them on your behalf. I run on your device, so you stay in control of your data and work.\n\nTo learn more about how I'm built, visit jan.ai, or explore the team's work at menlo.ai.",+ annotations: [],+ },+ },+ ],+ status: MessageStatus.Ready,+ created_at: now + 1,+ completed_at: now + 1,+ },+ {+ id: ulid(),+ object: 'message',+ thread_id: thread.id,+ role: ChatCompletionRole.User,+ content: [+ {+ type: ContentType.Text,+ text: { value: 'What can you do?', annotations: [] },+ },+ ],+ status: MessageStatus.Ready,+ created_at: now + 2,+ completed_at: now + 2,+ },+ {+ id: ulid(),+ object: 'message',+ thread_id: thread.id,+ role: ChatCompletionRole.Assistant,+ content: [+ {+ type: ContentType.Text,+ text: {+ value:+ "Quite a few things.\n\nYou can ask me questions, work through ideas, or get help with things like writing and code.\n\nYou can chat with me for quick questions, or start a project to organise longer work. You can also add files, and I'll use them as context.\n\nIf you like, you can switch between different models depending on what you're working on.\n\nWhat would you like to try first?",+ annotations: [],+ },+ },+ ],+ status: MessageStatus.Ready,+ created_at: now + 3,+ completed_at: now + 3,+ },+ ]++ for (const message of messages) {+ await serviceHub.messages().createMessage(message)+ }+ }++ // Create threads inside "Getting started" project+ if (defaultProjectId) {+ const projectMetadata = {+ id: defaultProjectId,+ name: 'Getting started',+ updated_at: Math.floor(Date.now() / 1000),+ }++ // Thread 1: Exploring project assistants+ const assistantThread = await createThread(+ { id: '', provider: '' },+ 'Exploring project assistants',+ undefined,+ projectMetadata+ )++ const assistantMessages = [+ {+ id: ulid(),+ object: 'message',+ thread_id: assistantThread.id,+ role: ChatCompletionRole.User,+ content: [+ {+ type: ContentType.Text,+ text: { value: 'How should I set up the assistant for a project?', annotations: [] },+ },+ ],+ status: MessageStatus.Ready,+ created_at: Date.now(),+ completed_at: Date.now(),+ },+ {+ id: ulid(),+ object: 'message',+ thread_id: assistantThread.id,+ role: ChatCompletionRole.Assistant,+ content: [+ {+ type: ContentType.Text,+ text: {+ value:+ "Think of the assistant as your project helper. You can choose one assistant per project. This helps keep guidance clear and avoids mixed responses.\n\nDescribe what the project is about, what you want help with, and how you want responses to sound.\n\nFor example, in a research project, you might write:\n\n\"Summarise clearly. Highlight key points and trade-offs. Flag anything uncertain or worth double-checking.\"\n\nA few clear lines are enough. You can change this anytime to tailor responses as your project evolves.",+ annotations: [],+ },+ },+ ],+ status: MessageStatus.Ready,+ created_at: Date.now() + 1,+ completed_at: Date.now() + 1,+ },+ ]++ for (const message of assistantMessages) {+ await serviceHub.messages().createMessage(message)+ }++ // Thread 2: Uploading helpful files+ const filesThread = await createThread(+ { id: '', provider: '' },+ 'Uploading helpful files',+ undefined,+ projectMetadata+ )++ const filesMessages = [+ {+ id: ulid(),+ object: 'message',+ thread_id: filesThread.id,+ role: ChatCompletionRole.User,+ content: [+ {+ type: ContentType.Text,+ text: { value: 'What types of files should I add to a project to improve responses?', annotations: [] },+ },+ ],+ status: MessageStatus.Ready,+ created_at: Date.now(),+ completed_at: Date.now(),+ },+ {+ id: ulid(),+ object: 'message',+ thread_id: filesThread.id,+ role: ChatCompletionRole.Assistant,+ content: [+ {+ type: ContentType.Text,+ text: {+ value:+ "Add files you'd normally keep open while working:\n\n- Notes or docs if you're thinking through ideas\n- Drafts if you're writing or editing\n- Specs or tickets if you're planning work\n- PDFs or research if you need summaries or comparisons\n- Code files if you want help understanding or improving them\n\nI'll use these files as shared context, so you don't have to repeat yourself.",+ annotations: [],+ },+ },+ ],+ status: MessageStatus.Ready,+ created_at: Date.now() + 1,+ completed_at: Date.now() + 1,+ },+ ]++ for (const message of filesMessages) {+ await serviceHub.messages().createMessage(message)+ }+ }+ } catch (error) {+ console.error('Failed to create default thread/project:', error)+ }+ }++ setupDefaults()+ }, []) // Empty dependency - runs once on mountconst fetchJanModel = useCallback(async () => {setMetadataFetchFailed(false)@@ -392,16 +620,20 @@ function SetupScreen() {<p className='text-muted-foreground leading-normal w-full mt-1'>{isDownloading ? 'Want to try a different look? You can change this later in Settings.' : 'Let’s download your first local AI model to run on your device.'}</p></div>- {isDownloading ?+ {isDownloading ?<div className='mt-8 space-y-6'><div className='space-y-4'><div className='text-muted-foreground'>Accent color</div><AccentColorPicker />- </div>+ </div><div className='space-y-4'><div className='text-muted-foreground'>Color system</div><ThemeSwitcher renderAsRadio /></div>+ <div className='space-y-4'>+ <div className='text-muted-foreground'>Font size</div>+ <FontSizeSwitcher renderAsRadio />+ </div></div>:<div className="flex gap-4 flex-col mt-6">diff --git a/web-app/src/containers/ThreadList.tsx b/web-app/src/containers/ThreadList.tsxindex 400ed869f..40d7ed6ab 100644--- a/web-app/src/containers/ThreadList.tsx+++ b/web-app/src/containers/ThreadList.tsx@@ -137,7 +137,7 @@ const ThreadItem = memo(return (<SidebarMenuItem>{currentProjectId ?- <Link to="/threads/$threadId" params={{ threadId: thread.id }} className="bg-card dark:bg-secondary/20 px-4 py-4 border hover:dark:bg-secondary/30 rounded-lg block">+ <Link to="/threads/$threadId" params={{ threadId: thread.id }} className="bg-card dark:bg-secondary/20 mb-2 px-4 py-4 border hover:dark:bg-secondary/30 rounded-lg block"><span>{thread.title || t('common:newThread')}</span>{currentProjectId && lastUserMessageText && (<div className="text-muted-foreground text-xs mt-1 line-clamp-1 pr-10">