Skip to content

Editor field widgets

The module adds two Svelte field components to the FlowDrop field registry. They render any node parameter whose JSON schema has the matching format, so other node processors can use them too.

Registry name Schema format Data source
flowdrop-agents:agent-selector ai_agent_selector /api/flowdrop/ai-agents/...
flowdrop-agents:search-index-selector ai_search_index_selector /api/flowdrop/search-indexes

Both store a string: the agent ID or the search index ID.

Using them in your own processor

Set the format on a string parameter in getParameterSchema():

'agent_id' => [
  'type' => 'string',
  'title' => 'AI Agent',
  'format' => 'ai_agent_selector',
],
'index' => [
  'type' => 'string',
  'title' => 'Search index',
  'format' => 'ai_search_index_selector',
],

The editor user needs administer flowdrop for the widgets to load data.

How they load

sequenceDiagram
    participant D as Drupal
    participant P as Editor or playground page
    participant R as FlowDrop field registry
    D->>P: flowdrop_ui_components/flowdrop library<br/>+ flowdrop_agents/agent-selector-field
    P->>P: flowdrop:editor:init or flowdrop:playground:init
    P->>R: register both components (priority 100)
    R->>P: render fields whose format matches
  • AgentHooks::libraryInfoAlter() adds flowdrop_agents/agent-selector-field as a dependency of the flowdrop_ui_components/flowdrop library. The editor and playground render through BareHtmlPageRenderer, which skips page attachment hooks, so the widget rides on that library instead.
  • lib/src/main.ts registers the components when the editor or the playground announces it is ready, once per page.
  • Each widget writes its value to a hidden input and to the config form's onChange, so FlowDrop saves it like a native field.

Building the JavaScript

Sources are in lib/src/. The built file lib/build/agent-selector-field.js is committed and loaded as an ES module.

cd lib
npm install
npm run build

npm run dev rebuilds on change. The build uses Vite with the Svelte 5 plugin. The agent preview renders descriptions as Markdown with marked and sanitises the HTML with DOMPurify.