Skip to main content

Developing Visual Editors for Backend Type Elements

After completing the Extend Your Own Element Families tutorial, you can create and run element instances. However, configuration parameters must be manually modified in files, which presents a challenge for business developers unfamiliar with code.

This guide demonstrates how to develop a visual configuration editor for a DingTalk robot, delivering the same graphical configuration experience as official JitAi elements.

Effect preview

Loading...
Editor Effect

Editor architecture

Element LevelfullNameMain Responsibilities
Editor ElementimRobots.dingTalkStreamType.EditorType points to editors.React; provides visual configuration interface for DingTalk robot
Target ElementimRobots.dingTalkStreamTypeThe backend Type element being edited, completed in previous chapters

Editor directory structure

Add Editor subdirectory under dingTalkStreamType
imRobots/
└── dingTalkStreamType/ # Backend Type element (completed)
├── e.json # Type element definition
├── config.json # Configuration template
├── loader.py # Loader implementation
├── client_manager.py # Client management
├── handler.py # Message handler
└── Editor/ # Editor directory (new)
├── e.json # Editor element definition
├── index.ts # Editor entry file
├── Editor.tsx # Editor implementation file
├── Editor.style.ts # Style file
└── utils.ts # Utility functions

Step-by-step guide

Creating the editor directory

Create an Editor subdirectory under the dingTalkStreamType directory:

# Execute in dingTalkStreamType directory
mkdir -p Editor

Installing dependencies

Add the Monaco Editor dependency to your project's package.json:

package.json
{
"dependencies": {
"@monaco-editor/react": "^4.7.0"
}
}

Implementing editor files

Create the editor element definition file Editor/e.json:

Editors are elements too

In JitAi, editors are elements with their own e.json definition files.

Editor/e.json
{
"frontBundleEntry": "./index.ts",
"outputName": "index",
"tag": "editor",
"targetType": [
"imRobots.dingTalkStreamType"
],
"title": "DingTalk Robot Configuration Editor",
"type": "editors.React"
}

Editor element configuration:

  • title: Display name for the editor element
  • type: Must be editors.React to indicate a React editor element
  • tag: Must be editor to indicate a backend element editor
  • targetType: Full name of the target backend element
  • frontBundleEntry: Entry point for the editor

Editor working principles

Backend element editor vs frontend component editor

AspectBackend Element EditorFrontend Component Editor
TargetBackend Type elements (like DingTalk robot)Frontend UI components (like Counter)
Configuration ScopeInstance-level configuration filesComponent runtime parameters
InterfaceelementInfo + onSave/onCancelCompEditorProps + onChangeCompConfig
Save MethodAsynchronous save via onSave callbackReal-time sync via onChangeCompConfig

Data flow

  1. Configuration Reception: Editor receives current element configuration through elementInfo
  2. Form Initialization: Initialize form fields and JSON editor content
  3. User Interaction: User modifies form fields or JSON configuration
  4. Validation: Validate form data and JSON format
  5. Save: Call onSave callback to persist configuration

Testing the editor

Making the editor take effect

  1. Clear cache: Delete the dist directory in the application directory
  2. Restart service: Restart the desktop client
  3. Trigger packaging: Access the application page, the system will automatically repackage

Verifying editor functionality

  1. Open element management: Enter JitAi development tool's element management interface
  2. Find target element: Locate the DingTalk robot element instance
  3. Open editor: Click edit button, the visual editor should open
  4. Test configuration: Try modifying AI Agent, Client ID and other configurations
  5. Save verification: Save configuration and restart element, confirm configuration takes effect

Troubleshooting common issues

  • Editor not opening: Check if targetType in e.json correctly points to the target element
  • Configuration not saving: Confirm if onSave callback is called correctly and handles errors properly
  • JSON format error: Check if JSON editor content format is correct

Advanced features

Dynamic agent list

You can enhance the editor by dynamically loading available AI Agent lists:

const [agentOptions, setAgentOptions] = useState([]);

useEffect(() => {
// Load available agents
const loadAgents = async () => {
try {
const agents = await fetchAvailableAgents(); // API call
setAgentOptions(agents);
} catch (error) {
console.error('Failed to load agents:', error);
}
};

loadAgents();
}, []);

Configuration validation

Add more comprehensive configuration validation:

export function validateDingTalkConfig(config: any): string[] {
const errors: string[] = [];

if (!config.agent) {
errors.push('AI Agent is required');
}

if (!config.clientId) {
errors.push('Client ID is required');
}

if (!config.clientSecret) {
errors.push('Client Secret is required');
}

if (config.clientId && !/^[a-zA-Z0-9]+$/.test(config.clientId)) {
errors.push('Client ID format is invalid');
}

return errors;
}

Summary

Core steps for developing visual editors for backend elements:

  1. Create Editor directory + configure editor element definition file e.json (type: "editors.React")
  2. Implement Editor component: Receive elementInfo + render configuration form
  3. Correct export: Export component named Editor
  4. Configuration persistence: Save configuration through onSave callback

Key differences from frontend component editors:

  • Use elementInfo interface instead of CompEditorProps
  • Asynchronous save via onSave callback instead of real-time sync
  • Target backend Type elements instead of frontend UI components
  • Handle instance-level configuration instead of component runtime parameters

Key points:

  • Export name Editor cannot be changed
  • Must handle asynchronous save operations and error handling
  • JSON editor is suitable for complex configuration scenarios
  • Form validation ensures configuration correctness
JitAI AssistantBeta
Powered by JitAI