sync from monorepo @ 2452e92e
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
use chrono::Utc;
|
||||
use dirigent_protocol::types::meta::{Meta, ProviderMeta};
|
||||
use dirigent_protocol::{Session, SessionMetadata};
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn main() {
|
||||
println!("=== SessionMetadata JSON Examples ===\n");
|
||||
|
||||
// Example 1: Without new fields (backward compatible)
|
||||
println!("1. Basic SessionMetadata (without new fields):");
|
||||
let basic = SessionMetadata {
|
||||
project_path: "/workspace/project".to_string(),
|
||||
model: Some("gpt-4".to_string()),
|
||||
total_messages: 10,
|
||||
system_message: None,
|
||||
current_mode_id: None,
|
||||
_meta: None,
|
||||
project_id: None,
|
||||
};
|
||||
let json = serde_json::to_string_pretty(&basic).unwrap();
|
||||
println!("{}\n", json);
|
||||
|
||||
// Example 2: With current_mode_id
|
||||
println!("2. SessionMetadata with current_mode_id:");
|
||||
let with_mode = SessionMetadata {
|
||||
project_path: "/workspace/project".to_string(),
|
||||
model: Some("claude-3-sonnet".to_string()),
|
||||
total_messages: 5,
|
||||
system_message: Some("You are a helpful coding assistant".to_string()),
|
||||
current_mode_id: Some("code_mode".to_string()),
|
||||
_meta: None,
|
||||
project_id: None,
|
||||
};
|
||||
let json = serde_json::to_string_pretty(&with_mode).unwrap();
|
||||
println!("{}\n", json);
|
||||
|
||||
// Example 3: With provider metadata
|
||||
println!("3. SessionMetadata with provider metadata:");
|
||||
let meta = Meta {
|
||||
provider: Some(ProviderMeta {
|
||||
name: "opencode".to_string(),
|
||||
original_ids: Some(HashMap::from([
|
||||
("session_id".to_string(), "ses_abc123xyz".to_string()),
|
||||
("project_id".to_string(), "proj_456".to_string()),
|
||||
])),
|
||||
raw_excerpt: Some(serde_json::json!({
|
||||
"version": "0.15.31",
|
||||
"share": null
|
||||
})),
|
||||
}),
|
||||
extra: HashMap::new(),
|
||||
};
|
||||
|
||||
let with_meta = SessionMetadata {
|
||||
project_path: "/workspace/project".to_string(),
|
||||
model: Some("gpt-4-turbo".to_string()),
|
||||
total_messages: 15,
|
||||
system_message: Some("System prompt here".to_string()),
|
||||
current_mode_id: Some("architect".to_string()),
|
||||
_meta: Some(meta),
|
||||
project_id: None,
|
||||
};
|
||||
let json = serde_json::to_string_pretty(&with_meta).unwrap();
|
||||
println!("{}\n", json);
|
||||
|
||||
// Example 4: Full Session object
|
||||
println!("4. Complete Session with all metadata fields:");
|
||||
let now = Utc::now();
|
||||
let session = Session {
|
||||
id: "ses_demo_123".to_string(),
|
||||
title: "My Coding Session".to_string(),
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
metadata: with_meta,
|
||||
models: None,
|
||||
modes: None,
|
||||
config_options: None,
|
||||
acp_client_id: None,
|
||||
cwd: None,
|
||||
};
|
||||
let json = serde_json::to_string_pretty(&session).unwrap();
|
||||
println!("{}\n", json);
|
||||
|
||||
// Example 5: Verify backward compatibility
|
||||
println!("5. Backward compatibility test (deserializing old format):");
|
||||
let old_json = r#"{
|
||||
"project_path": "/old/project",
|
||||
"model": "gpt-3.5",
|
||||
"total_messages": 3
|
||||
}"#;
|
||||
|
||||
let parsed: SessionMetadata = serde_json::from_str(old_json).unwrap();
|
||||
println!("Successfully parsed old JSON format:");
|
||||
println!(" project_path: {}", parsed.project_path);
|
||||
println!(" model: {:?}", parsed.model);
|
||||
println!(" total_messages: {}", parsed.total_messages);
|
||||
println!(" system_message: {:?}", parsed.system_message);
|
||||
println!(" current_mode_id: {:?}", parsed.current_mode_id);
|
||||
println!(" _meta: {:?}", parsed._meta);
|
||||
}
|
||||
Reference in New Issue
Block a user