Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

chore: update left panel menu with agent chat

Faisal Amir74438ed636bc
diff --git a/web-app/package.json b/web-app/package.json
index 59b8456bb..28ed50e39 100644
--- a/web-app/package.json
+++ b/web-app/package.json
@@ -68,7 +68,7 @@
"lodash.debounce": "4.0.8",
"lucide-react": "^0.563.0",
"matter-js": "^0.20.0",
- "motion": "^12.29.2",
+ "motion": "^12.35.0",
"next-themes": "0.4.6",
"posthog-js": "1.255.1",
"radix-ui": "^1.4.3",
diff --git a/web-app/src/components/animated-icon/bot.tsx b/web-app/src/components/animated-icon/bot.tsx
new file mode 100644
index 000000000..4e93f6ae9
--- /dev/null
+++ b/web-app/src/components/animated-icon/bot.tsx
@@ -0,0 +1,122 @@
+"use client";
+
+import { motion, useAnimation } from "motion/react";
+import type { HTMLAttributes } from "react";
+import { forwardRef, useCallback, useImperativeHandle, useRef } from "react";
+
+import { cn } from "@/lib/utils";
+
+export interface BotIconHandle {
+ startAnimation: () => void;
+ stopAnimation: () => void;
+}
+
+interface BotIconProps extends HTMLAttributes<HTMLDivElement> {
+ size?: number;
+}
+
+const BotIcon = forwardRef<BotIconHandle, BotIconProps>(
+ ({ onMouseEnter, onMouseLeave, className, size = 28, ...props }, ref) => {
+ const controls = useAnimation();
+ const isControlledRef = useRef(false);
+
+ useImperativeHandle(ref, () => {
+ isControlledRef.current = true;
+
+ return {
+ startAnimation: () => controls.start("animate"),
+ stopAnimation: () => controls.start("normal"),
+ };
+ });
+
+ const handleMouseEnter = useCallback(
+ (e: React.MouseEvent<HTMLDivElement>) => {
+ if (isControlledRef.current) {
+ onMouseEnter?.(e);
+ } else {
+ controls.start("animate");
+ }
+ },
+ [controls, onMouseEnter]
+ );
+
+ const handleMouseLeave = useCallback(
+ (e: React.MouseEvent<HTMLDivElement>) => {
+ if (isControlledRef.current) {
+ onMouseLeave?.(e);
+ } else {
+ controls.start("normal");
+ }
+ },
+ [controls, onMouseLeave]
+ );
+
+ return (
+ <div
+ className={cn(className)}
+ onMouseEnter={handleMouseEnter}
+ onMouseLeave={handleMouseLeave}
+ {...props}
+ >
+ <svg
+ fill="none"
+ height={size}
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="2"
+ viewBox="0 0 24 24"
+ width={size}
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path d="M12 8V4H8" />
+ <rect height="12" rx="2" width="16" x="4" y="8" />
+ <path d="M2 14h2" />
+ <path d="M20 14h2" />
+
+ <motion.line
+ animate={controls}
+ initial="normal"
+ variants={{
+ normal: { y1: 13, y2: 15 },
+ animate: {
+ y1: [13, 14, 13],
+ y2: [15, 14, 15],
+ transition: {
+ duration: 0.5,
+ ease: "easeInOut",
+ delay: 0.2,
+ },
+ },
+ }}
+ x1={15}
+ x2={15}
+ />
+
+ <motion.line
+ animate={controls}
+ initial="normal"
+ variants={{
+ normal: { y1: 13, y2: 15 },
+ animate: {
+ y1: [13, 14, 13],
+ y2: [15, 14, 15],
+ transition: {
+ duration: 0.5,
+ ease: "easeInOut",
+ delay: 0.2,
+ },
+ },
+ }}
+ x1={9}
+ x2={9}
+ />
+ </svg>
+ </div>
+ );
+ }
+);
+
+BotIcon.displayName = "Bot";
+
+export { BotIcon };
diff --git a/web-app/src/components/left-sidebar/NavMain.tsx b/web-app/src/components/left-sidebar/NavMain.tsx
index 366d5b994..12de39de0 100644
--- a/web-app/src/components/left-sidebar/NavMain.tsx
+++ b/web-app/src/components/left-sidebar/NavMain.tsx
@@ -29,11 +29,17 @@ import {
type SettingsIconHandle,
} from '@/components/animated-icon/settings'
import { BlocksIcon, type BlocksIconHandle } from '../animated-icon/blocks'
+import {
+ BotIcon,
+ type BotIconHandle,
+} from '@/components/animated-icon/bot'
import AddProjectDialog from '@/containers/dialogs/AddProjectDialog'
import { SearchDialog } from '@/containers/dialogs/SearchDialog'
import { useThreadManagement } from '@/hooks/useThreadManagement'
import { useSearchDialog } from '@/hooks/useSearchDialog'
import { useProjectDialog } from '@/hooks/useProjectDialog'
+import { useAgentMode } from '@/hooks/useAgentMode'
+import { TEMPORARY_CHAT_ID } from '@/constants/chat'
type AnimatedIconHandle =
| SearchIconHandle
@@ -41,6 +47,7 @@ type AnimatedIconHandle =
| MessageCircleIconHandle
| SettingsIconHandle
| BlocksIconHandle
+ | BotIconHandle
type NavMainItem = {
title: string
@@ -59,12 +66,14 @@ type NavMainItem = {
const getNavMainItems = (
onNewProject: () => void,
- onSearch: () => void
+ onSearch: () => void,
+ onNewChat: () => void,
+ onJanClaw: () => void
): NavMainItem[] => [
{
title: 'common:newChat',
- url: route.home,
animatedIcon: MessageCircleIcon,
+ onClick: onNewChat,
shortcut: (
<KbdGroup className="ml-auto scale-90 gap-0">
<Kbd className="bg-transparent size-3">
@@ -74,6 +83,19 @@ const getNavMainItems = (
</KbdGroup>
),
},
+ {
+ title: 'New Agent Chat',
+ animatedIcon: BotIcon,
+ onClick: onJanClaw,
+ shortcut: (
+ <KbdGroup className="ml-auto scale-90 gap-0">
+ <Kbd className="bg-transparent size-3">
+ <PlatformMetaKey />
+ </Kbd>
+ <Kbd className="bg-transparent size-3">F</Kbd>
+ </KbdGroup>
+ ),
+ },
{
title: 'common:projects.new',
animatedIcon: FolderPlusIcon,
@@ -155,7 +177,15 @@ export function NavMain() {
const navMainItems = getNavMainItems(
() => setProjectDialogOpen(true),
- () => setSearchOpen(true)
+ () => setSearchOpen(true),
+ () => {
+ useAgentMode.getState().removeThread(TEMPORARY_CHAT_ID)
+ navigate({ to: route.home })
+ },
+ () => {
+ useAgentMode.getState().setAgentMode(TEMPORARY_CHAT_ID, true)
+ navigate({ to: route.home })
+ }
)
const handleCreateProject = async (name: string, assistantId?: string) => {
diff --git a/web-app/src/containers/ChatInput.tsx b/web-app/src/containers/ChatInput.tsx
index 6a2d09ecb..93dd0fd93 100644
--- a/web-app/src/containers/ChatInput.tsx
+++ b/web-app/src/containers/ChatInput.tsx
@@ -1812,15 +1812,16 @@ const ChatInput = memo(function ChatInput({
</Tooltip>
))}
- {openClawAvailable && (
+ {openClawAvailable && (!!currentThreadId || isAgentMode) && (
<Tooltip>
<TooltipTrigger asChild>
<Button
variant={isAgentMode ? "default" : "ghost"}
size="icon-xs"
- onClick={handleAgentToggle}
+ onClick={currentThreadId ? handleAgentToggle : undefined}
className={cn(
- isAgentMode && 'text-primary bg-primary/10 hover:bg-primary/10 items-center'
+ isAgentMode && 'text-primary bg-primary/10 hover:bg-primary/10 items-center',
+ !currentThreadId && 'cursor-default pointer-events-none'
)}
>
<BotIcon
diff --git a/web-app/src/lib/shortcuts/const.ts b/web-app/src/lib/shortcuts/const.ts
index e7534f35a..b52f20abd 100644
--- a/web-app/src/lib/shortcuts/const.ts
+++ b/web-app/src/lib/shortcuts/const.ts
@@ -19,6 +19,9 @@ export const PlatformShortcuts: ShortcutMap = {
// New chat - different per platform to avoid browser "new window" conflict
[ShortcutAction.NEW_CHAT]: { key: 'n', usePlatformMetaKey: true },
+ // New agent chat - opens home screen with agent mode pre-enabled
+ [ShortcutAction.NEW_AGENT_CHAT]: { key: 'f', usePlatformMetaKey: true },
+
// New project - opens create project dialog
[ShortcutAction.NEW_PROJECT]: { key: 'p', usePlatformMetaKey: true },
diff --git a/web-app/src/lib/shortcuts/types.ts b/web-app/src/lib/shortcuts/types.ts
index 468c78f0c..0229a55a5 100644
--- a/web-app/src/lib/shortcuts/types.ts
+++ b/web-app/src/lib/shortcuts/types.ts
@@ -5,6 +5,7 @@
export enum ShortcutAction {
NEW_CHAT = 'newChat',
+ NEW_AGENT_CHAT = 'newAgentChat',
NEW_PROJECT = 'newProject',
TOGGLE_SIDEBAR = 'toggleSidebar',
GO_TO_SETTINGS = 'goSettings',
diff --git a/web-app/src/providers/KeyboardShortcuts.tsx b/web-app/src/providers/KeyboardShortcuts.tsx
index 92fc8c73e..94cf5ec6f 100644
--- a/web-app/src/providers/KeyboardShortcuts.tsx
+++ b/web-app/src/providers/KeyboardShortcuts.tsx
@@ -5,6 +5,8 @@ import { useProjectDialog } from '@/hooks/useProjectDialog'
import { useRouter } from '@tanstack/react-router'
import { route } from '@/constants/routes'
import { PlatformShortcuts, ShortcutAction } from '@/lib/shortcuts'
+import { useAgentMode } from '@/hooks/useAgentMode'
+import { TEMPORARY_CHAT_ID } from '@/constants/chat'
export function KeyboardShortcutsProvider() {
const { open, setLeftPanel } = useLeftPanel()
@@ -15,6 +17,7 @@ export function KeyboardShortcutsProvider() {
// Get shortcut specs from centralized configuration
const sidebarShortcut = PlatformShortcuts[ShortcutAction.TOGGLE_SIDEBAR]
const newChatShortcut = PlatformShortcuts[ShortcutAction.NEW_CHAT]
+ const newAgentChatShortcut = PlatformShortcuts[ShortcutAction.NEW_AGENT_CHAT]
const newProjectShortcut = PlatformShortcuts[ShortcutAction.NEW_PROJECT]
const settingsShortcut = PlatformShortcuts[ShortcutAction.GO_TO_SETTINGS]
const searchShortcut = PlatformShortcuts[ShortcutAction.SEARCH]
@@ -31,6 +34,16 @@ export function KeyboardShortcutsProvider() {
useKeyboardShortcut({
...newChatShortcut,
callback: () => {
+ useAgentMode.getState().removeThread(TEMPORARY_CHAT_ID)
+ router.navigate({ to: route.home })
+ },
+ })
+
+ // New Agent Chat
+ useKeyboardShortcut({
+ ...newAgentChatShortcut,
+ callback: () => {
+ useAgentMode.getState().setAgentMode(TEMPORARY_CHAT_ID, true)
router.navigate({ to: route.home })
},
})