feat(agent): 增强 Agent 配置,新增结构化字段与聊天功能支持
This commit is contained in:
1 parent
ac4262cd75
commit
c8ce77199e
183 files changed
+11690
-2300
No files matched your search
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* features/chat/training/trainingWorkspace.utils.test.ts
|
||||
* 用途:锁定培训工作区 Agent 识别契约(content_profile / extra_config,非名称)。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { matchesTrainingAgent } from './trainingWorkspace.utils';
|
||||
|
||||
describe('matchesTrainingAgent', () => {
|
||||
it('matches handler_config.content_profile=training', () => {
|
||||
expect(matchesTrainingAgent({
|
||||
name: '任意名称',
|
||||
handler_config: { content_profile: 'training' },
|
||||
})).toBe(true);
|
||||
});
|
||||
|
||||
it('matches explicit extra_config training flags', () => {
|
||||
expect(matchesTrainingAgent({
|
||||
name: '普通 Agent',
|
||||
extra_config: { training_workspace_enabled: true },
|
||||
})).toBe(true);
|
||||
});
|
||||
|
||||
it('does not match generic agent by name alone', () => {
|
||||
expect(matchesTrainingAgent({ name: '新人培训助手' })).toBe(false);
|
||||
});
|
||||
|
||||
it('respects training_workspace_enabled=false override', () => {
|
||||
expect(matchesTrainingAgent({
|
||||
handler_config: { content_profile: 'training' },
|
||||
extra_config: { training_workspace_enabled: false },
|
||||
})).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* 解析培训视频地址。
|
||||
|
||||
Reference in new issue
Block a user