发布 v1.10 #5
@@ -0,0 +1,115 @@
|
|||||||
|
package tech.easyflow.agent.config;
|
||||||
|
|
||||||
|
import tech.easyflow.common.web.exceptions.BusinessException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Agent 对话体验配置的规范化与校验工具。
|
||||||
|
*/
|
||||||
|
public final class AgentInteractionConfigSupport {
|
||||||
|
|
||||||
|
/** 欢迎语最大字符数。 */
|
||||||
|
public static final int MAX_WELCOME_MESSAGE_LENGTH = 300;
|
||||||
|
/** 猜你想问最大数量。 */
|
||||||
|
public static final int MAX_SUGGESTED_QUESTION_COUNT = 6;
|
||||||
|
/** 单条猜你想问最大字符数。 */
|
||||||
|
public static final int MAX_SUGGESTED_QUESTION_LENGTH = 80;
|
||||||
|
/** 输入提示最大字符数。 */
|
||||||
|
public static final int MAX_INPUT_PLACEHOLDER_LENGTH = 40;
|
||||||
|
|
||||||
|
private AgentInteractionConfigSupport() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 规范化并校验对话体验配置。
|
||||||
|
*
|
||||||
|
* @param source 原始配置
|
||||||
|
* @return 仅包含受支持字段的稳定配置
|
||||||
|
* @throws BusinessException 配置字段类型或内容不合法时抛出
|
||||||
|
*/
|
||||||
|
public static Map<String, Object> normalize(Map<String, Object> source) {
|
||||||
|
Map<String, Object> config = source == null ? Map.of() : source;
|
||||||
|
String welcomeMessage = optionalString(config.get("welcomeMessage"), "欢迎语");
|
||||||
|
if (welcomeMessage.length() > MAX_WELCOME_MESSAGE_LENGTH) {
|
||||||
|
throw new BusinessException("欢迎语不能超过 300 个字符");
|
||||||
|
}
|
||||||
|
|
||||||
|
String inputPlaceholder = optionalString(config.get("inputPlaceholder"), "输入提示");
|
||||||
|
if (inputPlaceholder.contains("\n") || inputPlaceholder.contains("\r")) {
|
||||||
|
throw new BusinessException("输入提示仅支持单行文本");
|
||||||
|
}
|
||||||
|
if (inputPlaceholder.length() > MAX_INPUT_PLACEHOLDER_LENGTH) {
|
||||||
|
throw new BusinessException("输入提示不能超过 40 个字符");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> suggestedQuestions = normalizeSuggestedQuestions(config.get("suggestedQuestions"));
|
||||||
|
Map<String, Object> normalized = new LinkedHashMap<>();
|
||||||
|
normalized.put("welcomeMessage", welcomeMessage);
|
||||||
|
normalized.put("suggestedQuestions", suggestedQuestions);
|
||||||
|
normalized.put("inputPlaceholder", inputPlaceholder);
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 规范化猜你想问列表,过滤空项并保留原有顺序。
|
||||||
|
*
|
||||||
|
* @param value 原始列表值
|
||||||
|
* @return 规范化后的问题列表
|
||||||
|
* @throws BusinessException 列表类型、数量、长度或重复性不合法时抛出
|
||||||
|
*/
|
||||||
|
private static List<String> normalizeSuggestedQuestions(Object value) {
|
||||||
|
if (value == null) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
if (!(value instanceof Collection<?> values)) {
|
||||||
|
throw new BusinessException("猜你想问格式不正确");
|
||||||
|
}
|
||||||
|
List<String> normalized = new ArrayList<>();
|
||||||
|
Set<String> uniqueQuestions = new LinkedHashSet<>();
|
||||||
|
for (Object item : values) {
|
||||||
|
if (!(item instanceof String question)) {
|
||||||
|
throw new BusinessException("猜你想问仅支持文本内容");
|
||||||
|
}
|
||||||
|
String trimmedQuestion = question.trim();
|
||||||
|
if (trimmedQuestion.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (trimmedQuestion.length() > MAX_SUGGESTED_QUESTION_LENGTH) {
|
||||||
|
throw new BusinessException("单条猜你想问不能超过 80 个字符");
|
||||||
|
}
|
||||||
|
if (!uniqueQuestions.add(trimmedQuestion)) {
|
||||||
|
throw new BusinessException("猜你想问不能重复");
|
||||||
|
}
|
||||||
|
normalized.add(trimmedQuestion);
|
||||||
|
}
|
||||||
|
if (normalized.size() > MAX_SUGGESTED_QUESTION_COUNT) {
|
||||||
|
throw new BusinessException("猜你想问最多配置 6 条");
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将可选字段转换为去除首尾空白的文本。
|
||||||
|
*
|
||||||
|
* @param value 原始字段值
|
||||||
|
* @param fieldName 字段名称
|
||||||
|
* @return 规范化后的文本
|
||||||
|
* @throws BusinessException 字段不是文本时抛出
|
||||||
|
*/
|
||||||
|
private static String optionalString(Object value, String fieldName) {
|
||||||
|
if (value == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (!(value instanceof String text)) {
|
||||||
|
throw new BusinessException(fieldName + "格式不正确");
|
||||||
|
}
|
||||||
|
return text.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,6 +43,9 @@ public class Agent extends DateEntity implements VisibilityResource, Serializabl
|
|||||||
private Map<String, Object> memoryConfigJson = new LinkedHashMap<>();
|
private Map<String, Object> memoryConfigJson = new LinkedHashMap<>();
|
||||||
@Column(typeHandler = FastjsonTypeHandler.class)
|
@Column(typeHandler = FastjsonTypeHandler.class)
|
||||||
private Map<String, Object> executionConfigJson = new LinkedHashMap<>();
|
private Map<String, Object> executionConfigJson = new LinkedHashMap<>();
|
||||||
|
/** 对话欢迎语、猜你想问和输入提示配置。 */
|
||||||
|
@Column(typeHandler = FastjsonTypeHandler.class)
|
||||||
|
private Map<String, Object> interactionConfigJson = new LinkedHashMap<>();
|
||||||
private Integer status;
|
private Integer status;
|
||||||
private String visibilityScope;
|
private String visibilityScope;
|
||||||
private String publishStatus;
|
private String publishStatus;
|
||||||
@@ -95,6 +98,18 @@ public class Agent extends DateEntity implements VisibilityResource, Serializabl
|
|||||||
public void setMemoryConfigJson(Map<String, Object> memoryConfigJson) { this.memoryConfigJson = memoryConfigJson == null ? new LinkedHashMap<>() : memoryConfigJson; }
|
public void setMemoryConfigJson(Map<String, Object> memoryConfigJson) { this.memoryConfigJson = memoryConfigJson == null ? new LinkedHashMap<>() : memoryConfigJson; }
|
||||||
public Map<String, Object> getExecutionConfigJson() { return executionConfigJson; }
|
public Map<String, Object> getExecutionConfigJson() { return executionConfigJson; }
|
||||||
public void setExecutionConfigJson(Map<String, Object> executionConfigJson) { this.executionConfigJson = executionConfigJson == null ? new LinkedHashMap<>() : executionConfigJson; }
|
public void setExecutionConfigJson(Map<String, Object> executionConfigJson) { this.executionConfigJson = executionConfigJson == null ? new LinkedHashMap<>() : executionConfigJson; }
|
||||||
|
/**
|
||||||
|
* 获取对话体验配置。
|
||||||
|
*
|
||||||
|
* @return 对话体验配置
|
||||||
|
*/
|
||||||
|
public Map<String, Object> getInteractionConfigJson() { return interactionConfigJson; }
|
||||||
|
/**
|
||||||
|
* 设置对话体验配置。
|
||||||
|
*
|
||||||
|
* @param interactionConfigJson 对话体验配置
|
||||||
|
*/
|
||||||
|
public void setInteractionConfigJson(Map<String, Object> interactionConfigJson) { this.interactionConfigJson = interactionConfigJson == null ? new LinkedHashMap<>() : interactionConfigJson; }
|
||||||
public Integer getStatus() { return status; }
|
public Integer getStatus() { return status; }
|
||||||
public void setStatus(Integer status) { this.status = status; }
|
public void setStatus(Integer status) { this.status = status; }
|
||||||
public String getVisibilityScope() { return visibilityScope; }
|
public String getVisibilityScope() { return visibilityScope; }
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package tech.easyflow.agent.publish;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
import com.mybatisflex.core.update.UpdateChain;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import tech.easyflow.agent.entity.Agent;
|
import tech.easyflow.agent.entity.Agent;
|
||||||
import tech.easyflow.agent.entity.AgentKnowledgeBinding;
|
import tech.easyflow.agent.entity.AgentKnowledgeBinding;
|
||||||
@@ -122,32 +123,33 @@ public class AgentApprovalSubjectHandler extends AbstractAiResourceLifecycleHand
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void persistResourceState(BigInteger resourceId, PublishStatus publishStatus, BigInteger currentApprovalInstanceId) {
|
protected void persistResourceState(BigInteger resourceId, PublishStatus publishStatus, BigInteger currentApprovalInstanceId) {
|
||||||
Agent agent = new Agent();
|
// 生命周期操作仅更新状态字段,避免实体默认空配置覆盖 Agent 草稿配置。
|
||||||
agent.setId(resourceId);
|
UpdateChain<Agent> updateChain = agentService.updateChain();
|
||||||
agent.setPublishStatus(publishStatus.getCode());
|
updateChain.set(Agent::getPublishStatus, publishStatus.getCode());
|
||||||
agent.setCurrentApprovalInstanceId(currentApprovalInstanceId);
|
updateChain.set(Agent::getCurrentApprovalInstanceId, currentApprovalInstanceId);
|
||||||
agentService.updateById(agent);
|
updateChain.eq(Agent::getId, resourceId);
|
||||||
|
updateChain.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void publishResource(BigInteger resourceId, Map<String, Object> resourceSnapshot, BigInteger operatorId) {
|
protected void publishResource(BigInteger resourceId, Map<String, Object> resourceSnapshot, BigInteger operatorId) {
|
||||||
Agent agent = new Agent();
|
UpdateChain<Agent> updateChain = agentService.updateChain();
|
||||||
agent.setId(resourceId);
|
updateChain.set(Agent::getPublishStatus, PublishStatus.PUBLISHED.getCode());
|
||||||
agent.setPublishStatus(PublishStatus.PUBLISHED.getCode());
|
updateChain.set(Agent::getPublishedSnapshotJson, resourceSnapshot);
|
||||||
agent.setPublishedSnapshotJson(resourceSnapshot);
|
updateChain.set(Agent::getPublishedAt, new Date());
|
||||||
agent.setPublishedAt(new Date());
|
updateChain.set(Agent::getPublishedBy, operatorId);
|
||||||
agent.setPublishedBy(operatorId);
|
updateChain.set(Agent::getCurrentApprovalInstanceId, null);
|
||||||
agent.setCurrentApprovalInstanceId(null);
|
updateChain.eq(Agent::getId, resourceId);
|
||||||
agentService.updateById(agent);
|
updateChain.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void markResourceOffline(BigInteger resourceId) {
|
protected void markResourceOffline(BigInteger resourceId) {
|
||||||
Agent agent = new Agent();
|
UpdateChain<Agent> updateChain = agentService.updateChain();
|
||||||
agent.setId(resourceId);
|
updateChain.set(Agent::getPublishStatus, PublishStatus.OFFLINE.getCode());
|
||||||
agent.setPublishStatus(PublishStatus.OFFLINE.getCode());
|
updateChain.set(Agent::getCurrentApprovalInstanceId, null);
|
||||||
agent.setCurrentApprovalInstanceId(null);
|
updateChain.eq(Agent::getId, resourceId);
|
||||||
agentService.updateById(agent);
|
updateChain.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import tech.easyflow.agent.config.AgentInteractionConfigSupport;
|
||||||
import tech.easyflow.agent.entity.Agent;
|
import tech.easyflow.agent.entity.Agent;
|
||||||
import tech.easyflow.agent.entity.AgentKnowledgeBinding;
|
import tech.easyflow.agent.entity.AgentKnowledgeBinding;
|
||||||
import tech.easyflow.agent.entity.AgentToolBinding;
|
import tech.easyflow.agent.entity.AgentToolBinding;
|
||||||
@@ -133,6 +134,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|||||||
snapshot.put("promptConfigJson", detail.getPromptConfigJson());
|
snapshot.put("promptConfigJson", detail.getPromptConfigJson());
|
||||||
snapshot.put("memoryConfigJson", detail.getMemoryConfigJson());
|
snapshot.put("memoryConfigJson", detail.getMemoryConfigJson());
|
||||||
snapshot.put("executionConfigJson", detail.getExecutionConfigJson());
|
snapshot.put("executionConfigJson", detail.getExecutionConfigJson());
|
||||||
|
snapshot.put("interactionConfigJson", detail.getInteractionConfigJson());
|
||||||
snapshot.put("visibilityScope", detail.getVisibilityScope());
|
snapshot.put("visibilityScope", detail.getVisibilityScope());
|
||||||
snapshot.put("toolBindings", snapshotToolBindings(detail.getToolBindings()));
|
snapshot.put("toolBindings", snapshotToolBindings(detail.getToolBindings()));
|
||||||
snapshot.put("knowledgeBindings", snapshotKnowledgeBindings(detail.getKnowledgeBindings()));
|
snapshot.put("knowledgeBindings", snapshotKnowledgeBindings(detail.getKnowledgeBindings()));
|
||||||
@@ -162,6 +164,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|||||||
agent.setModelId(toBigInteger(snapshot.get("modelId")));
|
agent.setModelId(toBigInteger(snapshot.get("modelId")));
|
||||||
agent.setCategoryId(toBigInteger(snapshot.get("categoryId")));
|
agent.setCategoryId(toBigInteger(snapshot.get("categoryId")));
|
||||||
agent.setPublishStatus(PublishStatus.PUBLISHED.getCode());
|
agent.setPublishStatus(PublishStatus.PUBLISHED.getCode());
|
||||||
|
agent.setInteractionConfigJson(AgentInteractionConfigSupport.normalize(agent.getInteractionConfigJson()));
|
||||||
agent.setPublishedSnapshotJson(snapshot);
|
agent.setPublishedSnapshotJson(snapshot);
|
||||||
agent.setToolBindings(objectMapper.convertValue(snapshot.get("toolBindings"), TOOL_BINDING_LIST_TYPE));
|
agent.setToolBindings(objectMapper.convertValue(snapshot.get("toolBindings"), TOOL_BINDING_LIST_TYPE));
|
||||||
agent.setKnowledgeBindings(objectMapper.convertValue(snapshot.get("knowledgeBindings"), KNOWLEDGE_BINDING_LIST_TYPE));
|
agent.setKnowledgeBindings(objectMapper.convertValue(snapshot.get("knowledgeBindings"), KNOWLEDGE_BINDING_LIST_TYPE));
|
||||||
@@ -191,6 +194,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|||||||
throw new BusinessException("Agent 模型不存在");
|
throw new BusinessException("Agent 模型不存在");
|
||||||
}
|
}
|
||||||
agent.setVisibilityScope(VisibilityScope.fromOrDefault(agent.getVisibilityScope(), VisibilityScope.PRIVATE).name());
|
agent.setVisibilityScope(VisibilityScope.fromOrDefault(agent.getVisibilityScope(), VisibilityScope.PRIVATE).name());
|
||||||
|
agent.setInteractionConfigJson(AgentInteractionConfigSupport.normalize(agent.getInteractionConfigJson()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyDraftDefaults(Agent agent) {
|
private void applyDraftDefaults(Agent agent) {
|
||||||
@@ -231,6 +235,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|||||||
existing.setPromptConfigJson(incoming.getPromptConfigJson());
|
existing.setPromptConfigJson(incoming.getPromptConfigJson());
|
||||||
existing.setMemoryConfigJson(incoming.getMemoryConfigJson());
|
existing.setMemoryConfigJson(incoming.getMemoryConfigJson());
|
||||||
existing.setExecutionConfigJson(incoming.getExecutionConfigJson());
|
existing.setExecutionConfigJson(incoming.getExecutionConfigJson());
|
||||||
|
existing.setInteractionConfigJson(incoming.getInteractionConfigJson());
|
||||||
existing.setStatus(incoming.getStatus() == null ? 1 : incoming.getStatus());
|
existing.setStatus(incoming.getStatus() == null ? 1 : incoming.getStatus());
|
||||||
existing.setVisibilityScope(incoming.getVisibilityScope());
|
existing.setVisibilityScope(incoming.getVisibilityScope());
|
||||||
existing.setModified(new Date());
|
existing.setModified(new Date());
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package tech.easyflow.agent.config;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import tech.easyflow.common.web.exceptions.BusinessException;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link AgentInteractionConfigSupport} 单元测试。
|
||||||
|
*/
|
||||||
|
public class AgentInteractionConfigSupportTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证空配置可以转换为稳定结构。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void shouldNormalizeEmptyConfig() {
|
||||||
|
Map<String, Object> normalized = AgentInteractionConfigSupport.normalize(null);
|
||||||
|
|
||||||
|
Assert.assertEquals("", normalized.get("welcomeMessage"));
|
||||||
|
Assert.assertEquals(List.of(), normalized.get("suggestedQuestions"));
|
||||||
|
Assert.assertEquals("", normalized.get("inputPlaceholder"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证空问题会被过滤,合法问题会去除首尾空白并保持顺序。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void shouldNormalizeSuggestedQuestions() {
|
||||||
|
Map<String, Object> source = new LinkedHashMap<>();
|
||||||
|
source.put("welcomeMessage", " 欢迎使用\n智能助手 ");
|
||||||
|
source.put("suggestedQuestions", List.of(" 第一个问题 ", "", " 第二个问题"));
|
||||||
|
source.put("inputPlaceholder", " 请输入问题 ");
|
||||||
|
|
||||||
|
Map<String, Object> normalized = AgentInteractionConfigSupport.normalize(source);
|
||||||
|
|
||||||
|
Assert.assertEquals("欢迎使用\n智能助手", normalized.get("welcomeMessage"));
|
||||||
|
Assert.assertEquals(List.of("第一个问题", "第二个问题"), normalized.get("suggestedQuestions"));
|
||||||
|
Assert.assertEquals("请输入问题", normalized.get("inputPlaceholder"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证重复问题会被拒绝。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void shouldRejectDuplicateQuestionsAfterTrim() {
|
||||||
|
Map<String, Object> source = Map.of(
|
||||||
|
"suggestedQuestions", List.of("如何使用?", " 如何使用? ")
|
||||||
|
);
|
||||||
|
|
||||||
|
assertBusinessException(() -> AgentInteractionConfigSupport.normalize(source));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证多行输入提示会被拒绝。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void shouldRejectMultilinePlaceholder() {
|
||||||
|
Map<String, Object> source = Map.of("inputPlaceholder", "第一行\n第二行");
|
||||||
|
|
||||||
|
assertBusinessException(() -> AgentInteractionConfigSupport.normalize(source));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证问题数量不能超过上限。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void shouldRejectTooManyQuestions() {
|
||||||
|
Map<String, Object> source = Map.of(
|
||||||
|
"suggestedQuestions",
|
||||||
|
List.of("问题1", "问题2", "问题3", "问题4", "问题5", "问题6", "问题7")
|
||||||
|
);
|
||||||
|
|
||||||
|
assertBusinessException(() -> AgentInteractionConfigSupport.normalize(source));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 断言操作会抛出业务异常。
|
||||||
|
*
|
||||||
|
* @param action 待执行操作
|
||||||
|
*/
|
||||||
|
private void assertBusinessException(Runnable action) {
|
||||||
|
try {
|
||||||
|
action.run();
|
||||||
|
Assert.fail("应抛出 BusinessException");
|
||||||
|
} catch (BusinessException expected) {
|
||||||
|
Assert.assertNotNull(expected.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +1,86 @@
|
|||||||
package tech.easyflow.agent.publish;
|
package tech.easyflow.agent.publish;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.mybatisflex.core.update.UpdateChain;
|
||||||
|
import com.mybatisflex.core.util.LambdaGetter;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import tech.easyflow.agent.entity.Agent;
|
||||||
import tech.easyflow.agent.service.AgentKnowledgeBindingService;
|
import tech.easyflow.agent.service.AgentKnowledgeBindingService;
|
||||||
|
import tech.easyflow.agent.service.AgentService;
|
||||||
import tech.easyflow.agent.service.AgentToolBindingService;
|
import tech.easyflow.agent.service.AgentToolBindingService;
|
||||||
|
import tech.easyflow.ai.enums.PublishStatus;
|
||||||
|
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link AgentApprovalSubjectHandler} 单元测试。
|
* {@link AgentApprovalSubjectHandler} 单元测试。
|
||||||
*/
|
*/
|
||||||
public class AgentApprovalSubjectHandlerTest {
|
public class AgentApprovalSubjectHandlerTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 审批状态变更必须使用字段级更新,避免覆盖 Agent 草稿配置。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void persistResourceStateShouldUseSelectiveUpdate() {
|
||||||
|
AgentService agentService = mock(AgentService.class);
|
||||||
|
UpdateChain<Agent> updateChain = prepareUpdateChain(agentService);
|
||||||
|
AgentApprovalSubjectHandler handler = handler(agentService);
|
||||||
|
|
||||||
|
handler.persistResourceState(
|
||||||
|
BigInteger.valueOf(1001),
|
||||||
|
PublishStatus.PUBLISH_PENDING,
|
||||||
|
BigInteger.valueOf(2001)
|
||||||
|
);
|
||||||
|
|
||||||
|
verifySelectiveUpdate(updateChain, BigInteger.valueOf(1001), 2);
|
||||||
|
verify(agentService, never()).updateById(any(Agent.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布 Agent 必须使用字段级更新,确保发布后草稿配置仍可回显。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void publishResourceShouldUseSelectiveUpdate() {
|
||||||
|
AgentService agentService = mock(AgentService.class);
|
||||||
|
UpdateChain<Agent> updateChain = prepareUpdateChain(agentService);
|
||||||
|
AgentApprovalSubjectHandler handler = handler(agentService);
|
||||||
|
Map<String, Object> snapshot = new LinkedHashMap<>();
|
||||||
|
snapshot.put("interactionConfigJson", Map.of("welcomeMessage", "你好"));
|
||||||
|
|
||||||
|
handler.publishResource(BigInteger.valueOf(1001), snapshot, BigInteger.valueOf(3001));
|
||||||
|
|
||||||
|
verifySelectiveUpdate(updateChain, BigInteger.valueOf(1001), 5);
|
||||||
|
verify(agentService, never()).updateById(any(Agent.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Agent 下线必须使用字段级更新,避免覆盖未发布配置。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void markResourceOfflineShouldUseSelectiveUpdate() {
|
||||||
|
AgentService agentService = mock(AgentService.class);
|
||||||
|
UpdateChain<Agent> updateChain = prepareUpdateChain(agentService);
|
||||||
|
AgentApprovalSubjectHandler handler = handler(agentService);
|
||||||
|
|
||||||
|
handler.markResourceOffline(BigInteger.valueOf(1001));
|
||||||
|
|
||||||
|
verifySelectiveUpdate(updateChain, BigInteger.valueOf(1001), 2);
|
||||||
|
verify(agentService, never()).updateById(any(Agent.class));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 审批删除 Agent 前必须同步清理工具绑定和知识库绑定,避免留下孤儿数据。
|
* 审批删除 Agent 前必须同步清理工具绑定和知识库绑定,避免留下孤儿数据。
|
||||||
*/
|
*/
|
||||||
@@ -39,6 +105,60 @@ public class AgentApprovalSubjectHandlerTest {
|
|||||||
Assert.assertEquals(1, knowledgeRemoveCalls.get());
|
Assert.assertEquals(1, knowledgeRemoveCalls.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建用于生命周期测试的处理器。
|
||||||
|
*
|
||||||
|
* @param agentService Agent 服务
|
||||||
|
* @return Agent 审批资源处理器
|
||||||
|
*/
|
||||||
|
private static AgentApprovalSubjectHandler handler(AgentService agentService) {
|
||||||
|
return new AgentApprovalSubjectHandler(
|
||||||
|
null,
|
||||||
|
new ObjectMapper(),
|
||||||
|
agentService,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 准备字段更新对象。
|
||||||
|
*
|
||||||
|
* @param agentService Agent 服务
|
||||||
|
* @return 字段更新对象
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static UpdateChain<Agent> prepareUpdateChain(AgentService agentService) {
|
||||||
|
UpdateChain<Agent> updateChain = mock(UpdateChain.class);
|
||||||
|
when(agentService.updateChain()).thenReturn(updateChain);
|
||||||
|
return updateChain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验生命周期操作仅通过指定主键执行字段更新。
|
||||||
|
*
|
||||||
|
* @param updateChain 字段更新对象
|
||||||
|
* @param resourceId Agent 主键
|
||||||
|
* @param fieldCount 更新字段数量
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static void verifySelectiveUpdate(UpdateChain<Agent> updateChain,
|
||||||
|
BigInteger resourceId,
|
||||||
|
int fieldCount) {
|
||||||
|
verify(updateChain, times(fieldCount)).set(any(LambdaGetter.class), any());
|
||||||
|
verify(updateChain).eq(any(LambdaGetter.class), eq(resourceId));
|
||||||
|
verify(updateChain).update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建只统计删除调用的服务代理。
|
||||||
|
*
|
||||||
|
* @param type 服务接口类型
|
||||||
|
* @param removeCalls 删除调用计数器
|
||||||
|
* @param <T> 服务接口类型
|
||||||
|
* @return 服务代理
|
||||||
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static <T> T proxy(Class<T> type, AtomicInteger removeCalls) {
|
private static <T> T proxy(Class<T> type, AtomicInteger removeCalls) {
|
||||||
return (T) Proxy.newProxyInstance(
|
return (T) Proxy.newProxyInstance(
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `tb_agent`
|
||||||
|
ADD COLUMN `interaction_config_json` json NULL COMMENT 'Agent 对话体验配置' AFTER `execution_config_json`;
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type {AiChatMessage, AiToolApprovalPayload} from './types';
|
import type { AiChatMessage, AiToolApprovalPayload } from './types';
|
||||||
|
|
||||||
import {Close} from '@element-plus/icons-vue';
|
import { Close } from '@element-plus/icons-vue';
|
||||||
import {ElButton} from 'element-plus';
|
import { ElButton } from 'element-plus';
|
||||||
|
|
||||||
import AiConversation from './AiConversation.vue';
|
import AiConversation from './AiConversation.vue';
|
||||||
import AiPromptInput from './AiPromptInput.vue';
|
import AiPromptInput from './AiPromptInput.vue';
|
||||||
@@ -13,6 +13,7 @@ defineProps<{
|
|||||||
emptyText?: string;
|
emptyText?: string;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
messages: AiChatMessage[];
|
messages: AiChatMessage[];
|
||||||
|
placeholder?: string;
|
||||||
subtitle?: string;
|
subtitle?: string;
|
||||||
title: string;
|
title: string;
|
||||||
}>();
|
}>();
|
||||||
@@ -63,6 +64,7 @@ defineSlots<{
|
|||||||
</slot>
|
</slot>
|
||||||
<AiPromptInput
|
<AiPromptInput
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
|
:placeholder="placeholder"
|
||||||
@send="emit('send', $event)"
|
@send="emit('send', $event)"
|
||||||
@stop="emit('stop')"
|
@stop="emit('stop')"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
defineProps<{
|
|
||||||
title: string;
|
|
||||||
}>();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<section class="agent-chat-welcome-state" aria-live="polite">
|
|
||||||
<h2 class="agent-chat-welcome-state__title">{{ title }}</h2>
|
|
||||||
</section>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.agent-chat-welcome-state {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.agent-chat-welcome-state__title {
|
|
||||||
max-width: min(720px, 100%);
|
|
||||||
margin: 0;
|
|
||||||
overflow-wrap: anywhere;
|
|
||||||
font-size: clamp(24px, 2.6vw, 36px);
|
|
||||||
font-weight: 600;
|
|
||||||
line-height: 1.16;
|
|
||||||
color: var(--el-text-color-primary);
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -4,32 +4,27 @@ import type {
|
|||||||
ChatTimelineMessageItem,
|
ChatTimelineMessageItem,
|
||||||
ChatTimelineToolApprovalPayload,
|
ChatTimelineToolApprovalPayload,
|
||||||
} from '@easyflow/common-ui';
|
} from '@easyflow/common-ui';
|
||||||
import {ChatTimeline, ChatTimelineBuilder} from '@easyflow/common-ui';
|
|
||||||
|
|
||||||
import type {AgentInfo} from '../agents/types';
|
import type { AgentInfo } from '../agents/types';
|
||||||
import type {AgentChatSessionView} from './api';
|
import type { AgentChatSessionView } from './api';
|
||||||
import {
|
|
||||||
approveAgentRun,
|
|
||||||
deleteAgentSession,
|
|
||||||
getAgentConversation,
|
|
||||||
getAgentSession,
|
|
||||||
getAgentSessions,
|
|
||||||
getPublishedAgents,
|
|
||||||
getPublishedKnowledges,
|
|
||||||
rejectAgentRun,
|
|
||||||
renameAgentSession,
|
|
||||||
saveAgentSessionExtraKnowledges,
|
|
||||||
} from './api';
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ChatInputTriggerGroup,
|
ChatInputTriggerGroup,
|
||||||
ChatInputTriggerItem,
|
ChatInputTriggerItem,
|
||||||
} from '#/components/chat-workspace/input-triggers/types';
|
} from '#/components/chat-workspace/input-triggers/types';
|
||||||
|
|
||||||
import {computed, onBeforeUnmount, onMounted, ref} from 'vue';
|
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||||
import {useRoute, useRouter} from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
|
||||||
import {Delete, EditPen, MoreFilled, Plus, Promotion,} from '@element-plus/icons-vue';
|
import { ChatTimeline, ChatTimelineBuilder } from '@easyflow/common-ui';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Delete,
|
||||||
|
EditPen,
|
||||||
|
MoreFilled,
|
||||||
|
Plus,
|
||||||
|
Promotion,
|
||||||
|
} from '@element-plus/icons-vue';
|
||||||
import {
|
import {
|
||||||
ElButton,
|
ElButton,
|
||||||
ElDropdown,
|
ElDropdown,
|
||||||
@@ -45,26 +40,28 @@ import {
|
|||||||
|
|
||||||
import ChatCapabilityMenu from '#/components/chat-workspace/ChatCapabilityMenu.vue';
|
import ChatCapabilityMenu from '#/components/chat-workspace/ChatCapabilityMenu.vue';
|
||||||
import ChatInputTriggerPanel from '#/components/chat-workspace/ChatInputTriggerPanel.vue';
|
import ChatInputTriggerPanel from '#/components/chat-workspace/ChatInputTriggerPanel.vue';
|
||||||
import {useChatInputTrigger} from '#/components/chat-workspace/input-triggers/useChatInputTrigger';
|
import { useChatInputTrigger } from '#/components/chat-workspace/input-triggers/useChatInputTrigger';
|
||||||
|
|
||||||
import {recordsToTimelineItems} from './adapters/agentTimelineAdapter';
|
import AgentWelcomeState from '../agents/components/AgentWelcomeState.vue';
|
||||||
import {agentChatRuntimeManager} from './agentChatRuntimeManager';
|
import { resolveInteractionDisplay } from '../agents/interaction-config';
|
||||||
import AgentChatWelcomeState from './components/AgentChatWelcomeState.vue';
|
import { recordsToTimelineItems } from './adapters/agentTimelineAdapter';
|
||||||
|
import { agentChatRuntimeManager } from './agentChatRuntimeManager';
|
||||||
|
import {
|
||||||
|
approveAgentRun,
|
||||||
|
deleteAgentSession,
|
||||||
|
getAgentConversation,
|
||||||
|
getAgentSession,
|
||||||
|
getAgentSessions,
|
||||||
|
getPublishedAgents,
|
||||||
|
getPublishedKnowledges,
|
||||||
|
rejectAgentRun,
|
||||||
|
renameAgentSession,
|
||||||
|
saveAgentSessionExtraKnowledges,
|
||||||
|
} from './api';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const WELCOME_TITLES = [
|
|
||||||
'我们应该做些什么',
|
|
||||||
'让协作发生',
|
|
||||||
'今天想推进什么',
|
|
||||||
'把想法变成行动',
|
|
||||||
'让智能体开始工作',
|
|
||||||
'从一个问题开始',
|
|
||||||
'一起把事情理清楚',
|
|
||||||
'把下一步交给协作',
|
|
||||||
];
|
|
||||||
|
|
||||||
const agents = ref<AgentInfo[]>([]);
|
const agents = ref<AgentInfo[]>([]);
|
||||||
const sessions = ref<AgentChatSessionView[]>([]);
|
const sessions = ref<AgentChatSessionView[]>([]);
|
||||||
const timelineItems = ref<ChatTimelineItem[]>([]);
|
const timelineItems = ref<ChatTimelineItem[]>([]);
|
||||||
@@ -73,6 +70,7 @@ const currentSessionId = ref('');
|
|||||||
const promptText = ref('');
|
const promptText = ref('');
|
||||||
const promptInputRef = ref();
|
const promptInputRef = ref();
|
||||||
const loadingAgents = ref(false);
|
const loadingAgents = ref(false);
|
||||||
|
const agentLoadError = ref('');
|
||||||
const loadingSessions = ref(false);
|
const loadingSessions = ref(false);
|
||||||
const loadingConversation = ref(false);
|
const loadingConversation = ref(false);
|
||||||
const loadingKnowledges = ref(false);
|
const loadingKnowledges = ref(false);
|
||||||
@@ -90,6 +88,9 @@ let runtimeUnsubscribe: (() => void) | undefined;
|
|||||||
const selectedAgent = computed(() =>
|
const selectedAgent = computed(() =>
|
||||||
agents.value.find((agent) => String(agent.id) === selectedAgentId.value),
|
agents.value.find((agent) => String(agent.id) === selectedAgentId.value),
|
||||||
);
|
);
|
||||||
|
const interactionDisplay = computed(() =>
|
||||||
|
resolveInteractionDisplay(selectedAgent.value),
|
||||||
|
);
|
||||||
const currentSession = computed(() =>
|
const currentSession = computed(() =>
|
||||||
sessions.value.find(
|
sessions.value.find(
|
||||||
(session) => String(session.sessionId) === currentSessionId.value,
|
(session) => String(session.sessionId) === currentSessionId.value,
|
||||||
@@ -104,7 +105,9 @@ const canSend = computed(
|
|||||||
!runtimeRunning.value,
|
!runtimeRunning.value,
|
||||||
);
|
);
|
||||||
const composerPlaceholder = computed(() =>
|
const composerPlaceholder = computed(() =>
|
||||||
selectedAgent.value ? '输入消息' : '请选择智能体',
|
selectedAgent.value
|
||||||
|
? interactionDisplay.value.inputPlaceholder
|
||||||
|
: '请选择智能体',
|
||||||
);
|
);
|
||||||
const selectedExtraKnowledges = computed(() => {
|
const selectedExtraKnowledges = computed(() => {
|
||||||
const knowledges: { id: string; title: string }[] = [];
|
const knowledges: { id: string; title: string }[] = [];
|
||||||
@@ -125,18 +128,12 @@ const capabilityDisabled = computed(
|
|||||||
);
|
);
|
||||||
const isWelcomeState = computed(
|
const isWelcomeState = computed(
|
||||||
() =>
|
() =>
|
||||||
|
Boolean(selectedAgent.value) &&
|
||||||
|
!loadingAgents.value &&
|
||||||
!loadingConversation.value &&
|
!loadingConversation.value &&
|
||||||
!currentSessionId.value &&
|
!currentSessionId.value &&
|
||||||
timelineItems.value.length === 0,
|
timelineItems.value.length === 0,
|
||||||
);
|
);
|
||||||
const welcomeTitle = computed(() => {
|
|
||||||
const agentKey = selectedAgentId.value || selectedAgent.value?.name || '';
|
|
||||||
const index = [...agentKey].reduce(
|
|
||||||
(total, char) => total + char.charCodeAt(0),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
return WELCOME_TITLES[index % WELCOME_TITLES.length] || '我们应该做些什么';
|
|
||||||
});
|
|
||||||
const agentSelectWidth = computed(() => {
|
const agentSelectWidth = computed(() => {
|
||||||
const name = selectedAgent.value?.name || '选择智能体';
|
const name = selectedAgent.value?.name || '选择智能体';
|
||||||
const textWidth = [...name].reduce(
|
const textWidth = [...name].reduce(
|
||||||
@@ -222,6 +219,7 @@ async function syncSessionRoute(sessionId?: string) {
|
|||||||
|
|
||||||
async function loadAgents() {
|
async function loadAgents() {
|
||||||
loadingAgents.value = true;
|
loadingAgents.value = true;
|
||||||
|
agentLoadError.value = '';
|
||||||
try {
|
try {
|
||||||
const res = await getPublishedAgents();
|
const res = await getPublishedAgents();
|
||||||
if (res.errorCode !== 0) {
|
if (res.errorCode !== 0) {
|
||||||
@@ -232,7 +230,9 @@ async function loadAgents() {
|
|||||||
selectedAgentId.value = String(agents.value[0].id);
|
selectedAgentId.value = String(agents.value[0].id);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ElMessage.error(error instanceof Error ? error.message : '智能体加载失败');
|
agentLoadError.value =
|
||||||
|
error instanceof Error ? error.message : '智能体加载失败';
|
||||||
|
ElMessage.error(agentLoadError.value);
|
||||||
} finally {
|
} finally {
|
||||||
loadingAgents.value = false;
|
loadingAgents.value = false;
|
||||||
}
|
}
|
||||||
@@ -571,8 +571,8 @@ function buildCapabilities() {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSend() {
|
async function sendContent(rawContent: string) {
|
||||||
const content = promptText.value.trim();
|
const content = rawContent.trim();
|
||||||
if (!content || !selectedAgentId.value || sending.value) {
|
if (!content || !selectedAgentId.value || sending.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -602,6 +602,14 @@ async function handleSend() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleSend() {
|
||||||
|
await sendContent(promptText.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSuggestedQuestion(question: string) {
|
||||||
|
void sendContent(question);
|
||||||
|
}
|
||||||
|
|
||||||
function handlePromptInput() {
|
function handlePromptInput() {
|
||||||
chatInputTrigger.sync();
|
chatInputTrigger.sync();
|
||||||
}
|
}
|
||||||
@@ -894,12 +902,36 @@ onBeforeUnmount(() => {
|
|||||||
class="agent-chat__timeline-wrap"
|
class="agent-chat__timeline-wrap"
|
||||||
:class="{ 'is-welcome': isWelcomeState }"
|
:class="{ 'is-welcome': isWelcomeState }"
|
||||||
>
|
>
|
||||||
<div v-if="loadingConversation" class="agent-chat__state is-center">
|
<div
|
||||||
|
v-if="loadingConversation || loadingAgents"
|
||||||
|
class="agent-chat__state is-center"
|
||||||
|
>
|
||||||
加载中
|
加载中
|
||||||
</div>
|
</div>
|
||||||
<AgentChatWelcomeState
|
<div
|
||||||
|
v-else-if="
|
||||||
|
agentLoadError && !currentSessionId && timelineItems.length === 0
|
||||||
|
"
|
||||||
|
class="agent-chat__state is-center"
|
||||||
|
>
|
||||||
|
{{ agentLoadError }}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else-if="
|
||||||
|
!selectedAgent && !currentSessionId && timelineItems.length === 0
|
||||||
|
"
|
||||||
|
class="agent-chat__state is-center"
|
||||||
|
>
|
||||||
|
暂无已发布智能体
|
||||||
|
</div>
|
||||||
|
<AgentWelcomeState
|
||||||
v-else-if="isWelcomeState"
|
v-else-if="isWelcomeState"
|
||||||
:title="welcomeTitle"
|
:agent-name="selectedAgent?.name || '智能体'"
|
||||||
|
:avatar="selectedAgent?.avatar"
|
||||||
|
:disabled="sending || runtimeRunning"
|
||||||
|
:suggested-questions="interactionDisplay.suggestedQuestions"
|
||||||
|
:welcome-message="interactionDisplay.welcomeMessage"
|
||||||
|
@select-question="handleSuggestedQuestion"
|
||||||
/>
|
/>
|
||||||
<ChatTimeline
|
<ChatTimeline
|
||||||
v-else
|
v-else
|
||||||
@@ -915,10 +947,7 @@ onBeforeUnmount(() => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div class="agent-chat__composer">
|
||||||
class="agent-chat__composer"
|
|
||||||
:class="{ 'is-welcome': isWelcomeState }"
|
|
||||||
>
|
|
||||||
<ChatCapabilityMenu
|
<ChatCapabilityMenu
|
||||||
:disabled="capabilityDisabled"
|
:disabled="capabilityDisabled"
|
||||||
:extra-knowledge-ids="extraKnowledgeIds"
|
:extra-knowledge-ids="extraKnowledgeIds"
|
||||||
@@ -1011,13 +1040,13 @@ onBeforeUnmount(() => {
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.agent-chat {
|
.agent-chat {
|
||||||
|
box-sizing: border-box;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 280px minmax(0, 1fr);
|
grid-template-columns: 280px minmax(0, 1fr);
|
||||||
height: var(--easyflow-content-height, 100%);
|
height: var(--easyflow-content-height, 100%);
|
||||||
max-height: var(--easyflow-content-height, 100%);
|
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
|
max-height: var(--easyflow-content-height, 100%);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
box-sizing: border-box;
|
|
||||||
background: var(--el-bg-color-page);
|
background: var(--el-bg-color-page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1143,26 +1172,26 @@ onBeforeUnmount(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.agent-chat__timeline-wrap {
|
.agent-chat__timeline-wrap {
|
||||||
|
box-sizing: border-box;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
padding-bottom: 176px;
|
padding-bottom: 176px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-chat__timeline-wrap.is-welcome {
|
.agent-chat__timeline-wrap.is-welcome {
|
||||||
justify-content: center;
|
padding: 0 min(8vw, 96px) 190px;
|
||||||
padding: 0 min(8vw, 96px) 252px;
|
overflow: hidden auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-chat__timeline-wrap :deep(.chat-timeline) {
|
.agent-chat__timeline-wrap :deep(.chat-timeline) {
|
||||||
|
box-sizing: border-box;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
padding: 24px min(8vw, 96px);
|
padding: 24px min(8vw, 96px);
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-chat__composer {
|
.agent-chat__composer {
|
||||||
@@ -1180,12 +1209,6 @@ onBeforeUnmount(() => {
|
|||||||
box-shadow: var(--el-box-shadow-light);
|
box-shadow: var(--el-box-shadow-light);
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-chat__composer.is-welcome {
|
|
||||||
top: calc(50% + 40px);
|
|
||||||
bottom: auto;
|
|
||||||
transform: translateY(-50%);
|
|
||||||
}
|
|
||||||
|
|
||||||
.agent-chat__trigger-panel {
|
.agent-chat__trigger-panel {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: calc(100% + 10px);
|
bottom: calc(100% + 10px);
|
||||||
@@ -1212,9 +1235,9 @@ onBeforeUnmount(() => {
|
|||||||
|
|
||||||
.agent-chat__composer-tools {
|
.agent-chat__composer-tools {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
|
gap: 4px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
gap: 4px;
|
|
||||||
max-width: calc(100% - 64px);
|
max-width: calc(100% - 64px);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1243,22 +1266,22 @@ onBeforeUnmount(() => {
|
|||||||
min-width: 0;
|
min-width: 0;
|
||||||
max-width: none;
|
max-width: none;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
color: var(--el-text-color-secondary);
|
color: var(--el-text-color-secondary);
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-chat__agent-select :deep(.el-select__caret) {
|
.agent-chat__agent-select :deep(.el-select__caret) {
|
||||||
color: var(--el-color-primary);
|
|
||||||
margin-left: 6px;
|
margin-left: 6px;
|
||||||
|
color: var(--el-color-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-chat__composer-actions {
|
.agent-chat__composer-actions {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
|
||||||
flex: none;
|
flex: none;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-chat__send-button {
|
.agent-chat__send-button {
|
||||||
@@ -1283,7 +1306,7 @@ onBeforeUnmount(() => {
|
|||||||
display: block;
|
display: block;
|
||||||
width: 12px;
|
width: 12px;
|
||||||
height: 12px;
|
height: 12px;
|
||||||
background: currentColor;
|
background: currentcolor;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1300,8 +1323,8 @@ onBeforeUnmount(() => {
|
|||||||
|
|
||||||
@media (max-width: 900px) {
|
@media (max-width: 900px) {
|
||||||
.agent-chat {
|
.agent-chat {
|
||||||
grid-template-columns: 1fr;
|
|
||||||
grid-template-rows: auto minmax(0, 1fr);
|
grid-template-rows: auto minmax(0, 1fr);
|
||||||
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-chat__history {
|
.agent-chat__history {
|
||||||
@@ -1324,7 +1347,13 @@ onBeforeUnmount(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.agent-chat__timeline-wrap.is-welcome {
|
.agent-chat__timeline-wrap.is-welcome {
|
||||||
padding: 0 16px 244px;
|
padding: 0 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-chat__timeline-wrap.is-welcome :deep(.agent-welcome) {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
min-height: 100%;
|
||||||
|
padding-bottom: 206px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-chat__timeline-wrap :deep(.chat-timeline) {
|
.agent-chat__timeline-wrap :deep(.chat-timeline) {
|
||||||
@@ -1337,11 +1366,6 @@ onBeforeUnmount(() => {
|
|||||||
left: 16px;
|
left: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-chat__composer.is-welcome {
|
|
||||||
top: calc(50% + 52px);
|
|
||||||
bottom: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.agent-chat__composer-footer {
|
.agent-chat__composer-footer {
|
||||||
align-items: flex-end;
|
align-items: flex-end;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ import type {
|
|||||||
AgentValidationIssue,
|
AgentValidationIssue,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
import { computed } from 'vue';
|
import { computed, nextTick, ref, watch } from 'vue';
|
||||||
|
|
||||||
import { Close } from '@element-plus/icons-vue';
|
import { Close } from '@element-plus/icons-vue';
|
||||||
import { ElButton } from 'element-plus';
|
import { ElButton, ElTabPane, ElTabs } from 'element-plus';
|
||||||
|
|
||||||
import AgentBaseForm from './AgentBaseForm.vue';
|
import AgentBaseForm from './AgentBaseForm.vue';
|
||||||
|
import AgentInteractionForm from './AgentInteractionForm.vue';
|
||||||
import AgentKnowledgeForm from './AgentKnowledgeForm.vue';
|
import AgentKnowledgeForm from './AgentKnowledgeForm.vue';
|
||||||
import AgentToolForm from './AgentToolForm.vue';
|
import AgentToolForm from './AgentToolForm.vue';
|
||||||
import AgentTryoutPanel from './AgentTryoutPanel.vue';
|
import AgentTryoutPanel from './AgentTryoutPanel.vue';
|
||||||
@@ -39,6 +40,36 @@ const selectedKnowledge = computed(() => {
|
|||||||
return props.state.knowledgeBindings.find((item) => item.localId === localId);
|
return props.state.knowledgeBindings.find((item) => item.localId === localId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const activeBaseTab = ref<'basic' | 'interaction'>('basic');
|
||||||
|
const interactionForm = ref<InstanceType<typeof AgentInteractionForm>>();
|
||||||
|
|
||||||
|
function isInteractionIssue(issue?: AgentValidationIssue) {
|
||||||
|
return issue?.field?.startsWith('interaction.');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function focusIssue(issue: AgentValidationIssue) {
|
||||||
|
if (issue.nodeId !== 'agent-base') return;
|
||||||
|
activeBaseTab.value = isInteractionIssue(issue) ? 'interaction' : 'basic';
|
||||||
|
if (isInteractionIssue(issue)) {
|
||||||
|
await nextTick();
|
||||||
|
await interactionForm.value?.focusField(issue.field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleIssueClick(issue: AgentValidationIssue) {
|
||||||
|
void focusIssue(issue);
|
||||||
|
emit('selectIssue', issue.nodeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.issues,
|
||||||
|
(issues) => {
|
||||||
|
const firstIssue = issues[0];
|
||||||
|
if (firstIssue?.nodeId === 'agent-base') void focusIssue(firstIssue);
|
||||||
|
},
|
||||||
|
{ deep: true },
|
||||||
|
);
|
||||||
|
|
||||||
const selectedTool = computed(() => {
|
const selectedTool = computed(() => {
|
||||||
if (!props.state.selectedNodeId.startsWith('tool:')) return;
|
if (!props.state.selectedNodeId.startsWith('tool:')) return;
|
||||||
const localId = props.state.selectedNodeId.slice('tool:'.length);
|
const localId = props.state.selectedNodeId.slice('tool:'.length);
|
||||||
@@ -88,19 +119,31 @@ const selectedToolOptions = computed(() => {
|
|||||||
:key="`${issue.nodeId}-${issue.field || issue.message}`"
|
:key="`${issue.nodeId}-${issue.field || issue.message}`"
|
||||||
class="agent-inspector__issue"
|
class="agent-inspector__issue"
|
||||||
type="button"
|
type="button"
|
||||||
@click="emit('selectIssue', issue.nodeId)"
|
@click="handleIssueClick(issue)"
|
||||||
>
|
>
|
||||||
{{ issue.message }}
|
{{ issue.message }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<AgentBaseForm
|
<template v-if="state.panelMode === 'base'">
|
||||||
v-if="state.panelMode === 'base'"
|
<ElTabs v-model="activeBaseTab" class="agent-inspector__tabs">
|
||||||
:agent="state.agent"
|
<ElTabPane label="基础设置" name="basic">
|
||||||
:categories="categories"
|
<AgentBaseForm
|
||||||
:models="models"
|
:agent="state.agent"
|
||||||
@change="emit('change')"
|
:categories="categories"
|
||||||
/>
|
:models="models"
|
||||||
|
@change="emit('change')"
|
||||||
|
/>
|
||||||
|
</ElTabPane>
|
||||||
|
<ElTabPane label="对话体验" name="interaction">
|
||||||
|
<AgentInteractionForm
|
||||||
|
ref="interactionForm"
|
||||||
|
:agent="state.agent"
|
||||||
|
@change="emit('change')"
|
||||||
|
/>
|
||||||
|
</ElTabPane>
|
||||||
|
</ElTabs>
|
||||||
|
</template>
|
||||||
<AgentKnowledgeForm
|
<AgentKnowledgeForm
|
||||||
v-else-if="selectedKnowledge"
|
v-else-if="selectedKnowledge"
|
||||||
:binding="selectedKnowledge"
|
:binding="selectedKnowledge"
|
||||||
@@ -186,6 +229,20 @@ const selectedToolOptions = computed(() => {
|
|||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.agent-inspector__tabs :deep(.el-tabs__header) {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 2;
|
||||||
|
padding: 0 var(--space-4);
|
||||||
|
margin: 0;
|
||||||
|
background: hsl(var(--surface-panel));
|
||||||
|
border-bottom: 1px solid hsl(var(--line-subtle));
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-inspector__tabs :deep(.el-tabs__nav-wrap::after) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.agent-inspector__empty {
|
.agent-inspector__empty {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,328 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { AgentInfo } from '../types';
|
||||||
|
|
||||||
|
import { computed, nextTick, ref } from 'vue';
|
||||||
|
|
||||||
|
import { Delete, Plus, Rank } from '@element-plus/icons-vue';
|
||||||
|
import { ElButton, ElForm, ElFormItem, ElIcon, ElInput } from 'element-plus';
|
||||||
|
|
||||||
|
import {
|
||||||
|
MAX_INPUT_PLACEHOLDER_LENGTH,
|
||||||
|
MAX_SUGGESTED_QUESTION_COUNT,
|
||||||
|
MAX_SUGGESTED_QUESTION_LENGTH,
|
||||||
|
MAX_WELCOME_MESSAGE_LENGTH,
|
||||||
|
} from '../interaction-config';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
agent: AgentInfo;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{ change: [] }>();
|
||||||
|
|
||||||
|
const welcomeInput = ref();
|
||||||
|
const placeholderInput = ref();
|
||||||
|
const questionInputs = ref<any[]>([]);
|
||||||
|
const draggingIndex = ref<number>();
|
||||||
|
|
||||||
|
const questions = computed(
|
||||||
|
() => props.agent.interactionConfigJson!.suggestedQuestions,
|
||||||
|
);
|
||||||
|
const duplicateQuestionIndexes = computed(() => {
|
||||||
|
const firstIndexes = new Map<string, number>();
|
||||||
|
const duplicates = new Set<number>();
|
||||||
|
questions.value.forEach((question, index) => {
|
||||||
|
const normalized = question.trim();
|
||||||
|
if (!normalized) return;
|
||||||
|
const firstIndex = firstIndexes.get(normalized);
|
||||||
|
if (firstIndex === undefined) {
|
||||||
|
firstIndexes.set(normalized, index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
duplicates.add(firstIndex);
|
||||||
|
duplicates.add(index);
|
||||||
|
});
|
||||||
|
return duplicates;
|
||||||
|
});
|
||||||
|
|
||||||
|
function questionError(index: number) {
|
||||||
|
const question = questions.value[index] || '';
|
||||||
|
if (question.trim().length > MAX_SUGGESTED_QUESTION_LENGTH) {
|
||||||
|
return '最多 80 个字符';
|
||||||
|
}
|
||||||
|
if (duplicateQuestionIndexes.value.has(index)) {
|
||||||
|
return '内容重复';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addQuestion() {
|
||||||
|
if (questions.value.length >= MAX_SUGGESTED_QUESTION_COUNT) return;
|
||||||
|
questions.value.push('');
|
||||||
|
emit('change');
|
||||||
|
await nextTick();
|
||||||
|
questionInputs.value.at(-1)?.focus?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeQuestion(index: number) {
|
||||||
|
questions.value.splice(index, 1);
|
||||||
|
emit('change');
|
||||||
|
}
|
||||||
|
|
||||||
|
function moveQuestion(from: number, to: number) {
|
||||||
|
if (from === to || to < 0 || to >= questions.value.length) return;
|
||||||
|
const [question] = questions.value.splice(from, 1);
|
||||||
|
questions.value.splice(to, 0, question || '');
|
||||||
|
emit('change');
|
||||||
|
void nextTick(() => questionInputs.value[to]?.focus?.());
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDragStart(index: number, event: DragEvent) {
|
||||||
|
draggingIndex.value = index;
|
||||||
|
event.dataTransfer?.setData('text/plain', String(index));
|
||||||
|
if (event.dataTransfer) event.dataTransfer.effectAllowed = 'move';
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDrop(index: number, event: DragEvent) {
|
||||||
|
event.preventDefault();
|
||||||
|
const from = draggingIndex.value;
|
||||||
|
draggingIndex.value = undefined;
|
||||||
|
if (from === undefined) return;
|
||||||
|
moveQuestion(from, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleMoveKeydown(index: number, event: KeyboardEvent) {
|
||||||
|
if (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') return;
|
||||||
|
event.preventDefault();
|
||||||
|
moveQuestion(index, index + (event.key === 'ArrowUp' ? -1 : 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function focusField(field?: string) {
|
||||||
|
await nextTick();
|
||||||
|
if (field === 'interaction.welcomeMessage') {
|
||||||
|
welcomeInput.value?.focus?.();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (field === 'interaction.inputPlaceholder') {
|
||||||
|
placeholderInput.value?.focus?.();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const match = field?.match(/^interaction\.suggestedQuestions\.(\d+)$/);
|
||||||
|
if (match) questionInputs.value[Number(match[1])]?.focus?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ focusField });
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ElForm label-position="top" class="agent-interaction-form">
|
||||||
|
<ElFormItem label="欢迎语">
|
||||||
|
<ElInput
|
||||||
|
ref="welcomeInput"
|
||||||
|
v-model="agent.interactionConfigJson!.welcomeMessage"
|
||||||
|
type="textarea"
|
||||||
|
:rows="5"
|
||||||
|
resize="vertical"
|
||||||
|
:maxlength="MAX_WELCOME_MESSAGE_LENGTH"
|
||||||
|
show-word-limit
|
||||||
|
placeholder="留空时使用默认欢迎语"
|
||||||
|
@input="emit('change')"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
|
||||||
|
<div class="agent-interaction-form__section-head">
|
||||||
|
<div>
|
||||||
|
<div class="agent-interaction-form__section-title">猜你想问</div>
|
||||||
|
<div class="agent-interaction-form__section-hint">
|
||||||
|
新会话中展示,点击后直接发送
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span class="agent-interaction-form__count">
|
||||||
|
{{ questions.length }}/{{ MAX_SUGGESTED_QUESTION_COUNT }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="questions.length > 0" class="agent-interaction-form__questions">
|
||||||
|
<div
|
||||||
|
v-for="(_, index) in questions"
|
||||||
|
:key="index"
|
||||||
|
class="agent-interaction-form__question"
|
||||||
|
:class="{ 'is-dragging': draggingIndex === index }"
|
||||||
|
@dragover.prevent
|
||||||
|
@drop="handleDrop(index, $event)"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
class="agent-interaction-form__drag"
|
||||||
|
type="button"
|
||||||
|
draggable="true"
|
||||||
|
:aria-label="`调整第 ${index + 1} 条问题顺序`"
|
||||||
|
title="拖动排序,或使用上下方向键"
|
||||||
|
@dragend="draggingIndex = undefined"
|
||||||
|
@dragstart="handleDragStart(index, $event)"
|
||||||
|
@keydown="handleMoveKeydown(index, $event)"
|
||||||
|
>
|
||||||
|
<ElIcon><Rank /></ElIcon>
|
||||||
|
</button>
|
||||||
|
<div class="agent-interaction-form__question-input">
|
||||||
|
<ElInput
|
||||||
|
:ref="(element) => (questionInputs[index] = element)"
|
||||||
|
v-model="questions[index]"
|
||||||
|
:maxlength="MAX_SUGGESTED_QUESTION_LENGTH"
|
||||||
|
:placeholder="`问题 ${index + 1}`"
|
||||||
|
@input="emit('change')"
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
v-if="questionError(index)"
|
||||||
|
class="agent-interaction-form__error"
|
||||||
|
>
|
||||||
|
{{ questionError(index) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<ElButton
|
||||||
|
:icon="Delete"
|
||||||
|
circle
|
||||||
|
text
|
||||||
|
type="danger"
|
||||||
|
:aria-label="`删除第 ${index + 1} 条问题`"
|
||||||
|
@click="removeQuestion(index)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-else class="agent-interaction-form__empty">暂无建议问题</div>
|
||||||
|
|
||||||
|
<ElButton
|
||||||
|
class="agent-interaction-form__add"
|
||||||
|
:icon="Plus"
|
||||||
|
:disabled="questions.length >= MAX_SUGGESTED_QUESTION_COUNT"
|
||||||
|
@click="addQuestion"
|
||||||
|
>
|
||||||
|
添加问题
|
||||||
|
</ElButton>
|
||||||
|
|
||||||
|
<ElFormItem label="输入提示" class="agent-interaction-form__placeholder">
|
||||||
|
<ElInput
|
||||||
|
ref="placeholderInput"
|
||||||
|
v-model="agent.interactionConfigJson!.inputPlaceholder"
|
||||||
|
:maxlength="MAX_INPUT_PLACEHOLDER_LENGTH"
|
||||||
|
show-word-limit
|
||||||
|
placeholder="输入消息"
|
||||||
|
@input="emit('change')"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.agent-interaction-form {
|
||||||
|
padding: var(--space-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__section-head {
|
||||||
|
display: flex;
|
||||||
|
gap: var(--space-3);
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: var(--space-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__section-title {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: hsl(var(--text-strong));
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__section-hint,
|
||||||
|
.agent-interaction-form__count {
|
||||||
|
margin-top: var(--space-1);
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 18px;
|
||||||
|
color: hsl(var(--text-muted));
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__questions {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: var(--space-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__question {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 28px minmax(0, 1fr) 32px;
|
||||||
|
gap: var(--space-2);
|
||||||
|
align-items: start;
|
||||||
|
padding: var(--space-2);
|
||||||
|
background: hsl(var(--surface-subtle));
|
||||||
|
border: 1px solid hsl(var(--line-subtle));
|
||||||
|
border-radius: var(--radius-toolbar);
|
||||||
|
transition:
|
||||||
|
border-color var(--motion-duration-fast) var(--motion-ease-standard),
|
||||||
|
opacity var(--motion-duration-fast) var(--motion-ease-standard);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__question:focus-within {
|
||||||
|
border-color: var(--el-color-primary-light-5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__question.is-dragging {
|
||||||
|
opacity: 0.56;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__drag {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 28px;
|
||||||
|
height: 32px;
|
||||||
|
padding: 0;
|
||||||
|
color: hsl(var(--text-muted));
|
||||||
|
cursor: grab;
|
||||||
|
background: transparent;
|
||||||
|
border: 0;
|
||||||
|
border-radius: var(--radius-control);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__drag:hover {
|
||||||
|
color: var(--el-color-primary);
|
||||||
|
background: var(--el-color-primary-light-9);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__drag:focus-visible {
|
||||||
|
outline: 2px solid var(--el-color-primary-light-5);
|
||||||
|
outline-offset: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__question-input {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__error {
|
||||||
|
display: block;
|
||||||
|
margin-top: var(--space-1);
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--el-color-danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__empty {
|
||||||
|
padding: var(--space-4);
|
||||||
|
font-size: 13px;
|
||||||
|
color: hsl(var(--text-muted));
|
||||||
|
text-align: center;
|
||||||
|
background: hsl(var(--surface-subtle));
|
||||||
|
border-radius: var(--radius-toolbar);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__add {
|
||||||
|
width: 100%;
|
||||||
|
margin-top: var(--space-2);
|
||||||
|
border-style: dashed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-interaction-form__placeholder {
|
||||||
|
margin-top: var(--space-6);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.agent-interaction-form__question {
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,18 +1,28 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type {ChatTimelineMessageItem, ChatTimelineToolApprovalPayload,} from '@easyflow/common-ui';
|
import type {
|
||||||
import {ChatTimeline} from '@easyflow/common-ui';
|
ChatTimelineMessageItem,
|
||||||
|
ChatTimelineToolApprovalPayload,
|
||||||
|
} from '@easyflow/common-ui';
|
||||||
|
|
||||||
import type {AgentInfo, AgentKnowledgeBinding, AgentToolBinding,} from '../types';
|
import type {
|
||||||
|
AgentInfo,
|
||||||
|
AgentKnowledgeBinding,
|
||||||
|
AgentToolBinding,
|
||||||
|
} from '../types';
|
||||||
|
|
||||||
import {onMounted, ref, watch} from 'vue';
|
import { computed, onMounted, ref, watch } from 'vue';
|
||||||
import {BrushCleaning} from '@easyflow/icons';
|
|
||||||
|
|
||||||
import {ElButton, ElMessage} from 'element-plus';
|
import { ChatTimeline } from '@easyflow/common-ui';
|
||||||
|
import { BrushCleaning } from '@easyflow/icons';
|
||||||
|
|
||||||
|
import { ElButton, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
import AiChatPanel from '#/components/ai-chat/AiChatPanel.vue';
|
import AiChatPanel from '#/components/ai-chat/AiChatPanel.vue';
|
||||||
|
|
||||||
import {approveAgentRun, rejectAgentRun} from '../api';
|
import { approveAgentRun, rejectAgentRun } from '../api';
|
||||||
import {useAgentTryoutStream} from '../composables/useAgentTryoutStream';
|
import { useAgentTryoutStream } from '../composables/useAgentTryoutStream';
|
||||||
|
import { resolveInteractionDisplay } from '../interaction-config';
|
||||||
|
import AgentWelcomeState from './AgentWelcomeState.vue';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
agent: AgentInfo;
|
agent: AgentInfo;
|
||||||
@@ -35,6 +45,9 @@ const {
|
|||||||
stop,
|
stop,
|
||||||
} = useAgentTryoutStream();
|
} = useAgentTryoutStream();
|
||||||
const approvalLoading = ref(false);
|
const approvalLoading = ref(false);
|
||||||
|
const interactionDisplay = computed(() =>
|
||||||
|
resolveInteractionDisplay(props.agent),
|
||||||
|
);
|
||||||
|
|
||||||
function getDraftContext() {
|
function getDraftContext() {
|
||||||
return {
|
return {
|
||||||
@@ -68,12 +81,17 @@ watch(
|
|||||||
);
|
);
|
||||||
|
|
||||||
async function handleSend(prompt: string) {
|
async function handleSend(prompt: string) {
|
||||||
|
if (loading.value || approvalLoading.value) return;
|
||||||
await sendDraft({
|
await sendDraft({
|
||||||
...getDraftContext(),
|
...getDraftContext(),
|
||||||
prompt,
|
prompt,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleSuggestedQuestion(question: string) {
|
||||||
|
void handleSend(question);
|
||||||
|
}
|
||||||
|
|
||||||
function canCopyMessage(item: ChatTimelineMessageItem) {
|
function canCopyMessage(item: ChatTimelineMessageItem) {
|
||||||
if (item.role === 'user') {
|
if (item.role === 'user') {
|
||||||
return Boolean(copyMessageText(item).trim());
|
return Boolean(copyMessageText(item).trim());
|
||||||
@@ -176,6 +194,7 @@ async function handleReject(payload: ChatTimelineToolApprovalPayload) {
|
|||||||
closable
|
closable
|
||||||
:messages="[]"
|
:messages="[]"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
|
:placeholder="interactionDisplay.inputPlaceholder"
|
||||||
:approval-loading="approvalLoading"
|
:approval-loading="approvalLoading"
|
||||||
@send="handleSend"
|
@send="handleSend"
|
||||||
@stop="handleStop"
|
@stop="handleStop"
|
||||||
@@ -194,19 +213,47 @@ async function handleReject(payload: ChatTimelineToolApprovalPayload) {
|
|||||||
@click="handleClearSession"
|
@click="handleClearSession"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<ChatTimeline
|
<div class="agent-tryout__conversation">
|
||||||
:items="timelineItems"
|
<AgentWelcomeState
|
||||||
empty-text="输入问题试运行当前智能体"
|
v-if="timelineItems.length === 0"
|
||||||
:approval-loading="approvalLoading"
|
:agent-name="agent.name || '智能体'"
|
||||||
:copyable="canCopyMessage"
|
:avatar="agent.avatar"
|
||||||
:regenerable="canRegenerateMessage"
|
:disabled="loading || approvalLoading"
|
||||||
:regenerate-disabled="true"
|
:suggested-questions="interactionDisplay.suggestedQuestions"
|
||||||
@approve="handleApprove"
|
:welcome-message="interactionDisplay.welcomeMessage"
|
||||||
@copy-message="handleCopyMessage"
|
@select-question="handleSuggestedQuestion"
|
||||||
@regenerate-message="handleRegenerateMessage"
|
/>
|
||||||
@reject="handleReject"
|
<ChatTimeline
|
||||||
@select-next-variant="handleSelectNextVariant"
|
v-else
|
||||||
@select-previous-variant="handleSelectPreviousVariant"
|
:items="timelineItems"
|
||||||
/>
|
empty-text="输入问题试运行当前智能体"
|
||||||
|
:approval-loading="approvalLoading"
|
||||||
|
:copyable="canCopyMessage"
|
||||||
|
:regenerable="canRegenerateMessage"
|
||||||
|
:regenerate-disabled="true"
|
||||||
|
@approve="handleApprove"
|
||||||
|
@copy-message="handleCopyMessage"
|
||||||
|
@regenerate-message="handleRegenerateMessage"
|
||||||
|
@reject="handleReject"
|
||||||
|
@select-next-variant="handleSelectNextVariant"
|
||||||
|
@select-previous-variant="handleSelectPreviousVariant"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</AiChatPanel>
|
</AiChatPanel>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.agent-tryout__conversation {
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
padding: 0 var(--space-4);
|
||||||
|
overflow: auto;
|
||||||
|
overscroll-behavior: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-tryout__conversation :deep(.chat-timeline) {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -0,0 +1,222 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import { ArrowRight } from '@element-plus/icons-vue';
|
||||||
|
import { ElIcon } from 'element-plus';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
agentName: string;
|
||||||
|
avatar?: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
suggestedQuestions?: string[];
|
||||||
|
welcomeMessage: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
selectQuestion: [question: string];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const avatarFailed = ref(false);
|
||||||
|
const headingId = `agent-welcome-${Math.random().toString(36).slice(2, 9)}`;
|
||||||
|
const initial = computed(() => [...props.agentName.trim()][0] || 'A');
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.avatar,
|
||||||
|
() => {
|
||||||
|
avatarFailed.value = false;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="agent-welcome" :aria-labelledby="headingId">
|
||||||
|
<div class="agent-welcome__content">
|
||||||
|
<div class="agent-welcome__avatar" aria-hidden="true">
|
||||||
|
<img
|
||||||
|
v-if="avatar && !avatarFailed"
|
||||||
|
:src="avatar"
|
||||||
|
alt=""
|
||||||
|
@error="avatarFailed = true"
|
||||||
|
/>
|
||||||
|
<span v-else>{{ initial }}</span>
|
||||||
|
</div>
|
||||||
|
<h2 :id="headingId" class="agent-welcome__name">{{ agentName }}</h2>
|
||||||
|
<p class="agent-welcome__message">{{ welcomeMessage }}</p>
|
||||||
|
|
||||||
|
<div v-if="suggestedQuestions?.length" class="agent-welcome__suggestions">
|
||||||
|
<div class="agent-welcome__suggestions-title">猜你想问</div>
|
||||||
|
<div class="agent-welcome__suggestions-grid">
|
||||||
|
<button
|
||||||
|
v-for="question in suggestedQuestions"
|
||||||
|
:key="question"
|
||||||
|
class="agent-welcome__question"
|
||||||
|
type="button"
|
||||||
|
:title="question"
|
||||||
|
:disabled="disabled"
|
||||||
|
@click="emit('selectQuestion', question)"
|
||||||
|
@keydown.enter.stop.prevent="emit('selectQuestion', question)"
|
||||||
|
@keydown.space.stop.prevent="emit('selectQuestion', question)"
|
||||||
|
>
|
||||||
|
<span>{{ question }}</span>
|
||||||
|
<ElIcon aria-hidden="true"><ArrowRight /></ElIcon>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.agent-welcome {
|
||||||
|
box-sizing: border-box;
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
min-height: 100%;
|
||||||
|
padding: var(--space-8) 0;
|
||||||
|
container-type: inline-size;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__content {
|
||||||
|
width: min(680px, 100%);
|
||||||
|
margin: auto;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__avatar {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 52px;
|
||||||
|
height: 52px;
|
||||||
|
overflow: hidden;
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--el-color-primary);
|
||||||
|
background: var(--el-color-primary-light-9);
|
||||||
|
border: 1px solid var(--el-color-primary-light-8);
|
||||||
|
border-radius: var(--radius-panel);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__avatar img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__name {
|
||||||
|
margin: var(--space-3) 0 0;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 24px;
|
||||||
|
color: hsl(var(--text-strong));
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__message {
|
||||||
|
max-width: 640px;
|
||||||
|
margin: var(--space-2) auto 0;
|
||||||
|
font-size: 17px;
|
||||||
|
line-height: 1.7;
|
||||||
|
color: var(--el-text-color-regular);
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__suggestions {
|
||||||
|
margin-top: var(--space-6);
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__suggestions-title {
|
||||||
|
margin-bottom: var(--space-2);
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: hsl(var(--text-muted));
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__suggestions-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: var(--space-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__question {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) 18px;
|
||||||
|
gap: var(--space-2);
|
||||||
|
align-items: center;
|
||||||
|
min-height: 48px;
|
||||||
|
padding: var(--space-3) var(--space-4);
|
||||||
|
font: inherit;
|
||||||
|
color: var(--el-text-color-primary);
|
||||||
|
text-align: left;
|
||||||
|
cursor: pointer;
|
||||||
|
background: hsl(var(--surface-subtle));
|
||||||
|
border: 1px solid hsl(var(--line-subtle));
|
||||||
|
border-radius: var(--radius-toolbar);
|
||||||
|
transition:
|
||||||
|
color var(--motion-duration-fast) var(--motion-ease-standard),
|
||||||
|
background-color var(--motion-duration-fast) var(--motion-ease-standard),
|
||||||
|
border-color var(--motion-duration-fast) var(--motion-ease-standard),
|
||||||
|
transform var(--motion-duration-fast) var(--motion-ease-standard);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__question span {
|
||||||
|
display: -webkit-box;
|
||||||
|
overflow: hidden;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 20px;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__question .el-icon {
|
||||||
|
color: hsl(var(--text-muted));
|
||||||
|
transition: transform var(--motion-duration-fast) var(--motion-ease-standard);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__question:hover:not(:disabled) {
|
||||||
|
color: var(--el-color-primary);
|
||||||
|
background: var(--el-color-primary-light-9);
|
||||||
|
border-color: var(--el-color-primary-light-7);
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__question:active:not(:disabled) {
|
||||||
|
background: var(--el-color-primary-light-8);
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__question:hover:not(:disabled) .el-icon {
|
||||||
|
color: var(--el-color-primary);
|
||||||
|
transform: translateX(2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__question:focus-visible {
|
||||||
|
outline: 2px solid var(--el-color-primary-light-5);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__question:disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.56;
|
||||||
|
}
|
||||||
|
|
||||||
|
@container (max-width: 560px) {
|
||||||
|
.agent-welcome__suggestions-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: var(--space-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agent-welcome__message {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.agent-welcome__question,
|
||||||
|
.agent-welcome__question .el-icon {
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -9,6 +9,13 @@ import type {
|
|||||||
|
|
||||||
import { computed, reactive } from 'vue';
|
import { computed, reactive } from 'vue';
|
||||||
|
|
||||||
|
import {
|
||||||
|
buildInteractionConfigPayload,
|
||||||
|
createEmptyInteractionConfig,
|
||||||
|
normalizeInteractionConfig,
|
||||||
|
validateInteractionConfig,
|
||||||
|
} from '../interaction-config';
|
||||||
|
|
||||||
const BASE_NODE_ID = 'agent-base';
|
const BASE_NODE_ID = 'agent-base';
|
||||||
const SAFE_TOOL_NAME_PATTERN = /^[\w-]+$/;
|
const SAFE_TOOL_NAME_PATTERN = /^[\w-]+$/;
|
||||||
|
|
||||||
@@ -85,6 +92,7 @@ export function createEmptyAgent(): AgentInfo {
|
|||||||
minCompressionTokenThreshold: 6000,
|
minCompressionTokenThreshold: 6000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
interactionConfigJson: createEmptyInteractionConfig(),
|
||||||
status: 1,
|
status: 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -119,6 +127,9 @@ function normalizeAgent(agent?: AgentInfo): AgentInfo {
|
|||||||
defaultCompressionParameter.minCompressionTokenThreshold,
|
defaultCompressionParameter.minCompressionTokenThreshold,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
interactionConfigJson: normalizeInteractionConfig(
|
||||||
|
source.interactionConfigJson,
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +171,7 @@ function normalizeToolBinding(
|
|||||||
String(
|
String(
|
||||||
binding.id ||
|
binding.id ||
|
||||||
createLocalId(String(binding.toolType || 'tool').toLowerCase()),
|
createLocalId(String(binding.toolType || 'tool').toLowerCase()),
|
||||||
),
|
),
|
||||||
toolName: normalizeBindingToolName(binding),
|
toolName: normalizeBindingToolName(binding),
|
||||||
optionsJson,
|
optionsJson,
|
||||||
sortNo: binding.sortNo ?? index + 1,
|
sortNo: binding.sortNo ?? index + 1,
|
||||||
@@ -302,6 +313,9 @@ export function useAgentDesignerState() {
|
|||||||
message: '请选择模型',
|
message: '请选择模型',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
issues.push(
|
||||||
|
...validateInteractionConfig(state.agent.interactionConfigJson),
|
||||||
|
);
|
||||||
state.knowledgeBindings.forEach((binding) => {
|
state.knowledgeBindings.forEach((binding) => {
|
||||||
if (!binding.knowledgeId) {
|
if (!binding.knowledgeId) {
|
||||||
issues.push({
|
issues.push({
|
||||||
@@ -339,6 +353,9 @@ export function useAgentDesignerState() {
|
|||||||
memoryConfigJson;
|
memoryConfigJson;
|
||||||
return {
|
return {
|
||||||
...state.agent,
|
...state.agent,
|
||||||
|
interactionConfigJson: buildInteractionConfigPayload(
|
||||||
|
state.agent.interactionConfigJson,
|
||||||
|
),
|
||||||
memoryConfigJson: {
|
memoryConfigJson: {
|
||||||
...restMemoryConfigJson,
|
...restMemoryConfigJson,
|
||||||
compressionParameter: {
|
compressionParameter: {
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
import {
|
||||||
|
buildInteractionConfigPayload,
|
||||||
|
resolveInteractionDisplay,
|
||||||
|
validateInteractionConfig,
|
||||||
|
} from './interaction-config';
|
||||||
|
|
||||||
|
describe('agent 对话体验配置', () => {
|
||||||
|
it('为空配置补充展示默认值', () => {
|
||||||
|
expect(resolveInteractionDisplay({ name: '数据助手' })).toEqual({
|
||||||
|
inputPlaceholder: '输入消息',
|
||||||
|
suggestedQuestions: [],
|
||||||
|
welcomeMessage: '你好,我是 数据助手,有什么可以帮你?',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('保存前清理首尾空白并过滤空问题', () => {
|
||||||
|
expect(
|
||||||
|
buildInteractionConfigPayload({
|
||||||
|
inputPlaceholder: ' 输入需求 ',
|
||||||
|
suggestedQuestions: [' 问题一 ', '', ' 问题二'],
|
||||||
|
welcomeMessage: ' 欢迎使用 ',
|
||||||
|
}),
|
||||||
|
).toEqual({
|
||||||
|
inputPlaceholder: '输入需求',
|
||||||
|
suggestedQuestions: ['问题一', '问题二'],
|
||||||
|
welcomeMessage: '欢迎使用',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('识别去除空白后的重复问题', () => {
|
||||||
|
const issues = validateInteractionConfig({
|
||||||
|
suggestedQuestions: ['如何开始?', ' 如何开始? '],
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(issues).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
field: 'interaction.suggestedQuestions.1',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
120
easyflow-ui-admin/app/src/views/ai/agents/interaction-config.ts
Normal file
120
easyflow-ui-admin/app/src/views/ai/agents/interaction-config.ts
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
import type {
|
||||||
|
AgentInfo,
|
||||||
|
AgentInteractionConfig,
|
||||||
|
AgentValidationIssue,
|
||||||
|
} from './types';
|
||||||
|
|
||||||
|
export const MAX_WELCOME_MESSAGE_LENGTH = 300;
|
||||||
|
export const MAX_SUGGESTED_QUESTION_COUNT = 6;
|
||||||
|
export const MAX_SUGGESTED_QUESTION_LENGTH = 80;
|
||||||
|
export const MAX_INPUT_PLACEHOLDER_LENGTH = 40;
|
||||||
|
export const DEFAULT_INPUT_PLACEHOLDER = '输入消息';
|
||||||
|
|
||||||
|
export function createEmptyInteractionConfig(): AgentInteractionConfig {
|
||||||
|
return {
|
||||||
|
inputPlaceholder: '',
|
||||||
|
suggestedQuestions: [],
|
||||||
|
welcomeMessage: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function normalizeInteractionConfig(
|
||||||
|
source?: Partial<AgentInteractionConfig> | Record<string, unknown>,
|
||||||
|
): AgentInteractionConfig {
|
||||||
|
return {
|
||||||
|
inputPlaceholder:
|
||||||
|
typeof source?.inputPlaceholder === 'string'
|
||||||
|
? source.inputPlaceholder
|
||||||
|
: '',
|
||||||
|
suggestedQuestions: Array.isArray(source?.suggestedQuestions)
|
||||||
|
? source.suggestedQuestions.filter(
|
||||||
|
(question): question is string => typeof question === 'string',
|
||||||
|
)
|
||||||
|
: [],
|
||||||
|
welcomeMessage:
|
||||||
|
typeof source?.welcomeMessage === 'string' ? source.welcomeMessage : '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildInteractionConfigPayload(
|
||||||
|
source?: Partial<AgentInteractionConfig> | Record<string, unknown>,
|
||||||
|
): AgentInteractionConfig {
|
||||||
|
const normalized = normalizeInteractionConfig(source);
|
||||||
|
return {
|
||||||
|
inputPlaceholder: normalized.inputPlaceholder.trim(),
|
||||||
|
suggestedQuestions: normalized.suggestedQuestions
|
||||||
|
.map((question) => question.trim())
|
||||||
|
.filter(Boolean),
|
||||||
|
welcomeMessage: normalized.welcomeMessage.trim(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveInteractionDisplay(agent?: AgentInfo) {
|
||||||
|
const config = buildInteractionConfigPayload(agent?.interactionConfigJson);
|
||||||
|
const agentName = String(agent?.name || '').trim() || '智能体';
|
||||||
|
return {
|
||||||
|
inputPlaceholder: config.inputPlaceholder || DEFAULT_INPUT_PLACEHOLDER,
|
||||||
|
suggestedQuestions: config.suggestedQuestions,
|
||||||
|
welcomeMessage:
|
||||||
|
config.welcomeMessage || `你好,我是 ${agentName},有什么可以帮你?`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function validateInteractionConfig(
|
||||||
|
source?: Partial<AgentInteractionConfig> | Record<string, unknown>,
|
||||||
|
): AgentValidationIssue[] {
|
||||||
|
const config = normalizeInteractionConfig(source);
|
||||||
|
const issues: AgentValidationIssue[] = [];
|
||||||
|
if (config.welcomeMessage.trim().length > MAX_WELCOME_MESSAGE_LENGTH) {
|
||||||
|
issues.push({
|
||||||
|
field: 'interaction.welcomeMessage',
|
||||||
|
message: '欢迎语不能超过 300 个字符',
|
||||||
|
nodeId: 'agent-base',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (/\r|\n/.test(config.inputPlaceholder)) {
|
||||||
|
issues.push({
|
||||||
|
field: 'interaction.inputPlaceholder',
|
||||||
|
message: '输入提示仅支持单行文本',
|
||||||
|
nodeId: 'agent-base',
|
||||||
|
});
|
||||||
|
} else if (
|
||||||
|
config.inputPlaceholder.trim().length > MAX_INPUT_PLACEHOLDER_LENGTH
|
||||||
|
) {
|
||||||
|
issues.push({
|
||||||
|
field: 'interaction.inputPlaceholder',
|
||||||
|
message: '输入提示不能超过 40 个字符',
|
||||||
|
nodeId: 'agent-base',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const questions = config.suggestedQuestions
|
||||||
|
.map((question, index) => ({ index, value: question.trim() }))
|
||||||
|
.filter((item) => item.value);
|
||||||
|
if (questions.length > MAX_SUGGESTED_QUESTION_COUNT) {
|
||||||
|
issues.push({
|
||||||
|
field: 'interaction.suggestedQuestions',
|
||||||
|
message: '猜你想问最多配置 6 条',
|
||||||
|
nodeId: 'agent-base',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const seenQuestions = new Set<string>();
|
||||||
|
for (const question of questions) {
|
||||||
|
if (question.value.length > MAX_SUGGESTED_QUESTION_LENGTH) {
|
||||||
|
issues.push({
|
||||||
|
field: `interaction.suggestedQuestions.${question.index}`,
|
||||||
|
message: `第 ${question.index + 1} 条猜你想问不能超过 80 个字符`,
|
||||||
|
nodeId: 'agent-base',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (seenQuestions.has(question.value)) {
|
||||||
|
issues.push({
|
||||||
|
field: `interaction.suggestedQuestions.${question.index}`,
|
||||||
|
message: `第 ${question.index + 1} 条猜你想问与已有内容重复`,
|
||||||
|
nodeId: 'agent-base',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
seenQuestions.add(question.value);
|
||||||
|
}
|
||||||
|
return issues;
|
||||||
|
}
|
||||||
@@ -3,6 +3,12 @@
|
|||||||
export type AgentPanelMode = 'base' | 'capability' | 'tryout';
|
export type AgentPanelMode = 'base' | 'capability' | 'tryout';
|
||||||
export type AgentCapabilityKind = 'knowledge' | 'plugin' | 'workflow' | 'mcp';
|
export type AgentCapabilityKind = 'knowledge' | 'plugin' | 'workflow' | 'mcp';
|
||||||
|
|
||||||
|
export interface AgentInteractionConfig {
|
||||||
|
inputPlaceholder: string;
|
||||||
|
suggestedQuestions: string[];
|
||||||
|
welcomeMessage: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface AgentInfo {
|
export interface AgentInfo {
|
||||||
id?: number | string;
|
id?: number | string;
|
||||||
name?: string;
|
name?: string;
|
||||||
@@ -15,6 +21,7 @@ export interface AgentInfo {
|
|||||||
promptConfigJson?: Record<string, any>;
|
promptConfigJson?: Record<string, any>;
|
||||||
memoryConfigJson?: Record<string, any>;
|
memoryConfigJson?: Record<string, any>;
|
||||||
executionConfigJson?: Record<string, any>;
|
executionConfigJson?: Record<string, any>;
|
||||||
|
interactionConfigJson?: AgentInteractionConfig;
|
||||||
status?: number;
|
status?: number;
|
||||||
visibilityScope?: string;
|
visibilityScope?: string;
|
||||||
publishStatus?: string;
|
publishStatus?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user