mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-17 06:04:56 +00:00
add agent schemas
This commit is contained in:
commit
c4153c5335
20 changed files with 2735 additions and 0 deletions
16
engine/packages/agent-schema/Cargo.toml
Normal file
16
engine/packages/agent-schema/Cargo.toml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
[package]
|
||||
name = "agent-schema"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
regress = "0.10"
|
||||
|
||||
[build-dependencies]
|
||||
typify = "0.4"
|
||||
serde_json = "1.0"
|
||||
schemars = "0.8"
|
||||
prettyplease = "0.2"
|
||||
syn = "2.0"
|
||||
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);
|
||||
}
|
||||
}
|
||||
76
engine/packages/agent-schema/src/lib.rs
Normal file
76
engine/packages/agent-schema/src/lib.rs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
//! Generated types from AI coding agent JSON schemas.
|
||||
//!
|
||||
//! This crate provides Rust types for:
|
||||
//! - OpenCode SDK
|
||||
//! - Claude Code SDK
|
||||
//! - Codex SDK
|
||||
//! - AMP Code SDK
|
||||
|
||||
pub mod opencode {
|
||||
//! OpenCode SDK types extracted from OpenAPI 3.1.1 spec.
|
||||
include!(concat!(env!("OUT_DIR"), "/opencode.rs"));
|
||||
}
|
||||
|
||||
pub mod claude {
|
||||
//! Claude Code SDK types extracted from TypeScript definitions.
|
||||
include!(concat!(env!("OUT_DIR"), "/claude.rs"));
|
||||
}
|
||||
|
||||
pub mod codex {
|
||||
//! Codex SDK types.
|
||||
include!(concat!(env!("OUT_DIR"), "/codex.rs"));
|
||||
}
|
||||
|
||||
pub mod amp {
|
||||
//! AMP Code SDK types.
|
||||
include!(concat!(env!("OUT_DIR"), "/amp.rs"));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_claude_bash_input() {
|
||||
let input = claude::BashInput {
|
||||
command: "ls -la".to_string(),
|
||||
timeout: Some(5000.0),
|
||||
description: Some("List files".to_string()),
|
||||
run_in_background: None,
|
||||
simulated_sed_edit: None,
|
||||
dangerously_disable_sandbox: None,
|
||||
};
|
||||
|
||||
let json = serde_json::to_string(&input).unwrap();
|
||||
assert!(json.contains("ls -la"));
|
||||
|
||||
let parsed: claude::BashInput = serde_json::from_str(&json).unwrap();
|
||||
assert_eq!(parsed.command, "ls -la");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_codex_thread_event() {
|
||||
let event = codex::ThreadEvent {
|
||||
type_: codex::ThreadEventType::ThreadCreated,
|
||||
thread_id: Some("thread-123".to_string()),
|
||||
item: None,
|
||||
error: serde_json::Map::new(),
|
||||
};
|
||||
|
||||
let json = serde_json::to_string(&event).unwrap();
|
||||
assert!(json.contains("thread.created"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_amp_message() {
|
||||
let msg = amp::Message {
|
||||
role: amp::MessageRole::User,
|
||||
content: "Hello".to_string(),
|
||||
tool_calls: vec![],
|
||||
};
|
||||
|
||||
let json = serde_json::to_string(&msg).unwrap();
|
||||
assert!(json.contains("user"));
|
||||
assert!(json.contains("Hello"));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue