Skip to content

汎用Receiver Registry APIを追加 - #591

Merged
tegnike merged 2 commits into
developfrom
codex/receiver-registry-api
Aug 4, 2026
Merged

汎用Receiver Registry APIを追加#591
tegnike merged 2 commits into
developfrom
codex/receiver-registry-api

Conversation

@tegnike

@tegnike tegnike commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • AITuberKitを開いているブラウザタブ・OBS Browser Sourceごとに一時的なreceiverIdを登録し、接続中Receiverを列挙する認証付きGET /api/v1/receiversを追加しました。
  • 発話・チャット・停止・Presentation操作の既存APIでreceiverIdを優先配送先として受け付け、従来のclientId経路も後方互換として維持しました。
  • Receiver固有経路と従来経路の二重処理を避けるタブリーダー互換処理、10秒TTL、capabilities、Producer非依存の責務境界を仕様書として追加しました。

Verification

  • npm exec -- eslint(変更したTypeScript/TSXファイル)
  • npm exec -- prettier --check(変更ファイルと仕様書)
  • npm test -- --runInBand src/__tests__/features/api/clientTabLeadership.test.ts src/__tests__/features/api/receiverRegistry.test.ts src/__tests__/pages/api/v1/externalApi.test.ts(3 suites / 30 tests passed)
  • npm run build(成功、/api/v1/receiversの生成を確認)
  • 全体テストは200 suites / 2205 testsが成功。既存のsrc/__tests__/features/stores/images.test.tsのみ、NodeのlocalStorage未設定による14件の失敗があり、未変更のdevelop系worktreeでも単独再現することを確認済みです。

Notes

  • Registryは既存のmessage gatewayと同じNode.jsプロセス内メモリを使用します。複数プロセス・サーバーレス間の共有は本PRの対象外です。
  • Receiver選択UIや自動フェイルオーバーなど、Producer固有の判断はAITuberKit側へ持ち込まず、外部アプリケーション側の責務としています。

Summary by CodeRabbit

  • 新機能

    • 接続中のReceiver一覧を取得するAPIを追加しました。
    • Receiverごとの種別、表示名、対応機能、発話状態、最終更新時刻を確認できます。
    • receiverIdを優先したメッセージ配送に対応し、従来のclientIdも引き続き利用できます。
    • Receiverの状態・能力情報を自動報告できるようになりました。
    • Receiver単位でメッセージを取得できるAPIを追加しました。
  • ドキュメント

    • Receiver Registry APIの仕様書を追加しました。
  • セキュリティ

    • Receiver関連APIにAPIキー認証とアクセス制御を適用しました。

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Receiver Registry APIを追加しました。Receiver ID、種別、表示名、能力、状態一覧、指定配送を実装しました。clientId互換を維持し、ReceiverモードとLegacyモードの通信を分離しました。

Changes

Receiver Registry

Layer / File(s) Summary
Receiver契約と記述子
src/features/api/receiverRegistry.ts, src/pages/api/v1/client/status.ts, src/__tests__/features/api/receiverRegistry.test.ts, docs/receiver-registry-api-spec.md
Receiver ID、種別、表示名、能力、記述子を追加しました。status入力の許可値と長さ制限を追加しました。仕様書と単体テストを追加しました。
一覧APIと指定配送
src/features/api/messageGateway.ts, src/features/api/http.ts, src/pages/api/v1/receivers.ts, src/pages/api/v1/client/messages.ts, src/pages/api/v1/events.ts, src/lib/accessPolicy/routePolicies.ts, src/__tests__/pages/api/v1/externalApi.test.ts
アクティブReceiverの抽出と一覧APIを追加しました。receiverIdを優先する配送先選択とclientIdフォールバックを追加しました。メッセージ取得APIとAPIキー必須のルートポリシーを追加しました。
Receiver通信とLegacy互換
src/components/messageReceiver.tsx
sessionStorageのタブIDからReceiver descriptorを生成します。Receiver IDごとにstatus、command、messageの取得とtimestamp管理を行います。Receiver割り当て時はLegacy側の同期を抑制します。

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Receiver as MessageReceiver
  participant Status as Client Status API
  participant Gateway as MessageGateway
  participant Control as External Control API
  participant Registry as Receivers API
  Receiver->>Status: Receiver statusを送信
  Status->>Gateway: ClientStatusを保存
  Control->>Registry: Receiver一覧を要求
  Registry->>Gateway: listActiveReceivers()を実行
  Gateway-->>Registry: ActiveReceiver一覧を返却
  Control->>Gateway: receiverIdを指定してメッセージを配送
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed タイトルは、Receiver Registry APIの追加というプルリクエストの主要な変更を簡潔かつ明確に示しています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/receiver-registry-api

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/messageReceiver.tsx`:
- Around line 590-602: Update fetchMessages so Receiver mode uses a new
API-key-protected message retrieval endpoint, while Legacy mode continues
calling the existing unauthenticated /api/messages route. Add the Receiver-only
endpoint with API-key authentication and dequeueMessages(clientId) behavior,
then route mode === 'receiver' requests through it without changing Legacy
behavior.

In `@src/pages/api/v1/events.ts`:
- Around line 17-22: Update the clientId selection logic to trim both
req.query.receiverId and req.query.clientId, prioritize receiverId only when its
trimmed value is non-empty, and otherwise fall back to the trimmed clientId.
Preserve undefined when neither value contains usable content so the existing
downstream behavior remains correct.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5a0bff46-b9e9-4d5b-866b-4a5f9464b4e8

📥 Commits

Reviewing files that changed from the base of the PR and between 2eab8c0 and 3f3bc15.

📒 Files selected for processing (11)
  • docs/receiver-registry-api-spec.md
  • src/__tests__/features/api/receiverRegistry.test.ts
  • src/__tests__/pages/api/v1/externalApi.test.ts
  • src/components/messageReceiver.tsx
  • src/features/api/http.ts
  • src/features/api/messageGateway.ts
  • src/features/api/receiverRegistry.ts
  • src/lib/accessPolicy/routePolicies.ts
  • src/pages/api/v1/client/status.ts
  • src/pages/api/v1/events.ts
  • src/pages/api/v1/receivers.ts

Comment thread src/components/messageReceiver.tsx
Comment thread src/pages/api/v1/events.ts Outdated

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/pages/api/v1/client/messages.ts (1)

7-14: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

HTTPメソッドを検証してください。

handler はHTTPメソッドを確認していません。dequeueMessages はキューからメッセージを削除する副作用を持つと推測されます。GET以外のメソッドでもこの副作用が発生します。

req.method が想定するメソッド(例:GET)でない場合、405を返す処理を追加してください。

💡 メソッド検証の追加案
 const handler = (req: NextApiRequest, res: NextApiResponse) => {
+  if (req.method !== 'GET') {
+    return res.status(405).json({ error: 'Method Not Allowed' })
+  }
+
   const clientId = getClientIdFromRequest(req)
   if (!clientId) {
     return res.status(400).json({ error: 'Client ID is required' })
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/api/v1/client/messages.ts` around lines 7 - 14,
handlerでgetClientIdFromRequestを呼ぶ前にreq.methodを検証し、想定するGET以外のメソッドには405を返して処理を終了するよう更新してください。GETの場合のみ既存のclientId検証とdequeueMessages(clientId)呼び出しを実行し、その他のレスポンス処理は維持してください。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/pages/api/v1/client/messages.ts`:
- Around line 7-14:
handlerでgetClientIdFromRequestを呼ぶ前にreq.methodを検証し、想定するGET以外のメソッドには405を返して処理を終了するよう更新してください。GETの場合のみ既存のclientId検証とdequeueMessages(clientId)呼び出しを実行し、その他のレスポンス処理は維持してください。

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 75c52de9-30db-4060-8173-fca6bbd14c34

📥 Commits

Reviewing files that changed from the base of the PR and between 3f3bc15 and 1d37e10.

📒 Files selected for processing (6)
  • docs/receiver-registry-api-spec.md
  • src/__tests__/pages/api/v1/externalApi.test.ts
  • src/components/messageReceiver.tsx
  • src/lib/accessPolicy/routePolicies.ts
  • src/pages/api/v1/client/messages.ts
  • src/pages/api/v1/events.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/pages/api/v1/events.ts
  • src/tests/pages/api/v1/externalApi.test.ts
  • src/lib/accessPolicy/routePolicies.ts
  • docs/receiver-registry-api-spec.md
  • src/components/messageReceiver.tsx

@tegnike
tegnike merged commit eb8f35a into develop Aug 4, 2026
8 checks passed
@tegnike
tegnike deleted the codex/receiver-registry-api branch August 4, 2026 13:06
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.

1 participant