Skip to content

Commit 31ad395

Browse files
fix(web): align AI chat page with raw API responses and unified token key
Consume the raw response shapes returned by the audits and AI endpoints and read the veridion_access_token key so the chat is authenticated.
1 parent 5077d59 commit 31ad395

1 file changed

Lines changed: 13 additions & 24 deletions

File tree

  • apps/web/src/app/dashboard/ai-chat

apps/web/src/app/dashboard/ai-chat/page.tsx

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ interface Citation {
1414
}
1515

1616
interface ApiChatResponse {
17-
success: boolean;
18-
data: {
19-
message: string;
20-
citations: Citation[];
21-
};
22-
message?: string;
17+
message: string;
18+
citations: Citation[];
2319
}
2420

2521
export default function AiChatPage() {
@@ -52,18 +48,15 @@ export default function AiChatPage() {
5248
}
5349

5450
const json = (await res.json()) as {
55-
success: boolean;
56-
data?: {
57-
data?: Array<{
58-
id: string;
59-
status: string;
60-
securityScore: number | null;
61-
project?: { name: string };
62-
}>;
63-
};
51+
data?: Array<{
52+
id: string;
53+
status: string;
54+
securityScore: number | null;
55+
project?: { name: string };
56+
}>;
6457
};
65-
if (json.success && json.data?.data) {
66-
const auditOptions: AuditOption[] = json.data.data.map((audit) => ({
58+
if (json.data) {
59+
const auditOptions: AuditOption[] = json.data.map((audit) => ({
6760
id: audit.id,
6861
name: audit.project?.name ?? `Audit ${audit.id.slice(0, 8)}`,
6962
status: audit.status,
@@ -199,15 +192,11 @@ export default function AiChatPage() {
199192

200193
const json = (await res.json()) as ApiChatResponse;
201194

202-
if (!json.success || !json.data) {
203-
throw new Error(json.message ?? 'Unexpected API response');
204-
}
205-
206195
const aiMsg: ChatMessage = {
207196
id: (Date.now() + 1).toString(),
208197
role: 'assistant',
209-
content: json.data.message,
210-
citations: json.data.citations,
198+
content: json.message,
199+
citations: json.citations,
211200
timestamp: new Date(),
212201
};
213202

@@ -291,7 +280,7 @@ export default function AiChatPage() {
291280

292281
function getAuthToken(): string | null {
293282
if (typeof window === 'undefined') return null;
294-
return localStorage.getItem('accessToken');
283+
return localStorage.getItem('veridion_access_token');
295284
}
296285

297286
function getApiBaseUrl(): string {

0 commit comments

Comments
 (0)