Skip to content

Commit 8828237

Browse files
committed
Lint
1 parent 1b3b85f commit 8828237

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

apps/sim/app/api/copilot/route.ts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import { type NextRequest, NextResponse } from 'next/server'
22
import { z } from 'zod'
33
import { getSession } from '@/lib/auth'
4-
import { createChat, deleteChat, generateChatTitle, getChat, listChats, sendMessage, updateChat } from '@/lib/copilot/service'
4+
import {
5+
createChat,
6+
deleteChat,
7+
generateChatTitle,
8+
getChat,
9+
listChats,
10+
sendMessage,
11+
updateChat,
12+
} from '@/lib/copilot/service'
513
import { createLogger } from '@/lib/logs/console-logger'
614

715
const logger = createLogger('CopilotAPI')
@@ -37,18 +45,26 @@ const CreateChatSchema = z.object({
3745
// Schema for updating chats
3846
const UpdateChatSchema = z.object({
3947
chatId: z.string().min(1, 'Chat ID is required'),
40-
messages: z.array(z.object({
41-
id: z.string(),
42-
role: z.enum(['user', 'assistant', 'system']),
43-
content: z.string(),
44-
timestamp: z.string(),
45-
citations: z.array(z.object({
46-
id: z.number(),
47-
title: z.string(),
48-
url: z.string(),
49-
similarity: z.number().optional(),
50-
})).optional(),
51-
})).optional(),
48+
messages: z
49+
.array(
50+
z.object({
51+
id: z.string(),
52+
role: z.enum(['user', 'assistant', 'system']),
53+
content: z.string(),
54+
timestamp: z.string(),
55+
citations: z
56+
.array(
57+
z.object({
58+
id: z.number(),
59+
title: z.string(),
60+
url: z.string(),
61+
similarity: z.number().optional(),
62+
})
63+
)
64+
.optional(),
65+
})
66+
)
67+
.optional(),
5268
title: z.string().optional(),
5369
})
5470

@@ -120,23 +136,23 @@ export async function POST(req: NextRequest) {
120136
// Handle StreamingExecution (from providers with tool calls)
121137
logger.info(`[${requestId}] StreamingExecution detected`)
122138
streamToRead = (result.response as any).stream
123-
139+
124140
// Extract citations from StreamingExecution at API level
125141
const execution = (result.response as any).execution
126142
logger.info(`[${requestId}] Extracting citations from StreamingExecution`, {
127143
hasExecution: !!execution,
128144
hasToolResults: !!execution?.toolResults,
129145
toolResultsLength: execution?.toolResults?.length || 0,
130146
})
131-
147+
132148
if (execution?.toolResults) {
133149
for (const toolResult of execution.toolResults) {
134150
logger.info(`[${requestId}] Processing tool result for citations`, {
135151
hasResult: !!toolResult,
136152
resultKeys: toolResult && typeof toolResult === 'object' ? Object.keys(toolResult) : [],
137153
hasResultsArray: !!(toolResult && typeof toolResult === 'object' && toolResult.results),
138154
})
139-
155+
140156
if (toolResult && typeof toolResult === 'object' && toolResult.results) {
141157
// Convert documentation search results to citations
142158
const extractedCitations = toolResult.results.map((res: any, index: number) => ({
@@ -146,7 +162,10 @@ export async function POST(req: NextRequest) {
146162
similarity: res.similarity,
147163
}))
148164
result.citations = extractedCitations
149-
logger.info(`[${requestId}] Extracted ${extractedCitations.length} citations from tool results:`, extractedCitations)
165+
logger.info(
166+
`[${requestId}] Extracted ${extractedCitations.length} citations from tool results:`,
167+
extractedCitations
168+
)
150169
break // Use first set of results found
151170
}
152171
}
@@ -354,12 +373,12 @@ export async function PATCH(req: NextRequest) {
354373

355374
// Get the current chat to check if it has a title
356375
const existingChat = await getChat(chatId, session.user.id)
357-
376+
358377
let titleToUse = title
359-
378+
360379
// Generate title if chat doesn't have one and we have messages
361380
if (!titleToUse && existingChat && !existingChat.title && messages && messages.length > 0) {
362-
const firstUserMessage = messages.find(msg => msg.role === 'user')
381+
const firstUserMessage = messages.find((msg) => msg.role === 'user')
363382
if (firstUserMessage) {
364383
logger.info('Generating LLM-based title for chat without title')
365384
try {

apps/sim/app/api/docs/ask/route.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ const DocsQuerySchema = z.object({
1919
stream: z.boolean().optional().default(false), // Enable streaming responses
2020
})
2121

22-
23-
2422
/**
2523
* Generate embedding for search query
2624
*/

apps/sim/stores/copilot/store.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -493,20 +493,22 @@ export const useCopilotStore = create<CopilotStore>()(
493493
saveChatMessages: async (chatId: string) => {
494494
try {
495495
const { messages, currentChat } = get()
496-
496+
497497
logger.info(`Saving ${messages.length} messages for chat ${chatId}`)
498-
498+
499499
// Let the API handle title generation if needed
500500
const result = await updateChatMessages(chatId, messages)
501-
501+
502502
if (result.success && result.chat) {
503503
// Update local state with the saved chat
504504
set({
505505
currentChat: result.chat,
506506
messages: result.chat.messages,
507507
})
508-
509-
logger.info(`Successfully saved chat ${chatId} with ${result.chat.messages.length} messages`)
508+
509+
logger.info(
510+
`Successfully saved chat ${chatId} with ${result.chat.messages.length} messages`
511+
)
510512
} else {
511513
logger.error(`Failed to save chat ${chatId}:`, result.error)
512514
}

0 commit comments

Comments
 (0)