wip: telemetry claude code matching

This commit is contained in:
Yeachan-Heo
2026-04-01 05:45:28 +00:00
parent e7e3ae2875
commit 828597024e
2 changed files with 31 additions and 11 deletions

View File

@@ -10,8 +10,9 @@ use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
pub const DEFAULT_ANTHROPIC_VERSION: &str = "2023-06-01";
pub const DEFAULT_APP_NAME: &str = "clawd-code";
pub const DEFAULT_APP_NAME: &str = "claude-code";
pub const DEFAULT_RUNTIME: &str = "rust";
pub const DEFAULT_AGENTIC_BETA: &str = "claude-code-20250219";
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ClientIdentity {
@@ -38,7 +39,7 @@ impl ClientIdentity {
#[must_use]
pub fn user_agent(&self) -> String {
format!("{}/{} ({})", self.app_name, self.app_version, self.runtime)
format!("{}/{}", self.app_name, self.app_version)
}
}
@@ -64,7 +65,7 @@ impl AnthropicRequestProfile {
Self {
anthropic_version: DEFAULT_ANTHROPIC_VERSION.to_string(),
client_identity,
betas: Vec::new(),
betas: vec![DEFAULT_AGENTIC_BETA.to_string()],
extra_body: Map::new(),
}
}
@@ -110,6 +111,12 @@ impl AnthropicRequestProfile {
for (key, value) in &self.extra_body {
object.insert(key.clone(), value.clone());
}
if !self.betas.is_empty() {
object.insert(
"betas".to_string(),
Value::Array(self.betas.iter().cloned().map(Value::String).collect()),
);
}
Ok(body)
}
}
@@ -423,7 +430,7 @@ mod tests {
#[test]
fn request_profile_emits_headers_and_merges_body() {
let profile = AnthropicRequestProfile::new(
ClientIdentity::new("clawd-code", "1.2.3").with_runtime("rust-cli"),
ClientIdentity::new("claude-code", "1.2.3").with_runtime("rust-cli"),
)
.with_beta("tools-2026-04-01")
.with_extra_body("metadata", serde_json::json!({"source": "test"}));
@@ -435,11 +442,11 @@ mod tests {
"anthropic-version".to_string(),
DEFAULT_ANTHROPIC_VERSION.to_string()
),
("user-agent".to_string(), "claude-code/1.2.3".to_string()),
(
"user-agent".to_string(),
"clawd-code/1.2.3 (rust-cli)".to_string()
"anthropic-beta".to_string(),
"claude-code-20250219,tools-2026-04-01".to_string(),
),
("anthropic-beta".to_string(), "tools-2026-04-01".to_string(),),
]
);
@@ -450,6 +457,10 @@ mod tests {
body["metadata"]["source"],
Value::String("test".to_string())
);
assert_eq!(
body["betas"],
serde_json::json!(["claude-code-20250219", "tools-2026-04-01"])
);
}
#[test]