From 5b5e4e0bea95ce979c57073f6903f2b79f9904d8 Mon Sep 17 00:00:00 2001 From: MrBT-nano Date: Tue, 12 May 2026 13:27:11 +0700 Subject: [PATCH 1/2] feat: implementation of serde and private registry connection --- .cargo/config.toml | 2 ++ .npmrc | 2 ++ pip.conf | 3 +++ tests/serde_roundtrip.rs | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 .npmrc create mode 100644 pip.conf create mode 100644 tests/serde_roundtrip.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..cd12d6b --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[registries.vtuber-registry] +index = "http://kellnr.cntm.labs:31500/api/v1/crates" diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..91614d5 --- /dev/null +++ b/.npmrc @@ -0,0 +1,2 @@ +@vtuber:registry=http://kellnr.cntm.labs:31500/api/v1/npm/ +//kellnr.cntm.labs:31500/api/v1/npm/:_authToken=${SHARED_TOKEN} diff --git a/pip.conf b/pip.conf new file mode 100644 index 0000000..4f21066 --- /dev/null +++ b/pip.conf @@ -0,0 +1,3 @@ +[global] +extra-index-url = http://kellnr.cntm.labs:31500/api/v1/pypi/simple +trusted-host = kellnr.cntm.labs diff --git a/tests/serde_roundtrip.rs b/tests/serde_roundtrip.rs new file mode 100644 index 0000000..c6f16fb --- /dev/null +++ b/tests/serde_roundtrip.rs @@ -0,0 +1,20 @@ +use vtuber_contracts::vtuber::v1::ConversationDirective; + +#[test] +fn test_directive_serde_json() { + let directive = ConversationDirective { + directive_id: "test-123".to_string(), + text_prompt: "Hello".to_string(), + ..Default::default() + }; + + // Serialize to JSON + let json = serde_json::to_string(&directive).expect("Failed to serialize"); + println!("Serialized JSON: {}", json); + + // Deserialize back to struct + let decoded: ConversationDirective = serde_json::from_str(&json).expect("Failed to deserialize"); + + assert_eq!(directive.directive_id, decoded.directive_id); + assert_eq!(directive.text_prompt, decoded.text_prompt); +} From a1616dbc05eef318ac514b636aa916ba70191834 Mon Sep 17 00:00:00 2001 From: MrBT-nano Date: Tue, 12 May 2026 13:54:34 +0700 Subject: [PATCH 2/2] feat: re-apply code changes for serde integration --- Cargo.toml | 7 ++++++- build.rs | 25 ++++++++++++++++--------- src/lib.rs | 1 + 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9f0687c..50e9cb3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,15 +9,20 @@ repository = "https://github.com/echo-layer/vtuber-contracts" readme = "README.md" keywords = ["vtuber", "grpc", "protobuf", "contracts"] categories = ["api-bindings"] +publish = ["vtuber-registry"] [dependencies] prost = "0.13" prost-types = "0.13" tonic = { version = "0.12", default-features = false, features = ["codegen", "prost"] } +serde = { version = "1.0", features = ["derive"] } +pbjson = "0.7" +pbjson-types = "0.7" [build-dependencies] tonic-build = { version = "0.12", default-features = false, features = ["prost"] } +pbjson-build = "0.7" [dev-dependencies] serde_yaml = "0.9" -serde = { version = "1", features = ["derive"] } +serde_json = "1.0" diff --git a/build.rs b/build.rs index 2fb8800..6f9d9d3 100644 --- a/build.rs +++ b/build.rs @@ -1,20 +1,27 @@ +use std::env; +use std::path::PathBuf; + fn main() -> Result<(), Box> { + let descriptor_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("proto_descriptor.bin"); + let protos = &[ - "proto/vtuber/v1/persona.proto", - "proto/vtuber/v1/voice_profile.proto", "proto/vtuber/v1/conversation.proto", + "proto/vtuber/v1/voice_profile.proto", + "proto/vtuber/v1/persona.proto", "proto/vtuber/v1/tool_call.proto", + "proto/vtuber/v1/assets.proto", ]; - for p in protos { - println!("cargo:rerun-if-changed={p}"); - } - println!("cargo:rerun-if-changed=build.rs"); - tonic_build::configure() - .build_server(true) - .build_client(true) + .file_descriptor_set_path(&descriptor_path) + .extern_path(".google.protobuf.Timestamp", "::pbjson_types::Timestamp") + .extern_path(".google.protobuf.Struct", "::pbjson_types::Struct") .compile_protos(protos, &["proto"])?; + let descriptor_set = std::fs::read(&descriptor_path)?; + pbjson_build::Builder::new() + .register_descriptors(&descriptor_set)? + .build(&[".vtuber.v1"])?; + Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index c6c4f7a..9fe5894 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,7 @@ pub mod vtuber { pub mod v1 { tonic::include_proto!("vtuber.v1"); + include!(concat!(env!("OUT_DIR"), "/vtuber.v1.serde.rs")); } }