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
This commit is contained in:
Siddharth Ganesan
2025-08-26 10:55:08 -07:00
committed by GitHub
parent e5c0b14367
commit 3d3443f68e
2 changed files with 18 additions and 36 deletions

View File

@@ -224,11 +224,6 @@ describe('Copilot Chat API Route', () => {
stream: true,
streamToolCalls: true,
mode: 'agent',
provider: {
provider: 'anthropic',
model: 'claude-3-haiku-20240307',
apiKey: 'test-sim-agent-key',
},
depth: 0,
origin: 'http://localhost:3000',
}),
@@ -292,11 +287,6 @@ describe('Copilot Chat API Route', () => {
stream: true,
streamToolCalls: true,
mode: 'agent',
provider: {
provider: 'anthropic',
model: 'claude-3-haiku-20240307',
apiKey: 'test-sim-agent-key',
},
depth: 0,
origin: 'http://localhost:3000',
}),
@@ -352,11 +342,6 @@ describe('Copilot Chat API Route', () => {
stream: true,
streamToolCalls: true,
mode: 'agent',
provider: {
provider: 'anthropic',
model: 'claude-3-haiku-20240307',
apiKey: 'test-sim-agent-key',
},
depth: 0,
origin: 'http://localhost:3000',
}),
@@ -452,11 +437,6 @@ describe('Copilot Chat API Route', () => {
stream: true,
streamToolCalls: true,
mode: 'ask',
provider: {
provider: 'anthropic',
model: 'claude-3-haiku-20240307',
apiKey: 'test-sim-agent-key',
},
depth: 0,
origin: 'http://localhost:3000',
}),

View File

@@ -401,24 +401,26 @@ export async function POST(req: NextRequest) {
}
const defaults = getCopilotModel('chat')
const providerToUse = (env.COPILOT_PROVIDER as any) || defaults.provider
const modelToUse = env.COPILOT_MODEL || defaults.model
let providerConfig: CopilotProviderConfig
let providerConfig: CopilotProviderConfig | undefined
const providerEnv = env.COPILOT_PROVIDER as any
if (providerToUse === 'azure-openai') {
providerConfig = {
provider: 'azure-openai',
model: modelToUse,
apiKey: env.AZURE_OPENAI_API_KEY,
apiVersion: env.AZURE_OPENAI_API_VERSION,
endpoint: env.AZURE_OPENAI_ENDPOINT,
}
} else {
providerConfig = {
provider: providerToUse,
model: modelToUse,
apiKey: env.COPILOT_API_KEY,
if (providerEnv) {
if (providerEnv === 'azure-openai') {
providerConfig = {
provider: 'azure-openai',
model: modelToUse,
apiKey: env.AZURE_OPENAI_API_KEY,
apiVersion: env.AZURE_OPENAI_API_VERSION,
endpoint: env.AZURE_OPENAI_ENDPOINT,
}
} else {
providerConfig = {
provider: providerEnv,
model: modelToUse,
apiKey: env.COPILOT_API_KEY,
}
}
}
@@ -438,7 +440,7 @@ export async function POST(req: NextRequest) {
stream: stream,
streamToolCalls: true,
mode: mode,
provider: providerConfig,
...(providerConfig ? { provider: providerConfig } : {}),
...(effectiveConversationId ? { conversationId: effectiveConversationId } : {}),
...(typeof effectiveDepth === 'number' ? { depth: effectiveDepth } : {}),
...(typeof effectivePrefetch === 'boolean' ? { prefetch: effectivePrefetch } : {}),