xonecas.io
53129
Pa

PAT / commit 4928da9

fix: several small fixes from user feedback

xonecas2025-12-22 4928da9c233547355af395fca7c4f5cedf97856b parent 9916a7f

5 files changed

app/globals.css+11−23
@@ -57,45 +57,33 @@
5757 }
5858
5959 @layer utilities {
60- @keyframes spin-and-color-cycle {
60+ @keyframes color-cycle {
6161 0% {
62- transform: rotate(0deg);
6362 color: rgb(239 68 68); /* red-500 */
6463 }
6564 33.33% {
66- transform: rotate(120deg);
6765 color: rgb(249 115 22); /* orange-500 */
6866 }
6967 66.66% {
70- transform: rotate(240deg);
7168 color: rgb(245 158 11); /* amber-500 */
7269 }
7370 100% {
74- transform: rotate(360deg);
7571 color: rgb(239 68 68); /* red-500 */
7672 }
7773 }
7874
79- .animate-spin-and-color-cycle {
80- animation: spin-and-color-cycle 3s linear infinite;
75+ .animate-color-cycle {
76+ animation:
77+ color-cycle 3s linear infinite,
78+ pulse 2s ease-in-out infinite;
8179 }
82-
83- @keyframes color-cycle {
84- 0% {
85- color: rgb(239 68 68); /* red-500 */
86- }
87- 33.33% {
88- color: rgb(249 115 22); /* orange-500 */
89- }
90- 66.66% {
91- color: rgb(245 158 11); /* amber-500 */
92- }
80+ @keyframes pulse {
81+ 0%,
9382 100% {
94- color: rgb(239 68 68); /* red-500 */
83+ opacity: 1;
84+ }
85+ 50% {
86+ opacity: 0.5;
9587 }
96- }
97-
98- .animate-color-cycle {
99- animation: color-cycle 3s linear infinite;
10088 }
10189 }
src/components/MessageEditor.tsx+25−22
@@ -35,13 +35,6 @@ export default function MessageEditor({
3535 (previousMessages) =>
3636 [
3737 ...previousMessages.filter((message) => message.id !== 0), // Remove messages that are not saved yet
38- {
39- id: 0, // Means it's not saved yet
40- createdAt: new Date(),
41- threadId: selectedThreadId,
42- role: "user",
43- content: userMessage,
44- },
4538 {
4639 id: 0, // Means it's not saved yet
4740 createdAt: new Date(),
@@ -79,6 +72,10 @@ export default function MessageEditor({
7972 }, [isCreatingThread, isCreatingThreadMessage]);
8073
8174 const handleSave = () => {
75+ if (userMessage.trim() === "") {
76+ return;
77+ }
78+
8279 if (!selectedThreadId) {
8380 createThread();
8481 } else {
@@ -102,25 +99,31 @@ export default function MessageEditor({
10299 value={userMessage}
103100 onChange={(e) => setUserMessage(e.target.value)}
104101 onKeyDown={handleKeyDown}
105- className="resize-none rounded-md bg-neutral-50 px-4 py-2 text-neutral-800 placeholder:italic focus:outline-none dark:bg-neutral-950 dark:text-neutral-300 "
102+ className="resize-none rounded-md bg-neutral-50 px-4 py-2 text-neutral-800 placeholder:italic focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 dark:bg-neutral-950 dark:text-neutral-300"
106103 disabled={isLoading}
107104 />
108105 <div className="flex flex-row items-center justify-end gap-2">
109- {userMessage && (
110- <Button
111- color="neutral"
112- type="button"
113- onClick={() => setUserMessage("")}
114- disabled={isLoading}
115- >
116- <TrashIcon className="h-8 w-10 p-1.5" />
117- Clear
118- </Button>
106+ {isLoading ? (
107+ <p className="animate-color-cycle text-sm font-bold">Loading...</p>
108+ ) : (
109+ <>
110+ {userMessage && (
111+ <Button
112+ color="neutral"
113+ type="button"
114+ onClick={() => setUserMessage("")}
115+ disabled={isLoading}
116+ >
117+ <TrashIcon className="h-8 w-10 p-1.5" />
118+ Clear
119+ </Button>
120+ )}
121+ <Button color="neutral" type="button" onClick={handleSave} disabled={isLoading}>
122+ <PaperPlaneIcon className="h-8 w-10 p-1.5" />
123+ Send
124+ </Button>
125+ </>
119126 )}
120- <Button color="neutral" type="button" onClick={handleSave} disabled={isLoading}>
121- <PaperPlaneIcon className="h-8 w-10 p-1.5" />
122- Send
123- </Button>
124127 </div>
125128 </div>
126129 </div>
src/components/MessageList.tsx+1−1
@@ -85,7 +85,7 @@ function UserMessage({ message }: { message: Message }) {
8585 }
8686
8787 function AssistantMessage({ message }: { message: Message }) {
88- const [isCollapsed, setIsCollapsed] = useState(message.id !== 0); // Only show opened optimistic thinking rendered messages
88+ const [isCollapsed, setIsCollapsed] = useState(message.content.trim() !== "");
8989 const { showToolMessages } = useAppContext();
9090
9191 return (
src/lib/chat.ts+6−2
@@ -79,8 +79,12 @@ async function agentLoop(
7979 if (calls.length) {
8080 for (const call of calls) {
8181 const toolResponse = await executeToolCall(call);
82- newMessages.push({ role: "tool", content: `[${call.function.name}] ${toolResponse}` });
83- enqueue({ role: "tool", content: `[${call.function.name}] ${toolResponse}` });
82+ const toolContent = toolResponse ? JSON.stringify(toolResponse) : "null";
83+ newMessages.push({
84+ role: "tool",
85+ content: `[${call.function.name}] ${toolContent}`,
86+ });
87+ enqueue({ role: "tool", content: `[${call.function.name}] ${toolContent}` });
8488 }
8589 } else {
8690 enqueue({
src/lib/tools/websearch.ts+13−4
@@ -1,13 +1,18 @@
11 import { getCache, incrementCache, setCache } from "@/src/lib/cache";
22 import { google } from "googleapis";
3-import type { customsearch_v1 } from "googleapis/build/src/apis/customsearch/v1";
43
54 const CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
65
7-export async function webSearch(query: string): Promise<customsearch_v1.Schema$Result[] | null> {
6+type WebSearchResult = {
7+ title: string;
8+ snippet: string;
9+ link: string;
10+};
11+
12+export async function webSearch(query: string): Promise<WebSearchResult[] | null> {
813 // Check cache first
914 const cacheKey = `websearch:${query.toLowerCase().trim()}`;
10- const cached = await getCache<customsearch_v1.Schema$Result[]>(cacheKey);
15+ const cached = await getCache<WebSearchResult[]>(cacheKey);
1116 if (cached !== null) {
1217 return cached;
1318 }
@@ -43,7 +48,11 @@ export async function webSearch(query: string): Promise<customsearch_v1.Schema$R
4348 return null;
4449 }
4550
46- const results = res.data.items;
51+ const results = res.data.items.map((item) => ({
52+ title: item.title || "",
53+ snippet: item.snippet || "",
54+ link: item.link || "",
55+ }));
4756 await setCache(cacheKey, results, CACHE_TTL_MS);
4857 return results;
4958 }