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

@@ -13,14 +13,14 @@ import {
type ComputedRef,
type Ref,
} from 'vue';
import { SHIPPING_NOTICE_AGENT_NAME } from '@/features/chat/api/shipping.api';
import { isShippingNoticeAgent as resolveShippingNoticeAgent } from '@/shared/utils/agent-registry.utils';
import type { AgentRegistryFields } from '@/shared/utils/agent-registry.utils';
import { hasActiveRunningChatRun } from '../shipping/shippingActionBusy';
import {
createShippingActionsRefresher,
createShippingConversationHelpers,
createShippingDecisionHandlers,
createShippingLocalMessages,
createShippingMappingFormHandlers,
createShippingMenuHandlers,
createShippingParseReviewHandlers,
@@ -49,8 +49,8 @@ import {
type ShippingTaskDetail,
type ShippingTaskSummary,
} from '@/features/chat/api/shipping.api';
import { buildShippingQueryShortageTurn } from '../shipping/shippingTurnActions';
import {
buildShortageDetailsMessage,
hasShortageLines,
isShippingShortageQueryIntent,
} from '../shipping/shippingShortageDetails';
@@ -62,7 +62,7 @@ import { listChatMessages } from '../api/chat.api';
export interface UseChatShippingOptions {
deps: ChatDeps;
currentAgent: Ref<{ name?: string } | null>;
currentAgent: Ref<AgentRegistryFields | null>;
currentAgentId: ComputedRef<number>;
messages: Ref<ChatMessage[]>;
conversationId: Ref<string | null>;
@@ -90,6 +90,7 @@ export interface UseChatShippingOptions {
context?: { task_id?: string; batch_no?: string; display_query?: string },
hooks?: { onAssistantMessageFinished?: (message: ChatMessage, runMessages: ChatMessage[]) => void | Promise<void> },
) => Promise<void>;
startChatTurn: (options: import('../types/chat-turn.types').StartChatTurnOptions) => Promise<boolean>;
buildFileSpecsForSend: () => Promise<ChatUploadFileSpec[]>;
loadConversation: (id: string, options?: { force?: boolean }) => Promise<void>;
createNewChatView: () => void;
@@ -154,6 +155,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
newLocalMessageId,
stripReasoningPrelude,
sendMessage,
startChatTurn,
buildFileSpecsForSend,
loadConversation,
createNewChatView,
@@ -165,7 +167,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
};
// ── 功能开关与 UI refs ────────────────────────────────────
const isShippingNoticeAgent = computed(() => currentAgent.value?.name === SHIPPING_NOTICE_AGENT_NAME);
const isShippingNoticeAgent = computed(() => resolveShippingNoticeAgent(currentAgent.value));
const isShippingActionBusy = computed(() => {
if (shippingActionBusy.value) return true;
return hasActiveRunningChatRun(isThinking.value, activeRunId.value, runs.value);
@@ -525,10 +527,23 @@ export function useChatShipping(options: UseChatShippingOptions) {
getActiveBatchTaskId,
});
const { pushShippingLocalUserMessage, pushShippingLocalAssistantMessage } = createShippingLocalMessages({
const {
openShippingInventoryMappingFormForTask,
applyShippingInventoryMappingForm,
reuploadShippingInventoryFromMappingForm,
} = createShippingMappingFormHandlers({
messages,
chatScrollContainer,
shippingInventorySchemaPreviewCache,
shippingInventoryPickerRef,
pendingShippingUploadTaskId,
resolvedShippingTaskId,
newLocalMessageId,
saveLocalMessageToBackend,
startChatTurn,
currentAgentId,
refreshShippingActions,
msg,
});
/**
@@ -573,10 +588,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
};
/**
* 在聊天流中输出确定性的缺口明细。
*
* 核心逻辑:追加一条本地用户意图消息和一条本地助手事实回复,不转发给 Dify,
* 避免大模型复述或重新计算预订单、料号与缺口数量。
* 在聊天流中输出确定性的缺口明细(Chat Turn SSE)。
*/
const queryShippingShortageDetails = async (taskNo?: string, displayText?: string) => {
const task = await resolveShippingTaskForShortageQuery(taskNo);
@@ -584,8 +596,19 @@ export function useChatShipping(options: UseChatShippingOptions) {
msg.warning(t('chat.shippingNoticeMissingTaskId'));
return true;
}
await pushShippingLocalUserMessage(displayText || t('chat.shippingNoticeUi.queryShortageDetails'));
await pushShippingLocalAssistantMessage(buildShortageDetailsMessage(task, t));
const normalizedTaskNo = String(task.task_no || '').trim().toUpperCase();
const turn = buildShippingQueryShortageTurn(
normalizedTaskNo,
displayText || t('chat.shippingNoticeUi.queryShortageDetails'),
);
await startChatTurn({
agentId: currentAgentId.value,
inputType: 'action',
displayText: turn.displayText,
actionType: turn.actionType,
payload: turn.payload,
refs: turn.refs,
});
return true;
};
@@ -599,36 +622,19 @@ export function useChatShipping(options: UseChatShippingOptions) {
sendMessage,
});
const {
openShippingInventoryMappingFormForTask,
applyShippingInventoryMappingForm,
reuploadShippingInventoryFromMappingForm,
} = createShippingMappingFormHandlers({
messages,
chatScrollContainer,
shippingInventorySchemaPreviewCache,
shippingInventoryPickerRef,
pendingShippingUploadTaskId,
resolvedShippingTaskId,
newLocalMessageId,
saveLocalMessageToBackend,
pushShippingLocalAssistantMessage,
refreshShippingActions,
msg,
});
const { executeShippingDecision, executeShippingManualUpload } = createShippingDecisionHandlers({
messages,
conversationId,
history,
isShippingNoticeAgent,
currentAgentId,
shippingInventorySchemaPreviewCache,
getActiveShippingTaskId,
newLocalMessageId,
saveLocalMessageToBackend,
getActiveShippingBatchNo: () => resolvedShippingBatchNo.value || shippingBatchNoFromQuery.value || '',
loadHistory,
openShippingInventoryMappingFormForTask,
refreshShippingActions,
startChatTurn,
msg,
t,
});
@@ -660,6 +666,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
useShippingSuggestedPrompt,
} = createShippingUploadHandlers({
conversationId,
currentAgentId,
attachments,
input,
shippingAutoFlowRequested,
@@ -676,9 +683,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
shippingInventorySelectionTaskId,
shippingInventorySchemaPreviewCache,
getActiveShippingTaskId,
sendShippingMenuMessage,
pushShippingLocalUserMessage,
pushShippingLocalAssistantMessage,
startChatTurn,
refreshShippingActions,
msg,
t,
@@ -686,10 +691,10 @@ export function useChatShipping(options: UseChatShippingOptions) {
const { handleShippingMenuAction, handleShippingActionClick } = createShippingMenuHandlers({
isThinking,
currentAgentId,
getActiveShippingTaskId,
getActiveShippingBatchNo: () => resolvedShippingBatchNo.value || shippingBatchNoFromQuery.value || '',
messages,
newLocalMessageId,
saveLocalMessageToBackend,
sendShippingMenuMessage,
openShippingInventoryMappingFormForTask,
openShippingInventoryPicker,
@@ -697,6 +702,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
executeShippingDecision,
executeShippingManualUpload,
refreshShippingActions,
startChatTurn,
msg,
t,
});
@@ -723,8 +729,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
buildFileSpecsForSend,
loadHistory,
sendShippingMenuMessage,
pushShippingLocalUserMessage,
pushShippingLocalAssistantMessage,
startChatTurn,
openShippingInventoryPicker,
executeShippingDecision,
executeShippingManualUpload,