Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ public ParameterParsingNode(ChatClient chatClient, String inputText, String inpu
}

private String renderTemplate(OverAllState state, String template) {
if (!StringUtils.hasText(template)) {
return template;
}
Map<String, Object> params = Stream.of(template)
.map(VAR_TEMPLATE_PATTERN::matcher)
.map(Matcher::results)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public QuestionClassifierNode(ChatClient chatClient, String inputTextKey, Map<St
}

private String renderTemplate(OverAllState state, String template) {
if (!StringUtils.hasText(template)) {
return template;
}
Map<String, Object> params = Stream.of(template)
.map(VAR_TEMPLATE_PATTERN::matcher)
.map(Matcher::results)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export const FlowEditor = memo((props: IProps) => {
try {
// 准备请求参数
const params = {
dependencies: 'spring-ai-alibaba-graph,web,spring-ai-alibaba-starter-dashscope',
dependencies: 'spring-ai-alibaba-graph,web,spring-ai-alibaba-starter-dashscope,spring-ai-starter-mcp-client',
appMode: 'workflow',
dslDialectType: 'studio',
type: 'maven-project',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ public enum NodeType {

QUESTION_CLASSIFIER("question-classifier", "question-classifier", "Classifier"),

HTTP("http", "http-request", "UNSUPPORTED"),
HTTP("http", "http-request", "API"),

LIST_OPERATOR("list-operator", "list-operator", "UNSUPPORTED"),

PARAMETER_PARSING("parameter-parsing", "parameter-extractor", "ParameterExtractor"),

TOOL("tool", "tool", "UNSUPPORTED"),

MCP("mcp", "UNSUPPORTED", "UNSUPPORTED"),
// Dify的MCP使用ToolNode定义
MCP("mcp", "UNSUPPORTED", "MCP"),

TEMPLATE_TRANSFORM("template-transform", "template-transform", "UNSUPPORTED"),

Expand Down Expand Up @@ -93,6 +94,11 @@ public String studioValue() {
return this.studioValue;
}

public static boolean isEmpty(NodeType nodeType) {
return NodeType.EMPTY.equals(nodeType) || NodeType.ITERATION_START.equals(nodeType)
|| NodeType.ITERATION_END.equals(nodeType);
}

public static Optional<NodeType> fromValue(String value) {
return Arrays.stream(NodeType.values()).filter(nodeType -> nodeType.value.equals(value)).findFirst();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.alibaba.cloud.ai.studio.admin.generator.model.VariableType;
import com.alibaba.cloud.ai.studio.admin.generator.model.workflow.NodeData;

import com.alibaba.cloud.ai.studio.admin.generator.service.dsl.DSLDialectType;
import org.springframework.http.HttpMethod;

/**
Expand All @@ -37,25 +38,30 @@
*/
public class HttpNodeData extends NodeData {

public static List<Variable> getDefaultOutputSchemas() {
return List.of(new Variable("body", VariableType.STRING), new Variable("status_code", VariableType.NUMBER),
new Variable("headers", VariableType.OBJECT), new Variable("files", VariableType.ARRAY_FILE));
public static List<Variable> getDefaultOutputSchemas(DSLDialectType dialectType) {
return switch (dialectType) {
case DIFY ->
List.of(new Variable("body", VariableType.STRING), new Variable("status_code", VariableType.NUMBER),
new Variable("headers", VariableType.OBJECT), new Variable("files", VariableType.ARRAY_FILE));
case STUDIO -> List.of(new Variable("output", VariableType.STRING));
default -> List.of();
};
}

/** HTTP method, default GET */
private HttpMethod method = HttpMethod.GET;
private HttpMethod method;

/** Request URL */
private String url;

/** Request header */
private Map<String, String> headers = Collections.emptyMap();
private Map<String, String> headers;

/** queryParams */
private Map<String, String> queryParams = Collections.emptyMap();
private Map<String, String> queryParams;

/** body */
private HttpRequestNodeBody body = new HttpRequestNodeBody();
private HttpRequestNodeBody body;

/**
* rawBodyMap
Expand All @@ -66,7 +72,7 @@ public static List<Variable> getDefaultOutputSchemas() {
private AuthConfig authConfig;

/** retryConfig */
private RetryConfig retryConfig = new RetryConfig(3, 1000, true);
private RetryConfig retryConfig;

/** TimeoutConfig */
private TimeoutConfig timeoutConfig;
Expand All @@ -90,12 +96,6 @@ public HttpNodeData(List<VariableSelector> inputs, List<Variable> outputs, HttpM
this.rawBodyMap = null;
}

public HttpNodeData(List<VariableSelector> inputs, List<Variable> outputs) {
this(inputs, outputs, HttpMethod.GET, null, Collections.emptyMap(), Collections.emptyMap(),
new HttpRequestNodeBody(), null, new RetryConfig(3, 1000, true),
new TimeoutConfig(10, 60, 20, 300, 600, 6000), null);
}

public HttpMethod getMethod() {
return method;
}
Expand Down Expand Up @@ -136,6 +136,14 @@ public void setBody(HttpRequestNodeBody body) {
this.body = body;
}

public Map<String, Object> getRawBodyMap() {
return rawBodyMap;
}

public void setRawBodyMap(Map<String, Object> rawBodyMap) {
this.rawBodyMap = rawBodyMap;
}

public AuthConfig getAuthConfig() {
return authConfig;
}
Expand All @@ -152,20 +160,20 @@ public void setRetryConfig(RetryConfig retryConfig) {
this.retryConfig = retryConfig;
}

public String getOutputKey() {
return outputKey;
public TimeoutConfig getTimeoutConfig() {
return timeoutConfig;
}

public void setOutputKey(String outputKey) {
this.outputKey = outputKey;
public void setTimeoutConfig(TimeoutConfig timeoutConfig) {
this.timeoutConfig = timeoutConfig;
}

public Map<String, Object> getRawBodyMap() {
return rawBodyMap;
public String getOutputKey() {
return outputKey;
}

public void setRawBodyMap(Map<String, Object> rawBodyMap) {
this.rawBodyMap = rawBodyMap;
public void setOutputKey(String outputKey) {
this.outputKey = outputKey;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,92 +16,71 @@

package com.alibaba.cloud.ai.studio.admin.generator.model.workflow.nodedata;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.alibaba.cloud.ai.studio.admin.generator.model.VariableSelector;
import com.alibaba.cloud.ai.studio.admin.generator.model.workflow.NodeData;

/**
* NodeData for McpNode: Contains fields such as url, tool, headers, params, outputKey,
* inputParamKeys, etc.
*/
import java.util.List;

// 本类仅考虑Studio的MCP使用,Dify的MCP使用ToolNode定义
public class MCPNodeData extends NodeData {

private String url;
private String toolName;

private String tool;
private String serverName;

private Map<String, String> headers;
private String serverCode;

private Map<String, Object> params;
private String inputJsonTemplate = "";

private String outputKey;
private List<String> inputKeys = List.of();

private List<String> inputParamKeys;
private String outputKey = "output";

public MCPNodeData() {
super(Collections.emptyList(), Collections.emptyList());
public String getToolName() {
return toolName;
}

public MCPNodeData(List<VariableSelector> inputs,
List<com.alibaba.cloud.ai.studio.admin.generator.model.Variable> outputs) {
super(inputs, outputs);
public void setToolName(String toolName) {
this.toolName = toolName;
}

public String getUrl() {
return url;
public String getServerName() {
return serverName;
}

public MCPNodeData setUrl(String url) {
this.url = url;
return this;
public void setServerName(String serverName) {
this.serverName = serverName;
}

public String getTool() {
return tool;
public String getServerCode() {
return serverCode;
}

public MCPNodeData setTool(String tool) {
this.tool = tool;
return this;
public void setServerCode(String serverCode) {
this.serverCode = serverCode;
}

public Map<String, String> getHeaders() {
return headers;
public String getInputJsonTemplate() {
return inputJsonTemplate;
}

public MCPNodeData setHeaders(Map<String, String> headers) {
this.headers = headers;
return this;
public void setInputJsonTemplate(String inputJsonTemplate) {
this.inputJsonTemplate = inputJsonTemplate;
}

public Map<String, Object> getParams() {
return params;
public List<String> getInputKeys() {
return inputKeys;
}

public MCPNodeData setParams(Map<String, Object> params) {
this.params = params;
return this;
public void setInputKeys(List<String> inputKeys) {
this.inputKeys = inputKeys;
}

public String getOutputKey() {
return outputKey;
}

public MCPNodeData setOutputKey(String outputKey) {
public void setOutputKey(String outputKey) {
this.outputKey = outputKey;
return this;
}

public List<String> getInputParamKeys() {
return inputParamKeys;
}

public MCPNodeData setInputParamKeys(List<String> inputParamKeys) {
this.inputParamKeys = inputParamKeys;
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private List<Node> constructNodes(List<Map<String, Object>> nodeMaps) {
NodeData data = converter.parseMapData(nodeDataMap, DSLDialectType.DIFY);

// Generate a readable varName and inject it into NodeData
int count = counters.merge(nodeType, 1, Integer::sum);
int count = counters.merge(NodeType.isEmpty(nodeType) ? NodeType.EMPTY : nodeType, 1, Integer::sum);
String varName = converter.generateVarName(count);

data.setVarName(varName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private Graph constructGraph(Map<String, Object> data) {
// 展开迭代节点内部的Node和Edge
nodeMap.forEach(map -> {
NodeType type = NodeType.fromStudioValue(MapReadUtil.getMapDeepValue(map, String.class, "type"))
.orElseThrow();
.orElseThrow(() -> new UnsupportedOperationException("unsupported node type " + map.get("type")));
if (NodeType.ITERATION.equals(type)) {
List<Map<String, Object>> innerNode = MapReadUtil.safeCastToListWithMap(
MapReadUtil.getMapDeepValue(map, List.class, "config", "node_param", "block", "nodes"));
Expand Down Expand Up @@ -242,7 +242,7 @@ private List<Node> constructNodes(List<Map<String, Object>> nodeMaps) {
NodeData data = converter.parseMapData(nodeMap, DSLDialectType.STUDIO);

// Generate a readable varName and inject it into NodeData
int count = counters.merge(nodeType, 1, Integer::sum);
int count = counters.merge(NodeType.isEmpty(nodeType) ? NodeType.EMPTY : nodeType, 1, Integer::sum);
String varName = converter.generateVarName(count);

data.setVarName(varName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ protected List<DialectConverter<EmptyNodeData>> getDialectConverters() {

@Override
public Boolean supportNodeType(NodeType nodeType) {
// 迭代节点的起始节点与迭代节点共享一个data,故转换时不需要提取数据
return NodeType.EMPTY.equals(nodeType) || NodeType.ITERATION_START.equals(nodeType)
|| NodeType.ITERATION_END.equals(nodeType);
return NodeType.isEmpty(nodeType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Map<String, Object> dump(EndNodeData nodeData) {
data.put("outputs", outputsMap);
return data;
}
}), STUDIO(new DialectConverter<EndNodeData>() {
}), STUDIO(new DialectConverter<>() {
@Override
public Boolean supportDialect(DSLDialectType dialectType) {
return DSLDialectType.STUDIO.equals(dialectType);
Expand Down
Loading
Loading