dcdc8d1ddd
全栈知识治理平台首次入库(P1-P10 + 发布链路模拟验证闭环): - 治理核心:源目录/变更集/人工审核/发布批次/发布执行(fail-closed 闸口) - 测试通道:WeKnora 测试 KB 上传/轮询/验收;poll 完成时写入 parser_generation/index_generation,修复 manual/seed 路径发布闸口永久拦截 - 发布适配器 v071(本地 source=测试角色 / 云端 target=生产角色 模拟验证通过): * ES 导出/导入 mapping 自适应(.keyword 子字段、可选 tenant_id) * OSS locator 支持嵌套 scheme;chunks.seq_id 由目标序列分配 * bundle 归档同身份重试原子替换;verifier 按 bundle chunk_type 计数 * 回滚 job payload 支持 prior_execution_id(strict 解码) - 三通道发布+回滚演练实测:publish 4/4 verified,检索命中, rollback 4/4 rolled_back,目标端 PG is_enabled=false、ES is_enabled=false - 前端 A·Data-console 风格全站统一,120 用例通过 - 门禁:go vet / go test 全包通过,gofmt 干净
85 lines
4.3 KiB
TypeScript
85 lines
4.3 KiB
TypeScript
import { newOperationID } from './operationKey'
|
|
export interface UISettings {
|
|
id: string
|
|
state: 'validated' | 'active' | 'retired' | 'failed'
|
|
document_refresh_seconds: 15 | 30 | 60
|
|
resource_refresh_seconds: 30 | 60
|
|
stalled_after_seconds: 1800 | 3600
|
|
finalizing_after_seconds: 7200 | 14400
|
|
updated_by: string
|
|
created_at: string
|
|
activated_at: string | null
|
|
retired_at: string | null
|
|
error_code: string
|
|
}
|
|
|
|
export interface UISettingsCandidateInput {
|
|
document_refresh_seconds: UISettings['document_refresh_seconds']
|
|
resource_refresh_seconds: UISettings['resource_refresh_seconds']
|
|
stalled_after_seconds: UISettings['stalled_after_seconds']
|
|
finalizing_after_seconds: UISettings['finalizing_after_seconds']
|
|
updated_by: string
|
|
}
|
|
|
|
export function settingsRefreshDelays(settings: Pick<UISettings, 'document_refresh_seconds' | 'resource_refresh_seconds'>) {
|
|
return { documentMs: settings.document_refresh_seconds * 1000, resourceMs: settings.resource_refresh_seconds * 1000 }
|
|
}
|
|
|
|
const states = new Set(['validated', 'active', 'retired', 'failed'])
|
|
const documentRefresh = new Set([15, 30, 60])
|
|
const resourceRefresh = new Set([30, 60])
|
|
const stalledAfter = new Set([1800, 3600])
|
|
const finalizingAfter = new Set([7200, 14400])
|
|
const isRecord = (value: unknown): value is Record<string, unknown> => Boolean(value) && typeof value === 'object' && !Array.isArray(value)
|
|
|
|
export function parseUISettingsResponse(value: unknown): UISettings {
|
|
if (!isRecord(value) || !isRecord(value.data)) throw new Error('invalid UI settings response')
|
|
const item = value.data
|
|
if (typeof item.id !== 'string' || !/^[A-Za-z0-9._:-]{2,36}$/.test(item.id) ||
|
|
typeof item.state !== 'string' || !states.has(item.state) ||
|
|
typeof item.document_refresh_seconds !== 'number' || !documentRefresh.has(item.document_refresh_seconds) ||
|
|
typeof item.resource_refresh_seconds !== 'number' || !resourceRefresh.has(item.resource_refresh_seconds) ||
|
|
typeof item.stalled_after_seconds !== 'number' || !stalledAfter.has(item.stalled_after_seconds) ||
|
|
typeof item.finalizing_after_seconds !== 'number' || !finalizingAfter.has(item.finalizing_after_seconds) ||
|
|
typeof item.updated_by !== 'string' || typeof item.created_at !== 'string' ||
|
|
(item.activated_at !== null && typeof item.activated_at !== 'string') ||
|
|
(item.retired_at !== null && typeof item.retired_at !== 'string') || typeof item.error_code !== 'string') {
|
|
throw new Error('invalid UI settings response')
|
|
}
|
|
return {
|
|
id: item.id,
|
|
state: item.state as UISettings['state'],
|
|
document_refresh_seconds: item.document_refresh_seconds as UISettings['document_refresh_seconds'],
|
|
resource_refresh_seconds: item.resource_refresh_seconds as UISettings['resource_refresh_seconds'],
|
|
stalled_after_seconds: item.stalled_after_seconds as UISettings['stalled_after_seconds'],
|
|
finalizing_after_seconds: item.finalizing_after_seconds as UISettings['finalizing_after_seconds'],
|
|
updated_by: item.updated_by,
|
|
created_at: item.created_at,
|
|
activated_at: item.activated_at as string | null,
|
|
retired_at: item.retired_at as string | null,
|
|
error_code: item.error_code,
|
|
}
|
|
}
|
|
|
|
async function readSettings(response: Response): Promise<UISettings> {
|
|
if (!response.ok) throw new Error(`UI settings request failed (${response.status})`)
|
|
return parseUISettingsResponse(await response.json())
|
|
}
|
|
|
|
export async function fetchActiveUISettings(signal?: AbortSignal): Promise<UISettings> {
|
|
return readSettings(await fetch('/api/v1/ui-settings', { signal }))
|
|
}
|
|
|
|
export async function createUISettingsCandidate(input: UISettingsCandidateInput): Promise<UISettings> {
|
|
return readSettings(await fetch('/api/v1/ui-settings/candidates', {
|
|
method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Governance-Action': 'ui-settings', 'Idempotency-Key': newOperationID() }, body: JSON.stringify(input),
|
|
}))
|
|
}
|
|
|
|
export async function activateUISettings(revisionID: string): Promise<UISettings> {
|
|
if (!/^[A-Za-z0-9._:-]{2,36}$/.test(revisionID)) throw new Error('invalid UI settings revision')
|
|
return readSettings(await fetch(`/api/v1/ui-settings/${encodeURIComponent(revisionID)}/activate`, {
|
|
method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Governance-Action': 'ui-settings', 'Idempotency-Key': newOperationID() }, body: '{}',
|
|
}))
|
|
}
|