Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(server,web): 局域网地址上打开时,密钥授权改为粘贴授权码(5.50)

lmlihengeaf62138f0b6
diff --git a/changelog/unreleased/2026-10-26-oauth-callback-origin.md b/changelog/unreleased/2026-10-26-oauth-callback-origin.md
new file mode 100644
index 00000000..bf91fa4e
--- /dev/null
+++ b/changelog/unreleased/2026-10-26-oauth-callback-origin.md
@@ -0,0 +1,52 @@
+# A key authorization opened on a LAN address falls back to the pasted code
+
+- **Date:** 2026-10-26
+- **Type:** fix
+- **Scope:** `server`, `web`
+- **Breaking:** no
+
+[中文](2026-10-26-oauth-callback-origin.zh.md)
+
+Connecting TokenDance from the Models page, with the Web App opened over plain HTTP on anything
+but loopback (a LAN address such as `http://192.168.1.10:4000`, a hostname, `0.0.0.0`), sent the
+browser to an authorization page that refused the whole request as invalid. That page redirects
+back only to an HTTPS address or to plain HTTP on `localhost`, `[::1]` or `127.x.x.x`, and the
+server had handed it the address the browser used.
+
+The server now asks for the redirect only when that address can receive it. Otherwise it opens the
+flow in manual mode: no callback address, the same S256 PKCE challenge. The start answer's new
+`mode` field says which mode the flow opened in, and the dialog follows it — it opens straight on
+the one-time code step, and the switch back to the automatic redirect is withdrawn for as long as
+it stays open, because the provider would refuse it again. On loopback and HTTPS addresses the
+redirect stays the default and the switch between the two works as before.
+
+## Details
+
+- `packages/server/src/services/model-oauth-service.ts`: new exported `openedMode(asked,
+ callbackOrigin)` — `manual` is never upgraded; a `callback` request keeps its redirect only on
+ `https:` or on `http:` to `localhost`, `[::1]` or `127.x.x.x`, the set the authorization page
+ accepts (its `callback_url` check, read from its own client bundle). An origin that does not
+ parse names nowhere a browser can be sent, so it falls back too. `start` uses it for the
+ callback URL **and** for the mode the flow is stored with, so a downgraded flow refuses a
+ redirect deposit exactly like a manual one; `start` also returns `mode`.
+- `packages/server/src/api/types.ts`: `ModelOAuthStartResponse.mode` (required — the server always
+ answers it) and the `ModelOAuthMode` comment now says why a `callback` request can open as
+ `manual`.
+- `packages/web/src/features/models/models-page.tsx` (`ModelOAuthDialog`): a `redirectRefused`
+ state set when a callback request comes back `manual`; it feeds a single `byHand` that replaces
+ the `manual` reads (code step, no poll, no redirect switch), so a retry keeps it that way. The
+ dialog only looks at `res.mode === "manual"`, so a server that predates the field behaves as
+ before. No new copy: the code step's existing hint already says what to do.
+- `packages/server/test/model-oauth.test.ts`: the opened-mode table (loopback and HTTPS keep the
+ redirect; LAN, hostname, `0.0.0.0`, `*.localhost` and an unparsable origin open as manual;
+ manual is never upgraded) plus a route case reached on `http://192.168.1.10:7364` that answers
+ `mode: "manual"`, carries no `callback_url`, keeps S256, and then redeems a pasted code.
+- Ported from upstream `12a58d4f` (#1328), applied as its own change rather than merged; its
+ header comment in the server test was merged by hand (upstream's version also describes a
+ disconnect path this tree does not have) and its web test was not taken — it needs jsdom, which
+ `packages/web` does not install, so the dialog half was verified in a real browser instead.
+
+## Compatibility
+
+- No dependency, stored-data, package-name or config change. `POST /api/projects/:p/model-oauth/start`
+ gains one response field (`mode`); nothing is removed and older Web Apps ignore it.
diff --git a/changelog/unreleased/2026-10-26-oauth-callback-origin.zh.md b/changelog/unreleased/2026-10-26-oauth-callback-origin.zh.md
new file mode 100644
index 00000000..cca69922
--- /dev/null
+++ b/changelog/unreleased/2026-10-26-oauth-callback-origin.zh.md
@@ -0,0 +1,45 @@
+# 通过局域网地址打开 Web App 时,密钥授权改为粘贴授权码
+
+- **Date:** 2026-10-26
+- **Type:** fix
+- **Scope:** `server`, `web`
+- **Breaking:** no
+
+[English](2026-10-26-oauth-callback-origin.md)
+
+以非回环地址的明文 HTTP 打开 Web App(局域网地址如 `http://192.168.1.10:4000`、主机名或
+`0.0.0.0`)时,在模型页连接 TokenDance 会被带到一个授权页,页面直接报「授权请求无效」:那个页面只
+接受跳回 HTTPS 地址,或 `localhost`、`[::1]`、`127.x.x.x` 上的明文 HTTP 地址,而服务端交给它的
+正是浏览器访问时用的地址。
+
+现在只有在该地址能接收跳转时,服务端才请求跳转回来;否则直接以手动模式打开授权流程:不带回调地址,
+S256 PKCE 照旧。发起接口的返回新增 `mode` 字段,说明流程实际以哪种模式打开,弹窗随之直接进入填写
+一次性授权码这一步;这次打开期间不再提供「改回自动跳转」,因为授权页会照样拒绝。回环地址与 HTTPS
+地址上仍默认自动跳转,两种方式之间照常可以切换。
+
+## 细节
+
+- `packages/server/src/services/model-oauth-service.ts`:新增导出 `openedMode(asked,
+ callbackOrigin)` —— 手动模式永远不会被升级;`callback` 请求只在 `https:` 或 `http:` 且主机是
+ `localhost` / `[::1]` / `127.x.x.x`(授权页自己的 `callback_url` 判据,照它前端包里那段读出来)时
+ 保留跳转。解析不出来的地址没有可跳之处,也一并降级。`start` 用它同时决定回调地址**和**流程记录的
+ 模式,所以被降级的流程拒绝投递授权码的行为与手动流程完全一致;`start` 另外返回 `mode`。
+- `packages/server/src/api/types.ts`:`ModelOAuthStartResponse.mode`(必填 —— 服务端总会给出)与
+ `ModelOAuthMode` 的注释补上「为什么 `callback` 请求可能以 `manual` 打开」。
+- `packages/web/src/features/models/models-page.tsx`(`ModelOAuthDialog`):新增 `redirectRefused`,
+ 在「请求了跳转、服务端却按手动打开」时置位,并与原来的 `manual` 合成一个 `byHand` 取代各处对
+ `manual` 的判断(走授权码那一步、不轮询、不给跳转开关),重试也保持这样。弹窗只看
+ `res.mode === "manual"`,所以对没有这个字段的旧服务端行为照旧。没有新增文案:授权码那一步原有的提示
+ 已经说清了怎么做。
+- `packages/server/test/model-oauth.test.ts`:打开模式的取值表(回环与 HTTPS 保留跳转;局域网地址、
+ 主机名、`0.0.0.0`、`*.localhost` 与不可解析的地址都按手动打开;手动模式不会被升级),另加一条路由
+ 用例:以 `http://192.168.1.10:7364` 发起,回 `mode: "manual"`、不带 `callback_url`、仍钉 S256,
+ 随后能兑换粘贴进来的授权码。
+- 移植自上游 `12a58d4f`(#1328),照改动落、不是合分支。服务端用例的文件头注释按本树现状手写合并
+ (上游那份还描述了一条本树没有的 disconnect 路径);上游的前端用例没有取 —— 它要 jsdom,而
+ `packages/web` 不装这个依赖,那半边改用真浏览器验证,见台账那一轮。
+
+## 兼容性
+
+- 不改依赖、不改已存数据、不改包名与配置格式。`POST /api/projects/:p/model-oauth/start` 的响应多一个
+ 字段(`mode`),没有删改;旧的 Web App 会忽略它。
diff --git a/docs/FORK-PROGRESS.md b/docs/FORK-PROGRESS.md
index 86cea20a..ff24a594 100644
--- a/docs/FORK-PROGRESS.md
+++ b/docs/FORK-PROGRESS.md
@@ -997,6 +997,18 @@ mock 路由导入序、`chat-page.tsx` 的旧探针体),自带 4 份用例
永远不加载**,对话页连 `selected` 都拿不到 —— 实测(一次性数据根 + 手写的机器侧会话行 + 真浏览器)
改前改后**同样停在骨架**,而 Agent 列表非空时旧代码的 `!agentId` 本来就通过。留在这里备查,
不重复这一轮的分析。
+- [x] **5.50 在局域网地址上打开 Web App 时,密钥授权改为粘贴授权码**(上游 `12a58d4f` `#1328`,
+ **2026-10-26 第一百三十六轮落地**,提交见该节):模型页连 TokenDance 时,只要 Web App 是以明文
+ HTTP 打开在**非回环**地址上(局域网 IP、主机名、`0.0.0.0`),服务端先前交给授权页的 `callback_url`
+ 就是那个地址,而授权页只接受 HTTPS 或 `localhost` / `[::1]` / `127.x.x.x` 上的明文 HTTP —— 它把整个
+ 请求判成「授权请求无效」,用户卡在那张错误页上(口径取自上游那一笔,它读过授权页前端
+ `APIKeyAuthorization` 包;本轮没有再去取那份 bundle,只把自己这一侧的两态都量了)。现在服务端先算自己该按哪种模式开:`openedMode(asked, origin)`,
+ 手动永不升级、`callback` 只在能接收跳转的地址上保留,其余一律按 `manual` 开(不带 `callback_url`、
+ S256 照旧),**并把 `mode` 写进发起接口的应答**;弹窗照它走 —— 直接落在填授权码那一步,这次打开
+ 期间不再给「改回自动跳转」。回环与 HTTPS 行为与切换方式一字未动。**为什么是这一条**:这一轮拉到的
+ 上游新提交里有十来笔可用,这一笔是其中唯一「真缺陷 + 本树文件全在 + 不引入新依赖 + 自带能在 Linux
+ 上真跑的用例」的;而且它正好压在这一产品的实际用法上(Adelie 本来就从局域网 / 远程地址用)。
+ 细节与实测见「第一百三十六轮」一节。
- **不学**:阿里云 OSS 分发(`feat/aliyun-oss-release-distribution`)、模型库「官方推荐」与 TokenDance
推荐分组(`FORK.md` 已写明不搬)、`web-mod-1…12` 那类大模块化重构(与我们改过的 77 个文件重叠,
现在合进来是净亏)。
@@ -2245,6 +2257,7 @@ v0.2.2」——它只加台账里 v0.2.2 那一节与两行表格,**跟本轮
| 2026-10-26 | 7.47 | **财务页改预算被拒时,框留着、填过的金额与原因都留着**(不是移植:1 处源码 `packages/web/src/features/company/finance-page.tsx`(+46 −5:`BudgetEditor` 多一份 `refusal` 与一句「读不懂」的自有提示(复用既有 `budgetHint` 文案)、画在框下方那一行(`role="alert"`);`FinancePage` 把拒绝文案按员工存在 `budgetRefusal` 里,开框 / 取消 / 落地都清掉;`saveBudget` 的 `catch` 不再 `toastError`,`toastError` 也从这份文件的 import 里去掉了。**顺手修一处真 bug**:写入在途时输入框被置灰、焦点随之离开,而「焦点离开也保存」又把同一次写入发了一遍 —— 一次保存过去写两次;编辑器现在用一个在途标记(`asking`,`busy` 落下时重置)挡掉第二发)+ 1 个新文件 `packages/web/e2e/finance-budget-refusal.spec.mjs`(2 条用例:被拒 → 取消重开 → 重试落地;读不懂的金额一次都不写)+ changelog 一对,**无新依赖、不碰接口、无新文案**):7.46 末尾点名的下一处里最靠前的「财务」那一处,也是那条「原因只进 toast」扫描线在这一页上的第十一处 | 六包 `typecheck` **`EXIT=0`**(六个 `Done`;`gen:ifaces` 报 **`src/ifaces.json unchanged`**,195 接口 / 589 类型 —— 本笔不动服务契约)· `npx oxlint` 两个改动文件 **0 警告 0 错误** · 四个改动文件`prettier --check` 干净 · `git diff --check` 干净 · 逐包 test **`EXIT=0`、0 失败**:core **69 通过文件 + 1 跳过 / 1420 通过 / 6 跳过** · ui **130 文件 / 1053 通过** · cli **38 文件 / 561 通过** · web **265 文件 / 3249 通过 / 2 跳过** · server **203 文件 / 2970 通过 / 4 跳过** · hmr 无测试文件 · **真服务 + 真浏览器单 spec**(`/root/adelie-fork-data/r133-e2e`,服务 8950、mock 8951,`packages/{core,server,web}/dist` 都是本轮新构建):新 spec **2 passed(4.7s)**;相邻回归 `company.spec.mjs` **1 passed(22.0s)** · **整套浏览器 e2e**(`SKIP_BUILD=1 bash e2e/run.sh`,自带 mock 与 `mktemp` 数据根):**164 passed(10.3m)、0 failed** · **反证(同一份 spec,两种产物)**:把这一处源码 `git stash push -- packages/web/src/features/company/finance-page.tsx`(只带这一个路径)、重建 web → 同一条命令 **2 failed**(第一条死在框里没有那句原话,第二条死在 `每月上限` 那条提示从 `role=alert` 里找不到);`git stash pop` 后重建即回到 2 / 2 · **两态实测真看一眼**(探针 `r133/probe.mjs`,改后产物起在 8950、改前产物(`r133/before-dist`)另起一台 8960,各一次、同一个 `page.route` 500,1440×900,读数取被拒后 1.5 s 与 6.5 s 两次):**改前** `{boxVisible:true, reasonInBox:0, reasonInNotice:2, value:"42"}` → 6.5 s 后 `reasonInNotice:0`(屏幕上一点解释都没有了),`writes:2`(**一次保存写了两次**);**改后** `{boxVisible:true, reasonInBox:1, reasonInNotice:0, value:"42"}`,6.5 s 后原样还在,`writes:1`;两态服务端上的预算都是原来的 100,截图 `r133/{before,after}/shots/{3-refused,4-six-seconds-later}.png` 里正好是「改前框里 42、上方两条红 toast、框下一句都没有」对「改后框下那行『操作被拒绝:the org chart is mid-rewrite』」;console 里的 error 只有既有的 `/machines` 403 与刻意造的 500,无 `pageerror` · 端口只用 8950 / 8951 / 8960(跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在 `/root/adelie-fork-data/r133-{e2e,before}` 与 scratchpad 的 `r133/` 下(`packages/*/dist`、`packages/web/test-results/` 都是产物,未 `git add`)· 没有切版本号、没发 npm、没发安装包、没发发布汇总 | `467c076d` |
| 2026-10-26 | 用户点单(火山方舟分组 + 视频输入输出) | **模型库多一个 Volcengine Ark 分组(11 条模型行),对话里能发视频、能看视频,另加一个 Seedance 出视频的插件**(不是移植:`packages/core/src/state/model-catalog.ts` 加 `volcengine` 分组、`supportsVideo` 与 `catalogSupportsVideo`;`pnpm patch` 给 agenthub 加 `video_url` 内容项(`patches/@prismshadow__agenthub.patch` + `patchedDependencies`);core / server / cli / web 四层把视频当一等输入(预算、按引用、轨迹播放器、窗口化历史);`packages/server/src/services/trace-images.ts` 改名合并为 `trace-media.ts` 并新增 `GET /:sessionId/trace-video`;新插件 `plugins/use-seedance`(`@adelie/use-seedance`,走方舟异步出片接口);新增 6 个测试文件与 3 对 changelog;两家品牌图标各一枚):用户 2026-10-25 点单,2026-10-26 补明用 `pnpm patch` 打 agenthub、要「Adelie 应用能产出视频」 | 六包 `typecheck` **`EXIT=0`**(六个 `Done`;`gen:ifaces` 报 **`src/ifaces.json unchanged`**,195 接口 / 590 类型)· `npx oxlint` **0 警告 0 错误**(2297 文件)· `npx prettier --check .` 干净 · `pnpm -r test` **`EXIT=0`、0 失败**:core **1421 通过 / 6 跳过**(69 文件 + 1 跳过)· ui **1053**(130)· cli **561**(38)· web **3273 通过 / 2 跳过**(268)· server **2988 通过 / 4 跳过**(204)· docs **62**(8)· amsp **68**(2)· desktop **304**(26)· ui-gallery **140**(20)· `plugins/use-seedance` **8**(桩服务端到端)· `pnpm -r build` `EXIT=0` · 方舟真端点:假 key 实测 401 `AuthenticationError`(视频部件与文本部件走同一句鉴权错)· **没做**:没在真浏览器里目视播放一次视频、Seedance 没拿真 key 出过一次片、Trace 详情页的 `events` 仍会整份返回那条记录的 base64 | 见本行提交 |
| 2026-10-26 | 7.48 | **智能体设置里「还原为默认配置」「更新内核」被拒时,原因留在框里**(不是移植:1 处源码 `packages/web/src/features/agents/agent-settings-page.tsx`(`OverviewTab` 新增 `resetRefusal` / `kernelRefusal`,两个 `ConfirmModal` 接上 `refusal` 槽并按 `S.common.refused` 加前缀,两个 `catch` 不再 `toastError`,开框 / 关框都清旧原因) + 1 个新文件 `packages/web/e2e/agent-config-refusal.spec.mjs`(2 条用例)+ changelog 一对,**无新依赖、不碰接口、无新文案**):台账点名的下一站是「插件市场 / 智能体设置 / 定时任务面板里带确认的写入」,实摸之后插件市场与定时任务面板早已接好 `refusal` 槽,只剩智能体设置概览页这两张;同一操作在智能体列表页(批量内核更新)与本页 API 标签页早就会把原因留在框里,这两张是最后一处没跟上的 | 六包 `typecheck` **`EXIT=0`**(六个 `Done`;`gen:ifaces` 报 **`src/ifaces.json unchanged`**,195 接口 / 590 类型)· `npx oxlint` 两个改动文件 **0 警告 0 错误** · 四个改动文件 `prettier --check` 干净 · `git diff --check` 干净 · 逐包 test **`EXIT=0`、0 失败**(两条扫全仓的 5 s 用例在本机与另一条线的发布测试并行时超时、单独复跑通过,见该节):core **69 通过文件 + 1 跳过 / 1421 通过 / 6 跳过** · ui **130 / 1053** · cli **38 / 561** · server **204 / 2990 通过 / 4 跳过** · web **267 文件 / 3272 通过 / 2 跳过** · **真服务 + 真浏览器单 spec**(`/root/adelie-fork-data/r135-e2e`,服务 8950、mock 8951,`packages/{core,server,web}/dist` 本轮新构建):新 spec **2 passed(9.1s)** · **反证(同一份 spec,两种产物)**:把这一处源码 `git stash push -- packages/web/src/features/agents/agent-settings-page.tsx`(只带这一个路径)、重建 web 成 `r135/before-dist`、另起一台服务端(8960,`/root/adelie-fork-data/r135-before`)→ **2 failed**(`element(s) not found`:改前框里没有那句原话);`git stash pop` 后重建即回到 2 / 2 · **两态实测真看一眼**(探针 `r135/probe.mjs`,两态各跑一次、两张框各测一遍,同一个 `page.route` 500,1440×900,读数取被拒后 1.5 s 与 6.5 s 两次):**改前** 两张框都是 `{cardVisible:true, alertInCard:0, noticeHasReason:true}` → 6.5 s 后 `noticeHasReason:false`(屏幕上一点解释都没有了);**改后** 两张框都是 `{cardVisible:true, alertInCard:1, noticeHasReason:false}`,6.5 s 后原样还在——截图 `r135/{before,after}/shots/{reset,kernel}-2-six-seconds-later.png` 里正好是「改前框里空着」对「改后框里那行『操作被拒绝:agent state is read-only』」;两态 console 的 error 只有既有的 `/machines` 403(普通成员读机器列表)与刻意造的 500,无 `pageerror` · **整套浏览器 e2e**(`SKIP_BUILD=1 bash e2e/run.sh`,自带 mock 与 `mktemp` 数据根):**167 passed(11.9m)、0 failed、`EXIT=0`**(第一百三十三轮整套是 164,+ 本笔 2 + 另一条线视频那 1) · 端口只用 8950 / 8951 / 8960 与整套的 8930 / 8931(跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在 `/root/adelie-fork-data/r135-{e2e,before}` 与 scratchpad 的 `r135/` 下(`packages/*/dist`、`packages/web/test-results/` 都是产物,未 `git add`)· 没有切版本号、没发 npm、没发安装包、没发发布汇总(0.5.7 的版本号与发布正文是另一条线推上来的 `d80630ec` / `63fa1064`,本线只 `merge --ff-only` 跟上) | 见本行提交 |
+| 2026-10-26 | 5.50 | **在局域网地址上打开 Web App 时,密钥授权改为粘贴授权码**(上游 `12a58d4f` `#1328` 移植,照改动落、不是合分支;上游 8 文件 / +289 −17 → 本树落下 5 个跟踪文件 / +133 −17 与 changelog 一对:上游那份前端用例要 jsdom(`packages/web` 不装),改由真浏览器取证,服务端用例的表头注释按本树现状手写合并):服务端新增导出 `openedMode(asked, origin)` —— `manual` 永不升级;`callback` 只在 `https:` 或 `http:` 且主机为 `localhost` / `[::1]` / `127.x.x.x`(授权页 `callback_url` 的判据)时保留,解析不出的地址一并降级;`start` 用它同时决定回调地址与流程记录的模式(被降级的流程拒绝投递授权码,与手动流程完全一致)并返回 `mode`;`ModelOAuthStartResponse.mode` 为必填。Web 侧 `ModelOAuthDialog` 新增 `redirectRefused`,与 `manual` 合成 `byHand` 取代各处判断(授权码那一步、不轮询、不给跳转开关),只看应答里的 `mode === "manual"`,对没有该字段的旧服务端行为照旧。**本地化**:本树已改名的 `ADELIE_TRUST_PROXY` 等措辞沿用;changelog 按本仓写法改名到本轮日期、去掉上游 PR 行、写明移植来源 | 六包 `typecheck` **`EXIT=0`**(六个 `Done`;`gen:ifaces` 重写 `src/ifaces.json` 后与版本库逐字节相同 —— 195 接口 / 590 类型,本笔不动组件契约)· `npx oxlint` 五个文件 **0 警告 0 错误** · 五个源码 / 用例文件与一对 changelog `prettier --check` 干净 · `git diff --check` 干净 · 逐包 test **`EXIT=0`、0 失败**:core **1425** / 6 跳过(69 文件 + 1 跳过)· ui **1053**(130)· cli **561**(38)· server **204 文件 / 2995 通过 / 4 跳过** · web **269 文件 / 3283 通过 / 2 跳过** · hmr 无测试文件 · **反证(单测)**:在 `openedMode` 开头插一句 `return asked;` → `test/model-oauth.test.ts` **2 failed / 44 passed**(「非回环明文 HTTP 按手动开」与 LAN 路由那两条都挂在 `expected "manual", received "callback"`),还原后 **46 全过** · **本轮主证据(真服务端 ×2 + 真浏览器:改前 / 改后两态 + 回环对照)**:`packages/{core,server,web}` 各自单独重建;两份服务端产物(`r136/before-server-dist` 取自把四份源码 stash 掉的树)与两份 web 产物(`r136/{before,after}-dist`)分别挂在一次性数据根 `/root/adelie-fork-data/r136-{before,after}` 上,**改后起在 `localhost:8954`、改前起在 `localhost:8955`**(`ADELIE_SEED_ADMIN_PASSWORD` + 登录页表单拿 cookie;空数据根不需要模型 key——即 3.6 那个卡点);浏览器用 `--host-resolver-rules=MAP app.lan 127.0.0.1` 以 **`http://app.lan:<port>`(明文 HTTP + 非回环主机名)** 访问,三腿读数:**改后 @ LAN** —— `POST …/model-oauth/start` 回 `mode: "manual"`、`authorizeUrl` 里**没有 `callback_url`**、`code_challenge_method=S256`,弹窗同时有「授权码」输入框 + 那句粘贴提示 + 「提交授权码」,**没有**「授权页跳不回来?改为手动填写授权码」这个开关(截图 `r136/shots/after-lan.png`);**改前 @ LAN** —— 应答无 `mode` 字段、`callback_url` 就是 `http://app.lan:8955/…`(正是授权页会拒的那个),弹窗只有「打开授权页」+ 那个开关、**没有授权码框**(`r136/shots/before-lan.png`);**改后 @ localhost(回环对照,行为不变)** —— 应答 `mode: "callback"`、`callback_url` 是 `http://localhost:8954/…`、开关照旧在(`r136/shots/after-localhost.png`)。三腿 console 各 **0 error**、**无一条 ≥400**(登录前的 `/api/me` 401 属这个 App 的正常首访)· 端口只用 8954 / 8955(跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在 `/root/adelie-fork-data/r136-{after,before}`,探针 / 两态产物 / 截图都在 scratchpad 的 `r136/` 下(`packages/*/dist` 是构建产物,未 `git add`) | 见本行提交 |
> **2026-10-11 与另一条线的交汇(第三十七轮)**:定时任务触发时(07:00)`git status --short` **不干净**
@@ -16467,3 +16480,103 @@ adelie 应用可以产出视频」。
- 汇报:校园邮箱照惯例只试一次(`/root/penguin-plugins/csu-mail/skills/csu-mail/scripts/mail.py check`
**超时 `RC=124`**、无输出,仍是 `202.197.0.0/16` 那个网段的问题、不是凭据),改走飞书,正文留底在
scratchpad 的 `release-057/report.txt`。
+
+## 第一百三十六轮:在局域网地址上打开 Web App 时,密钥授权改为粘贴授权码(2026-10-26,条目 5.50)
+
+### 开工自检
+
+- `/root/adelie-fork` 在 `main` 上,`git status --short` **干净**;`git merge --ff-only origin/main`
+ 跟上了另一条线的 v0.5.8(`680bdf76` 版本戳 + `5ab78bae` 发布正文,35 文件 / +92 −34)。
+ 没有切分支、没碰 `legacy/main`、没推 upstream。
+- 上游按第二十三轮那条路现拉:
+ `git fetch https://github.com/Prism-Shadow/penguin-harness.git refs/heads/main:refs/adelie-tmp/upstream-main-r136`,
+ 尖端 **`4694d853`**(`fallback --all-fetch` 式的一把,`2b8116ce..` 共 **126 笔**新提交,另有 tag `v0.2.17`)。
+ 探针引用是 `refs/adelie-tmp/upstream-main-r136`(要清就 `git update-ref -d`)。
+
+### 选活
+
+表上最靠前的未勾选条目仍是 **2.2c**(剩下三件:写侧全在桌面壳一侧、既有部署单元与发布动作、
+桌面壳自己的开关 —— 都不是这一条能自己做完的)、**3.5** 要用户拍板取哪个桌面壳、**3.6** 要模型 key(卡点)、
+**4.1–4.3** 明令不动、**5.3** 的②③④要第二台机器、**5.6** 与 **5.10** 等用户拍板;第 7 节全部勾完。
+于是按前几轮的惯例,从这一轮新拉到的上游提交里挑「真缺陷 + 本树文件全在 + 不引入新依赖」。
+
+126 笔逐笔量过的结论(省下一轮):
+
+- **能用**:`12a58d4f`(`#1328`,本轮落地,见下)。
+- **量过、没取**:`bf3395ff`(`#1325`,停靠栏贴着输入框停住,324 行,自带纯逻辑用例
+ `bottom-dock-size.test.ts`)—— `git apply -3 --check` 在 `chat-page.tsx` / `dock-panel.tsx` /
+ `dock-state.ts` **三处冲突**,且与紧随其后的 `ce9b3e69`(`#1335`,停靠面板跟随自己的会话)改同一批文件,
+ 两条要一起做才不互相返工 → 留给后面单独一轮。
+- **落不了**:`282eeab8` / `4694d853`(`#1332` / `#1333`,amsp 读历史时的重试与退避)—— 要改
+ `packages/amsp/src/reader.ts`,**本树没有那个文件**(它是上游 `#1301` "Agent API 流式记录" 的产物,
+ 本树尚未落)。`e0e4f463`(`#964`)要 `packages/skills` 整个包,也没有。
+- **不学(本仓一贯口径)**:`0195c73b` 之类的发版提交、`packages/landing` / `docs/blog` / `rfcs` 那一大批
+ 品牌面与站点面、依赖升级(vitest 4.1 / Electron / MCP SDK 等,属 4.x 的流水线面),以及
+ `c45a56cd`(把 OmniMessage 改名为 AMSP record)、`172c9e4c`(模型目录从 core 搬到 server)、
+ `0eafa6dc` 之后的 `#1154` / `#1161` 这类跨模块大重构 —— 都不是一轮的量、也不压在我们的收益上。
+
+### 做了什么
+
+- `packages/server/src/services/model-oauth-service.ts`:新增导出 **`openedMode(asked, callbackOrigin)`**
+ —— `manual` 永不升级;`callback` 只在 `https:` 或「`http:` + `localhost` / `[::1]` / `127.x.x.x`」时保留,
+ 解析不出的地址一并降级(没有可跳之处)。`ModelOAuthService.start` 用它**同时**决定回调地址与流程记录的模式
+ (因此被降级的流程拒绝投递授权码,行为与手动流程完全一致),并在结果里返回 `mode`。
+- `packages/server/src/api/types.ts`:`ModelOAuthStartResponse.mode` 必填;`ModelOAuthMode` 与
+ `ModelOAuthStartRequest.mode` 的注释补上「为什么 `callback` 可能以 `manual` 开」。
+- `packages/server/src/http/routes/model-oauth.ts`:`requestOrigin()` 与 `/start` 的注释跟着改(口径:跳转只
+ 在 HTTPS 或回环明文 HTTP 上成立)。
+- `packages/web/src/features/models/models-page.tsx`(`ModelOAuthDialog`):新增 `redirectRefused`,
+ 与原来的 `manual` 合成一个 `byHand` 取代各处判断(走授权码那一步、不轮询、不给「改回自动跳转」),
+ 重试也保持;只看应答里的 `mode === "manual"`,对没有该字段的旧服务端行为照旧。没有新增文案。
+- `packages/server/test/model-oauth.test.ts`:打开模式的取值表(回环与 HTTPS 保留跳转;LAN 地址、主机名、
+ `0.0.0.0`、`*.localhost`、不可解析的地址按手动;手动永不升级)+ 一条路由用例(以
+ `http://192.168.1.10:7364` 发起 → `mode: "manual"`、无 `callback_url`、仍钉 S256,随后兑换粘贴的授权码)。
+- changelog 一对 `changelog/unreleased/2026-10-26-oauth-callback-origin{,.zh}.md`(按本仓写法:去掉上游 PR 行、
+ 写明移植出处与「没有接口 / 数据 / 依赖变化」)。
+
+**有意没取**:上游那份 `packages/web/test/model-oauth-mode.test.ts`(`// @vitest-environment jsdom`)——
+`packages/web` 不装 jsdom(第六十二轮记过的同一条),装了就是引入新依赖;那半边改用真浏览器两态取证(见下)。
+服务端用例的文件头注释按本树合并:上游那一版还描述了一条本树没有的 disconnect 路径。
+
+### 验证(都不是推测)
+
+- 六包 `typecheck` **`EXIT=0`**(六个 `Done`)。server 的 `gen:ifaces` 报了那一串既有 warning 并「写」了
+ `src/ifaces.json`,但 `git diff` 为空 —— 内容与版本库逐字节相同(195 接口 / 590 类型)。
+- 逐包 test **`EXIT=0`、0 失败**:core **1425** / 6 跳过(69 文件 + 1 跳过)· ui **1053**(130 文件)·
+ cli **561**(38 文件)· server **204 文件 / 2995 通过 / 4 跳过** · web **269 文件 / 3283 通过 / 2 跳过** ·
+ hmr 无测试文件。`npx oxlint` 五个文件 **0 警告 0 错误**;五个源码 / 用例文件与一对 changelog
+ `prettier --check` 干净;`git diff --check` 干净。
+- **反证(单测)**:在 `openedMode` 开头插一句 `return asked;` 再跑 `test/model-oauth.test.ts` →
+ **2 failed / 44 passed**(取值表里那条与 LAN 路由那条都挂在 `expected "manual", received "callback"`),
+ 还原后 **46 全过**。
+- **两态实测(真服务端 ×2 + 真浏览器,主证据)**:`core` / `server` / `web` 各自单独重建(不同时 build,
+ 见第二十八轮 OOM 那条)。两份服务端产物:`r136/before-server-dist` 是「把四份源码 stash 掉」之后重建的,
+ `packages/server/dist` 在其间来回换过(`grep -c openedMode dist/index.js` 得 0 / 3 两端核过),
+ 两份 web 产物 `r136/{before,after}-dist` 同理。两个一次性数据根
+ `/root/adelie-fork-data/r136-{after,before}`,改后起在 **8954**、改前起在 **8955**
+ (`ADELIE_SEED_ADMIN_PASSWORD`,登录走登录页表单 —— 空数据根不需要模型 key,即 3.6 那个卡点)。
+ 浏览器用 `--host-resolver-rules=MAP app.lan 127.0.0.1` 以 `http://app.lan:<port>` 访问(**明文 HTTP +
+ 非回环主机名**,正是这台机器上访问 Adelie 的方式),在 `/models` 点 TokenDance 那行的「连接」:
+ - **改后 @ LAN**:`POST …/model-oauth/start` 回 `mode: "manual"`,`authorizeUrl` 里**没有 `callback_url`**、
+ `code_challenge_method=S256`;弹窗同时出现「授权码」输入框、粘贴提示与「提交授权码」,
+ **没有**「授权页跳不回来?改为手动填写授权码」这个开关 —— 截图 `r136/shots/after-lan.png`。
+ - **改前 @ LAN**:应答无 `mode` 字段,`callback_url` 就是 `http://app.lan:8955/…`(授权页会拒的那个地址);
+ 弹窗只有「打开授权页」+ 那个开关、**没有授权码框** —— `r136/shots/before-lan.png`。
+ - **改后 @ localhost(回环对照)**:`mode: "callback"`、`callback_url` 是 `http://localhost:8954/…`、
+ 开关照旧在 —— `r136/shots/after-localhost.png`(回环与 HTTPS 的行为与切换方式都没变)。
+ - 三腿 console 各 **0 error**、**无一条 ≥400**(登录前的 `/api/me` 401 是这个 App 的正常首访)。
+- 端口只用 8954 / 8955(跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在
+ `/root/adelie-fork-data/r136-{after,before}`;探针 `r136/probe.mjs`、两态产物、截图都在 scratchpad 的
+ `r136/` 下,一个字节没往 `~/.penguin` 或仓库里写(`packages/*/dist` 是构建产物,未 `git add`)。
+
+### 没做 / 还差什么
+
+- **真去授权一次没有做**:这一轮没有真去 TokenDance 授权(不铸造任何 key),判定口径取自上游那一笔
+ (它读过授权页前端的 `callback_url` 校验),本机核的是「我们这一侧现在会问什么、界面会怎么走」。
+ 真要端到端验,需要一次真实的 TokenDance 授权(会产生一个真 key),等用户愿意的时候再说。
+- **`app_url` 仍是上游的 `https://penguin.ooo/`**(两态实测的 `authorizeUrl` 里都看得到):这是 2.1c 之外
+ 遗留的上游品牌面,属发布期那条线(4.x),本轮不动。
+- **下一轮**:`bf3395ff`(`#1325`,底部停靠栏压在输入框上)+ `ce9b3e69`(`#1335`,停靠面板跟随自己的会话)
+ 是这一轮量过、最值得一起做的两条(同一批文件、都有现成用例);再往后是 `0c7725c2`(`#1250`,流式回复时
+ 往上滚不再被拽回去,自带 306 行 e2e)与 `12a58d4f` 之后那几笔要新前置的(`#1272` / `#1268` 的 API socket 面)。
+- 汇报邮件:照 `csu-mail` 技能试一次;不通就改走飞书(第 117 / 135 轮的先例)。
diff --git a/packages/server/src/api/types.ts b/packages/server/src/api/types.ts
index 4659a1d6..405515da 100644
--- a/packages/server/src/api/types.ts
+++ b/packages/server/src/api/types.ts
@@ -1167,7 +1167,8 @@ export interface ModelBalanceFailure {
/**
* How the authorization code travels back. `callback` sends the browser to a harness URL
* the provider redirects to; `manual` asks the provider for a one-time code the user copies
- * back by hand, for the case where that redirect cannot reach the harness.
+ * back by hand, for the case where that redirect cannot reach the harness — or where the
+ * provider would refuse it: only an HTTPS or loopback HTTP origin can be redirected to.
*/
export type ModelOAuthMode = "callback" | "manual";
@@ -1179,7 +1180,7 @@ export type ModelOAuthMode = "callback" | "manual";
export interface ModelOAuthStartRequest {
/** Provider group id (must be a catalog group that publishes a key-minting flow). */
provider: string;
- /** Defaults to `callback`. */
+ /** Defaults to `callback`; the response says which mode the flow was opened in. */
mode?: ModelOAuthMode;
}
@@ -1187,6 +1188,12 @@ export interface ModelOAuthStartRequest {
export interface ModelOAuthStartResponse {
flowId: string;
authorizeUrl: string;
+ /**
+ * The mode the flow was opened in: `manual` for a `callback` request when the origin the
+ * request reached this server on is neither HTTPS nor loopback HTTP, which the provider's
+ * authorization page refuses as a callback.
+ */
+ mode: ModelOAuthMode;
}
/** Why a flow failed, as a code the frontend phrases; never carries a code, a verifier or a key. */
diff --git a/packages/server/src/http/routes/model-oauth.ts b/packages/server/src/http/routes/model-oauth.ts
index 7d593aed..b5e10972 100644
--- a/packages/server/src/http/routes/model-oauth.ts
+++ b/packages/server/src/http/routes/model-oauth.ts
@@ -50,8 +50,9 @@ const CODE_RE = /^[A-Za-z0-9._~-]{1,512}$/;
/**
* Origin the browser reached this server on, which is the origin the provider must redirect
- * back to. Taken from the request's own URL, so loopback, a LAN address and a custom port
- * all work without configuration.
+ * back to. Taken from the request's own URL, so loopback and a custom port work without
+ * configuration. The provider redirects only to HTTPS or loopback HTTP, so an origin like a
+ * LAN address over plain HTTP gets a manual flow instead (the service's `openedMode`).
*
* `x-forwarded-proto` / `x-forwarded-host` are caller-supplied and are honoured only when
* the deployment says a reverse proxy sets them (ADELIE_TRUST_PROXY=1) — the same opt-in
@@ -211,7 +212,9 @@ export function modelOAuthRoutes(deps: ModelOauthRouteDeps): Hono<AppEnv> {
// Opens a flow and returns the page to send the user to. The provider is looked up in the
// built-in catalog inside the service, which is what rejects a group that publishes no
- // such flow and what keeps the authorize/exchange endpoints out of client control.
+ // such flow and what keeps the authorize/exchange endpoints out of client control. The
+ // answer carries the mode the flow actually opened in, since a redirect this origin cannot
+ // receive opens as manual.
app.post("/start", async (c) => {
const projectId = requireValidId(c, "projectId");
deps.access.requireProjectOwner(c.var.user.userId, projectId);
diff --git a/packages/server/src/services/model-oauth-service.ts b/packages/server/src/services/model-oauth-service.ts
index 0b398dad..b8c0cd9c 100644
--- a/packages/server/src/services/model-oauth-service.ts
+++ b/packages/server/src/services/model-oauth-service.ts
@@ -92,10 +92,44 @@ export type ModelOAuthErrorCode =
/** A key was minted but could not be written into the Project's models. */
| "apply_failed";
-/** What `start` hands back to the Web App: an opaque id plus the page to send the user to. */
+/**
+ * What `start` hands back to the Web App: an opaque id, the page to send the user to, and the
+ * mode the flow was actually opened in, which is `manual` whenever the redirect could not be.
+ */
export interface ModelOAuthStartResult {
flowId: string;
authorizeUrl: string;
+ mode: ModelOAuthMode;
+}
+
+/**
+ * The mode a flow opens in, given the one asked for and the origin the redirect would return
+ * to.
+ *
+ * The authorization page refuses the whole request as invalid when its `callback_url` is
+ * anything but HTTPS or plain HTTP to a loopback host — `localhost`, `[::1]` or a `127.x.x.x`
+ * address, the set it accepts. A Web App reached over plain HTTP on a LAN address, a hostname
+ * or `0.0.0.0` therefore cannot be redirected back to, and offering the redirect there only
+ * strands the user on an error page. Such a request opens a manual flow instead: no callback
+ * URL, the same S256 challenge, the one-time code carried back by hand.
+ */
+export function openedMode(asked: ModelOAuthMode, callbackOrigin: string): ModelOAuthMode {
+ if (asked === "manual") return "manual";
+ let origin: URL;
+ try {
+ origin = new URL(callbackOrigin);
+ } catch {
+ // A forwarded host that does not parse names nowhere a browser can be sent.
+ return "manual";
+ }
+ if (origin.protocol === "https:") return "callback";
+ // The URL parser has already lowercased the host and normalized IPv4 shorthand (`127.1`)
+ // and IPv6 (`[0:0:0:0:0:0:0:1]`) to the forms the page compares against.
+ const loopback =
+ origin.hostname === "localhost" ||
+ origin.hostname === "[::1]" ||
+ /^127(?:\.\d{1,3}){3}$/.test(origin.hostname);
+ return origin.protocol === "http:" && loopback ? "callback" : "manual";
}
/**
@@ -220,13 +254,17 @@ export class ModelOAuthService implements ModelOAuth {
* that declares no `oauth` cannot be talked into one, and the authorize/exchange
* endpoints are always the catalog's, so client input never chooses who receives the
* challenge or who is asked for a key.
+ *
+ * A redirect that the authorization page would refuse is not asked for: the flow opens in
+ * manual mode instead (see {@link openedMode}) and the result says so.
*/
start(input: {
projectId: string;
userId: string;
provider: string;
+ /** The mode asked for; `callback` can still open as `manual`. */
mode: ModelOAuthMode;
- /** Where the provider should send the browser back to; ignored in manual mode. */
+ /** Where the provider should send the browser back to; unused by a manual flow. */
callbackOrigin: string;
}): ModelOAuthStartResult {
const oauth = providerInfo(input.provider)?.oauth;
@@ -239,10 +277,11 @@ export class ModelOAuthService implements ModelOAuth {
const flowId = randomBytes(32).toString("base64url");
const verifier = createVerifier();
const createdAt = this.now();
+ const mode = openedMode(input.mode, input.callbackOrigin);
// The callback keeps its own query string: the provider appends `code=` to whatever
// path and parameters it was given, so the flow id rides back with the code.
const callbackUrl =
- input.mode === "callback"
+ mode === "callback"
? `${input.callbackOrigin}/api/projects/${encodeURIComponent(input.projectId)}/model-oauth/callback?flow=${encodeURIComponent(flowId)}`
: undefined;
this.flows.set(flowId, {
@@ -250,7 +289,7 @@ export class ModelOAuthService implements ModelOAuth {
projectId: input.projectId,
userId: input.userId,
provider: input.provider,
- mode: input.mode,
+ mode,
exchangeUrl: oauth.exchangeUrl,
verifier,
code: null,
@@ -265,6 +304,7 @@ export class ModelOAuthService implements ModelOAuth {
challenge: codeChallenge(verifier),
...(callbackUrl !== undefined ? { callbackUrl } : {}),
}),
+ mode,
};
}
diff --git a/packages/server/test/model-oauth.test.ts b/packages/server/test/model-oauth.test.ts
index 5fa2a8c7..82c4225b 100644
--- a/packages/server/test/model-oauth.test.ts
+++ b/packages/server/test/model-oauth.test.ts
@@ -11,6 +11,9 @@
* failed exchange or an unstorable key ends it with its reason. A redirect deposits the code
* once (a manual flow takes none) and only the owner's poll redeems it; an unpolled deposit
* expires with the flow. The callback origin follows the request unless a proxy is trusted.
+ * - A redirect opens only to an origin the authorization page accepts — HTTPS, or plain HTTP to
+ * `localhost`, `[::1]` or `127.x.x.x`; asked for anywhere else (a LAN address, a hostname,
+ * `0.0.0.0`), the flow opens in manual mode, says so, and still takes a pasted code.
* - The routes: only the owner starts, polls and redeems; the key lands on every model of the
* group and the Project's open Session channels hear credentials_updated; a rejected code
* reaches the dialog through the poll and touches no model; a malformed link answers a page.
@@ -42,6 +45,7 @@ import {
exchangeCode,
FLOW_TTL_MS,
ModelOAuthService,
+ openedMode,
} from "../src/services/model-oauth-service.js";
import { requestOrigin } from "../src/http/routes/model-oauth.js";
import { fakeFetch, jsonResponse, stubFetch } from "./fixtures/fetch.js";
@@ -376,6 +380,37 @@ describe("callback origin", () => {
});
});
+describe("opened mode", () => {
+ it("keeps the redirect for HTTPS and for plain HTTP to a loopback host", () => {
+ for (const origin of [
+ "http://localhost:7364",
+ "http://127.0.0.1:7364",
+ "http://127.8.9.10:7364",
+ "http://[::1]:7364",
+ "https://penguin.example",
+ "https://192.168.1.10:7364",
+ ]) {
+ expect(openedMode("callback", origin), origin).toBe("callback");
+ }
+ });
+
+ it("opens a manual flow where the provider refuses to redirect: plain HTTP off loopback", () => {
+ for (const origin of [
+ "http://192.168.1.10:7364",
+ "http://penguin.lan:7364",
+ "http://0.0.0.0:7364",
+ "http://app.localhost:7364",
+ "not a url",
+ ]) {
+ expect(openedMode("callback", origin), origin).toBe("manual");
+ }
+ });
+
+ it("never turns a manual request into a redirect", () => {
+ expect(openedMode("manual", "http://localhost:7364")).toBe("manual");
+ });
+});
+
/** The route describes' app and the owner of every Project in it. */
let t: TestApp;
let owner: ReturnType<typeof apiClient>;
@@ -436,6 +471,7 @@ describe("model-oauth routes", () => {
);
expect(q.get("key_name")).toBe("Adelie");
expect(q.get("app_url")).toBe(APP_URL);
+ expect(body.mode).toBe("callback");
expect((await member.post(`${base()}/start`, { provider: "tokendance" })).status).toBe(403);
expect((await owner.post(`${base()}/start`, { provider: "deepseek" })).status).toBe(400);
@@ -572,6 +608,24 @@ describe("model-oauth routes", () => {
expect(again.status).toBe(409);
});
+ it("a redirect asked for over plain HTTP on a LAN address opens as manual, says so, and redeems a pasted code", async () => {
+ const lan = (apiPath: string) => `http://192.168.1.10:7364${apiPath}`;
+ const res = await owner.post(lan(`${base()}/start`), { provider: "tokendance" });
+ expect(res.status).toBe(200);
+ const started = (await res.json()) as ModelOAuthStartResponse;
+ expect(started.mode).toBe("manual");
+ const q = new URL(started.authorizeUrl).searchParams;
+ expect(q.has("callback_url")).toBe(false);
+ expect(q.get("code_challenge_method")).toBe("S256");
+ expect(q.get("code_challenge")).toMatch(/^[A-Za-z0-9_-]{43}$/);
+
+ const redeemed = await owner.post(lan(`${base()}/${started.flowId}/code`), {
+ code: "pasted-code",
+ });
+ expect(((await redeemed.json()) as ModelOAuthCodeResponse).ok).toBe(true);
+ expect(exchanges()[0]!.body.code).toBe("pasted-code");
+ });
+
it("polling and redeeming both refuse a member, and 404 an unknown flow", async () => {
const started = (await (
await owner.post(`${base()}/start`, { provider: "tokendance" })
diff --git a/packages/web/src/features/models/models-page.tsx b/packages/web/src/features/models/models-page.tsx
index 00924fe8..bb55278e 100644
--- a/packages/web/src/features/models/models-page.tsx
+++ b/packages/web/src/features/models/models-page.tsx
@@ -4026,7 +4026,9 @@ const OAUTH_POLL_MS = 2000;
* The dialog never handles the key, and never handles the PKCE verifier either: it opens a
* flow, sends the user to the provider's page, and asks the server how that flow ended. Two
* routes back — the provider redirects to the server (polled here), or, when that redirect
- * cannot reach the harness, the user carries a one-time code across by hand.
+ * cannot reach the harness, the user carries a one-time code across by hand. The server has
+ * the last word on which: it opens a manual flow when the provider would refuse to redirect to
+ * the address this page is served from, and the dialog follows the flow it was given.
*/
function ModelOAuthDialog({
projectId,
@@ -4042,7 +4044,16 @@ function ModelOAuthDialog({
onClose: () => void;
onApplied: (applied: number) => void;
}) {
+ /** The route back the user picked. */
const [manual, setManual] = useState(false);
+ /**
+ * Set once a redirect was asked for and the server opened a manual flow: the provider does not
+ * redirect to this address (plain HTTP to anything but loopback), so the code is the only way
+ * back for as long as the dialog is open, and the switch to the redirect is withdrawn.
+ */
+ const [redirectRefused, setRedirectRefused] = useState(false);
+ /** Whether the flow in hand takes the code by hand rather than through the redirect. */
+ const byHand = manual || redirectRefused;
const [phase, setPhase] = useState<OAuthPhase>("starting");
const [flow, setFlow] = useState<{ flowId: string; authorizeUrl: string } | null>(null);
const [error, setError] = useState<string | null>(null);
@@ -4072,6 +4083,7 @@ function ModelOAuthDialog({
mode: manual ? "manual" : "callback",
});
if (cancelled) return;
+ if (!manual && res.mode === "manual") setRedirectRefused(true);
setFlow(res);
setPhase("ready");
} catch (e) {
@@ -4088,7 +4100,7 @@ function ModelOAuthDialog({
// Redirect mode: the outcome lands on the server, so this tab only learns of it by asking.
// A flow that has expired answers 404, which reads the same as never coming back.
useEffect(() => {
- if (phase !== "waiting" || manual || flow === null) return;
+ if (phase !== "waiting" || byHand || flow === null) return;
let stopped = false;
const tick = async (): Promise<void> => {
try {
@@ -4118,12 +4130,12 @@ function ModelOAuthDialog({
stopped = true;
window.clearInterval(timer);
};
- }, [phase, manual, flow, projectId, count]);
+ }, [phase, byHand, flow, projectId, count]);
const openAuthorizePage = (): void => {
if (flow === null) return;
window.open(flow.authorizeUrl, "_blank", "noopener,noreferrer");
- if (!manual) setPhase("waiting");
+ if (!byHand) setPhase("waiting");
};
const submitCode = async (): Promise<void> => {
@@ -4152,7 +4164,7 @@ function ModelOAuthDialog({
<Button size="sm" variant="primary" onClick={() => setAttempt((n) => n + 1)}>
{S.models.oauthRetry}
</Button>
- ) : manual ? (
+ ) : byHand ? (
<Button
size="sm"
variant="primary"
@@ -4199,7 +4211,7 @@ function ModelOAuthDialog({
{S.models.oauthIntro(provider.label, count)}
</p>
)}
- {phase !== "done" && manual && (
+ {phase !== "done" && byHand && (
<>
{/* In the dialog body, directly above the code Input: it takes the same rung the
field does, not the page-level md. */}
@@ -4218,14 +4230,14 @@ function ModelOAuthDialog({
/>
</>
)}
- {phase === "waiting" && !manual && (
+ {phase === "waiting" && !byHand && (
<p className="flex items-center gap-1.5 text-xs text-gray-500 dark:text-gray-400">
<Spinner size="xs" label={S.common.loading} />
{S.models.oauthWaiting}
</p>
)}
{error !== null && <p className="text-xs text-red-600 dark:text-red-400">{error}</p>}
- {phase !== "done" && (
+ {phase !== "done" && !redirectRefused && (
<Button variant="link" size="sm" onClick={() => setManual((v) => !v)}>
{manual ? S.models.oauthCallbackSwitch : S.models.oauthManualSwitch}
</Button>