Skip to content

refactor(core,ai,+8): HTTP 管道 helper 下沉 core::api + ai common 私有化(#330)#345

Merged
foxzool merged 1 commit into
mainfrom
feature/20260705/ai-common-sink-to-core
Jul 5, 2026
Merged

refactor(core,ai,+8): HTTP 管道 helper 下沉 core::api + ai common 私有化(#330)#345
foxzool merged 1 commit into
mainfrom
feature/20260705/ai-common-sink-to-core

Conversation

@foxzool

@foxzool foxzool commented Jul 5, 2026

Copy link
Copy Markdown
Owner

What

issue #330(补审 #313 confirmed "通用 HTTP helper 下沉缺失"):serialize_params/extract_response_data/ensure_success 此前在 10 个业务 crate 各有一份 common/api_utils.rs(locality 失守),统一到 openlark_core::api canonical。

改动

core::api 加 canonicalapi/helpers.rs,rich 诊断:operation/resource/request_id via map_context):

  • serialize_params(params, context)extract_response_data(response, context)ensure_success(response, context)

10 crate re-export(签名不变,调用点零改动——crate::common::api_utils::serialize_params resolve 到 re-export 即 core canonical):

  • ai/application/helpdesk/mail/platform/meeting/cardkit/communication:纯 re-export
  • workflow:re-export + 保留 missing_response_data_error(15文件)/request_serialization_error(11文件)(域专用 error 构造器,外部用)
  • docs:re-export + 保留 missing_response_data_error(1文件)
  • meeting:re-export + 保留 validate_required_field(11文件)

ai 私有化pub mod commonmod common(HTTP helper 不再公开泄漏;仓内零外部引用)

api_url! 移除 #[macro_export](各 crate,零生产调用,语义等同 format!

设计

  • re-export 而非 relocate:保留各 crate 的 common::api_utils 路径(re-export core),避免改 ~1100 个调用点;single source of truth 在 core,无 divergence。
  • canonical 用 rich 变体诊断(采纳 docs/workflow 风格),无 per-crate component(core 不知 crate),3 个 rich crate 的域专用 error fn 保留本地。

验证(含 CI 三连 + clippy 矩阵,本地预跑)

  • cargo build/test --workspace --all-features:7267 passed / 0 failed
  • clippy 矩阵 --all-features + --no-default-features-Dwarnings 干净
  • fmt 通过
  • CI 三连本地预跑全过(记忆 ci-only-checks-deletion-triad):machete 干净 / cargo doc -D warnings 干净 / msrv --locked 通过(Cargo.lock 未变,无新 dep)
  • ApiResponse = Response 别名确认(docs 兼容)

close #330

…uccess 下沉 core::api + ai common 私有化(#330)

- core::api 加 canonical helpers(serialize_params/extract_response_data/ensure_success,
  rich 诊断 operation/resource/request_id via map_context)
- 10 业务 crate 的 common/api_utils.rs 改 re-export core canonical(签名不变,调用点零改动):
  ai/application/helpdesk/mail/platform/meeting/cardkit/communication 纯 re-export;
  workflow 保留 missing_response_data_error+request_serialization_error(外部用);
  docs 保留 missing_response_data_error;meeting 保留 validate_required_field
- openlark-ai pub mod common → mod common(HTTP helper 不再公开泄漏)
- 各 crate api_url! macro 移除 #[macro_export](零生产调用)
- CHANGELOG v0.18 breaking

本地全过:workspace build/test 7267 passed、clippy 矩阵(--all-features/--no-default-features -Dwarnings)、
fmt、CI 三连(machete/doc -D/msrv --locked)。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 96f8acb004

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

assert!(url.contains("approve"));
}
}
pub use openlark_core::api::{ensure_success, extract_response_data, serialize_params};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve communication error component context

For communication APIs that call extract_response_data or serialize_params, this re-export now routes failures through the core helper, which only sets operation/resource/request_id and no longer sets component=openlark-communication as the removed wrappers did. docs/error-context-policy.md requires component for these standardized errors, so failures in paths like contact user/department requests lose crate attribution in logs and diagnostics; keep thin per-crate wrappers or use a component-aware core helper here.

Useful? React with 👍 / 👎.

use openlark_core::error;

// canonical HTTP 管道 helper(#330 下沉到 core)
pub use openlark_core::api::{ensure_success, extract_response_data, serialize_params};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep docs helper exports source-compatible

Because openlark_docs::common is still public, replacing the module with only these re-exports drops previously public helpers such as validate_required_field and request_serialization_error. External users that followed the public openlark_docs::common::api_utils::* path for validation/serialization error helpers will now fail to compile, and this removal is not covered by the documented breaking changes; keep compatibility wrappers or explicitly migrate these symbols.

Useful? React with 👍 / 👎.

@foxzool
foxzool merged commit a04eb8b into main Jul 5, 2026
120 checks passed
@foxzool
foxzool deleted the feature/20260705/ai-common-sink-to-core branch July 5, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] ai: pub mod common 下沉 core::api(serialize_params 返 Value / api_url! macro_export 污染)

1 participant