Files
ipass__ipass/rust/crates/plugin-apix/src/models.rs
T
admin 85ea0a1531 refactor(plugin): P4 拆 plugin-apix —— API 代理迁入独立插件,过渡期路由清空
- plugin-apix 新 crate:apix/handlers/api/config/models/store
- ApiProxy/ApiProxyStore、api-proxies.json 读写、ax: 键空间与 APIX_* 常量自内核迁入
- ApiProxyHandler 与 $apix_* 六变量注册归 ApixPlugin;用量记账仍走 plugin_llm::stats(同一片键空间、单一写入口)
- gateway 路由表只剩 trend 组合端点(需 users+upstreams+apix 三方名册)
- 行为等价:262 项回归全绿(gateway 102 + llm 160)
2026-09-13 12:16:47 +08:00

67 lines
2.4 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! API 代理持久化模型(`api-proxies.json`:以 slug 为 key)。
//!
//! 字段名与旧版 `data/api-proxies.json` **逐字对应**,以便新版直接接管旧数据文件。
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
/// API 代理表(`api-proxies.json`)。
///
/// 与 `llm-upstreams.json` 同构:每条记录 = 一个供应商(自带基址与密钥),
/// 由 `slug` 区分。调用方访问 `/apix/<slug>?参数=值`,网关用本记录里的密钥
/// 转发到供应商、并把响应原样返回。不同供应商彼此独立、互不耦合。
///
/// `key` 是供应商真 Key,**敏感级别等同 `users.json`**(data/ 已 gitignore)。
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApiProxyStore {
/// slug → 代理映射
#[serde(default)]
pub items: BTreeMap<String, ApiProxy>,
}
impl Default for ApiProxyStore {
fn default() -> Self {
Self { items: BTreeMap::new() }
}
}
/// 单个 API 代理条目:指向某一家供应商的一个可调用的资产。
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApiProxy {
/// 供应商侧的资产 id(如 `searxng-search`),决定具体调用哪个资产
pub asset_id: String,
/// 供应商名称(仅展示用,管理员自填,例如 `provider-x` / 客户自定)
#[serde(default)]
pub supplier: String,
/// 供应商基址,如 `https://api.example.com`
#[serde(default)]
pub base: String,
/// 供应商 API Key(`ak_...`)。留空 = 未配置,热路径直接 503。
/// **敏感**:写盘与回显都按密钥处理,管理台只回显掩码。
#[serde(default)]
pub key: String,
/// 展示名(中文)
#[serde(default)]
pub name: String,
/// 一句话说明
#[serde(default)]
pub desc: String,
/// **声明式参数清单**(如 `["q"]`)。
///
/// 只用于给调用方看的文档(管理台把 `?q=关键词` 拼出来、账号态接口回显),
/// 转发时**不按它过滤**——过滤要靠读请求体,而 access 阶段读不到。
/// 供应商侧自己会拒绝不认识的参数,拦在网关意义不大。
#[serde(default)]
pub params: Vec<String>,
#[serde(default = "default_true")]
pub enabled: bool,
#[serde(default)]
pub note: String,
#[serde(default)]
pub created_at: i64,
}
fn default_true() -> bool {
true
}