feat(training): 培训配置改造
This commit is contained in:
1 parent
d21c83433e
commit
15225ef1ce
15 files changed
+602
-56
No files matched your search
@@ -62,6 +62,11 @@ export interface TrainingPublishedConfigResource {
|
||||
} | null;
|
||||
}
|
||||
|
||||
export interface TrainingProgressItem {
|
||||
stage: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export interface TrainingPublishedConfig {
|
||||
id: number;
|
||||
trainingType: TrainingType;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* features/chat/training/trainingWorkspace.utils.test.ts
|
||||
* 用途:锁定培训工作区 Agent 识别契约(content_profile / extra_config,非名称)。
|
||||
* 用途:锁定培训工作区 Agent 识别契约,以及培训进度项/文本配置的解析规则。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { matchesTrainingAgent } from './trainingWorkspace.utils';
|
||||
import { matchesTrainingAgent, resolveLearnerCopyText, resolveLearnerProgressItems } from './trainingWorkspace.utils';
|
||||
|
||||
describe('matchesTrainingAgent', () => {
|
||||
it('matches handler_config.content_profile=training', () => {
|
||||
@@ -31,3 +31,61 @@ describe('matchesTrainingAgent', () => {
|
||||
})).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveLearnerProgressItems', () => {
|
||||
it('returns configured progress items in order', () => {
|
||||
expect(resolveLearnerProgressItems({
|
||||
id: 1,
|
||||
trainingType: 'custom',
|
||||
version: 'v1',
|
||||
passScore: 90,
|
||||
settings: {
|
||||
progress_items: [
|
||||
{ stage: 'video', label: '观看视频' },
|
||||
{ stage: 'exam', label: '参加考试' },
|
||||
],
|
||||
},
|
||||
resources: [],
|
||||
})).toEqual([
|
||||
{ stage: 'video', label: '观看视频' },
|
||||
{ stage: 'exam', label: '参加考试' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('filters invalid or duplicate items', () => {
|
||||
expect(resolveLearnerProgressItems({
|
||||
id: 1,
|
||||
trainingType: 'custom',
|
||||
version: 'v1',
|
||||
passScore: 90,
|
||||
settings: {
|
||||
progress_items: [
|
||||
{ stage: 'video', label: '观看视频' },
|
||||
{ stage: 'video', label: '重复步骤' },
|
||||
{ stage: '', label: '空阶段' },
|
||||
{ stage: 'summary', label: '' },
|
||||
],
|
||||
},
|
||||
resources: [],
|
||||
})).toEqual([
|
||||
{ stage: 'video', label: '观看视频' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveLearnerCopyText', () => {
|
||||
it('returns trimmed text when configured', () => {
|
||||
expect(resolveLearnerCopyText({
|
||||
id: 1,
|
||||
trainingType: 'custom',
|
||||
version: 'v1',
|
||||
passScore: 90,
|
||||
settings: { progress_hint_text: ' 按要求完成学习 ' },
|
||||
resources: [],
|
||||
}, 'progress_hint_text')).toBe('按要求完成学习');
|
||||
});
|
||||
|
||||
it('returns empty string for missing text', () => {
|
||||
expect(resolveLearnerCopyText(null, 'step_intro_text')).toBe('');
|
||||
});
|
||||
});
|
||||
@@ -2,9 +2,9 @@
|
||||
* features/chat/training/trainingWorkspace.utils.ts
|
||||
* 用途:沉淀新人培训工作区的纯函数规则,便于前端复用与单测。
|
||||
* 依赖:无运行时副作用,仅依赖 Agent extra_config 普通对象与 training.types。
|
||||
* 逻辑:统一判断某个 Agent 是否启用培训工作区,并解析培训视频、题库与复盘配置。
|
||||
* 逻辑:统一判断某个 Agent 是否启用培训工作区,并解析培训视频、题库、复盘配置与动态进度文案。
|
||||
*/
|
||||
import type { TrainingContentConfig, TrainingPublishedConfig, TrainingQuestion, TrainingQuestionOption } from './training.types';
|
||||
import type { TrainingContentConfig, TrainingProgressItem, TrainingPublishedConfig, TrainingQuestion, TrainingQuestionOption } from './training.types';
|
||||
|
||||
type TrainingAgentLike = {
|
||||
name?: string | null;
|
||||
@@ -153,6 +153,40 @@ const normalizeQuestionBank = (
|
||||
|
||||
const DEFAULT_PASS_SCORE = 90;
|
||||
|
||||
/**
|
||||
* 解析学员侧培训进度项。
|
||||
* AI 触发时机:当工作区需要按后台配置渲染流程卡片时调用;若后台未配置任何有效项,则返回空数组供页面整体隐藏该模块。
|
||||
*/
|
||||
export function resolveLearnerProgressItems(publishedConfig?: TrainingPublishedConfig | null): TrainingProgressItem[] {
|
||||
const settings = asRecord(publishedConfig?.settings);
|
||||
const rawItems = settings.progress_items;
|
||||
if (!Array.isArray(rawItems)) return [];
|
||||
|
||||
const seenStages = new Set<string>();
|
||||
return rawItems
|
||||
.map((item) => {
|
||||
const raw = asRecord(item);
|
||||
const stage = String(raw.stage || raw.key || '').trim();
|
||||
const label = String(raw.label || raw.title || '').trim();
|
||||
if (!stage || !label || seenStages.has(stage)) return null;
|
||||
seenStages.add(stage);
|
||||
return { stage, label };
|
||||
})
|
||||
.filter((item): item is TrainingProgressItem => Boolean(item));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取学员侧长文本配置。
|
||||
* AI 触发时机:培训进度说明和步骤引导只在后台返回非空文本时渲染,避免页面出现空占位。
|
||||
*/
|
||||
export function resolveLearnerCopyText(
|
||||
publishedConfig: TrainingPublishedConfig | null | undefined,
|
||||
key: 'progress_hint_text' | 'step_intro_text',
|
||||
): string {
|
||||
const settings = asRecord(publishedConfig?.settings);
|
||||
return String(settings[key] || '').trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析培训视频地址。
|
||||
* AI 触发时机:当培训工作区需要决定播放哪个培训视频时使用,若 Agent 未配置专属视频,则回退到默认地址。
|
||||
|
||||
Reference in new issue
Block a user