feat(schedule): 优化排程任务配置与进度契约处理逻辑
This commit is contained in:
1 parent
d54f51ddc3
commit
99453aa52a
65 files changed
+2837
-487
No files matched your search
@@ -7,13 +7,18 @@ import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
AGENT_CODE_SHIPPING_NOTICE,
|
||||
agentHasIntentUiProfile,
|
||||
agentHasProgress,
|
||||
agentHasTaskProgress,
|
||||
agentProgressRequiresScheduleTask,
|
||||
agentUsesScheduleRunCounterProgress,
|
||||
agentUsesWorkspaceStepperProgress,
|
||||
canUseLeaveFeature,
|
||||
isHrFocusedAgent,
|
||||
isShippingNoticeAgent,
|
||||
resolveAgentContentProfileKey,
|
||||
resolveAgentCode,
|
||||
resolveIntentRoutes,
|
||||
resolveProgressContract,
|
||||
} from './agent-registry.utils';
|
||||
|
||||
describe('agent-registry.utils', () => {
|
||||
@@ -58,4 +63,31 @@ describe('agent-registry.utils', () => {
|
||||
expect(agentHasIntentUiProfile({ intent_ui_profiles: ['maintenance'] }, 'maintenance')).toBe(true);
|
||||
expect(agentHasIntentUiProfile({ intent_ui_profiles: [] }, 'maintenance')).toBe(false);
|
||||
});
|
||||
|
||||
it('resolveProgressContract and helpers distinguish file_check vs shipping_notice', () => {
|
||||
const fileCheckContract = {
|
||||
enabled: true,
|
||||
data_source: { type: 'schedule_run' as const },
|
||||
presentation: { layout: 'card' as const, visualization: 'counter' as const },
|
||||
binding: { requires_schedule_task: true },
|
||||
};
|
||||
const shippingContract = {
|
||||
enabled: true,
|
||||
data_source: { type: 'domain_state' as const, domain: 'shipping_notice' },
|
||||
presentation: { layout: 'workspace' as const, visualization: 'stepper' as const },
|
||||
binding: { requires_schedule_task: false },
|
||||
};
|
||||
const fileCheckAgent = { capabilities: { task_progress: true }, progress_contract: fileCheckContract };
|
||||
const shippingAgent = { capabilities: { task_progress: true }, progress_contract: shippingContract };
|
||||
|
||||
expect(resolveProgressContract(fileCheckAgent)).toEqual(fileCheckContract);
|
||||
expect(agentHasProgress(fileCheckAgent)).toBe(true);
|
||||
expect(agentProgressRequiresScheduleTask(fileCheckAgent)).toBe(true);
|
||||
expect(agentUsesScheduleRunCounterProgress(fileCheckAgent)).toBe(true);
|
||||
expect(agentUsesWorkspaceStepperProgress(fileCheckAgent)).toBe(false);
|
||||
|
||||
expect(agentProgressRequiresScheduleTask(shippingAgent)).toBe(false);
|
||||
expect(agentUsesWorkspaceStepperProgress(shippingAgent)).toBe(true);
|
||||
expect(agentUsesScheduleRunCounterProgress(shippingAgent)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -27,6 +27,35 @@ export interface ToolRunProgressView {
|
||||
lock_input_when_running?: boolean;
|
||||
}
|
||||
|
||||
export type ProgressDataSourceType = 'schedule_run' | 'domain_state' | 'job_queue' | 'external_callback';
|
||||
export type ProgressTransport = 'polling' | 'sse' | 'manual_refresh';
|
||||
export type ProgressBindingType = 'chat_log_run' | 'conversation_context' | 'domain_key';
|
||||
export type ProgressLayout = 'card' | 'workspace' | 'inline' | 'drawer';
|
||||
export type ProgressVisualization = 'counter' | 'stepper' | 'timeline' | 'percent' | 'hybrid';
|
||||
|
||||
export interface ProgressContract {
|
||||
enabled?: boolean;
|
||||
data_source?: {
|
||||
type?: ProgressDataSourceType;
|
||||
domain?: string;
|
||||
};
|
||||
update?: {
|
||||
transport?: ProgressTransport;
|
||||
event?: string;
|
||||
interval_seconds?: number;
|
||||
};
|
||||
binding?: {
|
||||
type?: ProgressBindingType;
|
||||
keys?: string[];
|
||||
fallback?: string;
|
||||
requires_schedule_task?: boolean;
|
||||
};
|
||||
presentation?: {
|
||||
layout?: ProgressLayout;
|
||||
visualization?: ProgressVisualization;
|
||||
};
|
||||
}
|
||||
|
||||
export interface AgentRegistryFields {
|
||||
id?: number;
|
||||
name?: string | null;
|
||||
@@ -51,6 +80,7 @@ export interface AgentRegistryFields {
|
||||
[key: string]: unknown;
|
||||
} | null;
|
||||
tool_run_progress?: ToolRunProgressView | null;
|
||||
progress_contract?: ProgressContract | null;
|
||||
intent_ui_profiles?: string[] | null;
|
||||
leave_feature_enabled?: boolean | null;
|
||||
hr_focused_avatar?: boolean | null;
|
||||
@@ -123,10 +153,73 @@ export function agentHasIntentUiProfile(agent: AgentLike, profile: string): bool
|
||||
return Array.isArray(profiles) && profiles.includes(normalized);
|
||||
}
|
||||
|
||||
/** 是否声明异步任务进度(capabilities.task_progress === true)。 */
|
||||
/** 是否声明异步任务进度能力(capabilities.task_progress === true)。 */
|
||||
export function agentHasTaskProgress(agent: AgentLike): boolean {
|
||||
return resolveAgentCapabilities(agent).task_progress === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 progress_contract;优先 API 下发,缺失时返回 null。
|
||||
*/
|
||||
export function resolveProgressContract(agent: AgentLike): ProgressContract | null {
|
||||
const contract = agent?.progress_contract;
|
||||
if (!contract || typeof contract !== 'object' || contract.enabled !== true) {
|
||||
return null;
|
||||
}
|
||||
return contract;
|
||||
}
|
||||
|
||||
/** Agent 是否有可用进度契约(progress_contract.enabled === true)。 */
|
||||
export function agentHasProgress(agent: AgentLike): boolean {
|
||||
return resolveProgressContract(agent) !== null;
|
||||
}
|
||||
|
||||
/** 进度数据源类型。 */
|
||||
export function agentProgressDataSourceType(agent: AgentLike): ProgressDataSourceType | null {
|
||||
return resolveProgressContract(agent)?.data_source?.type ?? null;
|
||||
}
|
||||
|
||||
/** 进度更新传输方式。 */
|
||||
export function agentProgressTransport(agent: AgentLike): ProgressTransport | null {
|
||||
return resolveProgressContract(agent)?.update?.transport ?? null;
|
||||
}
|
||||
|
||||
/** 进度展示布局。 */
|
||||
export function agentProgressLayout(agent: AgentLike): ProgressLayout | null {
|
||||
return resolveProgressContract(agent)?.presentation?.layout ?? null;
|
||||
}
|
||||
|
||||
/** 进度可视化形态。 */
|
||||
export function agentProgressVisualization(agent: AgentLike): ProgressVisualization | null {
|
||||
return resolveProgressContract(agent)?.presentation?.visualization ?? null;
|
||||
}
|
||||
|
||||
/** 进度契约是否要求绑定排程任务。 */
|
||||
export function agentProgressRequiresScheduleTask(agent: AgentLike): boolean {
|
||||
return resolveProgressContract(agent)?.binding?.requires_schedule_task === true;
|
||||
}
|
||||
|
||||
/** 是否展示 workspace + stepper 形态的域状态进度(如货代发货)。 */
|
||||
export function agentUsesWorkspaceStepperProgress(agent: AgentLike): boolean {
|
||||
const contract = resolveProgressContract(agent);
|
||||
if (!contract) return false;
|
||||
return (
|
||||
contract.presentation?.layout === 'workspace'
|
||||
&& contract.presentation?.visualization === 'stepper'
|
||||
&& contract.data_source?.type === 'domain_state'
|
||||
);
|
||||
}
|
||||
|
||||
/** 是否展示 schedule_run + counter 形态的轮询进度卡片(如文件检核)。 */
|
||||
export function agentUsesScheduleRunCounterProgress(agent: AgentLike): boolean {
|
||||
const contract = resolveProgressContract(agent);
|
||||
if (!contract) return false;
|
||||
return (
|
||||
contract.data_source?.type === 'schedule_run'
|
||||
&& contract.presentation?.visualization === 'counter'
|
||||
&& contract.presentation?.layout === 'card'
|
||||
);
|
||||
}
|
||||
/** 是否启用 ERP 固资知识库特化(capabilities.erp_kb)。 */
|
||||
export function agentHasErpKb(agent: AgentLike): boolean {
|
||||
return Boolean(resolveAgentCapabilities(agent).erp_kb);
|
||||
|
||||
Reference in new issue
Block a user