Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Code-generate inbound (server→client) RPC dispatch for the Rust SDK

未关闭
#1,764 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
冷清
技术栈
rust, typescript

调研方向

从 scripts/codegen/rust.ts 开始,并将 scripts/codegen/{csharp,go,python,typescript}.ts 中的入站生成进行对比。然后检查 rust/src/canvas_dispatch.rs、rust/src/session_fs_dispatch.rs 和 rust/src/copilot_request_handler.rs,同时保留 ergonomic traits 和 streaming bridge。完成的标准是:生成的入站 traits 和 dispatch 替代手写的 matches,并且 cargo build、clippy 和完整的 Rust e2e suite 仍然通过。

由索引模型根据 Issue 内容生成。

描述

enhancement

Background

The SDK protocol has two directions of RPC:

  • Outbound (client→server): the SDK calls into the runtime.
  • Inbound (server→client): the runtime calls back into the SDK — e.g. clientSession.* (canvas, sessionFs) and the new clientGlobal.* (llmInference) callbacks added in #1689.

For inbound dispatch, the four SDKs split into two camps:

  • C#, Go, Python, TypeScript code-generate the inbound handler scaffolding (handler interfaces + the dispatch/registration glue) from api.schema.json. Adding the clientGlobal bucket in #1689 required teaching all four scripts/codegen/*.ts generators about it.

  • Rust generates only the inbound wire types (generated/api_types.rs) and method-name constants (rpc_methods::* in generated/rpc.rs). The per-group dispatch + handler trait is hand-written, consistently, across all three inbound groups:

    • canvas.* → rust/src/canvas_dispatch.rs
    • sessionFs.* → rust/src/session_fs_dispatch.rs
    • llmInference.* → rust/src/copilot_request_handler.rs (dispatch)

    Each follows the identical shape: prefix-check → match rpc_methods::* constant → deserialize generated params → call the hand-written handler trait → serialize the result.

  • Java has no codegen pipeline at all (entire RPC surface hand-authored), so it's out of scope here.

Proposal

Bring Rust to parity with the other generated SDKs by code-generating the inbound handler trait + dispatch helper per group into rust/src/generated/, so future inbound callbacks (new clientSession / clientGlobal groups) come for free, as they already do in C#/Go/Python/TS.

Why this is its own PR, not part of #1689

This was investigated during #1689 and deliberately deferred:

  1. Do all three groups, not a one-off. Rust's hand-written-dispatch convention is currently uniform across canvas, sessionFs, and llmInference. Generating only llmInference (the group #1689 touches) would trade Rust's internal consistency for cross-SDK symmetry and leave a confusing one-off. The clean change converts all three groups together — a cross-cutting refactor of shipped, well-tested dispatchers and their public trait surfaces (CanvasHandler, SessionFsProvider, CopilotRequestHandler), out of scope for a callbacks PR.

  2. Generate only the low-level wire trait; keep ergonomic traits + streaming bridges hand-written. The public CopilotRequestHandler (send_request + open_websocket) does not mirror the wire methods (httpRequestStart + httpRequestChunk); ~1200 lines bridge frame-oriented streaming ↔ that 2-method seam with stateful exchange correlation. Codegen should emit only the thin wire-level trait + dispatch (mirroring what TS generates), with the ergonomic traits and the llmInference bridge staying hand-written. Net hand-written savings are small (≈ the dispatch match + method constants); the value is future-proofing and symmetry, not LOC.

  3. Validation. The streaming handler is heavily covered by Rust e2e (cancel / error / session-id) record-replay tests that should gate the refactor in CI.

Suggested scope of work

  • Add inbound handler-trait + dispatch emission to scripts/codegen/rust.ts (read clientSession + clientGlobal), emitting into rust/src/generated/.
  • Migrate canvas_dispatch.rs, session_fs_dispatch.rs, and copilot_request_handler.rs to implement/use the generated trait + dispatch instead of their hand-rolled match + local method-name constants.
  • Keep ergonomic public traits (CanvasHandler, SessionFsProvider, CopilotRequestHandler) and the llmInference streaming bridge hand-written.
  • Verify cargo build + clippy + the full Rust e2e suite stay green.

References

  • PR #1689 (LLM inference callbacks) — where the clientGlobal bucket and the C#/Go/Python/TS generator changes landed.
  • Generators with inbound support: scripts/codegen/{csharp,go,python,typescript}.ts (emitClientGlobalApiRegistration / emitClientSessionApiRegistration).
  • Rust generator (outbound only today): scripts/codegen/rust.ts.
主要语言
Java
星标
10.5k
派生
1.5k
平均合并
1 天 9 小时
30 天内合并 PR
130

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

github/copilot-sdk 的其他 Issue

查看 github/copilot-sdk 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。