mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 15:13:55 +08:00
feat: add FastAPI manager API compatibility baseline
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HexFormat;
|
||||
|
||||
import xiaozhi.common.utils.AESUtils;
|
||||
|
||||
public final class AgentMcpCryptoInteropCli {
|
||||
private AgentMcpCryptoInteropCli() {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 2) {
|
||||
throw new IllegalArgumentException("usage: AgentMcpCryptoInteropCli <agent-id> <key>");
|
||||
}
|
||||
byte[] digest = MessageDigest.getInstance("MD5").digest(args[0].getBytes(StandardCharsets.UTF_8));
|
||||
String json = "{\"agentId\": \"%s\"}".formatted(HexFormat.of().formatHex(digest));
|
||||
System.out.print(AESUtils.encrypt(args[1], json));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import xiaozhi.modules.model.entity.ModelConfigEntity;
|
||||
import xiaozhi.modules.sys.vo.SysDictDataItem;
|
||||
import xiaozhi.modules.timbre.vo.TimbreDetailsVO;
|
||||
|
||||
public final class RedisCodecVectors {
|
||||
private RedisCodecVectors() {}
|
||||
|
||||
private static void vector(String name, Object value) {
|
||||
RedisSerializer<Object> serializer = RedisSerializer.json();
|
||||
byte[] bytes = serializer.serialize(value);
|
||||
Object decoded = serializer.deserialize(bytes);
|
||||
System.out.println(name + "\t" + new String(bytes, StandardCharsets.UTF_8)
|
||||
+ "\t" + (decoded == null ? "null" : decoded.getClass().getName()));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
vector("string", "hello");
|
||||
vector("integer", Integer.valueOf(7));
|
||||
vector("long", Long.valueOf(2147483648L));
|
||||
vector("boolean", Boolean.TRUE);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("text", "hello");
|
||||
map.put("number", Long.valueOf(2147483648L));
|
||||
map.put("list", new ArrayList<>(List.of("a", "b")));
|
||||
Map<String, Object> nested = new HashMap<>();
|
||||
nested.put("enabled", Boolean.TRUE);
|
||||
map.put("nested", nested);
|
||||
vector("map", map);
|
||||
vector("list", new ArrayList<>(List.of("a", Long.valueOf(2147483648L), nested)));
|
||||
vector("date", new Date(0));
|
||||
|
||||
TimbreDetailsVO timbre = new TimbreDetailsVO();
|
||||
timbre.setId("voice-1");
|
||||
timbre.setName("sample");
|
||||
timbre.setSort(2L);
|
||||
vector("pojo", timbre);
|
||||
|
||||
ModelConfigEntity model = new ModelConfigEntity();
|
||||
model.setId("model-1");
|
||||
model.setModelType("LLM");
|
||||
JSONObject config = new JSONObject();
|
||||
config.set("type", "openai");
|
||||
config.set("api_key", "secret");
|
||||
model.setConfigJson(config);
|
||||
vector("model-pojo", model);
|
||||
|
||||
SysDictDataItem item = new SysDictDataItem();
|
||||
item.setName("China");
|
||||
item.setKey("+86");
|
||||
vector("dict-list", new ArrayList<>(List.of(item)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import xiaozhi.common.utils.SM2Utils;
|
||||
|
||||
/** Tiny subprocess boundary used by the Python/Java SM2 interoperability tests. */
|
||||
public final class Sm2InteropCli {
|
||||
private Sm2InteropCli() {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length != 3) {
|
||||
throw new IllegalArgumentException("usage: encrypt <public-key> <plaintext> | decrypt <private-key> <ciphertext>");
|
||||
}
|
||||
switch (args[0]) {
|
||||
case "encrypt" -> System.out.print(SM2Utils.encrypt(args[1], args[2]));
|
||||
case "decrypt" -> System.out.print(SM2Utils.decrypt(args[1], args[2]));
|
||||
default -> throw new IllegalArgumentException("unknown operation: " + args[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user