Skip to main content

Develop Visual Editors for Backend Type Elements

After we completed Extend Your Own Element Families, although we can create instances and run them, configuration parameters need to be manually modified in files, which is not user-friendly for business developers who are not familiar with code.

This article will introduce how to develop a visual configuration editor for DingTalk robots, achieving the same graphical configuration experience as official elements in JitAi development tools.

Effect Preview

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 target 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

Operation Guide

Create Editor Directory

Create an Editor subdirectory under the dingTalkStreamType directory:

# Execute in dingTalkStreamType directory
mkdir -p Editor

Install Dependencies

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

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

Implement Editor Files

Create editor element definition file Editor/e.json:

Editors are also elements

In JitAi, editors themselves are also 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 description:

  • title: Editor element display name
  • type: Fixed as editors.React, indicating React editor element
  • tag: Fixed as editor, indicating backend element editor
  • targetType: Target backend element's fullName
  • frontBundleEntry: Editor entry file

Editor Working Principle

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

Make 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

Verify 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

Common Issue Troubleshooting

  • 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