Skip to content

docs: DownloadButton の外部 postMessage API パラメータ仕様をソースコメントに追加#394

Merged
ujiro99 merged 3 commits into
mainfrom
copilot/document-add-command-parameter-spec
May 3, 2026
Merged

docs: DownloadButton の外部 postMessage API パラメータ仕様をソースコメントに追加#394
ujiro99 merged 3 commits into
mainfrom
copilot/document-add-command-parameter-spec

Conversation

Copilot AI commented May 3, 2026

Copy link
Copy Markdown
Contributor

Hub ページから Content Script へのコマンド追加・削除に使う postMessage API の仕様がコード内に記述されておらず、実装を読まないと把握できない状態だった。

変更内容

  • DownloadButton.tsxhandleMessage 関数直前の useEffect に JSDoc コメントを追加
  • AddCommand アクションのメッセージ形式と command フィールド(JSON 文字列)の構造を記述
    • SearchCommand(openMode: popup / tab / window / backgroundTab / sidePanel
    • AiPromptCommand(openMode: aiPrompt)、aiPromptOptionserviceId, prompt, openMode)の各フィールドを含む
    • PageActionCommand(openMode: pageAction)、pageActionOption の各フィールドを含む
    • 共通任意フィールド: sourceType, sourceId
  • DeleteCommand アクションのメッセージ形式を記述
  • origin 制約(HUB_URL の origin のみ受け付ける)を明示
  • background_script.tsaddCommand ハンドラに AiPromptCommand の処理を追加(isAiPromptCommand による判定と aiPromptOption フィールドの保存)
/**
 * External postMessage API for adding/deleting commands from the Hub.
 *
 * This content script listens for messages from the Hub page (origin must match HUB_URL).
 * The message object must have the following shape:
 *
 * --- AddCommand ---
 * {
 *   action: "AddCommand",
 *   command: string  // JSON-stringified command object (see below)
 * }
 *
 * SearchCommand (openMode is one of "popup" | "tab" | "window" | "backgroundTab" | "sidePanel"):
 * {
 *   id: string, title: string, searchUrl: string, iconUrl: string,
 *   openMode: string, openModeSecondary?: string, spaceEncoding?: string,
 *   sourceType?: string, sourceId?: string
 * }
 *
 * AiPromptCommand (openMode is "aiPrompt"):
 * {
 *   id: string, title: string, iconUrl: string, openMode: "aiPrompt",
 *   aiPromptOption: { serviceId: string, prompt: string, openMode: string },
 *   sourceType?: string, sourceId?: string
 * }
 *
 * PageActionCommand (openMode is "pageAction"):
 * {
 *   id: string, title: string, iconUrl: string, openMode: "pageAction",
 *   pageActionOption: { startUrl, pageUrl?, openMode, steps, userVariables? },
 *   sourceType?: string, sourceId?: string
 * }
 *
 * --- DeleteCommand ---
 * { action: "DeleteCommand", id: string }
 */

Copilot AI changed the title [WIP] Document parameter specification for addCommand API docs: DownloadButton の外部 postMessage API パラメータ仕様をソースコメントに追加 May 3, 2026
Copilot AI requested a review from ujiro99 May 3, 2026 03:01
Copilot finished work on behalf of ujiro99 May 3, 2026 03:01
@ujiro99

ujiro99 commented May 3, 2026

Copy link
Copy Markdown
Owner

@copilot
AiPromotコマンドのケースを追加してください。

Copilot AI commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

@copilot
AiPromotコマンドのケースを追加してください。

AiPromptCommandのケースを追加しました(commit: 12bbf99)。

変更内容:

  • DownloadButton.tsx のAPIドキュメントコメントに AiPromptCommand の仕様を追加(serviceId, prompt, openMode フィールドを含む aiPromptOption
  • background_script.tsaddCommand ハンドラにも AiPromptCommand の処理を追加(これまで openMode: "aiPrompt" のコマンドは null になり失敗していました)

Copilot finished work on behalf of ujiro99 May 3, 2026 05:01
@ujiro99 ujiro99 marked this pull request as ready for review May 3, 2026 06:03
@ujiro99 ujiro99 merged commit e145abb into main May 3, 2026
1 check passed
@ujiro99 ujiro99 deleted the copilot/document-add-command-parameter-spec branch May 3, 2026 06:04
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.

外部からのコマンド追加APIのパラメータ仕様のドキュメント化

2 participants