| | |
| | | package com.smtaiserver.smtaiserver.javaai.jsonflow.node;
|
| | |
|
| | | import com.smtaiserver.smtaiserver.core.SMTAIServerApp;
|
| | | import com.smtaiserver.smtaiserver.core.SMTAIServerRequest;
|
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase;
|
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase.DBQueryNotify;
|
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase.DBRecord;
|
| | |
| | | import com.smtaiserver.smtaiserver.javaai.jsonflow.core.SMTJsonFlowManager;
|
| | | import com.smtaiserver.smtaiserver.javaai.jsonflow.core.SMTJsonFlowNodeOnlyOutput;
|
| | | import com.smtaiserver.smtaiserver.javaai.jsonflow.core.SMTJsonFlowScriptJet;
|
| | | import com.smtservlet.core.SMTRequest;
|
| | | import com.smtservlet.util.Json;
|
| | | import com.smtservlet.util.SMTHttpClient;
|
| | | import com.smtservlet.util.SMTJsonWriter;
|
| | | import com.smtservlet.util.SMTStatic;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Map.Entry;
|
| | |
|
| | | import okhttp3.FormBody;
|
| | | import okhttp3.OkHttpClient;
|
| | | import okhttp3.Request;
|
| | | import okhttp3.RequestBody;
|
| | | import okhttp3.Response;
|
| | | import org.mozilla.javascript.Context;
|
| | | import org.mozilla.javascript.Function;
|
| | | import org.mozilla.javascript.NativeArray;
|
| | | import org.mozilla.javascript.NativeObject;
|
| | | import org.osgi.service.component.annotations.Component;
|
| | |
|
| | | public class SMTJsonFlowNodeScript extends SMTJsonFlowNodeOnlyOutput |
| | | import javax.annotation.Resource;
|
| | |
|
| | | public class SMTJsonFlowNodeScript extends SMTJsonFlowNodeOnlyOutput
|
| | |
|
| | |
|
| | | {
|
| | | public static class SMTJsonFlowNodeScriptArg
|
| | | public class SMTJsonFlowNodeScriptArg
|
| | | {
|
| | |
|
| | | public SMTJsonFlowExecArg _execArg;
|
| | |
|
| | | public SMTJsonFlowNodeScriptArg(SMTJsonFlowExecArg execArg)
|
| | |
| | | }
|
| | |
|
| | | public String getGlobalConfig(String key, String defaultValue) throws Exception {
|
| | | String globalConfig = (String) SMTAIServerApp.getApp().getGlobalConfig(key, defaultValue);
|
| | | return globalConfig;
|
| | | return (String) SMTAIServerApp.getApp().getGlobalConfig(key, defaultValue);
|
| | | }
|
| | | public String getNowDate() throws Exception {
|
| | | return SMTStatic.toString(new Date());
|
| | |
| | | public String getUUID() throws Exception {
|
| | | return SMTStatic.newUUID();
|
| | | }
|
| | | public String getLoginUserIdByJs() throws Exception {
|
| | | return _execArg._tranReq.getLoginUserId();
|
| | | }
|
| | |
|
| | | public String sendPost(String url, Map<String, String> params) throws Exception {
|
| | | FormBody.Builder formBuilder = new FormBody.Builder();
|
| | | for (Map.Entry<String, String> entry : params.entrySet()) {
|
| | | formBuilder.add(entry.getKey(), entry.getValue());
|
| | | }
|
| | | RequestBody formBody = formBuilder.build();
|
| | | Request request = new Request.Builder()
|
| | | .url(url)
|
| | | .post(formBody)
|
| | | .addHeader("accept", "application/json")
|
| | | .addHeader("Content-Type", "application/x-www-form-urlencoded")
|
| | | .build();
|
| | |
|
| | | OkHttpClient client = new OkHttpClient();
|
| | | Response response = client.newCall(request).execute();
|
| | | if (!response.isSuccessful()) {
|
| | | throw new IOException("Unexpected code " + response);
|
| | | }
|
| | | if (response.body() != null) {
|
| | | return response.body().string();
|
| | | }
|
| | | return "";
|
| | | }
|
| | | public void webSocketBroadcast(NativeObject nativeObject) throws Exception {
|
| | | SMTJsonWriter jsonWr = new SMTJsonWriter(false);
|
| | | SMTAIServerApp.convJSToJsonWriter(nativeObject, jsonWr);
|
| | | SMTAIServerApp.getApp().webSocketApp(jsonWr.getFullJson());
|
| | | }
|
| | | |
| | | public Object llmAnswerToJson(String sJson)
|
| | | {
|
| | | Object object = SMTAIServerApp.convJsonToJS(SMTStatic.convLLMAnswerToJson(sJson, false));
|
| | | return object;
|
| | | }
|
| | |
|
| | | public Object getArg(String key)
|
| | | {
|