Skip to content

docs(hooks): correct UserPromptSubmit prompt field type to ContentPart[]#932

Open
itxaiohanglover wants to merge 2 commits into
MoonshotAI:mainfrom
itxaiohanglover:fix/docs-hook-prompt-contentpart-array
Open

docs(hooks): correct UserPromptSubmit prompt field type to ContentPart[]#932
itxaiohanglover wants to merge 2 commits into
MoonshotAI:mainfrom
itxaiohanglover:fix/docs-hook-prompt-contentpart-array

Conversation

@itxaiohanglover

Copy link
Copy Markdown

Problem

The Hooks documentation (docs/en/customization/hooks.md and docs/zh/customization/hooks.md) leads hook authors to believe the UserPromptSubmit payload field prompt is the submitted text string. In reality, the code sends the raw ContentPart[] array.

Source verification:

  • packages/agent-core/src/agent/turn/index.tsapplyUserPromptHook triggers the hook with inputData: { prompt: input } where input is readonly ContentPart[].
  • packages/agent-core/src/session/hooks/engine.tstriggerInner flattens matcherValue to text via matcherValueText(...) for the matcher regex, but spreads ...args.inputData (including prompt) into the payload verbatim. The payload prompt field never goes through the text join.

A hook that reads payload.prompt expecting a string gets [{"type":"text","text":"hello"}] instead, so naive string handling (payload.prompt.includes(...), .toLowerCase(), regex, etc.) silently produces wrong/empty results.

What changed

  • Event Reference table (UserPromptSubmit row): updated the description in both EN and ZH docs to mention that the payload includes a prompt field of type ContentPart[].
  • Added a tip callout after the Event Reference table in both EN and ZH docs that:
    • States prompt is a ContentPart[] array, not a plain string.
    • Shows the actual payload shape: {"prompt": [{"type": "text", "text": "user's message"}]}.
    • Explains that the matcher regex is applied to the joined text of those parts (which is why the Event Reference says "The text submitted by the user" — that describes the matcher, not the payload field).
    • Includes a code snippet showing how to recover the plain text: payload.prompt.filter(p => p.type === 'text').map(p => p.text).join(' ').

Docs-only change, no source code or behavior changes.

Fixes #917

@changeset-bot

changeset-bot Bot commented Jun 20, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8eb3705

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

docs(hooks): UserPromptSubmit hook payload prompt is a ContentPart[] array, not the submitted text string

1 participant