Skip to content

fix: migrate to github-copilot-sdk 1.0.2 API (closes #79)#90

Open
Fu-Jie wants to merge 3 commits into
mainfrom
trae/migrate-sdk-1.0.2
Open

fix: migrate to github-copilot-sdk 1.0.2 API (closes #79)#90
Fu-Jie wants to merge 3 commits into
mainfrom
trae/migrate-sdk-1.0.2

Conversation

@Fu-Jie

@Fu-Jie Fu-Jie commented Jun 20, 2026

Copy link
Copy Markdown
Owner

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.3cannot 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_pathconnection=StdioRuntimeConnection(path=...)
  • cwdworking_directory

2. SessionConfig 已移除

session_params 直接作为 dict 传给 create_session(**session_params),不再需要 SessionConfig 包装。

3. 参数重命名

config_dirconfig_directory(在 create_sessionresume_session 中,已通过 inspect.signature 验证)

4. Mode 相关

# 旧:
from copilot.generated.rpc import Mode, SessionModeSetParams
mode_enum = Mode(effective_session_mode)
session.rpc.mode.set(SessionModeSetParams(mode=mode_enum))

# 新:
from copilot.generated.rpc import SessionMode, ModeSetRequest
mode_enum = SessionMode(effective_session_mode)
session.rpc.mode.set(ModeSetRequest(mode=mode_enum))

SessionMode 枚举成员: INTERACTIVE='interactive', PLAN='plan', AUTOPILOT='autopilot'

5. get_state() 已移除

# 旧: state = client.get_state()
# 新: state = getattr(client, "_state", "disconnected")

1.0 移除了公开的 get_state(),连接状态移至私有 _state 属性(值: disconnected/connecting/connected/error)。

6. CopilotClient 创建

# 旧: new_client = CopilotClient(client_config, auto_start=True)
# 新: new_client = CopilotClient(**client_config); await new_client.start()

auto_start 参数已移除,需要手动 await client.start()

7. 版本号

  • requirements: github-copilot-sdk==0.2.21.0.2
  • scripts/deploy_pipe.py: 0.1.251.0.2
  • scripts/sync_to_workspace.py: 0.1.231.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

基于 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
@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

✅ Plugin Version Check / 插件版本检查

版本更新检测通过!PR 包含版本变化和更新说明。

Version check passed! PR contains version changes and update description.


版本变化 / Version Changes

Plugin Updates

  • GitHub Copilot Official SDK Pipe: v0.13.2 → v0.13.3 | 📖 README

This comment was generated automatically. / 此评论由自动生成。

@gemini-code-assist gemini-code-assist 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.

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.

Comment on lines +8452 to 8455
state = getattr(client, "_state", "disconnected")
if state == "connected":
return client
if state == "error":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

如果 client._state 是一个标准的 Enum(枚举)类型而非纯字符串,直接使用 state == "connected" 进行比较可能会由于类型不匹配而始终返回 False。这会导致每次请求都无法复用已连接的客户端,从而频繁重建客户端和会话,影响性能和效率。\n\n建议使用 getattr(state, "value", state) 来安全地获取其底层的字符串值,以确保兼容 Enumstr 类型。

                    state = getattr(client, "_state", "disconnected")
                    state_val = getattr(state, "value", state)
                    if state_val == "connected":
                        return client
                    if state_val == "error":

Fu-Jie added 2 commits June 20, 2026 22:27
补充迁移遗漏的两个 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
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.

[BUG] error loading module: github_copilot_official_sdk_pipe

1 participant