Skip to content

Commit 0cae2cd

Browse files
committed
add remove chat func
1 parent 2e967e9 commit 0cae2cd

11 files changed

+75
-38
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,4 @@ dist
135135
/src-tauri/target/
136136
/src-tauri/bin/
137137
.DS_Store
138+
/server/*.js

app/(chat)/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import { Chat } from '@/components/chat'
44
import { useSearchParams } from 'next/navigation'
55
export default function IndexPage() {
66
const params = useSearchParams()
7-
return <Chat id={params!.get('cid') || undefined}/>
7+
return <Chat id={params!.get('cid') || `chatid_${nanoid()}`}/>
88
}

components/chat-message.tsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,19 @@ export function ChatMessage({ message, ...props }: ChatMessageProps) {
3939
p({ children }) {
4040
return <p className="mb-2 last:mb-0">{children}</p>
4141
},
42-
code({ node, inline, className, children, ...props }) {
43-
if (children.length) {
44-
if (children[0] == '▍') {
42+
code({children, className, node, ...props }) {
43+
if(node?.children[0]){
44+
const child = node.children[0]
45+
if (child.data == '▍') {
4546
return (
4647
<span className="mt-1 cursor-default animate-pulse"></span>
4748
)
4849
}
49-
50-
children[0] = (children[0] as string).replace('`▍`', '▍')
5150
}
5251

5352
const match = /language-(\w+)/.exec(className || '')
5453

55-
if (inline) {
54+
if(node?.properties.inline === true) {
5655
return (
5756
<code className={className} {...props}>
5857
{children}
@@ -77,4 +76,4 @@ export function ChatMessage({ message, ...props }: ChatMessageProps) {
7776
</div>
7877
</div>
7978
)
80-
}
79+
}

components/chat.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ export function Chat({ id, className }: ChatProps) {
3030
const [initialMessages, setInitialMessages] = useState<Message[] | undefined>(undefined);
3131

3232
useEffect(() => {
33-
if (id){
33+
if (id) {
3434
const storedData = localStorage.getItem(id);
3535
if (storedData) {
3636
const parsedData = JSON.parse(storedData);
3737
setInitialMessages(parsedData);
38+
}else{
39+
setInitialMessages([]);
3840
}
3941
}else{
40-
setInitialMessages([]);
4142
id=`chatid_${nanoid()}`;
4243
}
4344
}, [id]);
@@ -83,7 +84,7 @@ export function Chat({ id, className }: ChatProps) {
8384
role: 'assistant',
8485
content: response.content
8586
})
86-
localStorage.setItem(id || `chatid_${nanoid()}`, JSON.stringify(msg))
87+
if(id!==undefined)localStorage.setItem(id, JSON.stringify(msg))
8788
}
8889
})
8990
return (
@@ -143,7 +144,7 @@ export function Chat({ id, className }: ChatProps) {
143144
/>
144145
<Input
145146
value={previewTokenInput.serp_api_key}
146-
placeholder="SERP API Key"
147+
placeholder="SERP API Key , from https://serpapi.com"
147148
onChange={e => setPreviewTokenInput(prevState => ({
148149
...prevState,
149150
serp_api_key: e.target.value

components/sidebar-actions.tsx

+3-9
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ import {
2424
} from '@/components/ui/tooltip'
2525

2626
interface SidebarActionsProps {
27-
chat: Chat
28-
removeChat: (args: { id: string; path: string }) => void
27+
chatId: string
2928
}
3029

3130
export function SidebarActions({
32-
chat,
33-
removeChat,
31+
chatId,
3432
}: SidebarActionsProps) {
3533
const router = useRouter()
3634
const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false)
@@ -75,11 +73,7 @@ export function SidebarActions({
7573
event.preventDefault()
7674
// @ts-ignore
7775
startRemoveTransition(async () => {
78-
const result = await removeChat({
79-
id: chat.id,
80-
path: chat.path
81-
})
82-
76+
localStorage.removeItem(chatId)
8377
setDeleteDialogOpen(false)
8478
router.push('/')
8579
router.refresh()

components/sidebar-item.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ import { cn } from '@/lib/utils'
2121
interface SidebarItemProps {
2222
index: number
2323
chat: string
24+
children: React.ReactNode
2425
}
2526

26-
export function SidebarItem({ index, chat }: SidebarItemProps) {
27+
export function SidebarItem({ index, chat, children }: SidebarItemProps) {
2728
const pathname = usePathname()
2829

2930
const isActive = pathname === chat
@@ -68,6 +69,7 @@ export function SidebarItem({ index, chat }: SidebarItemProps) {
6869
{chat}
6970
</div>
7071
</Link>
72+
<div className="absolute right-2 top-1">{children}</div>
7173
</motion.div>
7274
)
7375
}

components/sidebar-items.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export function SidebarItems({ chats }: SidebarItemsProps) {
2626
}}
2727
>
2828
<SidebarItem index={index} chat={chat}>
29-
29+
<SidebarActions
30+
chatId={chat}
31+
/>
3032
</SidebarItem>
3133
</motion.div>
3234
)

package.json

+12-8
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"private": true,
55
"scripts": {
66
"dev": "next dev -p 3100",
7-
"build": "next build",
8-
"start": "next start",
7+
"build": "next build && pnpm build-server",
8+
"start": "next start -p 3100",
99
"lint": "next lint",
10-
"build-server": "esbuild server/server.ts --bundle --platform=node --outfile=build/server.js && pkg build/server.js -o ./src-tauri/bin/server-x86_64-apple-darwin"
10+
"build-server": "esbuild ./server/server.ts --bundle --platform=node --outfile=./build/server.js",
11+
"pkg-server": "pnpm build-server && pkg build/server.js -o ./src-tauri/bin/server-x86_64-apple-darwin"
1112
},
1213
"dependencies": {
1314
"@fastify/cors": "^9.0.1",
@@ -50,15 +51,18 @@
5051
"tailwindcss-animate": "^1.0.7"
5152
},
5253
"devDependencies": {
53-
"@tauri-apps/cli": "^1.5.10",
54+
"@types/d3-scale": "^4.0.8",
5455
"@types/node": "^20",
5556
"@types/react": "^18",
5657
"@types/react-dom": "^18",
57-
"autoprefixer": "^10.0.1",
58-
"eslint": "^8",
58+
"eslint": "8.57.0",
5959
"eslint-config-next": "14.1.0",
6060
"postcss": "^8",
61-
"tailwindcss": "^3.3.0",
62-
"typescript": "^5"
61+
"prettier": "^3.2.5",
62+
"tailwindcss": "^3.4.1",
63+
"typescript": "^5",
64+
"@tauri-apps/cli": "^1.5.10",
65+
"@types/react-syntax-highlighter": "^15.5.11",
66+
"autoprefixer": "^10.0.1"
6367
}
6468
}

pnpm-lock.yaml

+33-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/searchAgent.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
77
import { nanoid } from '../lib/utils';
88
import { LLMResult } from '@langchain/core/outputs';
99
import { AgentExecutor, createReactAgent } from "langchain/agents";
10-
import { BingSerpAPI } from "@langchain/community/tools/bingserpapi";
10+
import { SerpAPI } from "@langchain/community/tools/serpapi";
1111
import { TextEncoder } from 'util';
1212
import{ FastifyRequest } from 'fastify';
1313

@@ -60,7 +60,10 @@ export async function searchAgent(request:FastifyRequest) {
6060
const messages = body.messages;
6161
const previousMessages = messages.slice(0, -1).map(convertVercelMessageToLangChainMessage);
6262
const currentMessageContent = messages[messages.length - 1].content;
63-
const tools = [new BingSerpAPI(body.previewToken.serp_api_key)];
63+
64+
process.env.SERPAPI_API_KEY = body.previewToken.serp_api_key
65+
66+
const tools = [new SerpAPI()];
6467
const prompt = await pull<PromptTemplate>("hwchase17/react");
6568
const model = new ChatOpenAI({
6669
temperature: 0.1,

src-tauri/tauri.conf.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"distDir": "../out"
88
},
99
"package": {
10-
"productName": "tauri-langchain",
10+
"productName": "next-langchain-tauri",
1111
"version": "0.1.0"
1212
},
1313
"tauri": {
@@ -36,7 +36,7 @@
3636
"icons/icon.icns",
3737
"icons/icon.ico"
3838
],
39-
"identifier": "com.tauri.dev",
39+
"identifier": "com.stackai.nextlang",
4040
"longDescription": "",
4141
"macOS": {
4242
"entitlements": null,
@@ -66,7 +66,7 @@
6666
"fullscreen": false,
6767
"height": 800,
6868
"resizable": true,
69-
"title": "tauri-langchain",
69+
"title": "next-langchain-tauri",
7070
"width": 1280
7171
}
7272
]

0 commit comments

Comments
 (0)