Make wpcom.req.*
default response type unknown
and add more zod schemas
#899
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.
Related issues
Proposed Changes
Our type definitions in
src/custom-package-definitions.d.ts
are very lax for theRequest
class in theWPCOM
module – it sets the default response data type toany
.Now that we have zod in the codebase, defaulting to
unknown
is much more fitting since this forces us to validate the response data.This PR makes that change, and fixes a few bugs I discovered along the way:
/studio-app/ai-assistant/chat
API responses was incorrect. The topmostid
prop is a number, not a string.Message[ 'chatApiId' ]
type was also invalid (previouslystring
, nownumber
). Same thing for thechatApiIdDict
state.promptUsageDict
object, dividing it by site. This doesn't make sense since we limit prompt usage per WordPress.com user, not per site. I changed the state structure accordingly.Testing Instructions
1.1 Ensure previous conversations load as expected
1.2 Ensure sending new messages works as expected
1.3 Ensure the prompt usage meter in the settings modal updates as you send messages to the Assistant
Pre-merge Checklist