forked from hangshuo652/aurak
fix: minor issues from code review
(M1) DTO: @IsObject({ each: true }) on dimensions array
(M2) audit log: add missing tenantId in submitAnswer
(M3) console.log -> this.logger in controller + service
This commit is contained in:
@@ -142,7 +142,7 @@ private async getModel(tenantId: string): Promise<ChatOpenAI> {
|
||||
scores: Record<string, number>,
|
||||
weightConfig: { prompt: number; other: number },
|
||||
): { finalScore: number; dimensionScores: Record<string, number>; radarData: Record<string, number> } {
|
||||
console.log('[calculateScores] Input:', {
|
||||
this.logger.debug('[calculateScores] Input:', {
|
||||
questionsCount: questions.length,
|
||||
scores,
|
||||
weightConfig,
|
||||
@@ -180,7 +180,7 @@ private async getModel(tenantId: string): Promise<ChatOpenAI> {
|
||||
? otherDimsWithScores.reduce((sum, dim) => sum + (dimensionAverages[dim] || 0), 0) / otherDimsWithScores.length
|
||||
: 0;
|
||||
|
||||
console.log('[calculateScores] Scoring debug:', { promptAvg, otherDimsWithScores, otherAvg, workCapability: dimensionAverages.workCapability });
|
||||
this.logger.debug('[calculateScores] Scoring debug:', { promptAvg, otherDimsWithScores, otherAvg, workCapability: dimensionAverages.workCapability });
|
||||
|
||||
const finalScore = promptAvg * (weightConfig.prompt / 100) + otherAvg * (weightConfig.other / 100);
|
||||
|
||||
@@ -189,7 +189,7 @@ private async getModel(tenantId: string): Promise<ChatOpenAI> {
|
||||
radarData[dim] = Math.round(dimensionAverages[dim] * 10) / 10;
|
||||
});
|
||||
|
||||
console.log('[calculateScores] Result:', {
|
||||
this.logger.debug('[calculateScores] Result:', {
|
||||
finalScore: Math.round(finalScore * 10) / 10,
|
||||
dimensionScores: dimensionAverages,
|
||||
promptAvg,
|
||||
@@ -709,7 +709,7 @@ const initialState: Partial<EvaluationState> = {
|
||||
const finalData = fullState.values as EvaluationState;
|
||||
|
||||
if (finalData && finalData.messages) {
|
||||
console.log(
|
||||
this.logger.debug(
|
||||
`[AssessmentService] startSessionStream Final Authoritative State messages:`,
|
||||
finalData.messages.length,
|
||||
);
|
||||
@@ -903,13 +903,13 @@ const initialState: Partial<EvaluationState> = {
|
||||
answer: string,
|
||||
language: string = 'en',
|
||||
): Observable<any> {
|
||||
console.log('[submitAnswerStream] START - sessionId:', sessionId, 'answer length:', answer?.length);
|
||||
this.logger.debug('[submitAnswerStream] START - sessionId:', sessionId, 'answer length:', answer?.length);
|
||||
let emittedNextQuestion = false;
|
||||
let hasEmittedNodes = false;
|
||||
return new Observable((observer) => {
|
||||
(async () => {
|
||||
try {
|
||||
console.log('[submitAnswerStream] After Observable - sessionId:', sessionId);
|
||||
this.logger.debug('[submitAnswerStream] After Observable - sessionId:', sessionId);
|
||||
const session = await this.sessionRepository.findOne({
|
||||
where: { id: sessionId, userId },
|
||||
});
|
||||
@@ -928,7 +928,7 @@ const initialState: Partial<EvaluationState> = {
|
||||
graphState &&
|
||||
graphState.values &&
|
||||
Object.keys(graphState.values).length > 0;
|
||||
console.log(
|
||||
this.logger.debug(
|
||||
`[AssessmentService] submitAnswerStream: sessionId=${sessionId}, hasState=${hasState}, nextNodes=[${graphState.next || ''}]`,
|
||||
);
|
||||
|
||||
@@ -954,8 +954,8 @@ const initialState: Partial<EvaluationState> = {
|
||||
let hasEmittedNodes = false;
|
||||
for await (const [mode, data] of stream) {
|
||||
streamCount++;
|
||||
console.log('[submitAnswerStream] Stream event:', streamCount, mode, Object.keys(data || {}));
|
||||
console.log('[submitAnswerStream] Data detail:', JSON.stringify(data).substring(0, 500));
|
||||
this.logger.debug('[submitAnswerStream] Stream event:', streamCount, mode, Object.keys(data || {}));
|
||||
this.logger.debug('[submitAnswerStream] Data detail:', JSON.stringify(data).substring(0, 500));
|
||||
if (mode === 'updates') {
|
||||
hasEmittedNodes = true;
|
||||
const node = Object.keys(data)[0];
|
||||
@@ -963,17 +963,17 @@ const initialState: Partial<EvaluationState> = {
|
||||
|
||||
// Skip interrupt nodes - they have no useful data
|
||||
if (node === '__interrupt__' || !updateData || Object.keys(updateData).length === 0) {
|
||||
console.log('[submitAnswerStream] Skipping empty interrupt node');
|
||||
this.logger.debug('[submitAnswerStream] Skipping empty interrupt node');
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log('[submitAnswerStream] Node update:', node, {
|
||||
this.logger.debug('[submitAnswerStream] Node update:', node, {
|
||||
hasMessages: !!updateData.messages,
|
||||
messageCount: updateData.messages?.length,
|
||||
currentIndex: updateData.currentQuestionIndex,
|
||||
dataKeys: Object.keys(updateData).join(',')
|
||||
});
|
||||
console.log('[submitAnswerStream] Sending to frontend:', JSON.stringify(updateData).substring(0, 500));
|
||||
this.logger.debug('[submitAnswerStream] Sending to frontend:', JSON.stringify(updateData).substring(0, 500));
|
||||
if (updateData.messages) {
|
||||
updateData.messages = this.mapMessages(updateData.messages);
|
||||
}
|
||||
@@ -984,7 +984,7 @@ const initialState: Partial<EvaluationState> = {
|
||||
}
|
||||
observer.next({ type: 'node', node, data: updateData });
|
||||
} else if (mode === 'values') {
|
||||
console.log('[submitAnswerStream] Values update - keys:', Object.keys(data || {}));
|
||||
this.logger.debug('[submitAnswerStream] Values update - keys:', Object.keys(data || {}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -995,13 +995,13 @@ const initialState: Partial<EvaluationState> = {
|
||||
const finalData = fullState.values as EvaluationState;
|
||||
|
||||
// Force emit the next question if stream didn't emit updates (hasEmittedNodes is false)
|
||||
console.log('[submitAnswerStream] Force check:', { hasEmittedNodes, hasFinalData: !!finalData, hasQuestions: !!finalData?.questions, qLen: finalData?.questions?.length, emittedNextQuestion });
|
||||
this.logger.debug('[submitAnswerStream] Force check:', { hasEmittedNodes, hasFinalData: !!finalData, hasQuestions: !!finalData?.questions, qLen: finalData?.questions?.length, emittedNextQuestion });
|
||||
if (!hasEmittedNodes && finalData && finalData.questions && finalData.questions.length > 0 && !emittedNextQuestion) {
|
||||
const currentIndex = finalData.currentQuestionIndex || 0;
|
||||
const nextQuestion = finalData.questions[currentIndex];
|
||||
if (nextQuestion) {
|
||||
const questionText = nextQuestion.questionText || '';
|
||||
console.log('[submitAnswerStream] Forcing emit next question:', {
|
||||
this.logger.debug('[submitAnswerStream] Forcing emit next question:', {
|
||||
currentIndex,
|
||||
questionPreview: questionText.substring(0, 50)
|
||||
});
|
||||
@@ -1021,7 +1021,7 @@ const initialState: Partial<EvaluationState> = {
|
||||
}
|
||||
|
||||
if (finalData && finalData.messages) {
|
||||
console.log(
|
||||
this.logger.debug(
|
||||
`[AssessmentService] submitAnswerStream Final Authoritative State messages:`,
|
||||
finalData.messages.length,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user