Skip to content

Commit 02c4112

Browse files
committed
Lint
1 parent d1fe209 commit 02c4112

File tree

9 files changed

+143
-120
lines changed

9 files changed

+143
-120
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { type NextRequest, NextResponse } from 'next/server'
22
import { z } from 'zod'
33
import { getSession } from '@/lib/auth'
4-
import { createLogger } from '@/lib/logs/console-logger'
54
import {
5+
createChat,
6+
generateChatTitle,
67
generateDocsResponse,
78
getChat,
8-
createChat,
99
updateChat,
10-
generateChatTitle,
1110
} from '@/lib/copilot/service'
11+
import { createLogger } from '@/lib/logs/console-logger'
1212

1313
const logger = createLogger('CopilotDocsAPI')
1414

@@ -254,4 +254,4 @@ export async function POST(req: NextRequest) {
254254
logger.error(`[${requestId}] Copilot docs error:`, error)
255255
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
256256
}
257-
}
257+
}

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
import { type NextRequest, NextResponse } from 'next/server'
22
import { z } from 'zod'
33
import { getSession } from '@/lib/auth'
4+
import { createChat, deleteChat, getChat, listChats, sendMessage } from '@/lib/copilot/service'
45
import { createLogger } from '@/lib/logs/console-logger'
5-
import {
6-
sendMessage,
7-
createChat,
8-
getChat,
9-
listChats,
10-
deleteChat,
11-
generateDocsResponse,
12-
type CopilotMessage,
13-
} from '@/lib/copilot/service'
146

157
const logger = createLogger('CopilotAPI')
168

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { and, eq, sql } from 'drizzle-orm'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { z } from 'zod'
44
import { getSession } from '@/lib/auth'
5+
import { getCopilotConfig, getCopilotModel } from '@/lib/copilot/config'
56
import { createLogger } from '@/lib/logs/console-logger'
67
import { generateEmbeddings } from '@/app/api/knowledge/utils'
78
import { db } from '@/db'
89
import { copilotChats, docsEmbeddings } from '@/db/schema'
910
import { executeProviderRequest } from '@/providers'
1011
import { getApiKey } from '@/providers/utils'
11-
import { getCopilotConfig, getCopilotModel } from '@/lib/copilot/config'
1212

1313
const logger = createLogger('DocsRAG')
1414

@@ -33,7 +33,7 @@ async function generateChatTitle(userMessage: string): Promise<string> {
3333
let apiKey: string
3434
try {
3535
// Use rotating key directly for hosted providers
36-
if ((provider === 'openai' || provider === 'anthropic')) {
36+
if (provider === 'openai' || provider === 'anthropic') {
3737
const { getRotatingApiKey } = require('@/lib/utils')
3838
apiKey = getRotatingApiKey(provider)
3939
} else {
@@ -120,7 +120,7 @@ async function generateResponse(
120120
conversationHistory: any[] = []
121121
): Promise<string | ReadableStream> {
122122
const config = getCopilotConfig()
123-
123+
124124
// Determine which provider and model to use - allow overrides
125125
const selectedProvider = provider || config.rag.defaultProvider
126126
const selectedModel = model || config.rag.defaultModel
@@ -129,15 +129,17 @@ async function generateResponse(
129129
let apiKey: string
130130
try {
131131
// Use rotating key directly for hosted providers
132-
if ((selectedProvider === 'openai' || selectedProvider === 'anthropic')) {
132+
if (selectedProvider === 'openai' || selectedProvider === 'anthropic') {
133133
const { getRotatingApiKey } = require('@/lib/utils')
134134
apiKey = getRotatingApiKey(selectedProvider)
135135
} else {
136136
apiKey = getApiKey(selectedProvider, selectedModel)
137137
}
138138
} catch (error) {
139139
logger.error(`Failed to get API key for ${selectedProvider} ${selectedModel}:`, error)
140-
throw new Error(`API key not configured for ${selectedProvider}. Please set up API keys for this provider or use a different one.`)
140+
throw new Error(
141+
`API key not configured for ${selectedProvider}. Please set up API keys for this provider or use a different one.`
142+
)
141143
}
142144

143145
// Format chunks as context with numbered sources

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/copilot.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import {
2121
import { Input } from '@/components/ui/input'
2222
import { ScrollArea } from '@/components/ui/scroll-area'
2323
import { createLogger } from '@/lib/logs/console-logger'
24-
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
2524
import { useCopilotStore } from '@/stores/copilot/store'
2625
import type { CopilotMessage } from '@/stores/copilot/types'
26+
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
2727
import { CopilotModal } from './components/copilot-modal/copilot-modal'
2828

2929
const logger = createLogger('Copilot')
@@ -56,7 +56,7 @@ export const Copilot = forwardRef<CopilotRef, CopilotProps>(
5656
const scrollAreaRef = useRef<HTMLDivElement>(null)
5757

5858
const { activeWorkflowId } = useWorkflowRegistry()
59-
59+
6060
// Use the new copilot store
6161
const {
6262
currentChat,
@@ -128,8 +128,8 @@ export const Copilot = forwardRef<CopilotRef, CopilotProps>(
128128
const handleSubmit = useCallback(
129129
async (e: React.FormEvent, message?: string) => {
130130
e.preventDefault()
131-
132-
const query = message || (inputRef.current?.value?.trim() || '')
131+
132+
const query = message || inputRef.current?.value?.trim() || ''
133133
if (!query || isSendingMessage || !activeWorkflowId) return
134134

135135
// Clear input if using the form input
@@ -408,12 +408,7 @@ export const Copilot = forwardRef<CopilotRef, CopilotProps>(
408408
className='flex-1'
409409
autoComplete='off'
410410
/>
411-
<Button
412-
type='submit'
413-
size='icon'
414-
disabled={isSendingMessage}
415-
className='h-10 w-10'
416-
>
411+
<Button type='submit' size='icon' disabled={isSendingMessage} className='h-10 w-10'>
417412
{isSendingMessage ? (
418413
<Loader2 className='h-4 w-4 animate-spin' />
419414
) : (

apps/sim/lib/copilot/config.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ When you reference information from documentation sources, use this format:
7272
- Each source should only be cited once in your response
7373
- Continue your full response after adding citations - don't stop mid-answer
7474
75-
IMPORTANT: Always provide complete, helpful responses. If you add citations, continue writing your full answer. Do not stop your response after adding a citation.`
75+
IMPORTANT: Always provide complete, helpful responses. If you add citations, continue writing your full answer. Do not stop your response after adding a citation.`,
7676
},
7777
rag: {
7878
defaultProvider: 'anthropic',
@@ -81,13 +81,13 @@ IMPORTANT: Always provide complete, helpful responses. If you add citations, con
8181
maxTokens: 2000,
8282
embeddingModel: 'text-embedding-3-small',
8383
maxSources: 5,
84-
similarityThreshold: 0.7
84+
similarityThreshold: 0.7,
8585
},
8686
general: {
8787
streamingEnabled: true,
8888
maxConversationHistory: 10,
89-
titleGenerationModel: 'claude-3-haiku-20240307' // Faster model for titles
90-
}
89+
titleGenerationModel: 'claude-3-haiku-20240307', // Faster model for titles
90+
},
9191
}
9292

9393
/**
@@ -129,23 +129,27 @@ export function getCopilotConfig(): CopilotConfig {
129129
config.rag.maxSources = Number.parseInt(process.env.COPILOT_RAG_MAX_SOURCES)
130130
}
131131
if (process.env.COPILOT_RAG_SIMILARITY_THRESHOLD) {
132-
config.rag.similarityThreshold = Number.parseFloat(process.env.COPILOT_RAG_SIMILARITY_THRESHOLD)
132+
config.rag.similarityThreshold = Number.parseFloat(
133+
process.env.COPILOT_RAG_SIMILARITY_THRESHOLD
134+
)
133135
}
134136

135137
// General configuration overrides
136138
if (process.env.COPILOT_STREAMING_ENABLED) {
137139
config.general.streamingEnabled = process.env.COPILOT_STREAMING_ENABLED === 'true'
138140
}
139141
if (process.env.COPILOT_MAX_CONVERSATION_HISTORY) {
140-
config.general.maxConversationHistory = Number.parseInt(process.env.COPILOT_MAX_CONVERSATION_HISTORY)
142+
config.general.maxConversationHistory = Number.parseInt(
143+
process.env.COPILOT_MAX_CONVERSATION_HISTORY
144+
)
141145
}
142146

143147
logger.info('Copilot configuration loaded', {
144148
chatProvider: config.chat.defaultProvider,
145149
chatModel: config.chat.defaultModel,
146150
ragProvider: config.rag.defaultProvider,
147151
ragModel: config.rag.defaultModel,
148-
streamingEnabled: config.general.streamingEnabled
152+
streamingEnabled: config.general.streamingEnabled,
149153
})
150154
} catch (error) {
151155
logger.warn('Error applying environment variable overrides, using defaults', { error })
@@ -157,24 +161,27 @@ export function getCopilotConfig(): CopilotConfig {
157161
/**
158162
* Get the model to use for a specific copilot function
159163
*/
160-
export function getCopilotModel(type: 'chat' | 'rag' | 'title'): { provider: ProviderId; model: string } {
164+
export function getCopilotModel(type: 'chat' | 'rag' | 'title'): {
165+
provider: ProviderId
166+
model: string
167+
} {
161168
const config = getCopilotConfig()
162-
169+
163170
switch (type) {
164171
case 'chat':
165172
return {
166173
provider: config.chat.defaultProvider,
167-
model: config.chat.defaultModel
174+
model: config.chat.defaultModel,
168175
}
169176
case 'rag':
170177
return {
171178
provider: config.rag.defaultProvider,
172-
model: config.rag.defaultModel
179+
model: config.rag.defaultModel,
173180
}
174181
case 'title':
175182
return {
176183
provider: config.chat.defaultProvider, // Use same provider as chat
177-
model: config.general.titleGenerationModel
184+
model: config.general.titleGenerationModel,
178185
}
179186
default:
180187
throw new Error(`Unknown copilot model type: ${type}`)
@@ -184,7 +191,10 @@ export function getCopilotModel(type: 'chat' | 'rag' | 'title'): { provider: Pro
184191
/**
185192
* Validate that a provider/model combination is available
186193
*/
187-
export function validateCopilotConfig(config: CopilotConfig): { isValid: boolean; errors: string[] } {
194+
export function validateCopilotConfig(config: CopilotConfig): {
195+
isValid: boolean
196+
errors: string[]
197+
} {
188198
const errors: string[] = []
189199

190200
// Validate chat provider/model
@@ -232,6 +242,6 @@ export function validateCopilotConfig(config: CopilotConfig): { isValid: boolean
232242

233243
return {
234244
isValid: errors.length === 0,
235-
errors
245+
errors,
236246
}
237-
}
247+
}

0 commit comments

Comments
 (0)