mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-17 08:01:03 +00:00
add agent schemas
This commit is contained in:
commit
c4153c5335
20 changed files with 2735 additions and 0 deletions
54
engine/packages/agent-schema/build.rs
Normal file
54
engine/packages/agent-schema/build.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let out_dir = std::env::var("OUT_DIR").unwrap();
|
||||
let schema_dir = Path::new("../../dist");
|
||||
|
||||
let schemas = [
|
||||
("opencode", "opencode.json"),
|
||||
("claude", "claude.json"),
|
||||
("codex", "codex.json"),
|
||||
("amp", "amp.json"),
|
||||
];
|
||||
|
||||
for (name, file) in schemas {
|
||||
let schema_path = schema_dir.join(file);
|
||||
|
||||
// Tell cargo to rerun if schema changes
|
||||
println!("cargo:rerun-if-changed={}", schema_path.display());
|
||||
|
||||
if !schema_path.exists() {
|
||||
eprintln!("Warning: Schema file not found: {}", schema_path.display());
|
||||
// Write empty module
|
||||
let out_path = Path::new(&out_dir).join(format!("{}.rs", name));
|
||||
fs::write(&out_path, "// Schema not found\n").unwrap();
|
||||
continue;
|
||||
}
|
||||
|
||||
let schema_content = fs::read_to_string(&schema_path)
|
||||
.unwrap_or_else(|e| panic!("Failed to read {}: {}", schema_path.display(), e));
|
||||
|
||||
let schema: schemars::schema::RootSchema = serde_json::from_str(&schema_content)
|
||||
.unwrap_or_else(|e| panic!("Failed to parse {}: {}", schema_path.display(), e));
|
||||
|
||||
let mut type_space = typify::TypeSpace::default();
|
||||
|
||||
type_space
|
||||
.add_root_schema(schema)
|
||||
.unwrap_or_else(|e| panic!("Failed to process {}: {}", schema_path.display(), e));
|
||||
|
||||
let contents = type_space.to_stream();
|
||||
|
||||
// Format the generated code
|
||||
let formatted = prettyplease::unparse(&syn::parse2(contents.clone()).unwrap_or_else(|e| {
|
||||
panic!("Failed to parse generated code for {}: {}", name, e)
|
||||
}));
|
||||
|
||||
let out_path = Path::new(&out_dir).join(format!("{}.rs", name));
|
||||
fs::write(&out_path, formatted)
|
||||
.unwrap_or_else(|e| panic!("Failed to write {}: {}", out_path.display(), e));
|
||||
|
||||
println!("cargo:warning=Generated {} types from {}", name, file);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue