(responseChars: number, stopReason?: string)
| 1105 | } |
| 1106 | |
| 1107 | complete(responseChars: number, stopReason?: string): void { |
| 1108 | this.endPhase(); |
| 1109 | const duration = Date.now() - this.summary.startTime; |
| 1110 | const assessment = assessCompletionOutcome(this.summary, this.payload, stopReason); |
| 1111 | this.summary.endTime = Date.now(); |
| 1112 | this.summary.status = assessment.status; |
| 1113 | this.summary.statusReason = assessment.statusReason; |
| 1114 | this.summary.issueTags = assessment.issueTags; |
| 1115 | this.summary.responseChars = responseChars; |
| 1116 | this.summary.stopReason = stopReason; |
| 1117 | const completionMessage = assessment.status === 'degraded' |
| 1118 | ? `降级完成 (${duration}ms, ${responseChars} chars, stop=${stopReason})${assessment.statusReason ? ` - ${assessment.statusReason}` : ''}` |
| 1119 | : `完成 (${duration}ms, ${responseChars} chars, stop=${stopReason})`; |
| 1120 | this.log(assessment.status === 'degraded' ? 'warn' : 'info', 'System', 'complete', completionMessage); |
| 1121 | logEmitter.emit('summary', this.summary); |
| 1122 | |
| 1123 | // ★ 持久化到文件 |
| 1124 | persistRequest(this.summary, this.payload); |
| 1125 | |
| 1126 | const retryInfo = this.summary.retryCount > 0 ? ` retry=${this.summary.retryCount}` : ''; |
| 1127 | const contInfo = this.summary.continuationCount > 0 ? ` cont=${this.summary.continuationCount}` : ''; |
| 1128 | const toolInfo = this.summary.toolCallsDetected > 0 ? ` tools_called=${this.summary.toolCallsDetected}` : ''; |
| 1129 | const ttftInfo = this.summary.ttft ? ` ttft=${this.summary.ttft}ms` : ''; |
| 1130 | const statusColor = assessment.status === 'degraded' ? '\x1b[33m' : '\x1b[32m'; |
| 1131 | const statusLabel = assessment.status === 'degraded' ? 'DEGRADED' : 'OK'; |
| 1132 | const reasonInfo = assessment.statusReason ? ` | reason=${assessment.statusReason}` : ''; |
| 1133 | console.log(`${statusColor}${statusLabel}\x1b[0m [${this.requestId}] ${duration}ms | ${responseChars} chars | stop=${stopReason || 'end_turn'}${ttftInfo}${retryInfo}${contInfo}${toolInfo}${reasonInfo}`); |
| 1134 | } |
| 1135 | |
| 1136 | intercepted(reason: string): void { |
| 1137 | this.summary.status = 'intercepted'; |
no test coverage detected