feat: consume server model reasoning capabilities
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
||||
} from '../route-utils';
|
||||
import { decodeRouteId, sendCodingRouteError } from './coding-route-errors';
|
||||
|
||||
const THINKING_LEVELS = new Set(['off', 'minimal', 'low', 'medium', 'high']);
|
||||
const THINKING_LEVELS = new Set(['off', 'minimal', 'low', 'medium', 'high', 'max']);
|
||||
|
||||
function invalidRequest(message: string): never {
|
||||
throw new CodingConversationServiceError(400, 'CODING_CONVERSATION_REQUEST_INVALID', message);
|
||||
@@ -187,7 +187,7 @@ export async function handleCodingConversationRoutes(
|
||||
sendJson(res, 200, {
|
||||
model: await service.setThinking(
|
||||
conversationId,
|
||||
body.thinkingLevel as 'off' | 'minimal' | 'low' | 'medium' | 'high',
|
||||
body.thinkingLevel as 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'max',
|
||||
),
|
||||
});
|
||||
return true;
|
||||
|
||||
@@ -20,8 +20,10 @@ import { seedWorksSquareAIGatewayCredential } from '../../services/works-square-
|
||||
import {
|
||||
NIANCODE_USER_MODEL_ACCOUNT_ID,
|
||||
NIANCODE_USER_MODEL_ACCOUNT_LABEL,
|
||||
normalizeImportedModelCapabilities,
|
||||
normalizeImportedUserModelId,
|
||||
} from '../../../shared/user-model-config';
|
||||
import type { ImportedModelCapabilities } from '../../../shared/imported-model-profile';
|
||||
|
||||
const legacyProviderRoutesWarned = new Set<string>();
|
||||
|
||||
@@ -141,6 +143,7 @@ type ImportedUserModelConfig = {
|
||||
credentialMode: string;
|
||||
apiKeyExpiresIn: number | null;
|
||||
models: string[];
|
||||
modelCapabilities?: ImportedModelCapabilities;
|
||||
};
|
||||
|
||||
const WORKS_SQUARE_AI_GATEWAY_CREDENTIAL_MODE = 'works_square_ai_gateway';
|
||||
@@ -157,7 +160,7 @@ class WorksSquareModelConfigError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeImportedUserModelConfig(payload: unknown): ImportedUserModelConfig {
|
||||
export function normalizeImportedUserModelConfig(payload: unknown): ImportedUserModelConfig {
|
||||
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
|
||||
throw new Error('Works Square model config response is invalid');
|
||||
}
|
||||
@@ -181,6 +184,7 @@ function normalizeImportedUserModelConfig(payload: unknown): ImportedUserModelCo
|
||||
const label = typeof record.label === 'string' && record.label.trim()
|
||||
? record.label.trim()
|
||||
: NIANCODE_USER_MODEL_ACCOUNT_LABEL;
|
||||
const modelCapabilities = normalizeImportedModelCapabilities(record.model_capabilities, models);
|
||||
|
||||
return {
|
||||
label,
|
||||
@@ -189,6 +193,7 @@ function normalizeImportedUserModelConfig(payload: unknown): ImportedUserModelCo
|
||||
credentialMode: credentialMode || 'api_key',
|
||||
apiKeyExpiresIn,
|
||||
models,
|
||||
...(modelCapabilities ? { modelCapabilities } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -211,9 +216,13 @@ function importedUserModelMetadata(
|
||||
if (useLocalAiProxy) {
|
||||
const metadata = { ...(existing?.metadata ?? {}) };
|
||||
delete metadata.worksSquareCredentialExpiresAt;
|
||||
delete metadata.worksSquareModelCapabilities;
|
||||
return {
|
||||
...metadata,
|
||||
customModels: modelConfig.models,
|
||||
...(modelConfig.modelCapabilities
|
||||
? { worksSquareModelCapabilities: modelConfig.modelCapabilities }
|
||||
: {}),
|
||||
worksSquareCredentialMode: WORKS_SQUARE_AI_GATEWAY_PROXY_CREDENTIAL_MODE,
|
||||
worksSquareOneApiBaseUrl: modelConfig.baseUrl,
|
||||
};
|
||||
@@ -222,12 +231,16 @@ function importedUserModelMetadata(
|
||||
const metadata = { ...(existing?.metadata ?? {}) };
|
||||
delete metadata.worksSquareCredentialExpiresAt;
|
||||
delete metadata.worksSquareOneApiBaseUrl;
|
||||
delete metadata.worksSquareModelCapabilities;
|
||||
const credentialExpiresAt = modelConfig.apiKeyExpiresIn === null
|
||||
? undefined
|
||||
: new Date(nowMs + modelConfig.apiKeyExpiresIn * 1000).toISOString();
|
||||
return {
|
||||
...metadata,
|
||||
customModels: modelConfig.models,
|
||||
...(modelConfig.modelCapabilities
|
||||
? { worksSquareModelCapabilities: modelConfig.modelCapabilities }
|
||||
: {}),
|
||||
worksSquareCredentialMode: modelConfig.credentialMode,
|
||||
...(credentialExpiresAt ? { worksSquareCredentialExpiresAt: credentialExpiresAt } : {}),
|
||||
};
|
||||
@@ -295,6 +308,7 @@ function providerAccountRuntimeShape(account: ProviderAccount): unknown {
|
||||
isDefault: account.isDefault,
|
||||
metadata: {
|
||||
customModels: account.metadata?.customModels,
|
||||
worksSquareModelCapabilities: account.metadata?.worksSquareModelCapabilities,
|
||||
worksSquareCredentialMode: account.metadata?.worksSquareCredentialMode,
|
||||
worksSquareOneApiBaseUrl: account.metadata?.worksSquareOneApiBaseUrl,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user