Skip to content

fix: 新增机器人渠道批量查询并收敛能力加载与错误码分支 - #1803

Merged
qqqqqf-q merged 2 commits into
felinics:mainfrom
qqqqqf-q:fix/memoh-315-bot-channels-and-capabilities
Nov 18, 2026
Merged

qqqqqf-q merged 2 commits into
felinics:mainfrom
qqqqqf-q:fix/memoh-315-bot-channels-and-capabilities

Conversation

@qqqqqf-q

@qqqqqf-q qqqqqf-q commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Author

  • Agent
  • Human

Type

  • bug
  • feat
  • test

Summary

  • 新增机器人渠道配置批量查询接口与前端单一路径收敛:
    • 在 internal/handlers/users.go 注册 GET /bots/{id}/channels(ListBotChannelConfigs),复用 channelStore.ListConfigs 与 authorizeBotAccess(要求 manage 权限),返回非空切片 items(ListBotChannelsResponse),并同步更新 OpenAPI 文档与 @memohai/sdk(getBotsByIdChannels);后端保留既有 GET /bots/{id}/channel/{platform}(GetBotChannelConfig)以兼容尚未升级的捆绑版客户端。
    • 精简 useBotChannels 为单次批量并发查询(Promise.all([getChannels, getBotsByIdChannels])),移除前端对旧服务端逐平台探测的回退逻辑;真实错误(403/5xx/断网与 bot.not_found 等)直接抛出,不再被误吞后渲染为空白“未配置”。
    • 提取共享权限判断 canManageBotPermissions;修复 bot-overview.vue 渠道错误未解包 error.value 的问题,并在 bot-channels.vue 与 bot-overview.vue 展示加载失败态与重试入口,无 manage 权限时跳过查询与平台空态。
  • 在客户端统一边界补齐 HTTP 错误状态码保留:
    • 在 apps/web/src/lib/api-client.ts 的 setupApiClient 中幂等安装 attachErrorResponseStatus 错误拦截器(client.interceptors.error),确保 @hey-api/client-fetch 在 throwOnError: true 抛出非 Problem Details JSON(如 { message: "..." })或纯文本响应体时,异常对象仍携带 status: response.status,网络异常(TypeError 等)原样透传;补充基于真实 Response 对象的单测。
  • 精简 /ping 能力加载至普通 Pinia Store:
    • 将 useCapabilitiesStore 收敛为带单飞去重(inflight)与会话代次隔离(sessionGeneration)的普通 Pinia store,不再依赖 localStorage 持久化查询缓存或访问内部 _pc_query 注册表,并修复登出与在途 /ping 响应交错导致的会话串号与重复请求问题。
  • 移除失效的英文错误文案子串匹配分支:
    • 删除 files-pane.vue(isTransientWorkspaceError)与 bot-settings.vue(isNameConflict)中依赖未本地化服务端英文文案的子串匹配死分支,统一改用稳定错误码 isApiErrorCode 及 409 状态码判断,并同步更新 .agents/skills/memoh-error-handling/SKILL.md 的状态码保留说明。

Related Issues

Validation

  • 自动检查:
    • go test ./internal/handlers/... ./internal/channel/... ./internal/apperror/... ./internal/server/... 与 golangci-lint run --new-from-rev=32e2ce05b ./internal/handlers/... 通过(含 TestListBotChannelConfigs 5 项子测试)。
    • node scripts/check-ui-contract.mjs、node scripts/check-settings-rows.mjs、node scripts/check-patched-deps.mjs 通过。
    • pnpm --filter @memohai/web typecheck、pnpm --filter @memohai/desktop typecheck、pnpm exec eslint apps/web/src apps/desktop/src(0 errors)通过。
    • pnpm vitest run(304 个测试文件全部通过,2789 passed / 1 skipped,含 api-client.test.ts 14/14、useBotChannels.test.ts、capabilities.test.ts)与 VITE_API_URL=/api pnpm --filter @memohai/web build 通过。
  • Agent 真实后端与浏览器自检:
    • 本地启动包含本次后端改动的 cmd/agent serve(127.0.0.1:18192)与 vite preview(127.0.0.1:18184),通过 ego-browser 验证:
      • 冷启动 /settings/bots/neko 仅发出 1 次 GET /api/ping(200)与 GET /api/bots/.../channels(200),GET /api/bots/.../channel/{platform} 请求次数为 0,无运行期 JS 异常。
      • 切至 Platforms 页签(/settings/bots/neko?tab=channels)仅使用批量接口,无运行期 JS 异常。
      • 在单页应用内切至 About 页(/settings/about)发出 0 次额外 GET /api/ping,无运行期 JS 异常。
  • 未覆盖范围:尚未经过真人 QA。

Screenshots / Recordings

Bot 概览页与平台状态正常渲染(单次 GET /api/ping 与 GET /api/bots/.../channels 200)
Bot Platforms 页签正常渲染(0 条 /channel/:platform 请求)

Human QA

  • Human QA passed

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T07:41:06.554935Z ccab606 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added bug Fixes a bug or unexpected behavior change:server Changes backend code, configuration, or API contracts change:web Changes web frontend or shared frontend packages size:M PR size uses the larger of added or deleted lines, excluding generated files labels Nov 18, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d18bf8d26

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

function isMissingEndpointFallback(error: unknown): boolean {
// Distinguish an older server without `GET /bots/:id/channels` (generic 404)
// from a deleted/unknown bot (`bot.not_found`).
return apiErrorStatus(error) === 404 && !isApiErrorCode(error, 'bot.not_found')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve HTTP status for legacy channel lookups

When Desktop connects to an older server returning HTTP 404 as {"message":"Not Found"}, the generated SDK throws only the parsed body (packages/sdk/src/client/client.gen.ts:189–211). Consequently, apiErrorStatus(error) is undefined, the legacy fallback never runs, and both Overview and Platforms fail despite the per-platform endpoints still working. Message-only 404s from the legacy per-platform probes have the same problem. Preserve the actual response.status in these compatibility lookups and test real HTTP response shapes rather than mocked errors that already contain status. Desktop directly reuses this Web implementation, so this affects the separately distributed client.

AGENTS.md reference: apps/web/AGENTS.md:L3-L3

Useful? React with 👍 / 👎.

@qqqqqf-q

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: ccab6064bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@qqqqqf-q
qqqqqf-q merged commit 2a2d6a0 into felinics:main Nov 18, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes a bug or unexpected behavior change:server Changes backend code, configuration, or API contracts change:web Changes web frontend or shared frontend packages size:M PR size uses the larger of added or deleted lines, excluding generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant