Skip to content

Commit 3d3443f

Browse files
authored
fix(copilot): enterprise api keys (#1138)
* Copilot enterprise * Fix validation and enterprise azure keys * Lint * update tests * Update * Lint * Remove hardcoded ishosted * Lint * Updatse * Add tests
1 parent e5c0b14 commit 3d3443f

File tree

2 files changed

+19
-37
lines changed

2 files changed

+19
-37
lines changed

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,6 @@ describe('Copilot Chat API Route', () => {
224224
stream: true,
225225
streamToolCalls: true,
226226
mode: 'agent',
227-
provider: {
228-
provider: 'anthropic',
229-
model: 'claude-3-haiku-20240307',
230-
apiKey: 'test-sim-agent-key',
231-
},
232227
depth: 0,
233228
origin: 'http://localhost:3000',
234229
}),
@@ -292,11 +287,6 @@ describe('Copilot Chat API Route', () => {
292287
stream: true,
293288
streamToolCalls: true,
294289
mode: 'agent',
295-
provider: {
296-
provider: 'anthropic',
297-
model: 'claude-3-haiku-20240307',
298-
apiKey: 'test-sim-agent-key',
299-
},
300290
depth: 0,
301291
origin: 'http://localhost:3000',
302292
}),
@@ -352,11 +342,6 @@ describe('Copilot Chat API Route', () => {
352342
stream: true,
353343
streamToolCalls: true,
354344
mode: 'agent',
355-
provider: {
356-
provider: 'anthropic',
357-
model: 'claude-3-haiku-20240307',
358-
apiKey: 'test-sim-agent-key',
359-
},
360345
depth: 0,
361346
origin: 'http://localhost:3000',
362347
}),
@@ -452,11 +437,6 @@ describe('Copilot Chat API Route', () => {
452437
stream: true,
453438
streamToolCalls: true,
454439
mode: 'ask',
455-
provider: {
456-
provider: 'anthropic',
457-
model: 'claude-3-haiku-20240307',
458-
apiKey: 'test-sim-agent-key',
459-
},
460440
depth: 0,
461441
origin: 'http://localhost:3000',
462442
}),

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -401,24 +401,26 @@ export async function POST(req: NextRequest) {
401401
}
402402

403403
const defaults = getCopilotModel('chat')
404-
const providerToUse = (env.COPILOT_PROVIDER as any) || defaults.provider
405404
const modelToUse = env.COPILOT_MODEL || defaults.model
406405

407-
let providerConfig: CopilotProviderConfig
408-
409-
if (providerToUse === 'azure-openai') {
410-
providerConfig = {
411-
provider: 'azure-openai',
412-
model: modelToUse,
413-
apiKey: env.AZURE_OPENAI_API_KEY,
414-
apiVersion: env.AZURE_OPENAI_API_VERSION,
415-
endpoint: env.AZURE_OPENAI_ENDPOINT,
416-
}
417-
} else {
418-
providerConfig = {
419-
provider: providerToUse,
420-
model: modelToUse,
421-
apiKey: env.COPILOT_API_KEY,
406+
let providerConfig: CopilotProviderConfig | undefined
407+
const providerEnv = env.COPILOT_PROVIDER as any
408+
409+
if (providerEnv) {
410+
if (providerEnv === 'azure-openai') {
411+
providerConfig = {
412+
provider: 'azure-openai',
413+
model: modelToUse,
414+
apiKey: env.AZURE_OPENAI_API_KEY,
415+
apiVersion: env.AZURE_OPENAI_API_VERSION,
416+
endpoint: env.AZURE_OPENAI_ENDPOINT,
417+
}
418+
} else {
419+
providerConfig = {
420+
provider: providerEnv,
421+
model: modelToUse,
422+
apiKey: env.COPILOT_API_KEY,
423+
}
422424
}
423425
}
424426

@@ -438,7 +440,7 @@ export async function POST(req: NextRequest) {
438440
stream: stream,
439441
streamToolCalls: true,
440442
mode: mode,
441-
provider: providerConfig,
443+
...(providerConfig ? { provider: providerConfig } : {}),
442444
...(effectiveConversationId ? { conversationId: effectiveConversationId } : {}),
443445
...(typeof effectiveDepth === 'number' ? { depth: effectiveDepth } : {}),
444446
...(typeof effectivePrefetch === 'boolean' ? { prefetch: effectivePrefetch } : {}),

0 commit comments

Comments
 (0)