Skip to content

Commit 776ae06

Browse files
committed
Lint
1 parent ccf5c2f commit 776ae06

File tree

7 files changed

+72
-46
lines changed

7 files changed

+72
-46
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,28 @@ export async function POST(req: NextRequest) {
7777

7878
// Handle streaming response (ReadableStream or StreamingExecution)
7979
let streamToRead: ReadableStream | null = null
80-
80+
8181
// Debug logging to see what we actually got
8282
logger.info(`[${requestId}] Response type analysis:`, {
8383
responseType: typeof result.response,
8484
isReadableStream: result.response instanceof ReadableStream,
85-
hasStreamProperty: typeof result.response === 'object' && result.response && 'stream' in result.response,
86-
hasExecutionProperty: typeof result.response === 'object' && result.response && 'execution' in result.response,
87-
responseKeys: typeof result.response === 'object' && result.response ? Object.keys(result.response) : [],
85+
hasStreamProperty:
86+
typeof result.response === 'object' && result.response && 'stream' in result.response,
87+
hasExecutionProperty:
88+
typeof result.response === 'object' && result.response && 'execution' in result.response,
89+
responseKeys:
90+
typeof result.response === 'object' && result.response ? Object.keys(result.response) : [],
8891
})
89-
92+
9093
if (result.response instanceof ReadableStream) {
9194
logger.info(`[${requestId}] Direct ReadableStream detected`)
9295
streamToRead = result.response
93-
} else if (typeof result.response === 'object' && result.response && 'stream' in result.response && 'execution' in result.response) {
96+
} else if (
97+
typeof result.response === 'object' &&
98+
result.response &&
99+
'stream' in result.response &&
100+
'execution' in result.response
101+
) {
94102
// Handle StreamingExecution (from providers with tool calls)
95103
logger.info(`[${requestId}] StreamingExecution detected`)
96104
streamToRead = (result.response as any).stream

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ export async function POST(req: NextRequest) {
4848

4949
logger.error(`[${requestId}] Documentation search error:`, error)
5050
return NextResponse.json(
51-
{
51+
{
5252
error: 'Failed to search documentation',
53-
details: error instanceof Error ? error.message : 'Unknown error'
54-
},
53+
details: error instanceof Error ? error.message : 'Unknown error',
54+
},
5555
{ status: 500 }
5656
)
5757
}

apps/sim/lib/copilot-api.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ export async function sendStreamingMessage(request: SendMessageRequest): Promise
251251
error?: string
252252
}> {
253253
try {
254-
console.log('[CopilotAPI] Sending streaming message request:', {
255-
message: request.message,
254+
console.log('[CopilotAPI] Sending streaming message request:', {
255+
message: request.message,
256256
stream: true,
257-
hasWorkflowId: !!request.workflowId
257+
hasWorkflowId: !!request.workflowId,
258258
})
259259

260260
const response = await fetch('/api/copilot', {
@@ -268,7 +268,7 @@ export async function sendStreamingMessage(request: SendMessageRequest): Promise
268268
status: response.status,
269269
statusText: response.statusText,
270270
hasBody: !!response.body,
271-
contentType: response.headers.get('content-type')
271+
contentType: response.headers.get('content-type'),
272272
})
273273

274274
if (!response.ok) {
@@ -351,19 +351,19 @@ export async function sendStreamingDocsMessage(request: DocsQueryRequest): Promi
351351
}> {
352352
try {
353353
console.log('[CopilotAPI] sendStreamingDocsMessage called with:', request)
354-
354+
355355
const response = await fetch('/api/copilot/docs', {
356356
method: 'POST',
357357
headers: { 'Content-Type': 'application/json' },
358358
body: JSON.stringify({ ...request, stream: true }),
359359
})
360360

361-
console.log('[CopilotAPI] Fetch response received:', {
362-
status: response.status,
363-
statusText: response.statusText,
361+
console.log('[CopilotAPI] Fetch response received:', {
362+
status: response.status,
363+
statusText: response.statusText,
364364
headers: Object.fromEntries(response.headers.entries()),
365365
ok: response.ok,
366-
hasBody: !!response.body
366+
hasBody: !!response.body,
367367
})
368368

369369
if (!response.ok) {

apps/sim/lib/copilot/service.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,26 +445,31 @@ export async function generateChatResponse(
445445
})
446446

447447
// Handle StreamingExecution (from providers with tool calls)
448-
if (typeof response === 'object' && response && 'stream' in response && 'execution' in response) {
448+
if (
449+
typeof response === 'object' &&
450+
response &&
451+
'stream' in response &&
452+
'execution' in response
453+
) {
449454
logger.info('Detected StreamingExecution from provider')
450455
return (response as any).stream
451456
}
452457

453458
// Handle ProviderResponse (non-streaming with tool calls)
454459
if (typeof response === 'object' && 'content' in response) {
455460
const content = response.content || 'Sorry, I could not generate a response.'
456-
461+
457462
// If streaming was requested, wrap the content in a ReadableStream
458463
if (stream) {
459464
return new ReadableStream({
460465
start(controller) {
461466
const encoder = new TextEncoder()
462467
controller.enqueue(encoder.encode(content))
463468
controller.close()
464-
}
469+
},
465470
})
466471
}
467-
472+
468473
return content
469474
}
470475

apps/sim/lib/copilot/tools.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export interface CopilotTool {
2727
const docsSearchTool: CopilotTool = {
2828
id: 'docs_search_internal',
2929
name: 'Search Documentation',
30-
description: 'Search Sim Studio documentation for information about features, tools, workflows, and functionality',
30+
description:
31+
'Search Sim Studio documentation for information about features, tools, workflows, and functionality',
3132
parameters: {
3233
type: 'object',
3334
properties: {
@@ -46,13 +47,13 @@ const docsSearchTool: CopilotTool = {
4647
execute: async (args: Record<string, any>): Promise<CopilotToolResult> => {
4748
try {
4849
const { query, topK = 5 } = args
49-
50+
5051
logger.info('Executing documentation search', { query, topK })
51-
52+
5253
const results = await searchDocumentation(query, { topK })
53-
54+
5455
logger.info(`Found ${results.length} documentation results`, { query })
55-
56+
5657
return {
5758
success: true,
5859
data: {
@@ -87,7 +88,7 @@ export async function executeCopilotTool(
8788
args: Record<string, any>
8889
): Promise<CopilotToolResult> {
8990
const tool = getCopilotTool(toolId)
90-
91+
9192
if (!tool) {
9293
logger.error(`Copilot tool not found: ${toolId}`)
9394
return {
@@ -113,4 +114,4 @@ export async function executeCopilotTool(
113114
// Get all available copilot tools (for tool definitions in LLM requests)
114115
export function getAllCopilotTools(): CopilotTool[] {
115116
return Object.values(copilotTools)
116-
}
117+
}

apps/sim/stores/copilot/store.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ export const useCopilotStore = create<CopilotStore>()(
196196
const { workflowId, currentChat } = get()
197197
const { stream = true } = options
198198

199-
console.log('[CopilotStore] sendMessage called:', {
200-
message,
201-
workflowId,
202-
hasCurrentChat: !!currentChat,
203-
stream
199+
console.log('[CopilotStore] sendMessage called:', {
200+
message,
201+
workflowId,
202+
hasCurrentChat: !!currentChat,
203+
stream,
204204
})
205205

206206
if (!workflowId) {
@@ -227,9 +227,9 @@ export const useCopilotStore = create<CopilotStore>()(
227227
timestamp: new Date().toISOString(),
228228
}
229229

230-
console.log('[CopilotStore] Adding messages to state:', {
231-
userMessageId: userMessage.id,
232-
streamingMessageId: streamingMessage.id
230+
console.log('[CopilotStore] Adding messages to state:', {
231+
userMessageId: userMessage.id,
232+
streamingMessageId: streamingMessage.id,
233233
})
234234

235235
set((state) => ({
@@ -246,10 +246,10 @@ export const useCopilotStore = create<CopilotStore>()(
246246
stream,
247247
})
248248

249-
console.log('[CopilotStore] Streaming result:', {
250-
success: result.success,
251-
hasStream: !!result.stream,
252-
error: result.error
249+
console.log('[CopilotStore] Streaming result:', {
250+
success: result.success,
251+
hasStream: !!result.stream,
252+
error: result.error,
253253
})
254254

255255
if (result.success && result.stream) {
@@ -353,7 +353,10 @@ export const useCopilotStore = create<CopilotStore>()(
353353

354354
// Handle streaming response (shared by both message types)
355355
handleStreamingResponse: async (stream: ReadableStream, messageId: string) => {
356-
console.log('[CopilotStore] handleStreamingResponse started:', { messageId, hasStream: !!stream })
356+
console.log('[CopilotStore] handleStreamingResponse started:', {
357+
messageId,
358+
hasStream: !!stream,
359+
})
357360

358361
const reader = stream.getReader()
359362
const decoder = new TextDecoder()
@@ -365,7 +368,7 @@ export const useCopilotStore = create<CopilotStore>()(
365368
try {
366369
while (true) {
367370
const { done, value } = await reader.read()
368-
371+
369372
if (done || streamComplete) break
370373

371374
const chunk = decoder.decode(value, { stream: true })
@@ -395,7 +398,10 @@ export const useCopilotStore = create<CopilotStore>()(
395398
} else if (data.type === 'content') {
396399
console.log('[CopilotStore] Received content chunk:', data.content)
397400
accumulatedContent += data.content
398-
console.log('[CopilotStore] Accumulated content length:', accumulatedContent.length)
401+
console.log(
402+
'[CopilotStore] Accumulated content length:',
403+
accumulatedContent.length
404+
)
399405

400406
// Update the streaming message
401407
set((state) => ({
@@ -443,7 +449,12 @@ export const useCopilotStore = create<CopilotStore>()(
443449
throw new Error(data.error || 'Streaming error')
444450
}
445451
} catch (parseError) {
446-
console.warn('[CopilotStore] Failed to parse SSE data:', parseError, 'Line:', line)
452+
console.warn(
453+
'[CopilotStore] Failed to parse SSE data:',
454+
parseError,
455+
'Line:',
456+
line
457+
)
447458
logger.warn('Failed to parse SSE data:', parseError)
448459
}
449460
} else if (line.trim()) {

apps/sim/tools/docs/search.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export interface DocsSearchResponse {
2020
export const docsSearchTool: ToolConfig<DocsSearchParams, DocsSearchResponse> = {
2121
id: 'docs_search_internal',
2222
name: 'Search Documentation',
23-
description: 'Search Sim Studio documentation for information about features, tools, workflows, and functionality',
23+
description:
24+
'Search Sim Studio documentation for information about features, tools, workflows, and functionality',
2425
version: '1.0.0',
2526

2627
params: {

0 commit comments

Comments
 (0)