pub struct Client { /* private fields */ }Expand description
主 API 客户端。Clone 廉价(内部 Arc)。
Implementations§
Source§impl Client
impl Client
Sourcepub fn crabcode_byok(&self) -> CrabCodeByokClient
pub fn crabcode_byok(&self) -> CrabCodeByokClient
CrabCode 远控 BYO 模型密钥管理面(契约 §18.2)。对应 TS client.crabcodeByok getter。
Source§impl Client
impl Client
Sourcepub fn agent_runs(&self) -> AgentRunsClient
pub fn agent_runs(&self) -> AgentRunsClient
SDK-facing cloud agent run gateway。对应 TS client.agentRuns getter。
§Examples
let runs = client.agent_runs();
let run = runs
.create(
&AgentRunCreateRequest {
app_id: "crabdesign".into(),
input: "Create a landing page mockup".into(),
..Default::default()
},
None,
)
.await?;
println!("run_id = {}", run.run_id);Source§impl Client
impl Client
Sourcepub async fn get_balance(
&self,
signal: Option<CancellationToken>,
) -> Result<EntitlementBalance>
pub async fn get_balance( &self, signal: Option<CancellationToken>, ) -> Result<EntitlementBalance>
查询当前用户的权益余额(聚合)。对应 TS getBalance。
Sourcepub async fn get_balance_detail(
&self,
signal: Option<CancellationToken>,
) -> Result<BalanceDetail>
pub async fn get_balance_detail( &self, signal: Option<CancellationToken>, ) -> Result<BalanceDetail>
查询详细余额(含每条权益明细)。对应 TS getBalanceDetail。
Sourcepub async fn list_entitlements(
&self,
status: &str,
signal: Option<CancellationToken>,
) -> Result<Vec<EntitlementItem>>
pub async fn list_entitlements( &self, status: &str, signal: Option<CancellationToken>, ) -> Result<Vec<EntitlementItem>>
查询当前用户权益列表;status:“ACTIVE” / “EXPIRED” / “”(全部)。对应 TS listEntitlements。
Sourcepub async fn list_consume_records(
&self,
page: i64,
page_size: i64,
signal: Option<CancellationToken>,
) -> Result<ConsumeRecordPage>
pub async fn list_consume_records( &self, page: i64, page_size: i64, signal: Option<CancellationToken>, ) -> Result<ConsumeRecordPage>
查询核销记录(分页)。对应 TS listConsumeRecords。
Sourcepub async fn claim_monthly_free(
&self,
signal: Option<CancellationToken>,
) -> Result<EntitlementItem>
pub async fn claim_monthly_free( &self, signal: Option<CancellationToken>, ) -> Result<EntitlementItem>
领取当月免费额度 —— 幂等:已领取时返回已有权益。对应 TS claimMonthlyFree。
Sourcepub async fn get_by_model(
&self,
model_id: &str,
signal: Option<CancellationToken>,
) -> Result<ModelByQuotaResponse>
pub async fn get_by_model( &self, model_id: &str, signal: Option<CancellationToken>, ) -> Result<ModelByQuotaResponse>
查询当前用户在指定模型下的剩余 token(raw + ETU)。对应 TS getByModel。
Sourcepub async fn list_buckets(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<ModelBucket>>
pub async fn list_buckets( &self, signal: Option<CancellationToken>, ) -> Result<Vec<ModelBucket>>
列出当前用户的全部桶。对应 TS listBuckets。
Sourcepub async fn list_coefficients(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<ModelCoefficient>>
pub async fn list_coefficients( &self, signal: Option<CancellationToken>, ) -> Result<Vec<ModelCoefficient>>
拉取模型系数表;SDK 自带 8s TTL 内存缓存以减小调用风暴。对应 TS listCoefficients。
@deprecated 系数已退役,网关恒返回 []。
Sourcepub fn invalidate_coefficient_cache(&self)
pub fn invalidate_coefficient_cache(&self)
手动失效系数缓存(admin 调价后建议立即调一次)。对应 TS invalidateCoefficientCache。
@deprecated 系数已退役。
Source§impl Client
impl Client
Sourcepub async fn list_token_packages(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<TokenPackage>>
pub async fn list_token_packages( &self, signal: Option<CancellationToken>, ) -> Result<Vec<TokenPackage>>
获取商城流量包列表(兼容 yudao 分页和直接数组两种格式)。对应 TS listTokenPackages。
Sourcepub async fn get_token_package_detail(
&self,
package_id: &str,
signal: Option<CancellationToken>,
) -> Result<TokenPackage>
pub async fn get_token_package_detail( &self, package_id: &str, signal: Option<CancellationToken>, ) -> Result<TokenPackage>
获取流量包详情。对应 TS getTokenPackageDetail。
Sourcepub async fn buy_token_package(
&self,
package_id: &str,
payload: Option<&PayPayload>,
signal: Option<CancellationToken>,
) -> Result<BuyResponse>
pub async fn buy_token_package( &self, package_id: &str, payload: Option<&PayPayload>, signal: Option<CancellationToken>, ) -> Result<BuyResponse>
购买流量包(创建订单)。对应 TS buyTokenPackage。
Sourcepub async fn get_order_status(
&self,
order_id: &str,
signal: Option<CancellationToken>,
) -> Result<BuyResponse>
pub async fn get_order_status( &self, order_id: &str, signal: Option<CancellationToken>, ) -> Result<BuyResponse>
查询订单支付状态。对应 TS getOrderStatus。
Sourcepub async fn list_my_orders(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<OrderListItem>>
pub async fn list_my_orders( &self, signal: Option<CancellationToken>, ) -> Result<Vec<OrderListItem>>
查询我的订单列表。对应 TS listMyOrders。
Sourcepub async fn wait_for_payment(
&self,
order_id: &str,
poll_interval_ms: i64,
signal: Option<CancellationToken>,
) -> Result<BuyResponse>
pub async fn wait_for_payment( &self, order_id: &str, poll_interval_ms: i64, signal: Option<CancellationToken>, ) -> Result<BuyResponse>
轮询订单支付状态直到终态。对应 TS waitForPayment。
成功支付返回 BuyResponse;终态失败抛 Error::OrderTerminal。
终态判定基于 paymentStatus(回退 orderStatus)。poll_interval_ms <= 0 时默认 2 秒。
Source§impl Client
impl Client
Sourcepub async fn get_wallet_stats(
&self,
signal: Option<CancellationToken>,
) -> Result<WalletStats>
pub async fn get_wallet_stats( &self, signal: Option<CancellationToken>, ) -> Result<WalletStats>
获取钱包统计(余额/月消费/月充值)。对应 TS getWalletStats。
Sourcepub async fn get_wallet_transactions(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<Transaction>>
pub async fn get_wallet_transactions( &self, signal: Option<CancellationToken>, ) -> Result<Vec<Transaction>>
获取最近交易记录。对应 TS getWalletTransactions。
Source§impl Client
impl Client
Sourcepub async fn list_lawyers(
&self,
params: Option<&ListLawyersParams>,
signal: Option<CancellationToken>,
) -> Result<Vec<LawyerSummary>>
pub async fn list_lawyers( &self, params: Option<&ListLawyersParams>, signal: Option<CancellationToken>, ) -> Result<Vec<LawyerSummary>>
列出已认证律师(公开端点,仅 VERIFIED + ACTIVE;PII L3 字段已脱敏)。对应 TS listLawyers。
@experimental 对应后端 consumer 端点尚未实现;调用将返回 404。空 data → []。
Sourcepub async fn get_lawyer(
&self,
id: i64,
signal: Option<CancellationToken>,
) -> Result<LawyerSummary>
pub async fn get_lawyer( &self, id: i64, signal: Option<CancellationToken>, ) -> Result<LawyerSummary>
获取律师公开详情(脱敏)。对应 TS getLawyer。
@experimental 404 未实现。空 data → Err(lawyer {id} not found)。
Sourcepub async fn submit_case_lead(
&self,
req: &SubmitCaseLeadRequest,
signal: Option<CancellationToken>,
) -> Result<CaseLeadIdResult>
pub async fn submit_case_lead( &self, req: &SubmitCaseLeadRequest, signal: Option<CancellationToken>, ) -> Result<CaseLeadIdResult>
提交案件线索(登录态)。对应 TS submitCaseLead。
@experimental 404 未实现。空 data → 回退 {id:0}(TS ?? {id:0})。
Sourcepub async fn list_my_case_leads(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<CaseLead>>
pub async fn list_my_case_leads( &self, signal: Option<CancellationToken>, ) -> Result<Vec<CaseLead>>
我的案件线索列表。对应 TS listMyCaseLeads。@experimental 404 未实现。空 data → []。
Sourcepub async fn get_my_cases(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<CaseMatter>>
pub async fn get_my_cases( &self, signal: Option<CancellationToken>, ) -> Result<Vec<CaseMatter>>
我的案件列表(委托后)。对应 TS getMyCases。@experimental 404 未实现。空 data → []。
Sourcepub async fn book_consultation(
&self,
req: &BookConsultationRequest,
signal: Option<CancellationToken>,
) -> Result<BookConsultationResult>
pub async fn book_consultation( &self, req: &BookConsultationRequest, signal: Option<CancellationToken>, ) -> Result<BookConsultationResult>
预约法律咨询(sku_code 必填;lawyer_id 留空走 AI 推荐池)。对应 TS bookConsultation。
@experimental 404 未实现。空 data → 回退 {consultationId:0}。
Sourcepub async fn list_my_consultations(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<LegalConsultation>>
pub async fn list_my_consultations( &self, signal: Option<CancellationToken>, ) -> Result<Vec<LegalConsultation>>
我的咨询单列表。对应 TS listMyConsultations。@experimental 404 未实现。空 data → []。
Sourcepub async fn list_my_legal_orders(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<LegalServiceOrder>>
pub async fn list_my_legal_orders( &self, signal: Option<CancellationToken>, ) -> Result<Vec<LegalServiceOrder>>
我的法律服务订单列表。对应 TS listMyLegalOrders。@experimental 404 未实现。空 data → []。
Sourcepub async fn list_legal_skus(
&self,
region: Option<&str>,
signal: Option<CancellationToken>,
) -> Result<Vec<LegalServiceSku>>
pub async fn list_legal_skus( &self, region: Option<&str>, signal: Option<CancellationToken>, ) -> Result<Vec<LegalServiceSku>>
列出公开的 LEGAL_SERVICE SKU(匿名可调用,复用 dist_compliance_sku benefit_type=‘LEGAL_SERVICE’)。
对应 TS listLegalSKUs。
@experimental 404 未实现。强制拼 benefitType=LEGAL_SERVICE(bug-for-bug)。空 data → []。
Sourcepub async fn get_my_lawyer_credential_status(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<LawyerCredentialMyView>>
pub async fn get_my_lawyer_credential_status( &self, signal: Option<CancellationToken>, ) -> Result<Vec<LawyerCredentialMyView>>
律师自查执业证审核状态 —— 返回登录用户作为律师身份提交的所有 credential 列表。
普通用户(无 lawyer_profile)调返 [] 不抛。对应 TS getMyLawyerCredentialStatus。
端点 GET /api/casehall/lawyer-credentials/my(注意:TS 原样裸路径,经 doJSON 前缀 base)。
Source§impl Client
impl Client
Sourcepub fn chat_bridge(&self) -> ChatBridgeClient
pub fn chat_bridge(&self) -> ChatBridgeClient
第三方聊天 bridge 控制面(Phase 7B;契约 §6/§12/ADR-8)。对应 TS client.chatBridge getter。
守卫(最小授权三档,chat_bridge 不进 all_scopes):
- chat_bridge:read → list_integrations / get_integration / list_credentials
- chat_bridge:write → create_integration / update_integration_status / store_credential
- chat_bridge:rotate → rotate_credential / revoke_credential(高风险)
Source§impl Client
impl Client
Sourcepub fn compliance(&self) -> ComplianceClient
pub fn compliance(&self) -> ComplianceClient
SDK-facing compliance 域子客户端。对应 TS client.compliance getter。
§Examples
let cc = client.compliance();
let stats = cc.get_tsa_stats(None).await?; // TSA 只读统计视图Sourcepub fn compliance_url(&self, path: &str) -> String
pub fn compliance_url(&self, path: &str) -> String
Compliance API URL 拼接。compliance_base_url 已配置时直接拼接;未配置时默认
{server_url}/admin-api + path,匹配 Java compliance controller 的 /compliance/... 路径。
对应 TS complianceURL。不复用 api_url(后者强制 /api/v4)。
Source§impl Client
impl Client
Sourcepub fn new(cfg: Config) -> Result<Self>
pub fn new(cfg: Config) -> Result<Self>
同步构造(对应 TS constructor)。校验并归一化 URL;不预载 token(见 Client::create)。
§Examples
use acosmi::{Client, Config};
let client = Client::new(Config {
server_url: Some("https://acosmi.com".into()),
..Default::default()
})
.unwrap();
assert_eq!(client.base_url(), "https://acosmi.com");Sourcepub fn new_with_transport(
cfg: Config,
transport: Arc<dyn HttpTransport>,
) -> Result<Self>
pub fn new_with_transport( cfg: Config, transport: Arc<dyn HttpTransport>, ) -> Result<Self>
Construct with an exclusive custom HTTP transport. Config.http is ignored.
Inject a TokenStore separately when caller-owned persistence is required.
Sourcepub async fn create_with_transport(
cfg: Config,
transport: Arc<dyn HttpTransport>,
) -> Result<Self>
pub async fn create_with_transport( cfg: Config, transport: Arc<dyn HttpTransport>, ) -> Result<Self>
Construct with custom transport and load the configured token store.
Create a client with caller-owned durable token authority. Config.store is ignored. Missing is an unauthenticated client; load errors and Pending fail.
Sourcepub async fn create(cfg: Config) -> Result<Self>
pub async fn create(cfg: Config) -> Result<Self>
异步工厂(对应 TS Client.create)。从 store 预载 token;store 损坏静默忽略。
是否已持有 token(同步)。
Sourcepub fn server_url(&self) -> &str
pub fn server_url(&self) -> &str
网关 base URL。
Sourcepub fn compliance_base_url(&self) -> Option<&str>
pub fn compliance_base_url(&self) -> Option<&str>
compliance 端点 base override(None = 走默认 {server_url}/admin-api)。
Sourcepub fn api_base_url(&self) -> Option<&str>
pub fn api_base_url(&self) -> Option<&str>
业务 API 端点 base override(None = 走默认 server_url)。
Sourcepub fn oauth_metadata_profile(&self) -> OAuthMetadataProfile
pub fn oauth_metadata_profile(&self) -> OAuthMetadataProfile
OAuth 元数据 profile。
Sourcepub fn browser_refresh_mode(&self) -> BrowserRefreshMode
pub fn browser_refresh_mode(&self) -> BrowserRefreshMode
浏览器刷新模式。
Sourcepub fn refresh_proxy_url(&self) -> Option<&str>
pub fn refresh_proxy_url(&self) -> Option<&str>
refresh 代理 URL。
Sourcepub async fn login(
&self,
app_name: &str,
scopes: &[String],
signal: Option<CancellationToken>,
) -> Result<()>
pub async fn login( &self, app_name: &str, scopes: &[String], signal: Option<CancellationToken>, ) -> Result<()>
完整授权流程:发现 → 注册 → 授权(PKCE loopback)→ 换 token → 持久化。
对应 TS login。app_name 为桌面智能体名称;scopes 见 crate::auth::scopes 预设。
Sourcepub async fn login_with_handler(
&self,
app_name: &str,
scopes: &[String],
handler: Option<&(dyn Fn(LoginEvent) + Send + Sync)>,
opts: &LoginOptions,
signal: Option<CancellationToken>,
) -> Result<()>
pub async fn login_with_handler( &self, app_name: &str, scopes: &[String], handler: Option<&(dyn Fn(LoginEvent) + Send + Sync)>, opts: &LoginOptions, signal: Option<CancellationToken>, ) -> Result<()>
带事件回调的登录流程(CrabCode 使用)。对应 TS loginWithHandler。
handler 在以下时刻被调用:EVENT_AUTH_URL(授权 URL 就绪)/ EVENT_COMPLETE
(登录成功,tokens 已持久化)/ EVENT_ERROR(某步骤失败,附错误码)。
Sourcepub async fn logout(&self, signal: Option<CancellationToken>) -> Result<()>
pub async fn logout(&self, signal: Option<CancellationToken>) -> Result<()>
吊销 token 并清除本地存储。对应 TS logout。
Sourcepub async fn ensure_token(
&self,
signal: Option<CancellationToken>,
) -> Result<String>
pub async fn ensure_token( &self, signal: Option<CancellationToken>, ) -> Result<String>
确保有有效 access_token,过期则自动刷新。对应 TS ensureToken。
并发语义(对齐 TS withMu + storeWithLock + syncFromDisk + tokenReady):
- tokens==null 且 login 进行中 → 等
token_ready(配合signal取消);非进行中 → 报未授权。 - 未过期 → 直接返回(无锁路径)。
- 过期 → 双层串行:
mu(进程内单航班)+store.lock(跨进程临界区);进入临界区后 先store.load()重读磁盘(多进程 rotation 防 400),双检过期决定是否真刷新。
Sourcepub async fn force_refresh(
&self,
signal: Option<CancellationToken>,
) -> Result<()>
pub async fn force_refresh( &self, signal: Option<CancellationToken>, ) -> Result<()>
强制刷新 token(401 重试用)。对应 TS forceRefresh。
同 Self::ensure_token 的刷新路径:mu + store.lock + syncFromDisk。别的进程刚 rotation
过的话磁盘上是新 RT,本进程用磁盘新 RT 即可成功;否则用旧 RT 必撞 “refresh token not found” 400。
Pure authority read, never refreshes or resolves durable Pending. The host must first resolve uncertain transactions and actor/revision fencing. Calling this explicitly accepts that host reconciliation has completed.
Sourcepub fn api_url(&self, path: &str) -> String
pub fn api_url(&self, path: &str) -> String
业务 API URL 拼接。api_base_url 覆盖(未配置时 === server_url);尾段非 /api/v4 时追加。
对应 TS apiURL。
Sourcepub async fn list_models(
&self,
signal: Option<CancellationToken>,
include_locked: bool,
) -> Result<Vec<ManagedModel>>
pub async fn list_models( &self, signal: Option<CancellationToken>, include_locked: bool, ) -> Result<Vec<ManagedModel>>
获取可用的托管模型列表。对应 TS listModels。
不返回 entitlement-filter-status header;想据 fallback 状态显示降级提示请改用
Self::list_models_with_status。include_locked=true 请求全集模式(picker=1)。
Sourcepub async fn list_models_with_status(
&self,
signal: Option<CancellationToken>,
include_locked: bool,
) -> Result<(Vec<ManagedModel>, FilterStatus)>
pub async fn list_models_with_status( &self, signal: Option<CancellationToken>, include_locked: bool, ) -> Result<(Vec<ManagedModel>, FilterStatus)>
获取可用模型列表,同时返回 X-Entitlement-Filter-Status header。对应 TS listModelsWithStatus。
include_locked=true → 全集模式(picker=1,含越档 locked 模型供 picker 展示),
不写 model_cache(避免 locked 模型混入可用集);缺省模式照旧缓存。
Sourcepub async fn get_quota_summary(
&self,
signal: Option<CancellationToken>,
) -> Result<QuotaSummary>
pub async fn get_quota_summary( &self, signal: Option<CancellationToken>, ) -> Result<QuotaSummary>
查询当前用户账户级权益总览(v0.19+)。对应 TS getQuotaSummary。
Sourcepub async fn get_model_capabilities(
&self,
model_id: &str,
signal: Option<CancellationToken>,
) -> Result<ModelCapabilities>
pub async fn get_model_capabilities( &self, model_id: &str, signal: Option<CancellationToken>, ) -> Result<ModelCapabilities>
查询单个模型的能力矩阵。优先从 list_models 缓存读取,miss 时刷新一次。
对应 TS getModelCapabilities。仍 miss → 零值(与 Go/TS 一致)。
Sourcepub async fn ensure_model_cached(
&self,
model_id: &str,
signal: Option<CancellationToken>,
) -> Result<ManagedModel>
pub async fn ensure_model_cached( &self, model_id: &str, signal: Option<CancellationToken>, ) -> Result<ManagedModel>
确保指定 model_id 的 ManagedModel 已在缓存中。对应 TS ensureModelCached。
- 缓存命中 → 直接返回;
- 未命中 → 调
list_models刷新一次; - 刷新后仍未命中 →
Error::ModelNotFound。
根因修复(对齐 TS):消除未预热场景下 provider="anthropic" 硬编码回退,
该回退会让 non-anthropic 模型被按 Anthropic 格式编码并打到错误端点。
Sourcepub async fn build_chat_request(
&self,
model_id: &str,
req: &ChatRequest,
signal: Option<CancellationToken>,
) -> Result<(String, Adapter)>
pub async fn build_chat_request( &self, model_id: &str, req: &ChatRequest, signal: Option<CancellationToken>, ) -> Result<(String, Adapter)>
构建完整聊天请求体(v0.5.0 adapter 模式)。对应 TS buildChatRequest。
ensure_model_cached → get_adapter_for_model → adapter build_request_body。
返回 (JSON body 字符串, adapter)。
Sourcepub async fn chat(
&self,
model_id: &str,
req: &ChatRequest,
signal: Option<CancellationToken>,
) -> Result<ChatResponse>
pub async fn chat( &self, model_id: &str, req: &ChatRequest, signal: Option<CancellationToken>, ) -> Result<ChatResponse>
同步聊天(适合短回复)。对应 TS chat。
响应的 token_remaining / call_remaining / model_token_remaining* 来自服务端响应头
(反映结算后余额);缺失保持 ChatResponse 默认哨兵。v0.5.0 按 provider 路由
/anthropic 或 /chat。
§Examples
let req = ChatRequest {
messages: Some(vec![ChatMessage { role: "user".into(), content: "Hi".into() }]),
max_tokens: Some(256),
..Default::default()
};
let resp = client.chat("claude-opus-4-7", &req, None).await?;
println!("{:?}", resp.content);Sourcepub async fn chat_with_options(
&self,
model_id: &str,
req: &ChatRequest,
signal: Option<CancellationToken>,
options: ChatOptions,
) -> Result<ChatResponse>
pub async fn chat_with_options( &self, model_id: &str, req: &ChatRequest, signal: Option<CancellationToken>, options: ChatOptions, ) -> Result<ChatResponse>
Chat with optional billing response observation.
Sourcepub async fn embeddings(
&self,
model_id: &str,
req: &EmbeddingRequest,
signal: Option<CancellationToken>,
) -> Result<EmbeddingResponse>
pub async fn embeddings( &self, model_id: &str, req: &EmbeddingRequest, signal: Option<CancellationToken>, ) -> Result<EmbeddingResponse>
向量(同步)。POST /managed-models/:id/embeddings。对应 TS embeddings。
model_id 须为向量托管模型(capabilities.supports_embedding=true,上游接 DashScope)。
响应为 OpenAI /v1/embeddings 标准格式(网关直通,无 {code,data} 包装)。
Sourcepub async fn rerank(
&self,
model_id: &str,
req: &RerankRequest,
signal: Option<CancellationToken>,
) -> Result<RerankResponse>
pub async fn rerank( &self, model_id: &str, req: &RerankRequest, signal: Option<CancellationToken>, ) -> Result<RerankResponse>
重排序(同步)。POST /managed-models/:id/rerank。对应 TS rerank。
model_id 须为重排序托管模型(capabilities.supports_rerank=true,上游接 DashScope)。
统一扁平契约;响应 { results: [{ index, relevance_score, document? }], usage, model }
(网关已把上游原生嵌套 / OpenAI 兼容扁平两线路归一化,无 {code,data} 包装)。
Sourcepub async fn generate_image(
&self,
model_id: &str,
req: &ImageGenerationRequest,
signal: Option<CancellationToken>,
) -> Result<ImageGenerationResponse>
pub async fn generate_image( &self, model_id: &str, req: &ImageGenerationRequest, signal: Option<CancellationToken>, ) -> Result<ImageGenerationResponse>
图片生成(同步)。POST /managed-models/:id/images/generations。对应 TS generateImage。
model_id 须为图片生成托管模型(capabilities.supports_image_generation=true)。
图片生成耗时常超 30s,用 chat 同级超时(11min)容纳上游。
Sourcepub async fn generate_video(
&self,
model_id: &str,
req: &VideoGenerationRequest,
signal: Option<CancellationToken>,
) -> Result<VideoTaskResponse>
pub async fn generate_video( &self, model_id: &str, req: &VideoGenerationRequest, signal: Option<CancellationToken>, ) -> Result<VideoTaskResponse>
创建视频生成任务(异步)。POST /managed-models/:id/videos/generations。对应 TS generateVideo。
返回 task_id;用 Self::poll_video_task 轮询直到 status=completed。
上报真物理量(视频秒数)需在 poll_video_task 时回传 duration。
预算用 CHAT_REQUEST_TIMEOUT_MS 而非控制面默认值:这是生成端点,上游排队 +
提交返回 task_id 本身就可能超过 30s。2026-08-06 前这里传的是
DEFAULT_JSON_TIMEOUT_MS,与同文件 chat / embeddings / rerank /
generate_image / chat_messages 五个兄弟不一致;同一处错误在 TS 与 Go 两个
兄弟 SDK 上同时存在,故本文件底部加了结构闸门。
Sourcepub async fn poll_video_task(
&self,
model_id: &str,
task_id: &str,
duration_seconds: Option<i64>,
signal: Option<CancellationToken>,
) -> Result<VideoTaskResponse>
pub async fn poll_video_task( &self, model_id: &str, task_id: &str, duration_seconds: Option<i64>, signal: Option<CancellationToken>, ) -> Result<VideoTaskResponse>
轮询视频任务状态。GET /managed-models/:id/videos/tasks/:taskId。对应 TS pollVideoTask。
duration_seconds(创建时的时长,秒)透传给网关在 completed 时上报用量。
Sourcepub async fn chat_messages(
&self,
model_id: &str,
req: &ChatRequest,
signal: Option<CancellationToken>,
) -> Result<AnthropicResponse>
pub async fn chat_messages( &self, model_id: &str, req: &ChatRequest, signal: Option<CancellationToken>, ) -> Result<AnthropicResponse>
Anthropic 原生格式同步聊天。对应 TS chatMessages。
v0.5.0 按 provider 路由:Anthropic → chat_messages_anthropic(POST /anthropic);
其他厂商 → chat_messages_openai(POST /chat,响应转换为 AnthropicResponse)。
Sourcepub async fn chat_messages_with_options(
&self,
model_id: &str,
req: &ChatRequest,
signal: Option<CancellationToken>,
options: ChatOptions,
) -> Result<AnthropicResponse>
pub async fn chat_messages_with_options( &self, model_id: &str, req: &ChatRequest, signal: Option<CancellationToken>, options: ChatOptions, ) -> Result<AnthropicResponse>
Chat with optional billing response observation.
Sourcepub fn chat_stream(
&self,
model_id: &str,
req: &ChatRequest,
signal: Option<CancellationToken>,
) -> impl Stream<Item = Result<StreamEvent>>
pub fn chat_stream( &self, model_id: &str, req: &ChatRequest, signal: Option<CancellationToken>, ) -> impl Stream<Item = Result<StreamEvent>>
流式聊天(SSE),返回 impl Stream<Item = Result<StreamEvent>>。对应 TS chatStream。
🔴 计费安全红线:流式路径只走单次 do_request(内部),绝不经 retry 包装——
SSE 一旦部分写出,重试 = 双 token + 重复消息 = 双扣。401 仅做一次 force_refresh 重试
(retried guard 防递归)。signal 经 select! 接入 SSE 读循环。
Sourcepub fn chat_stream_with_options(
&self,
model_id: &str,
req: &ChatRequest,
signal: Option<CancellationToken>,
options: ChatOptions,
) -> impl Stream<Item = Result<StreamEvent>>
pub fn chat_stream_with_options( &self, model_id: &str, req: &ChatRequest, signal: Option<CancellationToken>, options: ChatOptions, ) -> impl Stream<Item = Result<StreamEvent>>
The corresponding stream with optional activity and billing ID observers.
Sourcepub fn chat_stream_with_usage(
&self,
model_id: &str,
req: &ChatRequest,
signal: Option<CancellationToken>,
) -> impl Stream<Item = Result<ChatUsageEvent>>
pub fn chat_stream_with_usage( &self, model_id: &str, req: &ChatRequest, signal: Option<CancellationToken>, ) -> impl Stream<Item = Result<ChatUsageEvent>>
流式聊天 + 自动解析结算 / 搜索来源事件。对应 TS chatStreamWithUsage。
tagged 流:Settle(结算)/ Sources(搜索来源)/ Content(内容增量)。
started 控制事件被过滤;failed/error 事件经 parse_stream_error 转 Error::Stream。
Sourcepub fn chat_stream_with_usage_with_options(
&self,
model_id: &str,
req: &ChatRequest,
signal: Option<CancellationToken>,
options: ChatOptions,
) -> impl Stream<Item = Result<ChatUsageEvent>>
pub fn chat_stream_with_usage_with_options( &self, model_id: &str, req: &ChatRequest, signal: Option<CancellationToken>, options: ChatOptions, ) -> impl Stream<Item = Result<ChatUsageEvent>>
The corresponding stream with optional activity and billing ID observers.
Sourcepub fn chat_messages_stream(
&self,
model_id: &str,
req: &ChatRequest,
signal: Option<CancellationToken>,
) -> impl Stream<Item = Result<StreamEvent>>
pub fn chat_messages_stream( &self, model_id: &str, req: &ChatRequest, signal: Option<CancellationToken>, ) -> impl Stream<Item = Result<StreamEvent>>
Anthropic 原生格式流式聊天(SSE)。对应 TS chatMessagesStream。
调用 POST /managed-models/:id/anthropic(Anthropic 路由)或 /chat(OpenAI 路由,
经 OpenAIStreamConverter 转 Anthropic 兼容事件)。同样只走 do_request,绝不重试。
Sourcepub fn chat_messages_stream_with_options(
&self,
model_id: &str,
req: &ChatRequest,
signal: Option<CancellationToken>,
options: ChatOptions,
) -> impl Stream<Item = Result<StreamEvent>>
pub fn chat_messages_stream_with_options( &self, model_id: &str, req: &ChatRequest, signal: Option<CancellationToken>, options: ChatOptions, ) -> impl Stream<Item = Result<StreamEvent>>
The corresponding stream with optional activity and billing ID observers.
Source§impl Client
impl Client
Sourcepub fn set_defensive_sanitize(&self, cfg: MinimalSanitizeConfig)
pub fn set_defensive_sanitize(&self, cfg: MinimalSanitizeConfig)
配置请求前的底线防御(体积 / deny-list / 深度)。传 None(或空 cfg is_empty())
关闭。并发安全,可在任意时间调用。对应 TS setDefensiveSanitize。
TS 侧传 {}(全零字段)即关闭;Rust 侧将空 cfg 归一为 None(等价语义 + 维持
apply_request_sanitizers 的零开销 early-return)。
Sourcepub fn set_auto_strip_ephemeral_history(&self, on: bool)
pub fn set_auto_strip_ephemeral_history(&self, on: bool)
开启后,每次请求前 SDK 会从 raw_messages 中剥除带 acosmi_ephemeral:true 标记的 block,
并联动剥除引用已剥 tool_use 的 tool_result,避免 provider 报 “tool_use_id 不存在”。
对应 TS setAutoStripEphemeralHistory。
Source§impl Client
impl Client
Sourcepub async fn list_my_enterprises(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<EnterpriseSummary>>
pub async fn list_my_enterprises( &self, signal: Option<CancellationToken>, ) -> Result<Vec<EnterpriseSummary>>
列出我所在的企业。对应 TS listMyEnterprises。空 data → []。
Sourcepub async fn get_enterprise(
&self,
id: i64,
signal: Option<CancellationToken>,
) -> Result<EnterpriseSummary>
pub async fn get_enterprise( &self, id: i64, signal: Option<CancellationToken>, ) -> Result<EnterpriseSummary>
获取企业详情。对应 TS getEnterprise。空 data → Err(enterprise {id} not found)。
Sourcepub async fn invite_member(
&self,
req: &InviteMemberRequest,
signal: Option<CancellationToken>,
) -> Result<EnterpriseMember>
pub async fn invite_member( &self, req: &InviteMemberRequest, signal: Option<CancellationToken>, ) -> Result<EnterpriseMember>
邀请成员加入(P6a 简化:直接 add,OWNER/ADMIN 可调用)。对应 TS inviteMember。
空 data → Err(invite member failed)。
Sourcepub async fn list_enterprise_members(
&self,
enterprise_id: i64,
signal: Option<CancellationToken>,
) -> Result<Vec<EnterpriseMember>>
pub async fn list_enterprise_members( &self, enterprise_id: i64, signal: Option<CancellationToken>, ) -> Result<Vec<EnterpriseMember>>
列出企业成员。对应 TS listEnterpriseMembers。空 data → []。
Sourcepub async fn list_org_subscriptions(
&self,
enterprise_id: i64,
signal: Option<CancellationToken>,
) -> Result<Vec<OrgSubscription>>
pub async fn list_org_subscriptions( &self, enterprise_id: i64, signal: Option<CancellationToken>, ) -> Result<Vec<OrgSubscription>>
列出企业订阅。对应 TS listOrgSubscriptions。空 data → []。
Sourcepub async fn list_seats(
&self,
org_subscription_id: i64,
signal: Option<CancellationToken>,
) -> Result<Vec<OrgSeat>>
pub async fn list_seats( &self, org_subscription_id: i64, signal: Option<CancellationToken>, ) -> Result<Vec<OrgSeat>>
列出订阅下的席位(1 订阅 N 席,seat_no 1..N)。对应 TS listSeats。空 data → []。
Sourcepub async fn assign_seat(
&self,
req: &AssignSeatRequest,
signal: Option<CancellationToken>,
) -> Result<OrgSeat>
pub async fn assign_seat( &self, req: &AssignSeatRequest, signal: Option<CancellationToken>, ) -> Result<OrgSeat>
分配席位(月度变更次数 +1,超 3 次返 41xxx 业务码)。对应 TS assignSeat。
空 data → Err(assign seat failed)。
Sourcepub async fn revoke_seat(
&self,
seat_id: i64,
note: Option<&str>,
signal: Option<CancellationToken>,
) -> Result<()>
pub async fn revoke_seat( &self, seat_id: i64, note: Option<&str>, signal: Option<CancellationToken>, ) -> Result<()>
收回席位(席位状态 → AVAILABLE,累计用量保留)。对应 TS revokeSeat(返回 void)。
Sourcepub async fn get_org_consume_report(
&self,
enterprise_id: i64,
signal: Option<CancellationToken>,
) -> Result<OrgConsumeReport>
pub async fn get_org_consume_report( &self, enterprise_id: i64, signal: Option<CancellationToken>, ) -> Result<OrgConsumeReport>
企业消耗汇总(订阅维度池子合计)。对应 TS getOrgConsumeReport。
空 data → 回退全零 report(TS 默认对象)。
Sourcepub async fn get_my_enterprise_kyc_status(
&self,
signal: Option<CancellationToken>,
) -> Result<EnterpriseKycMyStatusView>
pub async fn get_my_enterprise_kyc_status( &self, signal: Option<CancellationToken>, ) -> Result<EnterpriseKycMyStatusView>
企业 OWNER 自查 KYC 状态。对应 TS getMyEnterpriseKycStatus。
用户不是任何企业 OWNER 时返空 view(enterpriseId 缺省)。空 data → 默认({})。
Source§impl Client
impl Client
Sourcepub async fn request_refund(
&self,
req: &RequestRefundInput,
signal: Option<CancellationToken>,
) -> Result<RefundRecord>
pub async fn request_refund( &self, req: &RequestRefundInput, signal: Option<CancellationToken>, ) -> Result<RefundRecord>
申请退款(决策 15:按 policyCode 自动判定;NO_REFUND 即时拒)。对应 TS requestRefund。
空 data → Err(refund/request: empty response)。
Sourcepub async fn list_my_refunds(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<RefundRecord>>
pub async fn list_my_refunds( &self, signal: Option<CancellationToken>, ) -> Result<Vec<RefundRecord>>
我的退款记录。对应 TS listMyRefunds。空 data → []。
Sourcepub async fn request_invoice(
&self,
req: &RequestInvoiceInput,
signal: Option<CancellationToken>,
) -> Result<Invoice>
pub async fn request_invoice( &self, req: &RequestInvoiceInput, signal: Option<CancellationToken>, ) -> Result<Invoice>
申请开票。对应 TS requestInvoice。空 data → Err(invoice/request: empty response)。
Sourcepub async fn list_my_invoices(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<Invoice>>
pub async fn list_my_invoices( &self, signal: Option<CancellationToken>, ) -> Result<Vec<Invoice>>
我的发票列表。对应 TS listMyInvoices。空 data → []。
Sourcepub async fn initiate_corporate_transfer(
&self,
req: &InitiateCorporateTransferInput,
signal: Option<CancellationToken>,
) -> Result<InitiateCorporateTransferResult>
pub async fn initiate_corporate_transfer( &self, req: &InitiateCorporateTransferInput, signal: Option<CancellationToken>, ) -> Result<InitiateCorporateTransferResult>
发起对公转账(决策 14)。对应 TS initiateCorporateTransfer。
服务端创建 INITIATED 记录,返回销售名片二维码 + 销售企微 ID + 财务邮箱。
空 data → Err(corporate-transfer/initiate: empty response)。
Sourcepub async fn upload_corporate_transfer_proof(
&self,
id: i64,
proof_url: &str,
signal: Option<CancellationToken>,
) -> Result<bool>
pub async fn upload_corporate_transfer_proof( &self, id: i64, proof_url: &str, signal: Option<CancellationToken>, ) -> Result<bool>
上传对公转账凭证 URL。对应 TS uploadCorporateTransferProof。
bug-for-bug:后端契约是 @RequestParam("proofUrl"),走 query 参数(非 body);
encodeURIComponent 直拼 path。空 data → false(TS ?? false)。
Sourcepub async fn list_my_corporate_transfers(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<CorporateTransfer>>
pub async fn list_my_corporate_transfers( &self, signal: Option<CancellationToken>, ) -> Result<Vec<CorporateTransfer>>
我的对公转账记录。对应 TS listMyCorporateTransfers。空 data → []。
Source§impl Client
impl Client
Sourcepub async fn list_notifications(
&self,
page: i64,
page_size: i64,
type_filter: &str,
signal: Option<CancellationToken>,
) -> Result<NotificationList>
pub async fn list_notifications( &self, page: i64, page_size: i64, type_filter: &str, signal: Option<CancellationToken>, ) -> Result<NotificationList>
分页查询通知列表。对应 TS listNotifications。
Sourcepub async fn get_unread_count(
&self,
signal: Option<CancellationToken>,
) -> Result<i64>
pub async fn get_unread_count( &self, signal: Option<CancellationToken>, ) -> Result<i64>
获取未读通知数量。对应 TS getUnreadCount。
Sourcepub async fn mark_notification_read(
&self,
id: &str,
signal: Option<CancellationToken>,
) -> Result<()>
pub async fn mark_notification_read( &self, id: &str, signal: Option<CancellationToken>, ) -> Result<()>
标记单条通知已读。对应 TS markNotificationRead。
Sourcepub async fn mark_all_notifications_read(
&self,
signal: Option<CancellationToken>,
) -> Result<()>
pub async fn mark_all_notifications_read( &self, signal: Option<CancellationToken>, ) -> Result<()>
标记全部通知已读。对应 TS markAllNotificationsRead。
Sourcepub async fn delete_notification(
&self,
id: &str,
signal: Option<CancellationToken>,
) -> Result<()>
pub async fn delete_notification( &self, id: &str, signal: Option<CancellationToken>, ) -> Result<()>
删除通知。对应 TS deleteNotification。
Sourcepub async fn register_device(
&self,
reg: &DeviceRegistration,
signal: Option<CancellationToken>,
) -> Result<()>
pub async fn register_device( &self, reg: &DeviceRegistration, signal: Option<CancellationToken>, ) -> Result<()>
注册推送设备 token。对应 TS registerDevice。
@experimental 网关尚未提供 /devices/* 与 /notification-preferences/* 端点,调用将 404。
后端实现落地前请勿在生产使用。
Sourcepub async fn unregister_device(
&self,
token: &str,
signal: Option<CancellationToken>,
) -> Result<()>
pub async fn unregister_device( &self, token: &str, signal: Option<CancellationToken>, ) -> Result<()>
注销推送设备 token。对应 TS unregisterDevice。
@experimental 见 Self::register_device。
Sourcepub async fn list_notification_preferences(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<NotificationPreference>>
pub async fn list_notification_preferences( &self, signal: Option<CancellationToken>, ) -> Result<Vec<NotificationPreference>>
获取通知偏好设置。对应 TS listNotificationPreferences。
@experimental 见 Self::register_device。
Sourcepub async fn update_notification_preference(
&self,
type_code: &str,
pref: &NotificationPreference,
signal: Option<CancellationToken>,
) -> Result<()>
pub async fn update_notification_preference( &self, type_code: &str, pref: &NotificationPreference, signal: Option<CancellationToken>, ) -> Result<()>
更新通知偏好。对应 TS updateNotificationPreference。
@experimental 见 Self::register_device。
Source§impl Client
impl Client
Sourcepub async fn connect(
&self,
cfg: WSConfig,
signal: Option<CancellationToken>,
) -> Result<()>
pub async fn connect( &self, cfg: WSConfig, signal: Option<CancellationToken>, ) -> Result<()>
建立 WebSocket 长连接 —— 等待首次连接成功或 abort。对应 TS connect。
Sourcepub async fn disconnect(&self)
pub async fn disconnect(&self)
优雅断开 WebSocket 连接。对应 TS disconnect。
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
WebSocket 是否已连接。对应 TS isConnected。
Source§impl Client
impl Client
Sourcepub async fn get_pricing_config(
&self,
key: Option<&str>,
signal: Option<CancellationToken>,
) -> Result<PricingConfig>
pub async fn get_pricing_config( &self, key: Option<&str>, signal: Option<CancellationToken>, ) -> Result<PricingConfig>
查询公开业务参数。对应 TS getPricingConfig。
不传 key → 默认返三件(tk_to_fen_ratio / usd_cny_rate / freezone_reset_timezone);
传 key(白名单内)→ 仅返该 key。空 data → 空 map(TS ?? {})。
Sourcepub async fn list_public_models(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<PublicModelSummary>>
pub async fn list_public_models( &self, signal: Option<CancellationToken>, ) -> Result<Vec<PublicModelSummary>>
公开模型列表(P3 商品中心会重做;P1 后端 stub 返空数组)。对应 TS listPublicModels。
Sourcepub async fn list_compliance_skus(
&self,
region: Option<&str>,
signal: Option<CancellationToken>,
) -> Result<Vec<ComplianceSku>>
pub async fn list_compliance_skus( &self, region: Option<&str>, signal: Option<CancellationToken>, ) -> Result<Vec<ComplianceSku>>
列出 csign 公开 SKU(匿名可调用)。对应 TS listComplianceSkus。
region:CN / OS / GLOBAL(空 fallback CN,同时返回 GLOBAL)。
Sourcepub async fn quote_compliance(
&self,
sku_code: &str,
quantity: Option<i64>,
region: Option<&str>,
signal: Option<CancellationToken>,
) -> Result<ComplianceQuoteResponse>
pub async fn quote_compliance( &self, sku_code: &str, quantity: Option<i64>, region: Option<&str>, signal: Option<CancellationToken>, ) -> Result<ComplianceQuoteResponse>
匿名估价(无用户态,不查覆盖余额,仅返回 overage 价 × 数量)。对应 TS quoteCompliance。
sku_code 必填(空 → Err)。空 data → 回退 {sku_code, available:false}(TS ?? {...})。
Source§impl Client
impl Client
Sourcepub async fn list_products_by_family(
&self,
family: Option<ProductFamily>,
audience: Option<Audience>,
region: Option<RegionScope>,
signal: Option<CancellationToken>,
) -> Result<Vec<Product>>
pub async fn list_products_by_family( &self, family: Option<ProductFamily>, audience: Option<Audience>, region: Option<RegionScope>, signal: Option<CancellationToken>, ) -> Result<Vec<Product>>
按商品族查询在售商品。全参可空(后端无过滤即返全部在售)。对应 TS listProductsByFamily。
region 命中时同时返回 GLOBAL 商品。空 data → 空数组。
Sourcepub async fn get_product_by_slug(
&self,
slug: &str,
region: Option<RegionScope>,
signal: Option<CancellationToken>,
) -> Result<Product>
pub async fn get_product_by_slug( &self, slug: &str, region: Option<RegionScope>, signal: Option<CancellationToken>, ) -> Result<Product>
按 slug 查询单个在售商品。slug = biz_product_id(UNIQUE)。对应 TS getProductBySlug。
找不到或已下架 → 抛 Error::Http 404(或空 data → Err)。
Source§impl Client
impl Client
Sourcepub async fn browse_skill_store(
&self,
query: &SkillStoreQuery,
signal: Option<CancellationToken>,
) -> Result<Vec<SkillStoreItem>>
pub async fn browse_skill_store( &self, query: &SkillStoreQuery, signal: Option<CancellationToken>, ) -> Result<Vec<SkillStoreItem>>
浏览技能商店(公共端点,无需认证)。对应 TS browseSkillStore。
Sourcepub async fn browse_skills(
&self,
page: i64,
page_size: i64,
category: &str,
keyword: &str,
tag: &str,
source: &str,
signal: Option<CancellationToken>,
) -> Result<SkillBrowseResponse>
pub async fn browse_skills( &self, page: i64, page_size: i64, category: &str, keyword: &str, tag: &str, source: &str, signal: Option<CancellationToken>, ) -> Result<SkillBrowseResponse>
浏览公共技能商店(V3 分页接口)。对应 TS browseSkills。
Sourcepub async fn browse_skills_list(
&self,
page: i64,
page_size: i64,
category: &str,
keyword: &str,
tag: &str,
source: &str,
signal: Option<CancellationToken>,
) -> Result<SkillBrowseListResponse>
pub async fn browse_skills_list( &self, page: i64, page_size: i64, category: &str, keyword: &str, tag: &str, source: &str, signal: Option<CancellationToken>, ) -> Result<SkillBrowseListResponse>
轻量浏览公共技能商店(fields=minimal,响应体积缩减 90%+)。对应 TS browseSkillsList。
Sourcepub async fn get_skill_detail(
&self,
skill_id: &str,
signal: Option<CancellationToken>,
) -> Result<SkillStoreItem>
pub async fn get_skill_detail( &self, skill_id: &str, signal: Option<CancellationToken>, ) -> Result<SkillStoreItem>
获取技能商店中某个技能的详情(公共端点)。对应 TS getSkillDetail。
Sourcepub async fn resolve_skill(
&self,
key: &str,
signal: Option<CancellationToken>,
) -> Result<SkillStoreItem>
pub async fn resolve_skill( &self, key: &str, signal: Option<CancellationToken>, ) -> Result<SkillStoreItem>
按 key 精确查找公共技能(公共端点)。对应 TS resolveSkill。
Sourcepub async fn install_skill(
&self,
skill_id: &str,
signal: Option<CancellationToken>,
) -> Result<SkillStoreItem>
pub async fn install_skill( &self, skill_id: &str, signal: Option<CancellationToken>, ) -> Result<SkillStoreItem>
安装技能到当前用户的租户空间(需 OAuth scope: skill_store)。对应 TS installSkill。
Sourcepub async fn download_skill(
&self,
skill_id: &str,
signal: Option<CancellationToken>,
) -> Result<SkillDownload>
pub async fn download_skill( &self, skill_id: &str, signal: Option<CancellationToken>, ) -> Result<SkillDownload>
下载技能 ZIP 包(公共端点,双模式)。对应 TS downloadSkill。
有 token 时自动附带(享受无限流),无 token 时匿名(受限流)。
50MB 上限走 MAX_DOWNLOAD_SIZE + crate::core::http::read_limited_result;限流时抛 Error::RateLimit。
Sourcepub async fn upload_skill(
&self,
zip_data: Vec<u8>,
scope: &str,
intent: &str,
signal: Option<CancellationToken>,
) -> Result<SkillStoreItem>
pub async fn upload_skill( &self, zip_data: Vec<u8>, scope: &str, intent: &str, signal: Option<CancellationToken>, ) -> Result<SkillStoreItem>
上传技能 ZIP 包。对应 TS uploadSkill。
scope:"TENANT"。intent:"PERSONAL"(仅自己用)或"PUBLIC_INTENT"(走认证→公开)。
Sourcepub async fn get_skill_summary(
&self,
signal: Option<CancellationToken>,
) -> Result<SkillSummary>
pub async fn get_skill_summary( &self, signal: Option<CancellationToken>, ) -> Result<SkillSummary>
获取技能统计概览。对应 TS getSkillSummary。
Sourcepub async fn certify_skill(
&self,
skill_id: &str,
signal: Option<CancellationToken>,
) -> Result<()>
pub async fn certify_skill( &self, skill_id: &str, signal: Option<CancellationToken>, ) -> Result<()>
触发技能认证管线(异步)。对应 TS certifySkill。
Sourcepub async fn get_certification_status(
&self,
skill_id: &str,
signal: Option<CancellationToken>,
) -> Result<CertificationStatus>
pub async fn get_certification_status( &self, skill_id: &str, signal: Option<CancellationToken>, ) -> Result<CertificationStatus>
查询技能认证状态。对应 TS getCertificationStatus。
Sourcepub async fn generate_skill(
&self,
req: &GenerateSkillRequest,
signal: Option<CancellationToken>,
) -> Result<GenerateSkillResult>
pub async fn generate_skill( &self, req: &GenerateSkillRequest, signal: Option<CancellationToken>, ) -> Result<GenerateSkillResult>
根据自然语言描述生成技能定义(基于独立 LLM)。对应 TS generateSkill。
Sourcepub async fn optimize_skill(
&self,
req: &OptimizeSkillRequest,
signal: Option<CancellationToken>,
) -> Result<OptimizeSkillResult>
pub async fn optimize_skill( &self, req: &OptimizeSkillRequest, signal: Option<CancellationToken>, ) -> Result<OptimizeSkillResult>
优化已有技能定义。对应 TS optimizeSkill。
Sourcepub async fn validate_skill(
&self,
skill_name: &str,
signal: Option<CancellationToken>,
) -> Result<()>
pub async fn validate_skill( &self, skill_name: &str, signal: Option<CancellationToken>, ) -> Result<()>
校验技能定义正确性。对应 TS validateSkill。
Source§impl Client
impl Client
Sourcepub async fn list_tools(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<ToolView>>
pub async fn list_tools( &self, signal: Option<CancellationToken>, ) -> Result<Vec<ToolView>>
获取当前用户租户下的所有工具(Skill 优先 + Plugin 兜底)。对应 TS listTools。
Source§impl Client
impl Client
Sourcepub async fn list_plans(
&self,
audience: Option<SubscriptionAudience>,
signal: Option<CancellationToken>,
) -> Result<Vec<SubscriptionPlan>>
pub async fn list_plans( &self, audience: Option<SubscriptionAudience>, signal: Option<CancellationToken>, ) -> Result<Vec<SubscriptionPlan>>
列出当前可售订阅计划;audience 可选过滤。对应 TS listPlans。
空 data → 空数组(对应 TS Array.isArray(resp.data) ? resp.data : [])。
Sourcepub async fn get_membership(
&self,
signal: Option<CancellationToken>,
) -> Result<Membership>
pub async fn get_membership( &self, signal: Option<CancellationToken>, ) -> Result<Membership>
查询当前用户会员/订阅概览(C 端会员中心)。对应 TS getMembership。
无活跃订阅时 has_active=false / is_free=true。
Sourcepub async fn get_subscription_tier(
&self,
signal: Option<CancellationToken>,
) -> Result<SubscriptionTier>
pub async fn get_subscription_tier( &self, signal: Option<CancellationToken>, ) -> Result<SubscriptionTier>
由活跃权益推导订阅层级(free/pro)。对应 TS getSubscriptionTier。
Sourcepub async fn subscription_precheck(
&self,
signal: Option<CancellationToken>,
) -> Result<SubscriptionPrecheckResult>
pub async fn subscription_precheck( &self, signal: Option<CancellationToken>, ) -> Result<SubscriptionPrecheckResult>
订阅支付前绑定硬闸。对应 TS subscriptionPrecheck。
返回 {ok:true} 表示已绑定手机/邮箱可放行支付;未绑定时网关返回 HTTP 403 + 业务码
41001(crate::Error::Http / crate::Error::Business),调用方据此引导用户先绑定联系方式。
Sourcepub async fn list_user_subscriptions(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<Membership>>
pub async fn list_user_subscriptions( &self, signal: Option<CancellationToken>, ) -> Result<Vec<Membership>>
@deprecated 网关无订阅列表端点;现委托 get_membership():有活跃订阅返回单元素数组,
否则空数组。对应 TS listUserSubscriptions。
Sourcepub async fn get_plan_by_code(
&self,
plan_code: &str,
signal: Option<CancellationToken>,
) -> Result<Option<SubscriptionPlan>>
pub async fn get_plan_by_code( &self, plan_code: &str, signal: Option<CancellationToken>, ) -> Result<Option<SubscriptionPlan>>
按 planCode 精确取单个可售订阅计划(复用 list_plans 客户端过滤)。对应 TS getPlanByCode。
未命中返回 None。空 plan_code 直接返回 None。
Source§impl Client
impl Client
Sourcepub async fn submit_bug_report(
&self,
report_data: &Value,
signal: Option<CancellationToken>,
) -> Result<BugReportResult>
pub async fn submit_bug_report( &self, report_data: &Value, signal: Option<CancellationToken>, ) -> Result<BugReportResult>
上报一份 CrabCode bug 报告。对应 TS submitBugReport。
report_data 是任意 JSON 可编码值,后端只解析为 map 做脱敏 + 字段抽取。
错误:
Error::Http401 —— token 过期(内部已做一次 refresh + retry,仍 401 抛出)。Error::Http403 type=“permission_error”(含 “Custom data retention settings”) —— 用户所在组织 ZDR,拒绝收集。Error::Http400 type=“invalid_request_error” —— content 不是合法 JSON。Error::Http429 —— 限流 20/h/user。Error::Network—— 传输层错误。
Sourcepub async fn get_bug_report(
&self,
bug_id: &str,
signal: Option<CancellationToken>,
) -> Result<BugView>
pub async fn get_bug_report( &self, bug_id: &str, signal: Option<CancellationToken>, ) -> Result<BugView>
取公开 ViewModel(无需 auth,任意人凭 ID 可读)。对应 TS getBugReport。
错误:
Error::Http404 —— bug 不存在或被软删。Error::Http429 —— 限流 60/min/IP。Error::Network—— 传输层错误。