Add Epiphany pressure reflection
This commit is contained in:
parent
d93cc8fcb5
commit
e1298e58a9
42 changed files with 986 additions and 90 deletions
|
|
@ -351,6 +351,11 @@ client_request_definitions! {
|
|||
params: v2::ThreadEpiphanyContextParams,
|
||||
response: v2::ThreadEpiphanyContextResponse,
|
||||
},
|
||||
#[experimental("thread/epiphany/pressure")]
|
||||
ThreadEpiphanyPressure => "thread/epiphany/pressure" {
|
||||
params: v2::ThreadEpiphanyPressureParams,
|
||||
response: v2::ThreadEpiphanyPressureResponse,
|
||||
},
|
||||
#[experimental("thread/epiphany/index")]
|
||||
ThreadEpiphanyIndex => "thread/epiphany/index" {
|
||||
params: v2::ThreadEpiphanyIndexParams,
|
||||
|
|
@ -1663,6 +1668,7 @@ mod tests {
|
|||
v2::ThreadEpiphanySceneAction::Index,
|
||||
v2::ThreadEpiphanySceneAction::Retrieve,
|
||||
v2::ThreadEpiphanySceneAction::Distill,
|
||||
v2::ThreadEpiphanySceneAction::Pressure,
|
||||
v2::ThreadEpiphanySceneAction::Update,
|
||||
v2::ThreadEpiphanySceneAction::Propose,
|
||||
v2::ThreadEpiphanySceneAction::Promote,
|
||||
|
|
@ -1743,6 +1749,7 @@ mod tests {
|
|||
"index",
|
||||
"retrieve",
|
||||
"distill",
|
||||
"pressure",
|
||||
"update",
|
||||
"propose",
|
||||
"promote"
|
||||
|
|
@ -1927,6 +1934,57 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_thread_epiphany_pressure_response() -> Result<()> {
|
||||
let response = ClientResponse::ThreadEpiphanyPressure {
|
||||
request_id: RequestId::Integer(8),
|
||||
response: v2::ThreadEpiphanyPressureResponse {
|
||||
thread_id: "thr_123".to_string(),
|
||||
source: v2::ThreadEpiphanyPressureSource::Live,
|
||||
pressure: v2::ThreadEpiphanyPressure {
|
||||
status: v2::ThreadEpiphanyPressureStatus::Ready,
|
||||
level: v2::ThreadEpiphanyPressureLevel::High,
|
||||
basis: v2::ThreadEpiphanyPressureBasis::AutoCompactLimit,
|
||||
used_tokens: Some(92_000),
|
||||
model_context_window: Some(128_000),
|
||||
model_auto_compact_token_limit: Some(100_000),
|
||||
remaining_tokens: Some(8_000),
|
||||
ratio_per_mille: Some(920),
|
||||
should_prepare_compaction: true,
|
||||
note: "Pressure is derived from the model auto-compact token limit."
|
||||
.to_string(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
assert_eq!(response.id(), &RequestId::Integer(8));
|
||||
assert_eq!(response.method(), "thread/epiphany/pressure");
|
||||
assert_eq!(
|
||||
json!({
|
||||
"method": "thread/epiphany/pressure",
|
||||
"id": 8,
|
||||
"response": {
|
||||
"threadId": "thr_123",
|
||||
"source": "live",
|
||||
"pressure": {
|
||||
"status": "ready",
|
||||
"level": "high",
|
||||
"basis": "autoCompactLimit",
|
||||
"usedTokens": 92000,
|
||||
"modelContextWindow": 128000,
|
||||
"modelAutoCompactTokenLimit": 100000,
|
||||
"remainingTokens": 8000,
|
||||
"ratioPerMille": 920,
|
||||
"shouldPrepareCompaction": true,
|
||||
"note": "Pressure is derived from the model auto-compact token limit."
|
||||
}
|
||||
}
|
||||
}),
|
||||
serde_json::to_value(&response)?,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_thread_epiphany_retrieve_response() -> Result<()> {
|
||||
let response = ClientResponse::ThreadEpiphanyRetrieve {
|
||||
|
|
@ -2827,6 +2885,18 @@ mod tests {
|
|||
assert_eq!(reason, Some("thread/epiphany/context"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thread_epiphany_pressure_is_marked_experimental() {
|
||||
let request = ClientRequest::ThreadEpiphanyPressure {
|
||||
request_id: RequestId::Integer(1),
|
||||
params: v2::ThreadEpiphanyPressureParams {
|
||||
thread_id: "thr_123".to_string(),
|
||||
},
|
||||
};
|
||||
let reason = crate::experimental_api::ExperimentalApi::experimental_reason(&request);
|
||||
assert_eq!(reason, Some("thread/epiphany/pressure"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thread_epiphany_index_is_marked_experimental() {
|
||||
let request = ClientRequest::ThreadEpiphanyIndex {
|
||||
|
|
|
|||
|
|
@ -3990,6 +3990,7 @@ pub enum ThreadEpiphanySceneAction {
|
|||
Distill,
|
||||
Context,
|
||||
Jobs,
|
||||
Pressure,
|
||||
Propose,
|
||||
Promote,
|
||||
Update,
|
||||
|
|
@ -4277,6 +4278,84 @@ pub struct ThreadEpiphanyContextMissing {
|
|||
pub evidence_ids: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct ThreadEpiphanyPressureParams {
|
||||
pub thread_id: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct ThreadEpiphanyPressureResponse {
|
||||
pub thread_id: String,
|
||||
pub source: ThreadEpiphanyPressureSource,
|
||||
pub pressure: ThreadEpiphanyPressure,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub enum ThreadEpiphanyPressureSource {
|
||||
Stored,
|
||||
Live,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct ThreadEpiphanyPressure {
|
||||
pub status: ThreadEpiphanyPressureStatus,
|
||||
pub level: ThreadEpiphanyPressureLevel,
|
||||
pub basis: ThreadEpiphanyPressureBasis,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional = nullable)]
|
||||
pub used_tokens: Option<i64>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional = nullable)]
|
||||
pub model_context_window: Option<i64>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional = nullable)]
|
||||
pub model_auto_compact_token_limit: Option<i64>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional = nullable)]
|
||||
pub remaining_tokens: Option<i64>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional = nullable)]
|
||||
pub ratio_per_mille: Option<u32>,
|
||||
pub should_prepare_compaction: bool,
|
||||
pub note: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub enum ThreadEpiphanyPressureStatus {
|
||||
Unknown,
|
||||
Ready,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub enum ThreadEpiphanyPressureLevel {
|
||||
Unknown,
|
||||
Low,
|
||||
Elevated,
|
||||
High,
|
||||
Critical,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub enum ThreadEpiphanyPressureBasis {
|
||||
Unknown,
|
||||
AutoCompactLimit,
|
||||
ModelContextWindow,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
|
|
@ -5103,6 +5182,9 @@ pub struct ThreadTokenUsage {
|
|||
// TODO(aibrahim): make this not optional
|
||||
#[ts(type = "number | null")]
|
||||
pub model_context_window: Option<i64>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(type = "number | null", optional)]
|
||||
pub model_auto_compact_token_limit: Option<i64>,
|
||||
}
|
||||
|
||||
impl From<CoreTokenUsageInfo> for ThreadTokenUsage {
|
||||
|
|
@ -5111,6 +5193,7 @@ impl From<CoreTokenUsageInfo> for ThreadTokenUsage {
|
|||
total: value.total_token_usage.into(),
|
||||
last: value.last_token_usage.into(),
|
||||
model_context_window: value.model_context_window,
|
||||
model_auto_compact_token_limit: value.model_auto_compact_token_limit,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue