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
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ categories = ["network-programming", "web-programming::http-server"]

# 二进制走 CalVer,crate 走 SemVer —— 两者是两回事,卖给不同的人。
# 这里是 crate 的版本。
version = "0.90.0"
version = "0.91.0"

[workspace.dependencies]
# ── 内部 crate ───────────────────────────────────────────
Expand Down
41 changes: 41 additions & 0 deletions crates/tw-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4023,6 +4023,10 @@ pub struct ProxyTest {
pub struct AliasInput {
pub name: String,
pub models: Vec<String>,
/// Hide target original names in client discovery only. Omission preserves an
/// existing alias's setting; new aliases default to false.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub hide_originals: Option<bool>,
}

/// 新建或保存一个别名(`POST /aliases`、`PUT /aliases/{name}`)。保存时名字可以改:
Expand Down Expand Up @@ -4050,6 +4054,9 @@ pub struct AliasModel {
#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
pub struct AliasView {
pub name: String,
/// Hide original model names from client discovery without changing access.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub hide_originals: bool,
/// 按书写顺序
pub models: Vec<AliasModel>,
/// 每家能服务它的上游实际发出的名称,按配置里的顺序。停用的上游不在里面;没有清单
Expand Down Expand Up @@ -4086,6 +4093,10 @@ pub struct AliasSuggestion {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
pub struct AliasesView {
/// This Core understands hide_originals. Absent/false on older servers;
/// clients must not offer the setting there.
#[serde(default)]
pub hide_originals_supported: bool,
/// 按书写顺序
pub aliases: Vec<AliasView>,
/// 同一个模型在不同上游上叫不同名称的几组。**只认 Claude**:各家清单里的名称归一之后
Expand Down Expand Up @@ -4123,6 +4134,10 @@ pub struct AliasPreview {
/// 规则同 [`AliasesView::suggestions`]。列表里已经有的名称、已经有列表里某个名称的
/// 上游不在里面
pub same_model: Vec<PinnedModel>,
/// Original names hidden by this alias in an unrestricted client catalog.
/// Actual client lists still apply protocol, availability and key permissions.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub hidden_originals: Vec<String>,
}

/// 一条写着这个名称的规则。
Expand Down Expand Up @@ -4305,6 +4320,10 @@ pub struct KnownModel {
pub alias: Option<Vec<String>>,
/// 列出了这个模型名的别名,按别名表的顺序。别名自己这一项是空的
pub aliases: Vec<String>,
/// Available aliases that hide this original name in an unrestricted client
/// catalog. Admins still receive the complete directory and original IDs.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub hidden_by: Vec<String>,
}

/// 聚合类端点的时间窗(`GET /summary`、`/latency`)。**缺省是「今天」而不是
Expand Down Expand Up @@ -7179,6 +7198,28 @@ pub struct PluginRunView {

#[cfg(test)]
mod tests {
#[test]
fn alias_discovery_fields_are_additive_and_keep_omission_distinct_from_false() {
let omitted: AliasInput =
serde_json::from_str(r#"{"name":"short","models":["raw"]}"#).unwrap();
assert_eq!(omitted.hide_originals, None);
let clear: AliasInput =
serde_json::from_str(r#"{"name":"short","models":["raw"],"hide_originals":false}"#)
.unwrap();
assert_eq!(clear.hide_originals, Some(false));
assert!(
serde_json::to_value(&omitted)
.unwrap()
.get("hide_originals")
.is_none()
);
let old: AliasesView = serde_json::from_str(r#"{"aliases":[],"suggestions":[]}"#).unwrap();
assert!(!old.hide_originals_supported);
let known: KnownModel =
serde_json::from_str(r#"{"id":"raw","providers":[],"aliases":[]}"#).unwrap();
assert!(known.hidden_by.is_empty());
}

/// 手动加入例外的请求带着原值:调试输出里不能有它
#[test]
fn an_exception_request_does_not_print_its_value() {
Expand Down
Loading
Loading