Files
ssw__ipass/rust/crates/plugin-apix/src/lib.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

57 lines
1.7 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.
//! plugin-apix —— API 代理插件。
//!
//! 把外部 **API 供应商**的资产挂到网关下,复用 LLM 的 `sk_` 鉴权 + 配额 +
//! 用量统计(slot 带 `api/` 前缀,天然归组)。数据文件
//! `data/api-proxies.json`(含供应商真 Key,敏感级别等同 users.json)。
//!
//! ## 装配点(gateway)
//!
//! * `preconfig` —— 注册 `$apix_target` / `$apix_host` / `$apix_key` /
//! `$apix_body` / `$apix_probe_target` / `$apix_probe_body` 六件套
//! * `postconfig` —— 注册 ApiProxyHandler(access 阶段)
//! * `zone_load` —— 全量装载 `ax:` 代理表
//! * `dispatch_api` —— 认领 apix 管理端点与账号态端点
//!
//! ## 依赖说明
//!
//! 下行鉴权 / 配额在内核 `ipass_core::auth`;用量记账入口在
//! `plugin_llm::stats`(apix 与 LLM 共用同一片键空间,单一写入口防漂移)。
pub mod api;
pub mod apix;
pub mod config;
pub mod handlers;
pub mod models;
pub mod store;
use ngx::core::Status;
use ngx::ffi::{ngx_conf_t, ngx_http_request_t};
use ipass_core::plugin::Plugin;
pub struct ApixPlugin;
impl Plugin for ApixPlugin {
fn name(&self) -> &'static str {
"apix"
}
fn preconfig(&self, cf: *mut ngx_conf_t) -> bool {
// SAFETY: cf 由 nginx 传入且有效
unsafe { apix::preconfig(cf) }
}
fn postconfig(&self, cf: *mut ngx_conf_t) -> bool {
// SAFETY: cf 由 nginx 传入且有效
ngx::http::add_phase_handler::<handlers::ApiProxyHandler>(unsafe { &mut *cf }).is_ok()
}
fn dispatch_api(&self, r: *mut ngx_http_request_t) -> Option<Status> {
api::dispatch(r)
}
fn zone_load(&self) -> usize {
apix::reload_shm()
}
}