同步已上线的智能分析执行协议、来源查询、图表报告与管理页面配套代码。 补齐数据库迁移、运行依赖和回归测试,保留原有指标计算口径。 统一午夜黑及其他主题的控件细节、中文和业务数字字体。 排除本地业务数据、凭据、预览、发布与验收产物。 验证:生产构建通过,320项前端回归通过;本轮仅同步Git,不再次部署。
41 lines
2.0 KiB
TypeScript
41 lines
2.0 KiB
TypeScript
type Context = Record<string, unknown> | undefined;
|
|
export type SubmissionInput = { sessionId: string; question: string; context?: Context; generation: number };
|
|
export type AnalysisSubmission = SubmissionInput & {
|
|
idempotencyKey: string;
|
|
contextKey: string;
|
|
inFlight: boolean;
|
|
turnRequestStarted: boolean;
|
|
uncertain: boolean;
|
|
cancelRequested: boolean;
|
|
acceptedTurnId?: string;
|
|
};
|
|
|
|
function canonical(value: unknown): string {
|
|
if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;
|
|
if (value && typeof value === 'object') return `{${Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => `${JSON.stringify(key)}:${canonical(item)}`).join(',')}}`;
|
|
return JSON.stringify(value ?? null);
|
|
}
|
|
|
|
/** Only an uncertain retry of the same question, session and frozen context reuses its key. */
|
|
export function beginAnalysisSubmission(previous: AnalysisSubmission | null, input: SubmissionInput, key: () => string = () => crypto.randomUUID()): AnalysisSubmission {
|
|
const contextKey = canonical(input.context || {});
|
|
if (previous?.uncertain && previous.generation === input.generation && previous.sessionId === input.sessionId
|
|
&& previous.question === input.question && previous.contextKey === contextKey) {
|
|
previous.inFlight = true;
|
|
return previous;
|
|
}
|
|
return { ...input, contextKey, idempotencyKey: key(), inFlight: true, turnRequestStarted: false, uncertain: false, cancelRequested: false };
|
|
}
|
|
|
|
/** A connection failure, server timeout or 5xx does not prove that a POST was rejected. */
|
|
export function submissionOutcomeUnknown(error: unknown): boolean {
|
|
const status = error && typeof error === 'object' && 'status' in error ? Number(error.status) : NaN;
|
|
return !Number.isFinite(status) || status < 400 || status === 408 || status >= 500;
|
|
}
|
|
|
|
export function requestSubmissionCancellation(attempt: AnalysisSubmission | null, generation: number): boolean {
|
|
if (!attempt || !attempt.inFlight || attempt.generation !== generation) return false;
|
|
attempt.cancelRequested = true;
|
|
return true;
|
|
}
|