Add Epiphany pressure reflection

This commit is contained in:
Meta Vens 2026-04-26 04:24:55 +01:00
commit e1298e58a9
42 changed files with 986 additions and 90 deletions

View file

@ -4736,6 +4736,13 @@
"last": {
"$ref": "#/definitions/TokenUsageBreakdown"
},
"modelAutoCompactTokenLimit": {
"format": "int64",
"type": [
"integer",
"null"
]
},
"modelContextWindow": {
"format": "int64",
"type": [

View file

@ -15032,6 +15032,101 @@
],
"type": "string"
},
"ThreadEpiphanyPressure": {
"properties": {
"basis": {
"$ref": "#/definitions/v2/ThreadEpiphanyPressureBasis"
},
"level": {
"$ref": "#/definitions/v2/ThreadEpiphanyPressureLevel"
},
"modelAutoCompactTokenLimit": {
"format": "int64",
"type": [
"integer",
"null"
]
},
"modelContextWindow": {
"format": "int64",
"type": [
"integer",
"null"
]
},
"note": {
"type": "string"
},
"ratioPerMille": {
"format": "uint32",
"minimum": 0.0,
"type": [
"integer",
"null"
]
},
"remainingTokens": {
"format": "int64",
"type": [
"integer",
"null"
]
},
"shouldPrepareCompaction": {
"type": "boolean"
},
"status": {
"$ref": "#/definitions/v2/ThreadEpiphanyPressureStatus"
},
"usedTokens": {
"format": "int64",
"type": [
"integer",
"null"
]
}
},
"required": [
"basis",
"level",
"note",
"shouldPrepareCompaction",
"status"
],
"type": "object"
},
"ThreadEpiphanyPressureBasis": {
"enum": [
"unknown",
"autoCompactLimit",
"modelContextWindow"
],
"type": "string"
},
"ThreadEpiphanyPressureLevel": {
"enum": [
"unknown",
"low",
"elevated",
"high",
"critical"
],
"type": "string"
},
"ThreadEpiphanyPressureSource": {
"enum": [
"stored",
"live"
],
"type": "string"
},
"ThreadEpiphanyPressureStatus": {
"enum": [
"unknown",
"ready"
],
"type": "string"
},
"ThreadEpiphanyRetrieveIndexSummary": {
"properties": {
"dirtyPaths": {
@ -15283,6 +15378,7 @@
"distill",
"context",
"jobs",
"pressure",
"propose",
"promote",
"update"
@ -17813,6 +17909,13 @@
"last": {
"$ref": "#/definitions/v2/TokenUsageBreakdown"
},
"modelAutoCompactTokenLimit": {
"format": "int64",
"type": [
"integer",
"null"
]
},
"modelContextWindow": {
"format": "int64",
"type": [

View file

@ -12919,6 +12919,101 @@
],
"type": "string"
},
"ThreadEpiphanyPressure": {
"properties": {
"basis": {
"$ref": "#/definitions/ThreadEpiphanyPressureBasis"
},
"level": {
"$ref": "#/definitions/ThreadEpiphanyPressureLevel"
},
"modelAutoCompactTokenLimit": {
"format": "int64",
"type": [
"integer",
"null"
]
},
"modelContextWindow": {
"format": "int64",
"type": [
"integer",
"null"
]
},
"note": {
"type": "string"
},
"ratioPerMille": {
"format": "uint32",
"minimum": 0.0,
"type": [
"integer",
"null"
]
},
"remainingTokens": {
"format": "int64",
"type": [
"integer",
"null"
]
},
"shouldPrepareCompaction": {
"type": "boolean"
},
"status": {
"$ref": "#/definitions/ThreadEpiphanyPressureStatus"
},
"usedTokens": {
"format": "int64",
"type": [
"integer",
"null"
]
}
},
"required": [
"basis",
"level",
"note",
"shouldPrepareCompaction",
"status"
],
"type": "object"
},
"ThreadEpiphanyPressureBasis": {
"enum": [
"unknown",
"autoCompactLimit",
"modelContextWindow"
],
"type": "string"
},
"ThreadEpiphanyPressureLevel": {
"enum": [
"unknown",
"low",
"elevated",
"high",
"critical"
],
"type": "string"
},
"ThreadEpiphanyPressureSource": {
"enum": [
"stored",
"live"
],
"type": "string"
},
"ThreadEpiphanyPressureStatus": {
"enum": [
"unknown",
"ready"
],
"type": "string"
},
"ThreadEpiphanyRetrieveIndexSummary": {
"properties": {
"dirtyPaths": {
@ -13170,6 +13265,7 @@
"distill",
"context",
"jobs",
"pressure",
"propose",
"promote",
"update"
@ -15700,6 +15796,13 @@
"last": {
"$ref": "#/definitions/TokenUsageBreakdown"
},
"modelAutoCompactTokenLimit": {
"format": "int64",
"type": [
"integer",
"null"
]
},
"modelContextWindow": {
"format": "int64",
"type": [

View file

@ -6,6 +6,13 @@
"last": {
"$ref": "#/definitions/TokenUsageBreakdown"
},
"modelAutoCompactTokenLimit": {
"format": "int64",
"type": [
"integer",
"null"
]
},
"modelContextWindow": {
"format": "int64",
"type": [

View file

@ -0,0 +1,8 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ThreadEpiphanyPressureBasis } from "./ThreadEpiphanyPressureBasis";
import type { ThreadEpiphanyPressureLevel } from "./ThreadEpiphanyPressureLevel";
import type { ThreadEpiphanyPressureStatus } from "./ThreadEpiphanyPressureStatus";
export type ThreadEpiphanyPressure = { status: ThreadEpiphanyPressureStatus, level: ThreadEpiphanyPressureLevel, basis: ThreadEpiphanyPressureBasis, usedTokens?: bigint | null, modelContextWindow?: bigint | null, modelAutoCompactTokenLimit?: bigint | null, remainingTokens?: bigint | null, ratioPerMille?: number | null, shouldPrepareCompaction: boolean, note: string, };

View file

@ -0,0 +1,5 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type ThreadEpiphanyPressureBasis = "unknown" | "autoCompactLimit" | "modelContextWindow";

View file

@ -0,0 +1,5 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type ThreadEpiphanyPressureLevel = "unknown" | "low" | "elevated" | "high" | "critical";

View file

@ -0,0 +1,5 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type ThreadEpiphanyPressureSource = "stored" | "live";

View file

@ -0,0 +1,5 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type ThreadEpiphanyPressureStatus = "unknown" | "ready";

View file

@ -2,4 +2,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type ThreadEpiphanySceneAction = "index" | "retrieve" | "distill" | "context" | "jobs" | "propose" | "promote" | "update";
export type ThreadEpiphanySceneAction = "index" | "retrieve" | "distill" | "context" | "jobs" | "pressure" | "propose" | "promote" | "update";

View file

@ -3,4 +3,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { TokenUsageBreakdown } from "./TokenUsageBreakdown";
export type ThreadTokenUsage = { total: TokenUsageBreakdown, last: TokenUsageBreakdown, modelContextWindow: number | null, };
export type ThreadTokenUsage = { total: TokenUsageBreakdown, last: TokenUsageBreakdown, modelContextWindow: number | null, modelAutoCompactTokenLimit?: number | null, };

View file

@ -326,6 +326,11 @@ export type { ThreadEpiphanyJob } from "./ThreadEpiphanyJob";
export type { ThreadEpiphanyJobKind } from "./ThreadEpiphanyJobKind";
export type { ThreadEpiphanyJobStatus } from "./ThreadEpiphanyJobStatus";
export type { ThreadEpiphanyJobsSource } from "./ThreadEpiphanyJobsSource";
export type { ThreadEpiphanyPressure } from "./ThreadEpiphanyPressure";
export type { ThreadEpiphanyPressureBasis } from "./ThreadEpiphanyPressureBasis";
export type { ThreadEpiphanyPressureLevel } from "./ThreadEpiphanyPressureLevel";
export type { ThreadEpiphanyPressureSource } from "./ThreadEpiphanyPressureSource";
export type { ThreadEpiphanyPressureStatus } from "./ThreadEpiphanyPressureStatus";
export type { ThreadEpiphanyRetrieveIndexSummary } from "./ThreadEpiphanyRetrieveIndexSummary";
export type { ThreadEpiphanyRetrieveResult } from "./ThreadEpiphanyRetrieveResult";
export type { ThreadEpiphanyRetrieveResultKind } from "./ThreadEpiphanyRetrieveResultKind";

View file

@ -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 {

View file

@ -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,
}
}
}