Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ that flexibility; do not use an opaque JSON fallback for a known schema merely
to avoid modeling it. Preserve native format variants and unknown extensions
explicitly when introducing shared types.

Put shared schema interpretation, validated lookup, lossless edits, and common
projections on the type that owns those rules. Keep filesystem, credential,
process, and event-ordering policy in the services that coordinate them. Organize
shared schemas around one primary owner per file, with small private companion
types alongside that owner. Keep single-use transport shapes data-only when
methods would merely duplicate field access.

Install the pinned tools with [mise](https://mise.jdx.dev). `mise install`
reads `.tool-versions` and `mise.toml`, then runs `make install-deps`:

Expand Down
27 changes: 27 additions & 0 deletions bt-daemon/src/agents/antigravity/schema/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Antigravity native records shared by live translation and transcript import.
use serde::Deserialize;

mod tool_call;
mod tool_calls;
mod transcript_record;

pub(crate) use tool_call::ToolCall;
pub(crate) use tool_calls::ToolCalls;
pub(crate) use transcript_record::TranscriptRecord;

pub(crate) fn optional_integer<'de, D: serde::Deserializer<'de>>(
deserializer: D,
) -> Result<Option<i64>, D::Error> {
#[derive(Deserialize)]
#[serde(untagged)]
enum Integer {
Number(i64),
Text(String),
}
Option::<Integer>::deserialize(deserializer)?
.map(|value| match value {
Integer::Number(value) => Ok(value),
Integer::Text(value) => value.parse().map_err(serde::de::Error::custom),
})
.transpose()
}
26 changes: 26 additions & 0 deletions bt-daemon/src/agents/antigravity/schema/tool_call.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::json::Extensions;
use serde::{Deserialize, Serialize};
use serde_json::Value;

#[derive(Clone, Serialize, Deserialize)]
pub(crate) struct ToolCall {
#[serde(default, alias = "tool_name", alias = "toolName")]
pub name: Option<String>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
alias = "arguments",
alias = "input",
deserialize_with = "crate::agents::schema::deserialize_present"
)]
pub args: Option<Value>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
alias = "result",
deserialize_with = "crate::agents::schema::deserialize_present"
)]
pub output: Option<Value>,
#[serde(flatten, deserialize_with = "crate::json::deserialize_extensions")]
pub extra: Extensions,
}
17 changes: 17 additions & 0 deletions bt-daemon/src/agents/antigravity/schema/tool_calls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use super::ToolCall;
use serde::{Deserialize, Serialize};

#[derive(Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub(crate) enum ToolCalls {
Many(Vec<ToolCall>),
One(ToolCall),
}
impl ToolCalls {
pub fn iter(&self) -> std::slice::Iter<'_, ToolCall> {
match self {
Self::Many(calls) => calls.iter(),
Self::One(call) => std::slice::from_ref(call).iter(),
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Antigravity native records shared by live translation and transcript import.
use super::{optional_integer, ToolCalls};
use crate::agents::usage::ProviderUsage;
use crate::json::Extensions;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -46,59 +46,29 @@ pub(crate) struct TranscriptRecord {
pub extra: Extensions,
}

pub(crate) fn optional_integer<'de, D: serde::Deserializer<'de>>(
deserializer: D,
) -> Result<Option<i64>, D::Error> {
#[derive(Deserialize)]
#[serde(untagged)]
enum Integer {
Number(i64),
Text(String),
impl TranscriptRecord {
pub fn normalized_kind(&self) -> &str {
self.kind
.strip_prefix("CORTEX_STEP_TYPE_")
.unwrap_or(&self.kind)
}
Option::<Integer>::deserialize(deserializer)?
.map(|value| match value {
Integer::Number(value) => Ok(value),
Integer::Text(value) => value.parse().map_err(serde::de::Error::custom),
})
.transpose()
}

#[derive(Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub(crate) enum ToolCalls {
Many(Vec<ToolCall>),
One(ToolCall),
}
impl ToolCalls {
pub fn iter(&self) -> std::slice::Iter<'_, ToolCall> {
match self {
Self::Many(calls) => calls.iter(),
Self::One(call) => std::slice::from_ref(call).iter(),
}
/// Native formats use three alternative content fields. Explicit null is
/// still content and must not accidentally expose a lower-priority field.
pub fn message_content(&self) -> Value {
self.content
.as_ref()
.or(self.message.as_ref())
.or(self.text.as_ref())
.cloned()
.unwrap_or(Value::Null)
}
}

#[derive(Clone, Serialize, Deserialize)]
pub(crate) struct ToolCall {
#[serde(default, alias = "tool_name", alias = "toolName")]
pub name: Option<String>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
alias = "arguments",
alias = "input",
deserialize_with = "crate::agents::schema::deserialize_present"
)]
pub args: Option<Value>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
alias = "result",
deserialize_with = "crate::agents::schema::deserialize_present"
)]
pub output: Option<Value>,
#[serde(flatten, deserialize_with = "crate::json::deserialize_extensions")]
pub extra: Extensions,
pub fn created_at_ms(&self) -> Option<i64> {
chrono::DateTime::parse_from_rfc3339(self.created_at.as_deref()?)
.ok()
.map(|timestamp| timestamp.timestamp_millis())
}
}

#[cfg(test)]
Expand Down
Loading
Loading