gadk_platform/tracking.rs
1// Copyright 2026 Chris Olson
2// Portions derived from ADK-Go (https://github.com/google/adk-go), Copyright 2026 Google LLC.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! The ADK tracking header value.
17
18/// The `user-agent` / `x-goog-api-client` value gadk sends with model and MCP requests:
19/// `gadk-rust/<crate version> rust/<rustc version>`. `GADK_RUSTC_VERSION` is set by this crate's
20/// `build.rs`; every workspace crate shares one version, so the value is the same whichever crate
21/// asks.
22pub fn tracking_header() -> String {
23 format!(
24 "gadk-rust/{} rust/{}",
25 env!("CARGO_PKG_VERSION"),
26 env!("GADK_RUSTC_VERSION")
27 )
28}
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33
34 /// Port of Go `TestTrackingHeader` (internal/version/version_test.go) for the gadk shape.
35 #[test]
36 fn tracking_header_has_the_gadk_shape() {
37 let got = tracking_header();
38 let prefix = format!("gadk-rust/{} rust/", env!("CARGO_PKG_VERSION"));
39 let Some(rustc) = got.strip_prefix(&prefix) else {
40 panic!("{got:?} does not start with {prefix:?}");
41 };
42 assert!(
43 rustc.starts_with(|c: char| c.is_ascii_digit()) && !rustc.contains(' '),
44 "rustc version {rustc:?} in {got:?} is not one version token"
45 );
46 }
47}