feat(agent): 增强 Agent 配置,新增结构化字段与聊天功能支持

This commit is contained in:
hugo committed 2026-07-07 11:10:32 +08:00
1 parent ac4262cd75
commit c8ce77199e
183 files changed
+11690 -2300

No files matched your search

@@ -8,6 +8,10 @@ import type { TrainingContentConfig, TrainingQuestion, TrainingQuestionOption }
type TrainingAgentLike = {
name?: string | null;
handler_config?: {
content_profile?: string | null;
[key: string]: unknown;
} | null;
extra_config?: Record<string, unknown> | null;
} | null | undefined;
@@ -19,8 +23,28 @@ export type TrainingGuideLike = {
file_path?: string | null;
} | null | undefined;
const TRAINING_AGENT_NAME_PATTERN = /(培训|考试|入职)/;
const DEFAULT_PASS_SCORE = 90;
export const TRAINING_CONTENT_PROFILE = 'training';
/**
* 判断当前 Agent 是否应启用培训工作区。
* AI 触发时机:聊天页决定是否渲染培训主链时调用;优先 content_profile / extra_config,禁止名称启发式。
*/
export function matchesTrainingAgent(agent: TrainingAgentLike): boolean {
const extraConfig = agent?.extra_config || {};
if (extraConfig.training_workspace_enabled === false || extraConfig.training_workspace_enabled === 'false') {
return false;
}
const contentProfile = String(agent?.handler_config?.content_profile || '').trim();
if (contentProfile === TRAINING_CONTENT_PROFILE) {
return true;
}
const explicitFlags = [
extraConfig.training_workspace_enabled,
extraConfig.training_mode,
extraConfig.training_agent,
];
return explicitFlags.some((value) => value === true || value === 'true');
}
const asRecord = (value: unknown): Record<string, unknown> => (
value && typeof value === 'object' && !Array.isArray(value)
@@ -94,26 +118,7 @@ const normalizeQuestionBank = (
.filter((item): item is TrainingQuestion => Boolean(item));
};
/**
* 判断当前 Agent 是否应启用培训工作区。
* AI 触发时机:当聊天页需要决定是否渲染“视频 -> 总结 -> 答题”培训主链时使用,优先读取显式配置,避免误伤普通 Agent。
*/
export function matchesTrainingAgent(agent: TrainingAgentLike): boolean {
const extraConfig = agent?.extra_config || {};
if (extraConfig.training_workspace_enabled === false || extraConfig.training_workspace_enabled === 'false') {
return false;
}
const explicitFlags = [
extraConfig.training_workspace_enabled,
extraConfig.training_mode,
extraConfig.training_agent,
];
if (explicitFlags.some((value) => value === true || value === 'true')) {
return true;
}
const name = String(agent?.name || '').trim();
return TRAINING_AGENT_NAME_PATTERN.test(name);
}
const DEFAULT_PASS_SCORE = 90;
/**
* 解析培训视频地址。