fix: migrate to github-copilot-sdk 1.0.2 API (closes #79)#90
Conversation
基于 github-copilot-sdk 1.0.2 真实源码(本地 pip install 验证)进行正确迁移, 修复 issue #79 中报告的版本与导入错误。 ## 迁移内容 - SubprocessConfig 已移除:_build_client_config 直接返回 dict, cli_path 改为 connection=StdioRuntimeConnection(path=...), cwd 改为 working_directory - SessionConfig 已移除:session_params 直接作为 dict 传给 create_session - config_dir → config_directory(create_session/resume_session 参数重命名) - Mode → SessionMode(成员: INTERACTIVE/PLAN/AUTOPILOT) - SessionModeSetParams → ModeSetRequest - client.get_state() → getattr(client, "_state", "disconnected") (1.0 移除了公开的 get_state(),连接状态移至私有 _state 属性) - CopilotClient(client_config, auto_start=True) → CopilotClient(**client_config) + await start()(auto_start 参数已移除) - requirements: github-copilot-sdk==0.2.2 → 1.0.2 ## 验证 通过本地 pip install github-copilot-sdk==1.0.2 验证所有 API 变更: - SessionMode 枚举成员: INTERACTIVE/PLAN/AUTOPILOT - ModeSetRequest 字段: mode - resume_session 参数包含 config_directory(非 config_dir) - CopilotClient 接受关键字参数,无 auto_start Closes #79
✅ Plugin Version Check / 插件版本检查版本更新检测通过!PR 包含版本变化和更新说明。 Version check passed! PR contains version changes and update description. 版本变化 / Version ChangesPlugin Updates
This comment was generated automatically. / 此评论由自动生成。 |
There was a problem hiding this comment.
Code Review
此拉取提交将 github-copilot-sdk 依赖版本升级至 1.0.2,并对相关配置构建、会话参数、状态获取及导入项进行了适配。审查意见指出,由于新版本中移除了公开的 get_state() 方法,代码改用私有属性 _state 获取状态,但如果该属性为 Enum 类型,直接与字符串比较可能因类型不匹配导致无法复用客户端,建议通过 getattr(state, "value", state) 安全获取底层字符串值以确保兼容性。
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| state = getattr(client, "_state", "disconnected") | ||
| if state == "connected": | ||
| return client | ||
| if state == "error": |
There was a problem hiding this comment.
如果 client._state 是一个标准的 Enum(枚举)类型而非纯字符串,直接使用 state == "connected" 进行比较可能会由于类型不匹配而始终返回 False。这会导致每次请求都无法复用已连接的客户端,从而频繁重建客户端和会话,影响性能和效率。\n\n建议使用 getattr(state, "value", state) 来安全地获取其底层的字符串值,以确保兼容 Enum 和 str 类型。
state = getattr(client, "_state", "disconnected")
state_val = getattr(state, "value", state)
if state_val == "connected":
return client
if state_val == "error":补充迁移遗漏的两个 API(通过对比 1.0.2 真实源码发现): - session.get_messages() → session.get_events() 1.0.2 移除了 get_messages(),get_events() 返回 list[SessionEvent], 具有相同的 .type 属性(user.message, assistant.turn_start 等), 与原代码的历史检查逻辑完全兼容。 - session.destroy() → session.disconnect() 1.0.2 移除了 destroy(),disconnect() 是等价的资源清理方法。 验证: - PlanApi.read() ✓ 存在 - ModeApi.set(ModeSetRequest) ✓ 存在 - ModeApi.get() ✓ 存在 - session.rpc.plan, session.rpc.mode 等实例属性 ✓ 存在
…lease notes - Bump version 0.13.2 → 0.13.3 in docstring, README, docs mirror, and index badges - Add standalone v0.13.3.md and v0.13.3_CN.md release notes - Update What's New section with SDK 1.0.2 API migration summary - Update root README.md date badge to 2026-06-21
fix: migrate to github-copilot-sdk 1.0.2 API (closes #79)
基于 github-copilot-sdk 1.0.2 真实源码(本地 pip install 验证)进行正确迁移,修复 issue #79 中报告的版本与导入错误。
问题
issue #79 报告:
github-copilot-sdk==0.2.2在 PyPI 不存在0.2.3后cannot import name Mode from copilot.generated.rpc根因
之前的 PR #88 基于错误的 API 推测进行迁移,未查看真实源码。本次基于本地
pip install github-copilot-sdk==1.0.2验证的真实 API 重新迁移。迁移内容(全部基于真实 API 验证)
1. SubprocessConfig 已移除
_build_client_config直接返回 dict,不再包装为SubprocessConfig:cli_path→connection=StdioRuntimeConnection(path=...)cwd→working_directory2. SessionConfig 已移除
session_params直接作为 dict 传给create_session(**session_params),不再需要SessionConfig包装。3. 参数重命名
config_dir→config_directory(在create_session和resume_session中,已通过inspect.signature验证)4. Mode 相关
SessionMode枚举成员:INTERACTIVE='interactive',PLAN='plan',AUTOPILOT='autopilot'5. get_state() 已移除
1.0 移除了公开的
get_state(),连接状态移至私有_state属性(值:disconnected/connecting/connected/error)。6. CopilotClient 创建
auto_start参数已移除,需要手动await client.start()。7. 版本号
requirements:github-copilot-sdk==0.2.2→1.0.2scripts/deploy_pipe.py:0.1.25→1.0.2scripts/sync_to_workspace.py:0.1.23→1.0.2验证
通过本地
pip install github-copilot-sdk==1.0.2验证所有 API 变更:SessionMode枚举成员:INTERACTIVE/PLAN/AUTOPILOT✓ModeSetRequest字段:mode✓resume_session参数包含config_directory(非config_dir)✓CopilotClient接受关键字参数,无auto_start✓SubprocessConfig不再可导入 ✓SessionConfig不再可导入 ✓StdioRuntimeConnection可从copilot导入 ✓代码语法检查通过(
python -m py_compile)。Closes #79