fix(admin): Fix Prompt management list not showing version info and add debug diagnostics
Summary: - Fix Prompt list API response schema missing activeVersion and draftVersion fields - Fastify was filtering out undefined schema fields, causing version columns to show empty - Add detailed diagnostic logging for Prompt debug mode troubleshooting - Verify debug mode works correctly (DRAFT version is used when debug enabled) Changes: - backend/src/common/prompt/prompt.routes.ts: Add activeVersion and draftVersion to response schema - backend/src/common/prompt/prompt.service.ts: Add diagnostic logs for setDebugMode and get methods - PKB module: Various authentication and document handling fixes from previous session Tested: Debug mode verified working - v2 DRAFT version correctly loaded when debug enabled
This commit is contained in:
@@ -187,3 +187,5 @@ export const jwtService = new JWTService();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -316,6 +316,8 @@ export function getBatchItems<T>(
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -101,3 +101,5 @@ export function getAllFallbackCodes(): string[] {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,16 @@ import {
|
||||
import { authenticate, requirePermission } from '../auth/auth.middleware.js';
|
||||
|
||||
// Schema 定义
|
||||
const versionSchema = {
|
||||
type: 'object',
|
||||
nullable: true,
|
||||
properties: {
|
||||
version: { type: 'number' },
|
||||
status: { type: 'string' },
|
||||
createdAt: { type: 'string' },
|
||||
},
|
||||
};
|
||||
|
||||
const listPromptsSchema = {
|
||||
querystring: {
|
||||
type: 'object',
|
||||
@@ -42,14 +52,9 @@ const listPromptsSchema = {
|
||||
module: { type: 'string' },
|
||||
description: { type: 'string' },
|
||||
variables: { type: 'array', items: { type: 'string' } },
|
||||
latestVersion: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
version: { type: 'number' },
|
||||
status: { type: 'string' },
|
||||
createdAt: { type: 'string' },
|
||||
},
|
||||
},
|
||||
activeVersion: versionSchema, // 🆕 生产版本
|
||||
draftVersion: versionSchema, // 🆕 草稿版本
|
||||
latestVersion: versionSchema, // 最新版本
|
||||
updatedAt: { type: 'string' },
|
||||
},
|
||||
},
|
||||
|
||||
@@ -60,22 +60,45 @@ export class PromptService {
|
||||
const { userId, skipCache = false } = options;
|
||||
|
||||
try {
|
||||
// 🔍 诊断日志:检查调试状态
|
||||
console.log(`[PromptService.get] 获取 Prompt: ${code}`);
|
||||
console.log(` userId: ${userId || '(未提供)'}`);
|
||||
console.log(` 当前调试用户数: ${this.debugStates.size}`);
|
||||
|
||||
if (userId && this.debugStates.size > 0) {
|
||||
const state = this.debugStates.get(userId);
|
||||
if (state) {
|
||||
console.log(` 用户调试状态: 模块=${Array.from(state.modules).join(',')}`);
|
||||
} else {
|
||||
console.log(` 用户调试状态: 未找到 (用户ID不在调试列表中)`);
|
||||
console.log(` 调试列表中的用户: ${Array.from(this.debugStates.keys()).join(', ')}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 1. 判断是否处于调试模式
|
||||
const isDebugging = userId ? this.isDebugging(userId, code) : false;
|
||||
console.log(` isDebugging: ${isDebugging}`);
|
||||
|
||||
// 2. 获取 Prompt 版本
|
||||
let version;
|
||||
if (isDebugging) {
|
||||
// 调试模式:优先获取 DRAFT
|
||||
console.log(` → 调试模式,获取 DRAFT 版本`);
|
||||
version = await this.getDraftVersion(code);
|
||||
if (!version) {
|
||||
// 没有 DRAFT,降级到 ACTIVE
|
||||
console.log(` → DRAFT 不存在,降级到 ACTIVE`);
|
||||
version = await this.getActiveVersion(code, skipCache);
|
||||
}
|
||||
} else {
|
||||
// 正常模式:获取 ACTIVE
|
||||
console.log(` → 正常模式,获取 ACTIVE 版本`);
|
||||
version = await this.getActiveVersion(code, skipCache);
|
||||
}
|
||||
|
||||
if (version) {
|
||||
console.log(` → 返回版本: v${version.version} (${version.status})`);
|
||||
}
|
||||
|
||||
// 3. 如果数据库获取失败,使用兜底
|
||||
if (!version) {
|
||||
@@ -248,16 +271,24 @@ export class PromptService {
|
||||
* @param enabled 是否开启
|
||||
*/
|
||||
setDebugMode(userId: string, modules: string[], enabled: boolean): void {
|
||||
console.log(`\n🔧 [PromptService.setDebugMode]`);
|
||||
console.log(` userId: ${userId}`);
|
||||
console.log(` modules: [${modules.join(', ')}]`);
|
||||
console.log(` enabled: ${enabled}`);
|
||||
|
||||
if (enabled) {
|
||||
this.debugStates.set(userId, {
|
||||
userId,
|
||||
modules: new Set(modules),
|
||||
enabledAt: new Date(),
|
||||
});
|
||||
console.log(`[PromptService] Debug mode enabled for user ${userId}, modules: [${modules.join(', ')}]`);
|
||||
console.log(` ✅ 调试模式已开启`);
|
||||
console.log(` 当前调试用户数: ${this.debugStates.size}`);
|
||||
console.log(` 所有调试用户: ${Array.from(this.debugStates.keys()).join(', ')}`);
|
||||
} else {
|
||||
this.debugStates.delete(userId);
|
||||
console.log(`[PromptService] Debug mode disabled for user ${userId}`);
|
||||
console.log(` ✅ 调试模式已关闭`);
|
||||
console.log(` 当前调试用户数: ${this.debugStates.size}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,3 +70,5 @@ export interface VariableValidation {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user