import { $t } from '@/locales'
|
|
const AI_PARAM_REPORT_TITLE = () => $t('pages.system.aiParam.reportTitle')
|
|
const PROVIDER_OPTIONS = [{ label: 'OPENAI_COMPATIBLE', value: 'OPENAI_COMPATIBLE' }]
|
|
const STATUS_OPTIONS = [
|
{ label: () => $t('pages.system.aiParam.status.default'), value: 1 },
|
{ label: () => $t('pages.system.aiParam.status.candidate'), value: 0 }
|
]
|
|
const VALIDATE_STATUS_META = {
|
VALID: { text: () => $t('pages.system.aiParam.validation.valid'), type: 'success' },
|
INVALID: { text: () => $t('pages.system.aiParam.validation.invalid'), type: 'danger' },
|
NOT_TESTED: { text: () => $t('pages.system.aiParam.validation.notTested'), type: 'info' }
|
}
|
|
function createAiParamSearchState() {
|
return {
|
condition: '',
|
providerType: '',
|
model: '',
|
status: ''
|
}
|
}
|
|
function createAiParamFormState() {
|
return {
|
id: null,
|
name: '',
|
providerType: 'OPENAI_COMPATIBLE',
|
baseUrl: '',
|
apiKey: '',
|
model: '',
|
temperature: 0.7,
|
topP: 1,
|
maxTokens: null,
|
timeoutMs: 60000,
|
streamingEnabled: true,
|
status: 1,
|
memo: '',
|
validateStatus: 'NOT_TESTED',
|
lastValidateMessage: '',
|
lastValidateElapsedMs: null,
|
'lastValidateTime$': '',
|
updateBy: '',
|
'updateTime$': ''
|
}
|
}
|
|
function getAiParamPaginationKey() {
|
return {
|
current: 'current',
|
size: 'pageSize'
|
}
|
}
|
|
function getAiParamProviderOptions() {
|
return PROVIDER_OPTIONS
|
}
|
|
function getAiParamStatusOptions() {
|
return STATUS_OPTIONS.map((item) => ({ ...item, label: item.label() }))
|
}
|
|
function getAiParamStatusMeta(status) {
|
return Number(status) === 1
|
? { text: $t('pages.system.aiParam.status.default'), type: 'success' }
|
: { text: $t('pages.system.aiParam.status.candidate'), type: 'info' }
|
}
|
|
function getAiParamValidateStatusMeta(status) {
|
const meta = VALIDATE_STATUS_META[String(status || '').trim()]
|
if (meta) {
|
return { text: meta.text(), type: meta.type }
|
}
|
return { text: status || $t('common.status.unknown'), type: 'info' }
|
}
|
|
function buildAiParamSearchParams(params = {}) {
|
return {
|
condition: normalizeText(params.condition),
|
providerType: normalizeText(params.providerType),
|
model: normalizeText(params.model),
|
status: normalizeOptionalNumber(params.status)
|
}
|
}
|
|
function buildAiParamPageQueryParams(params = {}) {
|
return {
|
current: Number(params.current) > 0 ? Number(params.current) : 1,
|
pageSize: Number(params.pageSize) > 0 ? Number(params.pageSize) : 20,
|
condition: normalizeText(params.condition),
|
providerType: normalizeText(params.providerType),
|
model: normalizeText(params.model),
|
status: normalizeOptionalNumber(params.status)
|
}
|
}
|
|
function buildAiParamDialogModel(record = {}) {
|
const base = createAiParamFormState()
|
return {
|
...base,
|
...record,
|
id: normalizeOptionalNumber(record.id) ?? null,
|
providerType: normalizeText(record.providerType) || base.providerType,
|
status: normalizeOptionalNumber(record.status) ?? base.status,
|
temperature: normalizeOptionalFloat(record.temperature) ?? base.temperature,
|
topP: normalizeOptionalFloat(record.topP) ?? base.topP,
|
maxTokens: normalizeOptionalNumber(record.maxTokens),
|
timeoutMs: normalizeOptionalNumber(record.timeoutMs) ?? base.timeoutMs,
|
streamingEnabled:
|
record.streamingEnabled === undefined || record.streamingEnabled === null
|
? base.streamingEnabled
|
: Boolean(record.streamingEnabled),
|
validateStatus: normalizeText(record.validateStatus) || base.validateStatus,
|
lastValidateMessage: normalizeText(record.lastValidateMessage),
|
lastValidateElapsedMs: normalizeOptionalNumber(record.lastValidateElapsedMs),
|
'lastValidateTime$': normalizeText(record['lastValidateTime$']),
|
updateBy: record.updateBy ?? '',
|
'updateTime$': normalizeText(record['updateTime$'])
|
}
|
}
|
|
function buildAiParamSavePayload(formData = {}) {
|
return {
|
...(normalizeOptionalNumber(formData.id) !== null ? { id: normalizeOptionalNumber(formData.id) } : {}),
|
name: normalizeText(formData.name),
|
providerType: normalizeText(formData.providerType) || 'OPENAI_COMPATIBLE',
|
baseUrl: normalizeText(formData.baseUrl),
|
apiKey: normalizeText(formData.apiKey),
|
model: normalizeText(formData.model),
|
temperature: normalizeOptionalFloat(formData.temperature),
|
topP: normalizeOptionalFloat(formData.topP),
|
maxTokens: normalizeOptionalNumber(formData.maxTokens),
|
timeoutMs: normalizeOptionalNumber(formData.timeoutMs),
|
streamingEnabled: Boolean(formData.streamingEnabled),
|
status: normalizeOptionalNumber(formData.status) ?? 1,
|
memo: normalizeText(formData.memo)
|
}
|
}
|
|
function normalizeAiParamRow(record = {}) {
|
const statusMeta = getAiParamStatusMeta(record.status)
|
const validateMeta = getAiParamValidateStatusMeta(record.validateStatus)
|
|
return {
|
...record,
|
providerType: normalizeText(record.providerType) || 'OPENAI_COMPATIBLE',
|
model: normalizeText(record.model),
|
baseUrl: normalizeText(record.baseUrl),
|
memo: normalizeText(record.memo),
|
statusBool: Number(record.status) === 1,
|
statusText: statusMeta.text,
|
statusType: statusMeta.type,
|
validateStatusText: validateMeta.text,
|
validateStatusType: validateMeta.type,
|
streamingEnabled: Boolean(record.streamingEnabled),
|
streamingText: record.streamingEnabled
|
? $t('pages.system.aiParam.streaming.enabled')
|
: $t('pages.system.aiParam.streaming.disabled'),
|
'createTime$': normalizeText(record['createTime$']),
|
'updateTime$': normalizeText(record['updateTime$']),
|
'lastValidateTime$': normalizeText(record['lastValidateTime$'])
|
}
|
}
|
|
function buildAiParamPrintRows(records = []) {
|
return records.map((item) => {
|
const row = normalizeAiParamRow(item)
|
return {
|
name: row.name || '-',
|
providerType: row.providerType || '-',
|
model: row.model || '-',
|
statusText: row.statusText,
|
validateStatusText: row.validateStatusText,
|
timeoutMs: row.timeoutMs ?? '--',
|
updateTime: row['updateTime$'] || '--',
|
memo: row.memo || '--'
|
}
|
})
|
}
|
|
function getAiParamReportColumns() {
|
return [
|
{ label: $t('pages.system.aiParam.table.name'), prop: 'name' },
|
{ label: $t('pages.system.aiParam.table.providerType'), prop: 'providerType' },
|
{ label: $t('pages.system.aiParam.table.model'), prop: 'model' },
|
{ label: $t('pages.system.aiParam.table.status'), prop: 'statusText' },
|
{ label: $t('pages.system.aiParam.table.validateStatus'), prop: 'validateStatusText' },
|
{ label: $t('pages.system.aiParam.table.timeoutMs'), prop: 'timeoutMs' },
|
{ label: $t('table.updateTime'), prop: 'updateTime' },
|
{ label: $t('table.remark'), prop: 'memo' }
|
]
|
}
|
|
function normalizeText(value) {
|
return value === undefined || value === null ? '' : String(value).trim()
|
}
|
|
function normalizeOptionalNumber(value) {
|
if (value === undefined || value === null || value === '') {
|
return null
|
}
|
const number = Number(value)
|
return Number.isFinite(number) ? number : null
|
}
|
|
function normalizeOptionalFloat(value) {
|
if (value === undefined || value === null || value === '') {
|
return null
|
}
|
const number = Number(value)
|
return Number.isFinite(number) ? number : null
|
}
|
|
export {
|
AI_PARAM_REPORT_TITLE,
|
buildAiParamDialogModel,
|
buildAiParamPageQueryParams,
|
buildAiParamPrintRows,
|
buildAiParamSavePayload,
|
buildAiParamSearchParams,
|
createAiParamFormState,
|
createAiParamSearchState,
|
getAiParamPaginationKey,
|
getAiParamProviderOptions,
|
getAiParamReportColumns,
|
getAiParamStatusMeta,
|
getAiParamStatusOptions,
|
getAiParamValidateStatusMeta,
|
normalizeAiParamRow
|
}
|