docs(hooks): correct UserPromptSubmit prompt field type to ContentPart[]#932
Open
itxaiohanglover wants to merge 2 commits into
Open
docs(hooks): correct UserPromptSubmit prompt field type to ContentPart[]#932itxaiohanglover wants to merge 2 commits into
itxaiohanglover wants to merge 2 commits into
Conversation
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Hooks documentation (
docs/en/customization/hooks.mdanddocs/zh/customization/hooks.md) leads hook authors to believe theUserPromptSubmitpayload fieldpromptis the submitted text string. In reality, the code sends the rawContentPart[]array.Source verification:
packages/agent-core/src/agent/turn/index.ts—applyUserPromptHooktriggers the hook withinputData: { prompt: input }whereinputisreadonly ContentPart[].packages/agent-core/src/session/hooks/engine.ts—triggerInnerflattensmatcherValueto text viamatcherValueText(...)for the matcher regex, but spreads...args.inputData(includingprompt) into the payload verbatim. The payloadpromptfield never goes through the text join.A hook that reads
payload.promptexpecting 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
UserPromptSubmitrow): updated the description in both EN and ZH docs to mention that the payload includes apromptfield of typeContentPart[].promptis aContentPart[]array, not a plain string.{"prompt": [{"type": "text", "text": "user's message"}]}.matcherregex 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).payload.prompt.filter(p => p.type === 'text').map(p => p.text).join(' ').Docs-only change, no source code or behavior changes.
Fixes #917