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,173 @@
|
||||
/**
|
||||
* shared/utils/agent-registry.utils.ts
|
||||
*
|
||||
* 用途:Chat / Workspace 侧读取 Agent Registry 结构化字段(与后端 resolver 对齐)。
|
||||
* 依赖:无(运行时只读 API 返回的结构化列)。
|
||||
* 逻辑:列缺失时返回默认值,不再从 extra_config 补读已迁移 Registry 键。
|
||||
*/
|
||||
|
||||
export const AGENT_CODE_GENERIC = 'generic';
|
||||
export const AGENT_CODE_SHIPPING_NOTICE = 'shipping_notice';
|
||||
export const AGENT_CODE_FILE_CHECK = 'file_check';
|
||||
|
||||
export interface AgentRegistryCapabilities {
|
||||
streaming?: boolean;
|
||||
file_upload?: boolean;
|
||||
task_progress?: boolean;
|
||||
human_confirm?: boolean;
|
||||
source_citation?: boolean;
|
||||
guide?: boolean;
|
||||
erp_kb?: boolean;
|
||||
}
|
||||
|
||||
export interface ToolRunProgressView {
|
||||
type?: string;
|
||||
schedule_task_id?: number;
|
||||
poll_interval_seconds?: number;
|
||||
lock_input_when_running?: boolean;
|
||||
}
|
||||
|
||||
export interface AgentRegistryFields {
|
||||
id?: number;
|
||||
name?: string | null;
|
||||
description?: string | null;
|
||||
icon_url?: string | null;
|
||||
type?: string | null;
|
||||
agent_code?: string | null;
|
||||
runtime_provider?: string | null;
|
||||
conversation_mode?: string | null;
|
||||
dify_app_type?: 'chatflow' | 'workflow' | string | null;
|
||||
iframe_url?: string | null;
|
||||
welcome_message?: string | null;
|
||||
suggested_questions_style?: 'plain' | 'styled' | string | null;
|
||||
suggested_questions?: unknown;
|
||||
bound_schedule_task_id?: number | null;
|
||||
capabilities?: AgentRegistryCapabilities | null;
|
||||
handler_config?: {
|
||||
intent_routes?: string[] | null;
|
||||
content_profile?: string | null;
|
||||
poll_interval_seconds?: number;
|
||||
lock_input_when_running?: boolean;
|
||||
[key: string]: unknown;
|
||||
} | null;
|
||||
tool_run_progress?: ToolRunProgressView | null;
|
||||
intent_ui_profiles?: string[] | null;
|
||||
leave_feature_enabled?: boolean | null;
|
||||
hr_focused_avatar?: boolean | null;
|
||||
content_profile_key?: AgentContentProfileKey;
|
||||
/** 实验/培训等未结构化字段;运行时业务逻辑禁止读取已迁移 Registry 键。 */
|
||||
extra_config?: {
|
||||
training_workspace_enabled?: boolean;
|
||||
training_pass_score?: number;
|
||||
[key: string]: unknown;
|
||||
} | null;
|
||||
}
|
||||
|
||||
type AgentLike = AgentRegistryFields | null | undefined;
|
||||
|
||||
/**
|
||||
* API 未返回 capabilities 时的极薄兜底(正常路径 /api/agents 应返回完整列)。
|
||||
* 与 manifest platform.default_capabilities 对齐;勿在此处叠加业务分支。
|
||||
*/
|
||||
const FALLBACK_CAPABILITIES: AgentRegistryCapabilities = {
|
||||
streaming: true,
|
||||
file_upload: false,
|
||||
task_progress: false,
|
||||
human_confirm: false,
|
||||
source_citation: true,
|
||||
guide: true,
|
||||
erp_kb: false,
|
||||
};
|
||||
|
||||
/**
|
||||
* 解析 agent_code;只读结构化列,缺失时返回 generic。
|
||||
*/
|
||||
export function resolveAgentCode(agent: AgentLike): string {
|
||||
return String(agent?.agent_code || '').trim() || AGENT_CODE_GENERIC;
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化 capabilities;优先 API 结构化列,缺失键才用 FALLBACK 补全。
|
||||
*/
|
||||
export function resolveAgentCapabilities(agent: AgentLike): AgentRegistryCapabilities {
|
||||
const columnCaps = agent?.capabilities;
|
||||
if (columnCaps && typeof columnCaps === 'object') {
|
||||
return { ...FALLBACK_CAPABILITIES, ...columnCaps };
|
||||
}
|
||||
return { ...FALLBACK_CAPABILITIES };
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 handler_config.intent_routes 为 Set。
|
||||
*/
|
||||
export function resolveIntentRoutes(agent: AgentLike): Set<string> {
|
||||
const raw = agent?.handler_config?.intent_routes;
|
||||
if (!Array.isArray(raw)) return new Set();
|
||||
const routes = raw
|
||||
.map((item) => String(item || '').trim())
|
||||
.filter(Boolean);
|
||||
return new Set(routes);
|
||||
}
|
||||
|
||||
/** 是否声明指定 Intent 快路径。 */
|
||||
export function agentHasIntentRoute(agent: AgentLike, route: string): boolean {
|
||||
const normalized = String(route || '').trim();
|
||||
return normalized ? resolveIntentRoutes(agent).has(normalized) : false;
|
||||
}
|
||||
|
||||
/** Agent 是否带有指定 UI profile(由后端 intent route 注册表聚合)。 */
|
||||
export function agentHasIntentUiProfile(agent: AgentLike, profile: string): boolean {
|
||||
const normalized = String(profile || '').trim();
|
||||
if (!normalized) return false;
|
||||
const profiles = agent?.intent_ui_profiles;
|
||||
return Array.isArray(profiles) && profiles.includes(normalized);
|
||||
}
|
||||
|
||||
/** 是否声明异步任务进度(capabilities.task_progress === true)。 */
|
||||
export function agentHasTaskProgress(agent: AgentLike): boolean {
|
||||
return resolveAgentCapabilities(agent).task_progress === true;
|
||||
}
|
||||
/** 是否启用 ERP 固资知识库特化(capabilities.erp_kb)。 */
|
||||
export function agentHasErpKb(agent: AgentLike): boolean {
|
||||
return Boolean(resolveAgentCapabilities(agent).erp_kb);
|
||||
}
|
||||
|
||||
/** 是否为发货通知 Agent(agent_code=shipping_notice)。 */
|
||||
export function isShippingNoticeAgent(agent: AgentLike): boolean {
|
||||
return resolveAgentCode(agent) === AGENT_CODE_SHIPPING_NOTICE;
|
||||
}
|
||||
|
||||
/** 是否启用本地请假表单(后端 leave_feature_enabled)。 */
|
||||
export function canUseLeaveFeature(agent: AgentLike): boolean {
|
||||
return Boolean(agent?.leave_feature_enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* 侧栏头像缩写:仅 HR 专岗 Agent 显示 HR,其余为 AI(后端 hr_focused_avatar)。
|
||||
*/
|
||||
export function isHrFocusedAgent(agent: AgentLike): boolean {
|
||||
return Boolean(agent?.hr_focused_avatar);
|
||||
}
|
||||
|
||||
export type AgentContentProfileKey = string | null;
|
||||
|
||||
/**
|
||||
* 读取 content_profile(优先 API 序列化的 content_profile_key,回退 handler_config.content_profile)。
|
||||
*/
|
||||
export function resolveAgentContentProfileKey(agent: AgentLike): AgentContentProfileKey {
|
||||
const serverKey = agent?.content_profile_key;
|
||||
if (typeof serverKey === 'string' && serverKey.trim()) {
|
||||
return serverKey.trim();
|
||||
}
|
||||
const configured = String(agent?.handler_config?.content_profile || '').trim();
|
||||
return configured || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 tool_run_progress 视图(API 顶层字段;列 native 组装)。
|
||||
*/
|
||||
export function resolveToolRunProgressView(agent: AgentLike): ToolRunProgressView | null {
|
||||
const view = agent?.tool_run_progress;
|
||||
if (!view || typeof view !== 'object') return null;
|
||||
return view;
|
||||
}
|
||||
Reference in new issue
Block a user