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
4 changes: 2 additions & 2 deletions src-tauri/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 src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tauri-plugin-deep-link = "2"
# 编出来的东西不一样;而更要紧的是,打进 `.app` 的那个 twcore 二进制
# 必须和这里编译进去的协议镜像来自同一个 core 版本 —— 打包脚本正是从
# 这个 tag 去取二进制的(见 scripts/fetch-core.sh)。
tw-api = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.8.1" }
tw-api = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.8.2" }

anyhow = "1"
libc = "0.2"
Expand Down
5 changes: 5 additions & 0 deletions src-tauri/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,11 @@ impl ControlClient {
.await
}

/// 补问缺失、失败、过期的模型清单。**立刻回**:答案随 `models_changed` 到
pub async fn refresh_stale_models(&self) -> Result<tw_api::ModelsRefreshing> {
self.post_json("/models/refresh", &()).await
}

// ───────────────────────────────────────── ChatGPT 账号

/// 开始一次登录。回来的地址要在浏览器里打开,core 在本机等回调
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,7 @@ pub fn run() {
upstreams::preview_provider,
upstreams::provider_models,
upstreams::refresh_provider_models,
upstreams::refresh_stale_models,
upstreams::upstream_stats,
upstreams::create_proxy,
upstreams::update_proxy,
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/upstreams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ pub async fn refresh_provider_models(
.map_err(text)
}

/// 打开上游页时补问模型清单:还没有的、没问到的、过期的。不等上游回话。
#[tauri::command]
pub async fn refresh_stale_models(
state: tauri::State<'_, AppState>,
) -> Out<tw_api::ModelsRefreshing> {
state.control.refresh_stale_models().await.map_err(text)
}

/// 上游列表那几列统计:24 小时的请求与费用、首字节耗时、订阅额度。
///
/// **一起取。**列表上它们是同一行的几格,分几次 invoke 会让一行数字分几次
Expand Down
4 changes: 3 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ export default function App() {
seeded,
settled,
health,
models,
locallyAnswered,
rejected,
configVersion,
Expand Down Expand Up @@ -644,6 +645,7 @@ export default function App() {
*
* · 配置换了一份(`configVersion` 跟着 `config_reloaded` 走)
* · 某家上游熔断了或恢复了(`health`,core 现在会报)
* · 某家上游的模型清单开始获取或获取完了(`models`)
* · 守护状态变了 —— 重启之后监听地址和 pid 都可能不一样
* · 用户自己刚改完东西(`nudge`)
*/
Expand Down Expand Up @@ -691,7 +693,7 @@ export default function App() {
alive = false;
if (timer) clearTimeout(timer);
};
}, [configVersion, nudge, health, core, setStatus, setOv]);
}, [configVersion, nudge, health, models, core, setStatus, setOv]);

const c = describeCore(core);
/** 连上过、又断了。**只在这时候挂那条带子** */
Expand Down
26 changes: 26 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ export type CoreEvent =
* 列表上都看得见。没有它,界面只能定时重读整份配置概览才能发现。
*/
| { kind: "health_changed"; id: number; provider: string; state: "open" | "closed"; at_ms: number }
/**
* 某家上游的模型清单开始获取了,或者获取完了。后台获取(启动时、每天、
* 改了地址或凭据之后)不挂在任何一次调用上,界面靠它知道要重读概览。
*/
| { kind: "models_changed"; id: number; provider: string; at_ms: number }
/**
* 出站脱敏动手了。
*
Expand Down Expand Up @@ -308,6 +313,7 @@ export function applyEvent(rows: Map<number, RequestRow>, ev: CoreEvent): void {
case "scan_alert":
case "clients_changed":
case "health_changed":
case "models_changed":
// 都不进请求列表。配置事件、扫描告警、熔断状态说的都是「现在
// 什么情况」,而这张表装的是「刚才发生过什么」。App 单独接。
break;
Expand Down Expand Up @@ -894,6 +900,13 @@ export interface ProviderView {
models_only?: string[] | null;
/** `discovered` / `manual` / `none` */
model_source: string;
/** 最近一次向上游获取清单的结果。停用的上游不去获取,一直是 `pending` */
model_status: ModelStatus;
/** 正在获取。上一次的结果照常有效 */
model_fetching: boolean;
model_checked_at_ms?: number | null;
/** `no_list` / `failed` 的原因 */
model_error?: string | null;
/** 现在能服务的模型数,已按启用范围过滤。停用时是 0 */
model_count: number;
disabled: boolean;
Expand Down Expand Up @@ -1564,10 +1577,23 @@ export interface ProviderPreview {
}

/** 一个上游的模型清单 */
/**
* 获取模型清单的结果:还没获取、上游列出了、上游不提供清单、没问到。
* **和清单来源不是一回事** —— 没问到时清单可能来自手动清单。
*/
export type ModelStatus = "pending" | "listed" | "no_list" | "failed";

/** 打开上游页时补问:开始获取的是哪几家 */
export interface ModelsRefreshing {
providers: string[];
}

export interface ProviderModelsView {
provider: string;
/** `discovered` / `manual` / `none` */
source: string;
status: ModelStatus;
fetching: boolean;
checked_at_ms?: number | null;
error?: string | null;
models: ModelRow[];
Expand Down
Loading
Loading