Trim online context from AI chat editors

This commit is contained in:
2026-06-09 00:06:35 +08:00
parent cd355180f6
commit 0a86fa80b4
7 changed files with 29 additions and 63 deletions
@@ -3,7 +3,11 @@ import type { DesignPreviewData } from './types';
import { computed, ref, watch } from 'vue'; import { computed, ref, watch } from 'vue';
import { Check, Copy, X } from '@vben/icons'; import {
Check,
Close as X,
CopyDocument as Copy,
} from '@element-plus/icons-vue';
import { import {
ElButton, ElButton,
@@ -71,13 +75,14 @@ const summaryItems = computed(() => {
const fieldItems = computed(() => { const fieldItems = computed(() => {
const source = payload.value as Record<string, any>; const source = payload.value as Record<string, any>;
const fields = source.form_fields || source.fields || source.schema?.fields; const fields =
source.schema_fields || source.form_fields || source.fields || source.schema?.fields;
return Array.isArray(fields) ? fields.slice(0, 12) : []; return Array.isArray(fields) ? fields.slice(0, 12) : [];
}); });
const tableItems = computed(() => { const tableItems = computed(() => {
const source = payload.value as Record<string, any>; const source = payload.value as Record<string, any>;
const tables = source.table_configs || source.tables || source.data_sources; const tables = source.data_sources || source.table_configs || source.tables;
return Array.isArray(tables) ? tables.slice(0, 8) : []; return Array.isArray(tables) ? tables.slice(0, 8) : [];
}); });
@@ -91,7 +91,7 @@ export function useChatApi(props: AiChatPanelProps): {
const adapter: ChatApiAdapter = { const adapter: ChatApiAdapter = {
sendMessage: ( sendMessage: (
message: string, message: string,
inputs: Record<string, any> | undefined, _inputs: Record<string, any> | undefined,
onEvent: (event: StreamEvent) => void, onEvent: (event: StreamEvent) => void,
onError: (error: Error) => void, onError: (error: Error) => void,
onComplete: () => void, onComplete: () => void,
@@ -110,16 +110,12 @@ export function useChatApi(props: AiChatPanelProps): {
type: att.type, type: att.type,
})); }));
// 从 inputs 中提取 form_code(如果存在)
const formCode = inputs?.form_code;
return sendAgentMessageStream( return sendAgentMessageStream(
props.agentId, props.agentId,
{ {
message, message,
conversation_id: conversationId.value || undefined, conversation_id: conversationId.value || undefined,
attachments: attachmentInputs, attachments: attachmentInputs,
form_code: formCode,
}, },
(event) => { (event) => {
// 捕获 conversation_id // 捕获 conversation_id
@@ -97,8 +97,8 @@ export function useEventHandler(config: EventHandlerConfig) {
title: configData.title || '设计预览', title: configData.title || '设计预览',
data: configData.data || {}, data: configData.data || {},
nodeId: event.node_id || '', nodeId: event.node_id || '',
form_fields: configData.form_fields, data_sources: configData.data_sources || configData.table_configs,
table_configs: configData.table_configs, schema_fields: configData.schema_fields || configData.form_fields,
layoutOptions: configData.layoutOptions, layoutOptions: configData.layoutOptions,
themeOptions: configData.themeOptions, themeOptions: configData.themeOptions,
}; };
@@ -70,8 +70,8 @@ export interface DesignPreviewData {
title: string; title: string;
data: Record<string, any>; data: Record<string, any>;
nodeId: string; nodeId: string;
form_fields?: any[]; data_sources?: any[];
table_configs?: any[]; schema_fields?: any[];
layoutOptions?: any[]; layoutOptions?: any[];
themeOptions?: any[]; themeOptions?: any[];
} }
@@ -89,6 +89,7 @@ export interface NodeEvent {
node_id: string; node_id: string;
node_type?: string; node_type?: string;
node_label?: string; node_label?: string;
event_type?: string;
status?: 'failed' | 'running' | 'success'; status?: 'failed' | 'running' | 'success';
inputs?: Record<string, any>; inputs?: Record<string, any>;
outputs?: Record<string, any>; outputs?: Record<string, any>;
@@ -96,6 +97,7 @@ export interface NodeEvent {
tokens_used?: number; tokens_used?: number;
error_message?: string; error_message?: string;
loop_iteration?: number; loop_iteration?: number;
warnings?: any[];
} }
/** 循环迭代事件 */ /** 循环迭代事件 */
@@ -132,7 +134,7 @@ export interface AiChatPanelProps {
agent?: AgentInfo | null; agent?: AgentInfo | null;
/** 当前对话 IDagent-chat 模式用于加载历史) */ /** 当前对话 IDagent-chat 模式用于加载历史) */
conversationId?: null | string; conversationId?: null | string;
/** 初始输入参数(如 form_code 等系统变量) */ /** 初始输入参数 */
initialInputs?: Record<string, any>; initialInputs?: Record<string, any>;
// ========== 功能开关 ========== // ========== 功能开关 ==========
@@ -71,9 +71,9 @@ const waitingConfig = ref<any>(null);
// 设计面板状态 // 设计面板状态
const currentDesign = ref<null | { const currentDesign = ref<null | {
data: any; data: any;
form_fields?: any[]; data_sources?: any[];
nodeId: string; nodeId: string;
table_configs?: any[]; schema_fields?: any[];
title: string; title: string;
type: string; type: string;
}>(null); }>(null);
@@ -273,7 +273,7 @@ async function doSendMessage(message: string, addUserMessage: boolean = true) {
scrollToBottom(); scrollToBottom();
// 发送流式请求 // 发送流式请求
// 系统变量(application_id 等)由 API 层自动注入 // 业务上下文由 API 层按 Agent 配置解析
cancelStream = sendAgentMessageStream( cancelStream = sendAgentMessageStream(
props.agentId, props.agentId,
{ {
@@ -491,8 +491,8 @@ function handleStreamEvent(
$t('ai-platform.agent.chatPanel.designPreview'), $t('ai-platform.agent.chatPanel.designPreview'),
data: configData.data || {}, data: configData.data || {},
nodeId: event.node_id || '', nodeId: event.node_id || '',
form_fields: configData.form_fields || [], data_sources: configData.data_sources || configData.table_configs || [],
table_configs: configData.table_configs || [], schema_fields: configData.schema_fields || configData.form_fields || [],
}; };
showDesignPanel.value = true; showDesignPanel.value = true;
@@ -838,8 +838,8 @@ onUnmounted(() => {
title: currentDesign.title, title: currentDesign.title,
data: currentDesign.data, data: currentDesign.data,
nodeId: currentDesign.nodeId, nodeId: currentDesign.nodeId,
form_fields: currentDesign.form_fields, data_sources: currentDesign.data_sources,
table_configs: currentDesign.table_configs, schema_fields: currentDesign.schema_fields,
}" }"
@confirm="handleDesignConfirm" @confirm="handleDesignConfirm"
@close="handleDesignCancel" @close="handleDesignCancel"
@@ -215,7 +215,7 @@ const runWorkflow = (userMessage: string, inputs: Record<string, any>) => {
running.value = true; running.value = true;
// 流式运行(编辑器调试模式,使用草稿版本) // 流式运行(编辑器调试模式,使用草稿版本)
// 系统变量(application_id 等)由 API 层自动注入 // 业务上下文由 API 层按 Workflow 配置解析
cancelStream = runWorkflowStreamApi( cancelStream = runWorkflowStreamApi(
props.workflowId, props.workflowId,
inputs, inputs,
@@ -589,8 +589,10 @@ const handleStreamEvent = (event: WorkflowStreamEvent, msgId: string) => {
$t('ai-platform.workflow.editor.chatPanel.designPreviewTitle'), $t('ai-platform.workflow.editor.chatPanel.designPreviewTitle'),
data: configData.data || {}, data: configData.data || {},
nodeId: event.node_id || '', nodeId: event.node_id || '',
form_fields: configData.form_fields || [], // 传递表单字段列表(用于列表设计) data_sources:
table_configs: configData.table_configs || [], // 传递数据表配置(用于表单设计) configData.data_sources || configData.table_configs || [],
schema_fields:
configData.schema_fields || configData.form_fields || [],
}; };
showDesignPanel.value = true; showDesignPanel.value = true;
} }
@@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch } from 'vue'; import { ref, watch } from 'vue';
import { Plus, Trash2 } from '@vben/icons'; import { Delete as Trash2, Plus } from '@element-plus/icons-vue';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { ElButton, ElForm, ElInput, ElOption, ElSelect } from 'element-plus'; import { ElButton, ElForm, ElInput, ElOption, ElSelect } from 'element-plus';
@@ -50,45 +50,6 @@ const handleDelete = (index: number) => {
</div> </div>
</div> </div>
<!-- 默认的 application_id 变量不可删除 -->
<div class="border-primary/30 bg-primary/5 rounded border p-3">
<div class="mb-2 flex items-center justify-between">
<span class="text-primary text-sm font-medium">application_id</span>
<span class="text-muted-foreground text-xs">{{
$t('ai-platform.workflow.panels.common.sysVar')
}}</span>
</div>
<div class="text-muted-foreground text-xs">
{{ $t('ai-platform.workflow.panels.start.appIdDesc') }}
</div>
</div>
<!-- 默认的 application_code 变量不可删除 -->
<div class="border-primary/30 bg-primary/5 rounded border p-3">
<div class="mb-2 flex items-center justify-between">
<span class="text-primary text-sm font-medium">application_code</span>
<span class="text-muted-foreground text-xs">{{
$t('ai-platform.workflow.panels.common.sysVar')
}}</span>
</div>
<div class="text-muted-foreground text-xs">
{{ $t('ai-platform.workflow.panels.start.appCodeDesc') }}
</div>
</div>
<!-- 默认的 form_code 变量不可删除 -->
<div class="border-primary/30 bg-primary/5 rounded border p-3">
<div class="mb-2 flex items-center justify-between">
<span class="text-primary text-sm font-medium">form_code</span>
<span class="text-muted-foreground text-xs">{{
$t('ai-platform.workflow.panels.common.sysVar')
}}</span>
</div>
<div class="text-muted-foreground text-xs">
{{ $t('ai-platform.workflow.panels.start.formCodeDesc') }}
</div>
</div>
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<span class="text-foreground text-sm font-medium">{{ <span class="text-foreground text-sm font-medium">{{
$t('ai-platform.workflow.panels.common.customVars') $t('ai-platform.workflow.panels.common.customVars')