Skip to content
Merged
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
16 changes: 7 additions & 9 deletions apps/web/src/app/api/ai/page-agents/create/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function POST(request: Request) {
// Get next position
const nextPosition = await pageAgentRepository.getNextPosition(drive.id, parentId || null);

// Prepare agent data
// Prepare agent data with default PageSpace provider and standard model
const agentData: AgentData = {
title,
type: 'AI_CHAT',
Expand All @@ -95,18 +95,16 @@ export async function POST(request: Request) {
parentId: parentId || null,
isTrashed: false,
systemPrompt,
// Default to PageSpace provider with "standard" model
// Agents can use 'standard' or 'pro' as friendly aliases
aiProvider: aiProvider || 'pagespace',
aiModel: aiModel || 'standard',
};

// Add optional configuration (save even if empty array)
if (enabledTools !== undefined) {
agentData.enabledTools = enabledTools;
}
if (aiProvider) {
agentData.aiProvider = aiProvider;
}
if (aiModel) {
agentData.aiModel = aiModel;
}

// Create the agent
const newAgent = await pageAgentRepository.createAgent(agentData);
Expand Down Expand Up @@ -143,8 +141,8 @@ export async function POST(request: Request) {
systemPrompt: systemPrompt.substring(0, 100) + (systemPrompt.length > 100 ? '...' : ''),
enabledToolsCount: enabledTools?.length || 0,
enabledTools: enabledTools || [],
aiProvider: aiProvider || 'default',
aiModel: aiModel || 'default',
aiProvider: agentData.aiProvider,
aiModel: agentData.aiModel,
hasWelcomeMessage: !!welcomeMessage
},
stats: {
Expand Down
38 changes: 35 additions & 3 deletions apps/web/src/lib/ai/core/ai-providers-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,42 @@
* Single source of truth for all AI models across the application
*/

/**
* PageSpace Model Aliases
* Allows agents to use friendly names (standard/pro) instead of underlying model IDs.
* This abstraction lets agents update their model without knowing the specific backend model.
*/
export const PAGESPACE_MODEL_ALIASES: Record<string, string> = {
standard: 'glm-4.5-air',
pro: 'glm-4.7',
} as const;

/**
* Resolve a PageSpace model alias to the actual model ID
* @param modelOrAlias - Either an alias ('standard', 'pro') or actual model ID
* @returns The resolved model ID
*/
export function resolvePageSpaceModel(modelOrAlias: string): string {
const lowercased = modelOrAlias.toLowerCase();
return PAGESPACE_MODEL_ALIASES[lowercased] || modelOrAlias;
}

/**
* Check if a string is a PageSpace model alias
*/
export function isPageSpaceModelAlias(model: string): boolean {
return model.toLowerCase() in PAGESPACE_MODEL_ALIASES;
}

export const AI_PROVIDERS = {
pagespace: {
name: 'PageSpace',
models: {
'glm-4.5-air': 'Standard',
'glm-4.7': 'Pro (Pro/Business)',
// Aliases are also valid model selections
standard: 'Standard',
pro: 'Pro (Pro/Business)',
},
},
openrouter: {
Expand Down Expand Up @@ -366,7 +396,7 @@ export type AIModel<T extends AIProvider> = keyof typeof AI_PROVIDERS[T]['models
* For all other providers: Shows "PageSpace AI" to abstract away the underlying model
*
* @param provider - The AI provider (e.g., 'pagespace', 'openrouter', 'google')
* @param model - The model identifier (e.g., 'glm-4.5-air', 'glm-4.7')
* @param model - The model identifier (e.g., 'glm-4.5-air', 'glm-4.7', 'standard', 'pro')
* @returns User-friendly display name
*/
export function getUserFacingModelName(provider: string | null | undefined, model: string | null | undefined): string {
Expand All @@ -377,10 +407,12 @@ export function getUserFacingModelName(provider: string | null | undefined, mode

// For PageSpace provider, show tier-based naming
if (provider === 'pagespace') {
if (model === 'glm-4.7') {
// Resolve alias to actual model for comparison
const resolvedModel = resolvePageSpaceModel(model);
if (resolvedModel === 'glm-4.7') {
return 'PageSpace Pro';
}
if (model === 'glm-4.5-air') {
if (resolvedModel === 'glm-4.5-air') {
return 'PageSpace Standard';
}
// Any other PageSpace model defaults to Standard
Expand Down
8 changes: 7 additions & 1 deletion apps/web/src/lib/ai/core/provider-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
getUserMiniMaxSettings,
createMiniMaxSettings,
} from './ai-utils';
import { resolvePageSpaceModel } from './ai-providers-config';

export interface ProviderRequest {
selectedProvider?: string;
Expand Down Expand Up @@ -86,7 +87,12 @@ export async function createAIProvider(
// Get user's current AI provider settings
const [user] = await db.select().from(users).where(eq(users.id, userId));
const currentProvider = selectedProvider || user?.currentAiProvider || 'pagespace';
const currentModel = selectedModel || user?.currentAiModel || 'glm-4.5-air';
let currentModel = selectedModel || user?.currentAiModel || 'glm-4.5-air';

// Resolve model aliases for PageSpace provider (e.g., 'standard' -> 'glm-4.5-air')
if (currentProvider === 'pagespace') {
currentModel = resolvePageSpaceModel(currentModel);
}

try {
let model;
Expand Down