|
@@ -1,5 +1,7 @@
|
|
|
package cn.com.yusys.ai.plus.harness.controller;
|
|
package cn.com.yusys.ai.plus.harness.controller;
|
|
|
|
|
|
|
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import io.agentscope.core.agent.Agent;
|
|
import io.agentscope.core.agent.Agent;
|
|
|
import io.agentscope.core.agent.RuntimeContext;
|
|
import io.agentscope.core.agent.RuntimeContext;
|
|
|
import io.agentscope.core.agui.adapter.AguiAdapterConfig;
|
|
import io.agentscope.core.agui.adapter.AguiAdapterConfig;
|
|
@@ -10,15 +12,13 @@ import io.agentscope.core.agui.model.RunAgentInput;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.codec.ServerSentEvent;
|
|
import org.springframework.http.codec.ServerSentEvent;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RequestHeader;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import reactor.core.publisher.Flux;
|
|
import reactor.core.publisher.Flux;
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
|
|
+@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
|
|
public class HarnessAgentRest {
|
|
public class HarnessAgentRest {
|
|
|
AguiAgentAdapter adapter;
|
|
AguiAgentAdapter adapter;
|
|
|
Agent harnessAgent;
|
|
Agent harnessAgent;
|
|
@@ -35,11 +35,12 @@ public class HarnessAgentRest {
|
|
|
.build());
|
|
.build());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private final ObjectMapper jackson2 = new ObjectMapper();
|
|
|
@PostMapping(value = "/harness", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
|
@PostMapping(value = "/harness", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
|
|
public Flux<ServerSentEvent<String>> run(
|
|
public Flux<ServerSentEvent<String>> run(
|
|
|
- @RequestBody RunAgentInput input,
|
|
|
|
|
- @RequestHeader(value = "x-user-id", required = true) String userId) {
|
|
|
|
|
-
|
|
|
|
|
|
|
+ @RequestBody String body,
|
|
|
|
|
+ @RequestHeader(value = "x-user-id", required = true) String userId) throws JsonProcessingException {
|
|
|
|
|
+ RunAgentInput input = jackson2.readValue(body, RunAgentInput.class);
|
|
|
RuntimeContext ctx = RuntimeContext.builder()
|
|
RuntimeContext ctx = RuntimeContext.builder()
|
|
|
.userId(userId) // null 也没关系 = 匿名
|
|
.userId(userId) // null 也没关系 = 匿名
|
|
|
.build();
|
|
.build();
|