Skip to content

Commit daf328d

Browse files
committed
remove console.logs, ensure docId starts with /
1 parent 9d2915d commit daf328d

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

docs/src/components/chat/ai-chat.tsx

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client';
22

33
import { useChat } from '@ai-sdk/react';
4+
import { runAsynchronously } from '@stackframe/stack-shared/dist/utils/promises';
45
import { ExternalLink, FileText, Maximize2, Minimize2, Send, X } from 'lucide-react';
56
import { useEffect, useRef, useState } from 'react';
67
import { useSidebar } from '../layouts/sidebar-context';
@@ -36,12 +37,11 @@ const ToolCallDisplay = ({
3637
const docId = toolCall.args?.id;
3738
let docTitle = "Loading...";
3839

39-
if (toolCall.result && toolCall.result.content.length > 0) {
40-
const newDocTitle =
41-
toolCall.result.content[0].text.match(/Title:\s*(.*)/);
42-
if (newDocTitle && newDocTitle[1]) {
43-
docTitle = newDocTitle[1].trim();
44-
}
40+
const titleMatch = toolCall.result?.content[0]?.text.match(/Title:\s*(.*)/);
41+
if (titleMatch?.[1]) {
42+
docTitle = titleMatch[1].trim();
43+
} else {
44+
toolCall.result = { content: [{ text: "No title found" }] };
4545
}
4646

4747
return (
@@ -52,7 +52,7 @@ const ToolCallDisplay = ({
5252
</span>
5353
{docId && (
5454
<a
55-
href={`https://docs.stack-auth.com${docId}`}
55+
href={`https://docs.stack-auth.com${docId.startsWith('/') ? docId : `/${docId}`}`}
5656
target="_blank"
5757
rel="noopener noreferrer"
5858
className="flex items-center gap-1 text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-200 transition-colors"
@@ -192,10 +192,7 @@ export function AIChatDrawer() {
192192
},
193193
onFinish: (message) => {
194194
// Send AI response to Discord
195-
// eslint-disable-next-line no-restricted-syntax
196-
sendAIResponseToDiscord(message.content).catch(error => {
197-
console.error('Failed to send AI response to Discord:', error);
198-
});
195+
runAsynchronously(() => sendAIResponseToDiscord(message.content));
199196
},
200197
});
201198

@@ -284,10 +281,7 @@ export function AIChatDrawer() {
284281
}));
285282

286283
// Send message to Discord webhook
287-
// eslint-disable-next-line no-restricted-syntax
288-
sendToDiscord(input.trim()).catch(error => {
289-
console.error('Discord webhook error:', error);
290-
});
284+
runAsynchronously(() => sendToDiscord(input.trim()));
291285

292286
// Continue with normal chat submission
293287
handleSubmit(e);
@@ -317,6 +311,11 @@ export function AIChatDrawer() {
317311
handleInputChange({ target: { value: prompt } } as React.ChangeEvent<HTMLInputElement>);
318312
};
319313

314+
// Helper function for safe async event handling
315+
const handleSubmitSafely = () => {
316+
runAsynchronously(() => handleChatSubmit({} as React.FormEvent));
317+
};
318+
320319
return (
321320
<div
322321
className={`fixed ${topPosition} right-0 ${height} bg-fd-background border-l border-fd-border flex flex-col transition-all duration-300 ease-out z-50 ${
@@ -475,10 +474,7 @@ export function AIChatDrawer() {
475474
onKeyDown={(e) => {
476475
if (e.key === "Enter" && !e.shiftKey) {
477476
e.preventDefault();
478-
// eslint-disable-next-line no-restricted-syntax
479-
handleChatSubmit({} as React.FormEvent).catch(error => {
480-
console.error('Chat submit error:', error);
481-
});
477+
handleSubmitSafely();
482478
}
483479
}}
484480
onPaste={(e) => {
@@ -496,12 +492,7 @@ export function AIChatDrawer() {
496492
</div>
497493
<button
498494
disabled={!input.trim() || isLoading}
499-
onClick={() => {
500-
// eslint-disable-next-line no-restricted-syntax
501-
handleChatSubmit({} as React.FormEvent).catch(error => {
502-
console.error('Chat submit error:', error);
503-
});
504-
}}
495+
onClick={handleSubmitSafely}
505496
className="h-8 w-8 rounded-full p-0 shrink-0 bg-fd-primary text-fd-primary-foreground hover:bg-fd-primary/90 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center"
506497
>
507498
<Send className="w-4 h-4" />

0 commit comments

Comments
 (0)