Use shared service tier type in app-server protocol

This commit is contained in:
Ahmed Ibrahim
2026-05-03 07:24:43 +03:00
parent 405339b5d0
commit 6aaeebcecd
11 changed files with 38 additions and 125 deletions
@@ -11323,7 +11323,7 @@
"type": "string"
},
"id": {
"$ref": "#/definitions/v2/ServiceTierId"
"$ref": "#/definitions/v2/ServiceTier"
},
"name": {
"type": "string"
@@ -14258,13 +14258,7 @@
"type": "object"
},
"ServiceTier": {
"enum": [
"fast",
"flex"
],
"type": "string"
},
"ServiceTierId": {
"description": "String-backed service tier identifier. Known values include `priority` and `flex`, but other backend-provided ids are allowed.",
"type": "string"
},
"SessionMigration": {
@@ -7976,7 +7976,7 @@
"type": "string"
},
"id": {
"$ref": "#/definitions/ServiceTierId"
"$ref": "#/definitions/ServiceTier"
},
"name": {
"type": "string"
@@ -12144,13 +12144,7 @@
"type": "object"
},
"ServiceTier": {
"enum": [
"fast",
"flex"
],
"type": "string"
},
"ServiceTierId": {
"description": "String-backed service tier identifier. Known values include `priority` and `flex`, but other backend-provided ids are allowed.",
"type": "string"
},
"SessionMigration": {
@@ -135,7 +135,7 @@
"type": "string"
},
"id": {
"$ref": "#/definitions/ServiceTierId"
"$ref": "#/definitions/ServiceTier"
},
"name": {
"type": "string"
@@ -204,7 +204,8 @@
],
"type": "object"
},
"ServiceTierId": {
"ServiceTier": {
"description": "String-backed service tier identifier. Known values include `priority` and `flex`, but other backend-provided ids are allowed.",
"type": "string"
}
},
@@ -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 ServiceTier = "fast" | "flex";
export type ServiceTier = string;
@@ -1,6 +1,6 @@
// 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 { ServiceTierId } from "./ServiceTierId";
import type { ServiceTier } from "../ServiceTier";
export type ModelServiceTier = { id: ServiceTierId, name: string, description: string, };
export type ModelServiceTier = { id: ServiceTier, name: string, description: string, };
@@ -1,5 +0,0 @@
// 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 ServiceTierId = string;
@@ -242,7 +242,6 @@ export type { ModelAvailabilityNux } from "./ModelAvailabilityNux";
export type { ModelListParams } from "./ModelListParams";
export type { ModelListResponse } from "./ModelListResponse";
export type { ModelServiceTier } from "./ModelServiceTier";
export type { ServiceTierId } from "./ServiceTierId";
export type { ModelProviderCapabilitiesReadParams } from "./ModelProviderCapabilitiesReadParams";
export type { ModelProviderCapabilitiesReadResponse } from "./ModelProviderCapabilitiesReadResponse";
export type { ModelRerouteReason } from "./ModelRerouteReason";
@@ -25,10 +25,8 @@ use codex_protocol::config_types::ForcedLoginMethod;
use codex_protocol::config_types::ModeKind;
use codex_protocol::config_types::Personality;
use codex_protocol::config_types::ReasoningSummary;
use codex_protocol::config_types::SERVICE_TIER_FLEX;
use codex_protocol::config_types::SERVICE_TIER_PRIORITY;
use codex_protocol::config_types::SandboxMode as CoreSandboxMode;
use codex_protocol::config_types::ServiceTier as CoreServiceTier;
pub use codex_protocol::config_types::ServiceTier;
use codex_protocol::config_types::Verbosity;
use codex_protocol::config_types::WebSearchMode;
use codex_protocol::config_types::WebSearchToolConfig;
@@ -124,60 +122,6 @@ use serde_with::serde_as;
use thiserror::Error;
use ts_rs::TS;
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "lowercase")]
#[ts(export)]
pub enum ServiceTier {
Fast,
Flex,
}
impl From<ServiceTier> for CoreServiceTier {
fn from(value: ServiceTier) -> Self {
match value {
ServiceTier::Fast => SERVICE_TIER_PRIORITY.into(),
ServiceTier::Flex => SERVICE_TIER_FLEX.into(),
}
}
}
impl TryFrom<&CoreServiceTier> for ServiceTier {
type Error = ();
fn try_from(value: &CoreServiceTier) -> Result<Self, Self::Error> {
if value.as_ref() == SERVICE_TIER_PRIORITY {
Ok(ServiceTier::Fast)
} else if value.as_ref() == SERVICE_TIER_FLEX {
Ok(ServiceTier::Flex)
} else {
Err(())
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(transparent)]
#[ts(type = "string", export_to = "v2/")]
pub struct ServiceTierId(pub String);
impl From<ServiceTierId> for CoreServiceTier {
fn from(value: ServiceTierId) -> Self {
Self::from(value.0)
}
}
impl From<CoreServiceTier> for ServiceTierId {
fn from(value: CoreServiceTier) -> Self {
Self(value.to_string())
}
}
impl From<&CoreServiceTier> for ServiceTierId {
fn from(value: &CoreServiceTier) -> Self {
Self(value.to_string())
}
}
// Macro to declare a camelCased API v2 enum mirroring a core enum which
// tends to use either snake_case or kebab-case.
macro_rules! v2_enum_from_core {
@@ -2570,7 +2514,7 @@ impl From<CoreModelAvailabilityNux> for ModelAvailabilityNux {
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ModelServiceTier {
pub id: ServiceTierId,
pub id: ServiceTier,
pub name: String,
pub description: String,
}
@@ -2578,7 +2522,7 @@ pub struct ModelServiceTier {
impl From<CoreModelServiceTier> for ModelServiceTier {
fn from(value: CoreModelServiceTier) -> Self {
Self {
id: value.id.into(),
id: value.id,
name: value.name,
description: value.description,
}
@@ -2588,7 +2532,7 @@ impl From<CoreModelServiceTier> for ModelServiceTier {
impl From<ModelServiceTier> for CoreModelServiceTier {
fn from(value: ModelServiceTier) -> Self {
Self {
id: value.id.into(),
id: value.id,
name: value.name,
description: value.description,
}