Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ NEXT_PUBLIC_COMPOSIO_USER_ID=user@example.com
# NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN=your_mapbox_public_token_here

# AI Provider API Keys
# Azure AI Foundry (Azure OpenAI)
AZURE_RESOURCE_NAME=your_azure_resource_name_here
AZURE_ENDPOINT=your_azure_endpoint_here
AZURE_API_KEY=your_azure_api_key_here
AZURE_DEPLOYMENT_NAME=gpt-5.5
Comment thread
coderabbitai[bot] marked this conversation as resolved.

# Gemini 3.1 Pro (Google Generative AI)
GEMINI_3_PRO_API_KEY=your_gemini_3_pro_api_key_here

Expand Down
11 changes: 10 additions & 1 deletion app/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,16 @@ async function submit(formData?: FormData, skip?: boolean) {
} as CoreMessage)
}

const userId = 'anonymous'
let actualUserId: string | null = null;
try {
const { getCurrentUserIdOnServer } = await import(
'@/lib/auth/get-current-user'
)
actualUserId = await getCurrentUserIdOnServer()
} catch (authError) {
console.error('Error retrieving user ID in submit:', authError);
}
const userId = actualUserId || 'anonymous'
const currentSystemPrompt = (await getSystemPrompt(userId)) || ''
const mapProvider = formData?.get('mapProvider') as 'mapbox' | 'google'

Expand Down
13 changes: 13 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions components/settings/components/model-selection-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ const models = [
badge: "Expert",
badgeVariant: "outline" as const,
},
{
id: "Azure GPT 5.5",
name: "Azure GPT 5.5",
description: "Enterprise-grade intelligence powered by Azure AI Foundry, delivering high-reliability and security.",
icon: Cpu,
badge: "Enterprise",
badgeVariant: "outline" as const,
},
];

export function ModelSelectionForm({ form }: ModelSelectionFormProps) {
Expand Down
10 changes: 7 additions & 3 deletions lib/actions/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,21 @@ export async function saveSystemPrompt(
export async function getSystemPrompt(
userId: string
): Promise<string | null> {
if (!userId) return null
if (!userId || userId === 'anonymous') return null

try {
// console.log(`getSystemPrompt: Fetching prompt for user: ${userId}`);
const result = await db.select({ systemPrompt: users.systemPrompt })
.from(users)
.where(eq(users.id, userId))
.limit(1);

return result[0]?.systemPrompt || null;
} catch (error) {
console.error('getSystemPrompt: Error:', error)
} catch (error: any) {
console.error('getSystemPrompt: Error:', error.message || error);
if (error.stack) {
console.error('getSystemPrompt: Stack trace:', error.stack);
}
return null
}
}
62 changes: 60 additions & 2 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { createOpenAI } from '@ai-sdk/openai'
import { createGoogleGenerativeAI } from '@ai-sdk/google'
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock'
import { createXai } from '@ai-sdk/xai';
import { createAzure } from '@ai-sdk/azure';
import { v4 as uuidv4 } from 'uuid';
import { LanguageModel } from 'ai'

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
Expand All @@ -21,7 +23,7 @@ export function generateUUID(): string {
*/
export { generateUUID as nanoid };

export async function getModel(requireVision: boolean = false) {
export async function getModel(requireVision: boolean = false): Promise<LanguageModel> {
const selectedModel = await getSelectedModel();

const xaiApiKey = process.env.XAI_API_KEY;
Expand All @@ -31,6 +33,10 @@ export async function getModel(requireVision: boolean = false) {
const awsRegion = process.env.AWS_REGION;
const bedrockModelId = process.env.BEDROCK_MODEL_ID || 'anthropic.claude-3-5-sonnet-20241022-v2:0';
const openaiApiKey = process.env.OPENAI_API_KEY;
const azureResourceName = process.env.AZURE_RESOURCE_NAME;
const azureApiKey = process.env.AZURE_API_KEY;
const azureEndpoint = process.env.AZURE_ENDPOINT;
const azureDeploymentName = process.env.AZURE_DEPLOYMENT_NAME || 'gpt-5.5';

if (selectedModel) {
switch (selectedModel) {
Expand Down Expand Up @@ -76,10 +82,61 @@ export async function getModel(requireVision: boolean = false) {
console.error('User selected "GPT-5.1" but OPENAI_API_KEY is not set.');
throw new Error('Selected model is not configured.');
}
case 'Azure GPT 5.5':
if (azureEndpoint && azureApiKey) {
const azureOpenAI = createOpenAI({
baseURL: azureEndpoint,
apiKey: azureApiKey,
});
try {
return azureOpenAI(azureDeploymentName);
} catch (error) {
console.error('Selected model "Azure GPT 5.5" (via endpoint) failed to initialize.', error);
throw new Error('Failed to initialize selected model.');
}
} else if (azureResourceName && azureApiKey) {
const azure = createAzure({
resourceName: azureResourceName,
apiKey: azureApiKey,
});
try {
return azure(azureDeploymentName) as unknown as LanguageModel;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚖️ Poor tradeoff

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check the `@ai-sdk/azure` package type definitions
cat node_modules/@ai-sdk/azure/package.json | jq '.version, .types'

# Search for type definitions and exported interfaces
fd -e d.ts -e ts . node_modules/@ai-sdk/azure --exec cat {} \; | rg -A 5 'createAzure|LanguageModel'

Repository: QueueLab/QCX

Length of output: 242


🌐 Web query:

What is the correct return type for createAzure() in @ai-sdk/azure version 3.0.64?

💡 Result:

In @ai-sdk/azure v3.0.64, createAzure returns a provider factory function (the “azure provider”), i.e. a callable that you use like azure(deploymentName) to create Azure language model instances. Evidence: the official Azure provider docs show createAzure({... }) assigned to a variable named azure, and then used as azure('your-deployment-name') when calling generateText for “Responses models” [1]. The docs also note the returned provider is typed via AzureResponsesProviderMetadata, which only makes sense if createAzure returns a provider factory callable with a deployment name [1].

Citations:


🏁 Script executed:

# First, locate and examine the lib/utils/index.ts file
cat -n lib/utils/index.ts | head -100

Repository: QueueLab/QCX

Length of output: 4692


🏁 Script executed:

# Get more context around line 91
sed -n '80,100p' lib/utils/index.ts

Repository: QueueLab/QCX

Length of output: 948


🏁 Script executed:

# Check imports at the top of the file
head -30 lib/utils/index.ts

Repository: QueueLab/QCX

Length of output: 1076


Remove the double type cast on the Azure provider.

The expression azure(azureDeploymentName) as unknown as LanguageModel uses a double cast, which is inconsistent with all other providers in the same function. Lines 49, 65, and 79 return their provider calls directly without type assertions:

  • return xai('grok-4-fast-non-reasoning')
  • return google('gemini-3.1-pro-preview')
  • return openai('gpt-4o')

Since the Azure provider follows the same invocation pattern (azure(deploymentName)) as the others, it should return a compatible type without requiring explicit casting. The double cast suggests a type mismatch that either should be resolved at the API call level or indicates the cast is unnecessary.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/utils/index.ts` at line 91, The Azure provider return currently uses a
double cast ("azure(azureDeploymentName) as unknown as LanguageModel"); remove
the unnecessary "as unknown as LanguageModel" and return
azure(azureDeploymentName) directly, and if TypeScript still complains update
the azure(...) function/type signature to return the correct LanguageModel type
instead of masking the mismatch; reference the azure function call and the
azureDeploymentName variable and ensure the return matches the other providers
(xai, google, openai) without double casting.

} catch (error) {
console.error('Selected model "Azure GPT 5.5" (via resource) failed to initialize.', error);
throw new Error('Failed to initialize selected model.');
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
} else {
console.error('User selected "Azure GPT 5.5" but Azure environment variables are not set.');
throw new Error('Selected model is not configured.');
}
}
}

// Default behavior: Azure -> Gemini -> Grok -> Bedrock -> OpenAI
if (azureEndpoint && azureApiKey) {
const azureOpenAI = createOpenAI({
baseURL: azureEndpoint,
apiKey: azureApiKey,
});
try {
return azureOpenAI(azureDeploymentName);
} catch (error) {
console.warn('Azure OpenAI API (via endpoint) unavailable, falling back to next provider:', error);
}
}

if (azureResourceName && azureApiKey) {
const azure = createAzure({
resourceName: azureResourceName,
apiKey: azureApiKey,
});
try {
return azure(azureDeploymentName) as unknown as LanguageModel;
} catch (error) {
console.warn('Azure OpenAI API (via resource) unavailable, falling back to next provider:', error);
}
}

// Default behavior: Gemini -> Grok -> Bedrock -> OpenAI
if (gemini3ProApiKey) {
const google = createGoogleGenerativeAI({
apiKey: gemini3ProApiKey,
Expand All @@ -103,6 +160,7 @@ export async function getModel(requireVision: boolean = false) {
}
}


if (awsAccessKeyId && awsSecretAccessKey) {
const bedrock = createAmazonBedrock({
bedrockOptions: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@ai-sdk/amazon-bedrock": "^1.1.6",
"@ai-sdk/anthropic": "^1.2.12",
"@ai-sdk/azure": "^3.0.64",
"@ai-sdk/google": "^1.2.22",
"@ai-sdk/openai": "^1.3.24",
"@ai-sdk/xai": "^1.2.18",
Expand Down