Overview
Reviewing #3555154: Canvas AI: Update the image's src prop to use latest schema. I confused what modules/canvas_ai/src/PropsSchema.json is actually used for.
If you search modules/canvas_ai for "PropsSchema.json" or just "PropsSchema" you wouldn't find any results.
So at first I thought this wasn't used but then I found it is referenced in ui/src/components/aiExtension/AiWizard.tsx
import fixtureProps from '../../../../modules/canvas_ai/src/PropsSchema.json';
This weird because this is the only case where our js is importing files from the php src directory
Weirder is the client doesn't actually use these values it just appends to the request as `derived_proptypes`, No other client code references this.
Where this is used is \Drupal\canvas_ai\Controller\CanvasBuilder::render in a call to \Drupal\ai_agents\PluginBase\AiAgentEntityWrapper::setTokenContexts
'derived_proptypes' => isset($prompt['derived_proptypes']) ? Json::encode($prompt['derived_proptypes']) : NULL,
and $prompt['derived_proptypes'] is just decoded from the request.
so I am confused as to why
- the client imports modules/canvas_ai/src/PropsSchema.json which is in a php src code directory,
- appends it to the request without doing anything else with it
- the server side code decodes and uses this for a token value
If only the server needs this why doesn't it just decode modules/canvas_ai/src/PropsSchema.json directly? Why does it need to do come from the client at all
Proposed resolution
Either
- Add comments in appropriate places as to why the current workflow is needed
- Move PropsSchema.json out of source into canvas_ai/assets/PropsSchema.json and have \Drupal\canvas_ai\Controller\CanvasBuilder::render just decode canvas_ai/assets/PropsSchema.json directly without it coming from the client.
User interface changes
none
Comments