hpp) 二.select 核心概念与缺陷复盘2.1 fd_set 与操作宏2.
如今,在北京怀柔科学城,第四代高能同步辐射光源自2025年底已经投入试运行,已支撑完成超400组用户开展课题实验,在航空发动机叶片缺陷检测、新能源电池原位充放电过程解析等难题攻克过程中发力,在一个个项目推进中,摸索出从科研导向过渡为科研与产业并重的突破模式。
parallel import prange with nogil: for i in prange(n, num_threads=num_threads): _softmax_row(&x[i, 0], &result[i, 0], d) return np.
天苍苍, 野茫茫, 风吹草低见(xian4)牛羊。①敕勒川――敕勒族居住的平川。
// ai-interaction-state.ts —— AI 交互状态机// 将 AI 生成过程拆解为可感知、可控制的阶段type Phase = | "idle" // 空闲:等待用户输入 | "understanding" // 理解中:解析用户意图 | "structuring" // 构建中:生成整体结构 | "detailing" // 填充中:细化内容 | "reviewing" // 审阅中:等待用户确认 | "refining" // 微调中:局部重生成 | "completed" // 完成:结果已确认 | "failed"; // 失败:生成异常interface PhaseConfig { /** 该阶段的用户可见提示文案 */ label: string; /** 该阶段的最大允许时长(ms) */ maxDurationMs: number; /** 该阶段允许的用户操作 */ allowedActions: string[]; /** 该阶段失败时的降级策略 */ onTimeout: "retry" | "skip" | "abort";}const PHASE_CONFIG: Record = { idle: { label: "准备就绪,请描述你的创意", maxDurationMs: Infinity, allowedActions: ["submit"], onTimeout: "abort", }, understanding: { label: "正在理解你的意图...", maxDurationMs: 3_000, allowedActions: ["cancel"], onTimeout: "retry", }, structuring: { label: "正在构建整体框架...", maxDurationMs: 5_000, allowedActions: ["cancel", "preview"], onTimeout: "skip", }, detailing: { label: "正在填充细节内容...", maxDurationMs: 8_000, allowedActions: ["cancel", "preview", "adjust"], onTimeout: "skip", }, reviewing: { label: "请审阅生成结果", maxDurationMs: Infinity, allowedActions: ["accept", "regenerate", "partial_refine", "cancel"], onTimeout: "abort", }, refining: { label: "正在局部调整...", maxDurationMs: 5_000, allowedActions: ["cancel"], onTimeout: "retry", }, completed: { label: "生成完成", maxDurationMs: Infinity, allowedActions: ["restart", "export"], onTimeout: "abort", }, failed: { label: "生成遇到问题,请重试", maxDurationMs: Infinity, allowedActions: ["retry", "cancel"], onTimeout: "abort", },};/** * AI 交互状态机: * 管理生成流程的阶段转换、超时保护和用户操作权限。 * 核心设计原则:每个阶段都是可感知的,每个操作都是可控的。 */export class AIInteractionStateMachine { private currentPhase: Phase = "idle"; private phaseStartTime = 0; private timeoutHandle: ReturnType | null = null; private listeners = new Map>(); /** 阶段转换:状态机的核心逻辑 */ transition(nextPhase: Phase): void { const config = PHASE_CONFIG[nextPhase]; if (!config) { throw new Error(`未知阶段: ${nextPhase}`); } // 清理上一阶段的超时计时器 this.clearTimeout(); this.currentPhase = nextPhase; this.phaseStartTime = Date.now(); // 广播阶段变更事件,UI 层据此更新提示文案和操作按钮 this.emit("phase:change", { phase: nextPhase, label: config.label, allowedActions: config.allowedActions, }); // 设置阶段超时保护:防止某个阶段无限等待 if (config.maxDurationMs !== Infinity) { this.timeoutHandle = setTimeout(() => { this.handlePhaseTimeout(config.onTimeout); }, config.maxDurationMs); } } /** 用户操作校验:只允许当前阶段声明的操作 */ canPerformAction(action: string): boolean { const config = PHASE_CONFIG[this.currentPhase]; return config.allowedActions.includes(action); } /** 执行用户操作:带权限校验的操作执行 */ performAction(action: string, payload?: unknown): void { if (!canPerformAction(action)) { this.emit("action:rejected", { action, currentPhase: this.currentPhase, reason: `当前阶段不允许执行 ${action}`, }); return; } // 根据操作类型执行阶段转换 const transitions: Record = { submit: "understanding", cancel: "idle", preview: this.currentPhase, // 预览不改变阶段 adjust: "refining", accept: "completed", regenerate: "structuring", partial_refine: "refining", restart: "idle", export: "completed", retry: "understanding", }; const nextPhase = transitions[action]; if (nextPhase && nextPhase !== this.currentPhase) { this.transition(nextPhase); } } /** 阶段超时处理:按配置策略降级 */ private handlePhaseTimeout(strategy: "retry" | "skip" | "abort"): void { this.emit("phase:timeout", { phase: this.currentPhase, strategy, }); switch (strategy) { case "retry": // 重试当前阶段:重置计时器,重新执行 this.transition(this.currentPhase); break; case "skip": // 跳过当前阶段:用已有中间结果进入下一阶段 this.transition(this.getNextPhase(this.currentPhase)); break; case "abort": // 终止生成:回到空闲状态 this.transition("failed"); break; } } private getNextPhase(current: Phase): Phase { const order: Phase[] = [ "idle", "understanding", "structuring", "detailing", "reviewing", "completed", ]; const idx = order.indexOf(current); return idx < order.length - 1 ? order[idx + 1] : "completed"; } private clearTimeout(): void { if (this.timeoutHandle) { clearTimeout(this.timeoutHandle); this.timeoutHandle = null; } } /** 事件系统:轻量级发布订阅 */ on(event: string, handler: (...args: unknown[]) => void): void { if (!this.listeners.has(event)) { this.listeners.set(event, new Set()); } this.listeners.get(event)!.add(handler); } off(event: string, handler: (...args: unknown[]) => void): void { this.listeners.get(event)?.delete(handler); } private emit(event: string, ...args: unknown[]): void { this.listeners.get(event)?.forEach((fn) => fn(...args)); } /** 获取当前状态快照:用于 UI 渲染 */ getSnapshot() { const config = PHASE_CONFIG[this.currentPhase]; const elapsed = Date.now() - this.phaseStartTime; return { phase: this.currentPhase, label: config.label, allowedActions: config.allowedActions, elapsedMs: elapsed, progress: this.estimateProgress(), }; } /** 进度估算:基于当前阶段在流程中的位置 */ private estimateProgress(): number { const weights: Record = { idle: 0, understanding: 0.15, structuring: 0.35, detailing: 0.65, reviewing: 0.85, refining: 0.75, completed: 1, failed: 0, }; return weights[this.currentPhase]; }}这段代码的设计逻辑很简单:状态就是规则。