🔐workos-widgets
- プラグイン
- workos
- ソース
- GitHub で見る ↗
説明
次のような場合に使用: ユーザーが WorkOS Widget(具体的には User Management、User Profile、Admin Portal SSO Connection、または Admin Portal Domain Verification の各 Widget)を実装・埋め込み・デバッグしている場合。 フルスタックに対応しており、フロントエンド(Next.js、React、React Router、TanStack Start、Vite、SvelteKit)の検出、バックエンド SDK(Node、Python、Go、Ruby、PHP、Java、.NET)を使用したアクセストークンの生成、およびバンドルされた OpenAPI 仕様に基づく Widget コンポーネントの正確な配線設定を処理します。 また、コードが `@workos-inc/widgets` からインポートしている場合、またはユーザーが `<UserManagement />` や `<UserProfile />` の JSX を貼り付けた場合にも使用します。
原文を表示
Use when the user is implementing, embedding, or debugging a WorkOS Widget — specifically the User Management, User Profile, Admin Portal SSO Connection, or Admin Portal Domain Verification widgets. Handles the full stack — detecting the frontend (Next.js, React, React Router, TanStack Start, Vite, SvelteKit), generating access tokens via the backend SDK in use (Node, Python, Go, Ruby, PHP, Java, .NET), and wiring up the widget component correctly per the bundled OpenAPI spec. Also use when code imports from @workos-inc/widgets or the user pastes <UserManagement /> or <UserProfile /> JSX.
ユースケース
- ✓WorkOS Widgetを実装・埋め込みしている
- ✓WorkOS Widgetをデバッグしている
- ✓@workos-inc/widgetsからインポートしている
- ✓UserManagementやUserProfileのJSXを貼り付けている
- ✓アクセストークン生成やWidget配線設定を行っている
本文(日本語訳)
WorkOS Widgets
ワークフロー概要
- ユーザーリクエストからウィジェットのターゲットを特定する
(
user-management、user-profile、admin-portal-sso-connection、admin-portal-domain-verification)。 - 以下の順序でプロジェクトファイルをスキャンする:
- パッケージ/依存関係マニフェスト
- フレームワーク/ルーターのエントリポイント
- 認証/トークンユーティリティ
- スタイリング/コンポーネントパターン
- references/detection.md を参照し、スタック・データレイヤースタイル・スタイリング・コンポーネントシステム・パッケージマネージャーを検出する。
- AuthKit/WorkOS の存在を確認する:
- 検出された場合は処理を続行する
- 検出されなかった場合は、
WORKOS_MODE=agent npx workos@latest installを実行するようユーザーに案内し、確認を待ってから続行する。
- 検出結果が曖昧または矛盾している場合は、的を絞った質問を1つ行い、その後続行する。
- 検出されたスタックおよびウィジェットに関連するリファレンスファイルのみを読み込む。
- スタックの構成に応じて統合を実装する:
- ウィジェットUIが同一アプリ内に存在する場合: フロントエンドのルート/ページ + ウィジェットコンポーネント
- バックエンドファースト/マルチアプリ構成が検出された場合: トークンエンドポイント/サービス + クライアント統合インターフェース
- 完了前にルーティング/配線・インポート・トークン/API の使用状況を検証する。
標準入力
ユーザーリクエストから以下の入力が提供されている場合は受け取る:
- ウィジェットの種類(またはリクエストの意図から推定)
- コンポーネントパス(任意)
- ページ/ルートパス(任意)
- トークンエンドポイント/サービスの優先指定(任意)
- 制約条件(任意。例: 広範なリファクタリングを避けるなど)
入力が不足している場合は、既存のプロジェクト規約と検出されたスタックから推定する。
検出と曖昧性解消のプロトコル
- references/detection.md の検出ヒューリスティックを適用する。
- まず調査してから質問する。マニフェストおよびルート/認証エントリポイントを確認した後も曖昧さが残る場合にのみ質問する。
- 1つの判断を解決する、具体的な質問を1問だけ行う。
- ユーザーからの回答がない場合は、検出された最も確度の高いオーナーシップシグナルをデフォルトとして採用する。
- インストールが必要な場合は、プロジェクトファイル/ロックファイルから検出したパッケージマネージャーを使用する。
リファレンス読み込みマップ
以下のコアリファレンスは常に読み込む:
- references/detection.md
- references/token-strategies.md
- references/fetching-apis.md
- references/styling-and-components.md
React/TypeScript スタック(Next.js、React Router、TanStack Router、TanStack Start、Vite)の場合は、追加で以下も読み込む:
スタック固有のリファレンスガイダンスを読み込む:
- Next.js: references/framework-nextjs.md
- React Router: references/framework-react-router.md
- TanStack Router: references/framework-tanstack-router.md
- TanStack Start: references/framework-tanstack-start.md
- Vite: references/framework-vite.md
- SvelteKit: references/framework-sveltekit.md
- Ruby: references/framework-ruby.md
- Python: references/framework-python.md
- Go: references/framework-go.md
- PHP: references/framework-php.md
- Java: references/framework-java.md
- 混合リポジトリ: references/framework-mixed-repositories.md
次に、ウィジェットリファレンスをちょうど1つ読み込む:
- User Management: references/widget-user-management.md
- User Profile: references/widget-user-profile.md
- Admin Portal SSO Connection: references/widget-admin-portal-sso-connection.md
- Admin Portal Domain Verification: references/widget-admin-portal-domain-verification.md
ウィジェット全体共通のガイダンス
- ウィジェット操作の実装には references/fetching-apis.md に記載されたエンドポイントパス/メソッドを使用する。リクエストボディの構築やレスポンスの解析を行う際は、対象ウィジェットのスキーマについて OpenAPI スペックを以下のコマンドでクエリする:
利用可能なウィジェットグループを確認するにはnode references/scripts/query-spec.cjs --widget <widget-name>--listを使用する。 - ローディング状態・空状態・エラー状態は明示的にし、ユーザーに見える形で表示する。
- ミューテーションの結果を可視化し、変更が成功した後は影響を受けるデータを更新/再読み込みする。
- テーブル/リスト/アクションのUIは既存のプロジェクト規約に合わせる。
- 部分的/任意のデータに対して動作が堅牢になるようにし、脆弱なUI前提を避ける。
コアガイドライン
- ホストプロジェクトの既存ドメイン型および OpenAPI スキーマを再利用し、モデル定義の重複を避ける。
- ウィジェットリクエストの構築には references/fetching-apis.md を参照してパス・メソッド・スキーマクエリを取得する。
- エンドポイント呼び出しには直接
fetch/HTTP 呼び出し(またはサーバー側の同等の HTTP クライアント)を使用する。 - ウィジェットリクエストに対して一貫した認可レイヤーを実装する。必要に応じて機密エンドポイント向けの昇格トークン処理も含める。
- アプリがすでに React Query や SWR を使用している場合は、それらの直接呼び出しに対するオーケストレーション/キャッシュレイヤーとして活用する。
- React/TypeScript ウィジェットコードの品質基準については references/react-ts-standards.md に従う。
- AuthKit/WorkOS が存在しない場合は、処理を続ける前に
WORKOS_MODE=agent npx workos@latest installを実行するようユーザーに促す。WORKOS_MODE=agentはインストーラーを確定的に動作させる(プロンプトなし・ブラウザなし・ホスト信頼なし)。出力を解析する必要がある場合は--jsonを渡す。 - 追加の依存関係は厳密に必要な場合のみインストールし、検出したパッケージマネージャー/ツールを使用する。
- サーバーステートの処理は選択したデータレイヤーアプローチに合わせて統一する。
- UI インタラクション状態にはローカルステート/リデューサーを必要に応じて使用する。
- 既存のデザインシステムおよびスタイリング規約を優先する。
- 関連のない広範なリファクタリングやグローバルなスタイルの書き直しは避ける。
完了要件
完了前に、以下の該当項目をすべて確認する:
- コンポーネントレベルの統合が対象である場合、ウィジェットコンポーネントが存在し、
accessToken: stringを受け取ること。 - ルート統合が対象である場合、ルート/ページの配線が完了していること。
- トークンのソースが既存のアプリアーキテクチャと一致していること(AuthKit クライアントフロー、またはバックエンド WorkOS トークンフロー)。
- API メソッドおよびパスがバンドルされた OpenAPI スペックと一致し、データレイヤーの使用方法がプロジェクト規約と一致していること。
- 必要なクエリ/ミューテーションフローにローディングおよびエラーの分岐が存在すること。
バリデーションチェックリスト
- エンドポイントパスおよび HTTP メソッドがバンドルされた OpenAPI スペックに基づいていることを確認する。
- リクエスト/レスポンスの処理がスペックのスキーマ仕様に従っていることを確認する。
- ミューテーション成功後に必要な箇所でクエリ/ミューテーションの無効化/再フェッチが適用されていることを確認する。
- 空/エラー/ローディング状態が明示的にユーザーに表示されることを確認する。
- パッケージのインストール(実施した場合)に検出されたパッケージマネージャー/ツールが使用されていることを確認する。
- 実装が既存のコードベース規約と一致していることを確認する。
- 既存のコンポーネントに
classNameやstyleプロパティを渡して組み込みスタイリングを上書きしていないことを確認する。各コンポーネントはそのままか、固有の props API(variant、sizeなど)を通じて使用すること。
原文(English)を表示
WorkOS Widgets
Workflow Overview
- Identify widget target from the user request (
user-management,user-profile,admin-portal-sso-connection,admin-portal-domain-verification). - Scan project files in this order:
- package/dependency manifests
- framework/router entrypoints
- auth/token utilities
- styling/component patterns
- Detect stack, data-layer style, styling, component system, and package manager using references/detection.md.
- Check for AuthKit/WorkOS presence:
- if detected, continue;
- if not detected, ask the user to run
WORKOS_MODE=agent npx workos@latest install. Wait for confirmation, then continue.
- If detection is ambiguous or conflicting, ask one focused question, then continue.
- Load only the relevant reference files for the detected stack and widget.
- Implement integration based on stack shape:
- frontend route/page + widget component when widget UI lives in the same app
- token endpoint/service + client integration surface when backend-first/multi-app architecture is detected
- Validate routing/wiring, imports, and token/API usage before finishing.
Canonical Inputs
Accept these inputs from the user request when available:
- widget type (or infer from request intent)
- optional component path
- optional page/route path
- optional token endpoint/service preference
- optional constraints (for example: avoid broad refactors)
When input is missing, infer from existing project conventions and detected stack.
Detection and Ambiguity Protocol
- Apply detection heuristics from references/detection.md.
- Explore before asking. Ask only when ambiguity remains after checking manifests and route/auth entrypoints.
- Ask a single concrete question that resolves one decision.
- Default to the strongest detected ownership signals when no user response is available.
- When installs are required, use the package manager detected from project files/lockfiles.
Reference Loading Map
Always load these core references:
- references/detection.md
- references/token-strategies.md
- references/fetching-apis.md
- references/styling-and-components.md
For React/TypeScript stacks (Next.js, React Router, TanStack Router, TanStack Start, Vite), also load:
Load stack-specific reference guidance:
- Next.js: references/framework-nextjs.md
- React Router: references/framework-react-router.md
- TanStack Router: references/framework-tanstack-router.md
- TanStack Start: references/framework-tanstack-start.md
- Vite: references/framework-vite.md
- SvelteKit: references/framework-sveltekit.md
- Ruby: references/framework-ruby.md
- Python: references/framework-python.md
- Go: references/framework-go.md
- PHP: references/framework-php.md
- Java: references/framework-java.md
- Mixed repositories: references/framework-mixed-repositories.md
Then load exactly one widget reference:
- User Management: references/widget-user-management.md
- User Profile: references/widget-user-profile.md
- Admin Portal SSO Connection: references/widget-admin-portal-sso-connection.md
- Admin Portal Domain Verification: references/widget-admin-portal-domain-verification.md
Global Widget Guidance
- Implement widget operations using endpoint paths/methods from references/fetching-apis.md. When building request bodies or parsing responses, query the OpenAPI spec for the relevant widget's schemas:
Usenode references/scripts/query-spec.cjs --widget <widget-name>--listto see available widget groups. - Keep loading, empty, and error states explicit and user-visible.
- Keep mutation outcomes visible and refresh/reload affected data after successful changes.
- Align table/list/action UI with existing project conventions.
- Keep behavior resilient for partial/optional data and avoid brittle UI assumptions.
Core Guidelines
- Reuse existing domain types from the host project and OpenAPI schemas; avoid duplicating model definitions.
- Build widget requests using references/fetching-apis.md for paths, methods, and schema queries.
- Use direct
fetch/HTTP calls (or equivalent server HTTP client) for endpoint calls. - Implement a consistent authorization layer for widget requests, including elevated-token handling for sensitive endpoints when required.
- If the app already uses React Query or SWR, use them as orchestration/cache layers around those direct calls.
- For React/TypeScript widget code quality expectations, follow references/react-ts-standards.md.
- If AuthKit/WorkOS is missing, prompt the user to run
WORKOS_MODE=agent npx workos@latest installbefore continuing.WORKOS_MODE=agentkeeps the installer deterministic (no prompts, no browser, no host-trust); pass--jsonwhen you need to parse the output. - Install additional dependencies only when strictly necessary, using the detected package manager/tooling.
- Keep server-state handling aligned with the selected data-layer approach.
- Use local state/reducers for UI interaction state as needed.
- Prefer existing design system and styling conventions.
- Avoid broad unrelated refactors and global style rewrites.
Completion Requirements
Before finishing, verify all relevant items:
- Widget component exists and accepts
accessToken: stringwhen component-level integration is in scope. - Route/page wiring is complete when route integration is in scope.
- Token source matches existing app architecture (AuthKit client flow or backend WorkOS token flow).
- API methods and paths match the bundled OpenAPI spec, and data-layer usage matches project conventions.
- Loading and error branches exist for required query/mutation flows.
Validation Checklist
- Confirm endpoint paths and HTTP methods come from the bundled OpenAPI spec.
- Confirm request/response handling follows schema expectations from the spec.
- Confirm query/mutation invalidation/refetch is applied after successful mutations where required.
- Confirm empty/error/loading states are explicit and user-visible.
- Confirm package installs (if any) used the detected package manager/tooling.
- Confirm implementation stays aligned with existing codebase conventions.
- Confirm no existing component has been passed
classNameorstyleprops to override its built-in styling. Use each component as-is or via its own props API (variant,size, etc.).
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。