Skip to content

支持通过 OpenCode pair 链接添加服务器 #179

Closed

Description

@0x79H

OpenCode v2.0.17 加入了一次性 pair 链接,v2.0.25 又支持通过 opencode pair --remote 连接 background service。

目前 OpenCodeUI 添加远程服务器仍需要手动填写 URL、用户名和密码,建议支持直接粘贴 pair 链接。

处理方式:

  1. 请求 pair 链接中的 /auth/connect/<code>,设置 Accept: application/json,获取 session token。
  2. 使用链接的 origin 作为服务器 URL。
  3. 用户名使用 opencode,session token 作为密码。
  4. 后续复用现有的 Basic Auth、服务器存储和健康检查逻辑。

测试环境:

  • OpenCode v2.0.29
  • OpenCodeUI v0.7.12
  • 在线版 https://lehhair.github.io/OpenCodeUI/
  • OpenCode background service + OpenTunnel

测试过程:

  1. 为 background service 配置在线版的 CORS origin:

    opencode service set cors https://lehhair.github.io
  2. 生成远程 pair 链接:

    opencode pair --remote --yes
  3. 请求 pair 链接并设置 Accept: application/json,成功返回 session token。

  4. 将 OpenTunnel 地址作为服务器 URL,用户名填写 opencode,session token 作为密码,手动添加到在线版 OpenCodeUI。

  5. OpenCodeUI 可以正常连接和使用。浏览器网络请求结果如下:

    • pair 链接请求返回 200,并返回 Access-Control-Allow-Origin: https://lehhair.github.io。
    • 带 Authorization 的请求触发 OPTIONS 预检,返回 204,并允许 authorization header。
    • /api/info、/api/session 和 /api/event 均返回 200,SSE 连接正常。

这套测试手动执行了 OpenCodeUI 需要新增的 pair 链接解析、token 获取和服务器配置流程。

需要注意,pair code 只有 5 分钟有效期且只能使用一次。通过 pair 链接成功获取 token 后,即使后续健康检查失败,也应该保留 token 并允许重试。

首版只需要支持使用 pair 链接添加服务器,不需要负责生成 pair 或管理 OpenTunnel。

相关:#172、#159。

Activity

  1. lehhair commented on Oct 15, 2026

    @lehhair
    Owner

    下个版本支持,并且手机端应该会支持扫码添加服务器

  2. added a commit that references this issue on Oct 15, 2026
    9363cac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions