Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
Fix the Android Tool Nodes Schema Update Feature.
trohitg7b6994235955
diff --git a/client/src/components/parameterPanel/LocationPanelLayout.tsx b/client/src/components/parameterPanel/LocationPanelLayout.tsxindex ca1359e3..72b34b79 100644--- a/client/src/components/parameterPanel/LocationPanelLayout.tsx+++ b/client/src/components/parameterPanel/LocationPanelLayout.tsx@@ -42,6 +42,7 @@ const LocationPanelLayout: React.FC<LocationPanelLayoutProps> = ({{/* Middle: Parameter Content */}<div style={{ flex: 1, height: '100%', overflow: 'hidden' }}><MiddleSection+ nodeId={selectedNode.id}nodeDefinition={nodeDefinition}parameters={parameters}onParameterChange={onParameterChange}diff --git a/client/src/components/parameterPanel/MiddleSection.tsx b/client/src/components/parameterPanel/MiddleSection.tsxindex ba38e104..a2b9558c 100644--- a/client/src/components/parameterPanel/MiddleSection.tsx+++ b/client/src/components/parameterPanel/MiddleSection.tsx@@ -1,10 +1,15 @@import React, { useState } from 'react';import ParameterRenderer from '../ParameterRenderer';+import ToolSchemaEditor from './ToolSchemaEditor';import { useAppTheme } from '../../hooks/useAppTheme';import { INodeTypeDescription, INodeProperties } from '../../types/INodeProperties';import { ExecutionResult } from '../../services/executionService';+// Tool node types that support schema editing+const TOOL_NODE_TYPES = ['androidTool', 'calculatorTool', 'currentTimeTool', 'webSearchTool'];+interface MiddleSectionProps {+ nodeId: string;nodeDefinition: INodeTypeDescription;parameters: Record<string, any>;onParameterChange: (paramName: string, value: any) => void;@@ -37,6 +42,7 @@ const shouldShowParameter = (param: INodeProperties, allParameters: Record<strin};const MiddleSection: React.FC<MiddleSectionProps> = ({+ nodeId,nodeDefinition,parameters,onParameterChange,@@ -52,6 +58,9 @@ const MiddleSection: React.FC<MiddleSectionProps> = ({// Check if this is a code executor node (Python or JavaScript)const isCodeExecutorNode = nodeDefinition.name === 'pythonExecutor' || nodeDefinition.name === 'javascriptExecutor';+ // Check if this is a tool node that supports schema editing+ const isToolNode = TOOL_NODE_TYPES.includes(nodeDefinition.name);+// Extract console output from execution resultsconst getConsoleOutput = (): string => {if (executionResults.length === 0) return '';@@ -156,6 +165,15 @@ const MiddleSection: React.FC<MiddleSectionProps> = ({/></div>))}++ {/* Tool Schema Editor - Only for tool nodes */}+ {isToolNode && (+ <ToolSchemaEditor+ nodeId={nodeId}+ toolName={parameters.toolName || nodeDefinition.name}+ toolDescription={parameters.toolDescription || nodeDefinition.description || ''}+ />+ )}</div></div>diff --git a/client/src/components/parameterPanel/ParameterPanelLayout.tsx b/client/src/components/parameterPanel/ParameterPanelLayout.tsxindex 3b84cde8..a32bd2c3 100644--- a/client/src/components/parameterPanel/ParameterPanelLayout.tsx+++ b/client/src/components/parameterPanel/ParameterPanelLayout.tsx@@ -55,6 +55,7 @@ const ParameterPanelLayout: React.FC<ParameterPanelLayoutProps> = ({{/* Middle: Parameter Content */}<div style={{ flex: 1.6, height: '100%', overflow: 'hidden', minWidth: 0 }}><MiddleSection+ nodeId={selectedNode.id}nodeDefinition={nodeDefinition}parameters={parameters}onParameterChange={onParameterChange}diff --git a/client/src/components/parameterPanel/ToolSchemaEditor.tsx b/client/src/components/parameterPanel/ToolSchemaEditor.tsxnew file mode 100644index 00000000..d67b7b3a--- /dev/null+++ b/client/src/components/parameterPanel/ToolSchemaEditor.tsx@@ -0,0 +1,436 @@+/**+ * ToolSchemaEditor - Schema editor for Android Toolkit node+ *+ * Shows connected Android service nodes and schema fields for the LLM+ */++import React, { useState, useEffect, useCallback, useMemo } from 'react';+import { Node } from 'reactflow';+import { useAppTheme } from '../../hooks/useAppTheme';+import { useToolSchema, ToolSchemaConfig, SchemaFieldConfig } from '../../hooks/useToolSchema';+import { useWebSocket } from '../../contexts/WebSocketContext';+import { useAppStore } from '../../store/useAppStore';+import { ANDROID_SERVICE_NODE_TYPES } from '../../nodeDefinitions/androidServiceNodes';++interface ToolSchemaEditorProps {+ nodeId: string;+ toolName: string;+ toolDescription: string;+}++const FIELD_TYPES = ['string', 'number', 'integer', 'boolean', 'object', 'array'] as const;++// Default schema for androidTool+const DEFAULT_SCHEMA: ToolSchemaConfig = {+ description: 'Control Android device via connected services',+ fields: {+ service_id: {+ type: 'string',+ description: 'Service to use (determined by connected Android nodes)',+ required: true+ },+ action: {+ type: 'string',+ description: 'Action to perform (see service list for available actions)',+ required: true+ },+ parameters: {+ type: 'object',+ description: 'Action parameters. Examples: {package_name: "com.app"} for app_launcher',+ required: false+ }+ }+};++const ToolSchemaEditor: React.FC<ToolSchemaEditorProps> = ({ nodeId }) => {+ const theme = useAppTheme();+ const { getToolSchema, saveToolSchema, deleteToolSchema, isLoading } = useToolSchema();+ const { isConnected } = useWebSocket();+ const { currentWorkflow } = useAppStore();++ // Get the current node+ const currentNode = useMemo(() => {+ if (!currentWorkflow?.nodes) return null;+ return currentWorkflow.nodes.find(n => n.id === nodeId);+ }, [currentWorkflow?.nodes, nodeId]);++ const isAndroidTool = currentNode?.type === 'androidTool';++ // Only show for androidTool+ if (!isAndroidTool) return null;++ // Find connected Android service nodes via edges+ const connectedServices = useMemo(() => {+ if (!currentWorkflow?.edges || !currentWorkflow?.nodes) return [];++ // Find all edges targeting this androidTool node+ const incomingEdges = currentWorkflow.edges.filter(edge => edge.target === nodeId);++ const services: Node[] = [];+ for (const edge of incomingEdges) {+ const sourceNode = currentWorkflow.nodes.find(n => n.id === edge.source);+ if (sourceNode && ANDROID_SERVICE_NODE_TYPES.includes(sourceNode.type || '')) {+ services.push(sourceNode);+ }+ }+ return services;+ }, [currentWorkflow?.edges, currentWorkflow?.nodes, nodeId]);++ const [selectedServiceId, setSelectedServiceId] = useState<string | null>(null);+ const [localSchema, setLocalSchema] = useState<ToolSchemaConfig>(DEFAULT_SCHEMA);+ const [hasChanges, setHasChanges] = useState(false);+ const [isExpanded, setIsExpanded] = useState(true);+ const [saveStatus, setSaveStatus] = useState<'idle' | 'saving' | 'saved' | 'error'>('idle');++ // Auto-select first connected service if none selected+ useEffect(() => {+ if (connectedServices.length > 0 && !selectedServiceId) {+ setSelectedServiceId(connectedServices[0].id);+ } else if (connectedServices.length === 0) {+ setSelectedServiceId(null);+ } else if (selectedServiceId && !connectedServices.find(s => s.id === selectedServiceId)) {+ // Selected service was disconnected, select first available+ setSelectedServiceId(connectedServices[0]?.id || null);+ }+ }, [connectedServices, selectedServiceId]);++ const selectedService = useMemo(() => {+ if (!selectedServiceId) return null;+ return connectedServices.find(s => s.id === selectedServiceId) || null;+ }, [connectedServices, selectedServiceId]);++ // Build default schema for selected service+ const getDefaultSchemaForService = useCallback((service: Node | null): ToolSchemaConfig => {+ if (!service) return DEFAULT_SCHEMA;++ const serviceType = service.type || 'unknown';+ const serviceName = service.data?.label || serviceType;++ // Create service-specific default schema+ return {+ description: `Control ${serviceName} on Android device`,+ fields: {+ action: {+ type: 'string',+ description: `Action to perform on ${serviceName}`,+ required: true+ },+ parameters: {+ type: 'object',+ description: `Parameters for the ${serviceName} action`,+ required: false+ }+ }+ };+ }, []);++ // Load existing schema for selected service+ useEffect(() => {+ const loadSchema = async () => {+ if (!isConnected || !selectedServiceId) {+ setLocalSchema(DEFAULT_SCHEMA);+ return;+ }++ // Use service node ID as the key for storing schema+ const schema = await getToolSchema(selectedServiceId);+ if (schema?.schema_config && Object.keys(schema.schema_config.fields || {}).length > 0) {+ setLocalSchema(schema.schema_config);+ } else {+ // Use service-specific default+ setLocalSchema(getDefaultSchemaForService(selectedService));+ }+ setHasChanges(false);+ };+ loadSchema();+ }, [selectedServiceId, selectedService, isConnected, getToolSchema, getDefaultSchemaForService]);++ const handleAddField = useCallback(() => {+ const newFieldName = `field_${Object.keys(localSchema.fields).length + 1}`;+ setLocalSchema(prev => ({+ ...prev,+ fields: {+ ...prev.fields,+ [newFieldName]: { type: 'string', description: '', required: false }+ }+ }));+ setHasChanges(true);+ }, [localSchema.fields]);++ const handleRemoveField = useCallback((fieldName: string) => {+ setLocalSchema(prev => {+ const { [fieldName]: _, ...rest } = prev.fields;+ return { ...prev, fields: rest };+ });+ setHasChanges(true);+ }, []);++ const handleFieldChange = useCallback((oldName: string, newName: string, config: SchemaFieldConfig) => {+ setLocalSchema(prev => {+ const fields = { ...prev.fields };+ if (oldName !== newName) delete fields[oldName];+ fields[newName] = config;+ return { ...prev, fields };+ });+ setHasChanges(true);+ }, []);++ const handleSave = useCallback(async () => {+ if (!selectedServiceId || !selectedService) return;+ setSaveStatus('saving');+ const serviceName = selectedService.data?.label || selectedService.type || 'unknown';+ const success = await saveToolSchema(selectedServiceId, serviceName, localSchema.description, localSchema);+ setSaveStatus(success ? 'saved' : 'error');+ if (success) setHasChanges(false);+ setTimeout(() => setSaveStatus('idle'), 2000);+ }, [selectedServiceId, selectedService, localSchema, saveToolSchema]);++ const handleReset = useCallback(async () => {+ if (!selectedServiceId) return;+ await deleteToolSchema(selectedServiceId);+ setLocalSchema(getDefaultSchemaForService(selectedService));+ setHasChanges(false);+ }, [selectedServiceId, selectedService, deleteToolSchema, getDefaultSchemaForService]);++ const fieldEntries = Object.entries(localSchema.fields);++ return (+ <div style={{+ backgroundColor: theme.colors.background,+ border: `1px solid ${theme.colors.border}`,+ borderRadius: theme.borderRadius.md,+ overflow: 'hidden'+ }}>+ {/* Header */}+ <div+ onClick={() => setIsExpanded(!isExpanded)}+ style={{+ display: 'flex',+ justifyContent: 'space-between',+ alignItems: 'center',+ padding: theme.spacing.md,+ backgroundColor: theme.colors.backgroundAlt,+ cursor: 'pointer',+ borderBottom: isExpanded ? `1px solid ${theme.colors.border}` : 'none'+ }}+ >+ <div style={{ display: 'flex', alignItems: 'center', gap: theme.spacing.sm }}>+ <span>{isExpanded ? '▼' : '▶'}</span>+ <span style={{ fontWeight: theme.fontWeight.semibold, color: theme.colors.text }}>+ Connected Services+ </span>+ </div>+ <span style={{ fontSize: theme.fontSize.sm, color: theme.colors.textSecondary }}>+ {connectedServices.length} service(s)+ </span>+ </div>++ {isExpanded && (+ <div style={{ padding: theme.spacing.md }}>+ {/* Service Selector Dropdown */}+ {connectedServices.length > 0 ? (+ <div style={{ marginBottom: theme.spacing.md }}>+ <label style={{+ display: 'block',+ fontSize: theme.fontSize.sm,+ color: theme.colors.textSecondary,+ marginBottom: theme.spacing.xs+ }}>+ Select Service+ </label>+ <select+ value={selectedServiceId || ''}+ onChange={(e) => setSelectedServiceId(e.target.value)}+ style={{+ width: '100%',+ padding: `${theme.spacing.sm} ${theme.spacing.md}`,+ borderRadius: theme.borderRadius.sm,+ border: `1px solid ${theme.colors.border}`,+ backgroundColor: theme.colors.background,+ color: theme.colors.text,+ fontSize: theme.fontSize.sm,+ cursor: 'pointer'+ }}+ >+ {connectedServices.map(service => (+ <option key={service.id} value={service.id}>+ {service.data?.label || service.type}+ </option>+ ))}+ </select>+ {selectedService && (+ <div style={{+ marginTop: theme.spacing.xs,+ fontSize: theme.fontSize.xs,+ color: theme.colors.textMuted+ }}>+ Type: {selectedService.type}+ </div>+ )}+ </div>+ ) : (+ <div style={{+ padding: theme.spacing.sm,+ backgroundColor: `${theme.dracula.orange}10`,+ borderRadius: theme.borderRadius.sm,+ border: `1px solid ${theme.dracula.orange}30`,+ fontSize: theme.fontSize.sm,+ color: theme.dracula.orange,+ marginBottom: theme.spacing.md+ }}>+ Connect Android nodes to the input handle+ </div>+ )}++ {/* Schema Fields */}+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: theme.spacing.sm }}>+ <label style={{ fontSize: theme.fontSize.sm, color: theme.colors.textSecondary }}>+ Schema Fields+ </label>+ <button+ onClick={handleAddField}+ style={{+ padding: `2px ${theme.spacing.sm}`,+ backgroundColor: `${theme.dracula.cyan}20`,+ color: theme.dracula.cyan,+ border: `1px solid ${theme.dracula.cyan}40`,+ borderRadius: theme.borderRadius.sm,+ cursor: 'pointer',+ fontSize: theme.fontSize.xs+ }}+ >+ + Add+ </button>+ </div>++ <div style={{ display: 'flex', flexDirection: 'column', gap: theme.spacing.xs }}>+ {fieldEntries.map(([name, config]) => (+ <FieldRow+ key={name}+ fieldName={name}+ config={config}+ onChange={(newName, newConfig) => handleFieldChange(name, newName, newConfig)}+ onRemove={() => handleRemoveField(name)}+ theme={theme}+ />+ ))}+ </div>++ {/* Save/Reset */}+ {hasChanges && (+ <div style={{ display: 'flex', justifyContent: 'flex-end', gap: theme.spacing.sm, marginTop: theme.spacing.md }}>+ <button+ onClick={handleReset}+ style={{+ padding: `${theme.spacing.xs} ${theme.spacing.sm}`,+ backgroundColor: 'transparent',+ color: theme.colors.textSecondary,+ border: `1px solid ${theme.colors.border}`,+ borderRadius: theme.borderRadius.sm,+ cursor: 'pointer',+ fontSize: theme.fontSize.sm+ }}+ >+ Reset+ </button>+ <button+ onClick={handleSave}+ disabled={isLoading}+ style={{+ padding: `${theme.spacing.xs} ${theme.spacing.sm}`,+ backgroundColor: `${theme.dracula.green}20`,+ color: theme.dracula.green,+ border: `1px solid ${theme.dracula.green}40`,+ borderRadius: theme.borderRadius.sm,+ cursor: 'pointer',+ fontSize: theme.fontSize.sm+ }}+ >+ {saveStatus === 'saving' ? 'Saving...' : saveStatus === 'saved' ? 'Saved!' : 'Save'}+ </button>+ </div>+ )}+ </div>+ )}+ </div>+ );+};++// Field Row Component+const FieldRow: React.FC<{+ fieldName: string;+ config: SchemaFieldConfig;+ onChange: (newName: string, newConfig: SchemaFieldConfig) => void;+ onRemove: () => void;+ theme: any;+}> = ({ fieldName, config, onChange, onRemove, theme }) => {+ const [localName, setLocalName] = useState(fieldName);++ useEffect(() => {+ setLocalName(fieldName);+ }, [fieldName]);++ return (+ <div style={{+ padding: theme.spacing.sm,+ backgroundColor: theme.colors.backgroundAlt,+ borderRadius: theme.borderRadius.sm,+ border: `1px solid ${theme.colors.border}`+ }}>+ <div style={{ display: 'flex', gap: theme.spacing.xs, alignItems: 'center', marginBottom: '4px' }}>+ <input+ value={localName}+ onChange={(e) => setLocalName(e.target.value.replace(/\s/g, '_'))}+ onBlur={() => localName !== fieldName && onChange(localName, config)}+ style={{+ flex: 1,+ padding: '4px 8px',+ borderRadius: theme.borderRadius.sm,+ border: `1px solid ${theme.colors.border}`,+ backgroundColor: theme.colors.background,+ color: theme.colors.text,+ fontSize: theme.fontSize.sm+ }}+ />+ <select+ value={config.type}+ onChange={(e) => onChange(fieldName, { ...config, type: e.target.value as any })}+ style={{+ padding: '4px',+ borderRadius: theme.borderRadius.sm,+ border: `1px solid ${theme.colors.border}`,+ backgroundColor: theme.colors.background,+ color: theme.colors.text,+ fontSize: theme.fontSize.xs+ }}+ >+ {FIELD_TYPES.map(t => <option key={t} value={t}>{t}</option>)}+ </select>+ <label style={{ display: 'flex', alignItems: 'center', gap: '2px', fontSize: theme.fontSize.xs, color: theme.colors.textSecondary }}>+ <input type="checkbox" checked={config.required || false} onChange={(e) => onChange(fieldName, { ...config, required: e.target.checked })} />+ Req+ </label>+ <button onClick={onRemove} style={{ padding: '2px 6px', backgroundColor: `${theme.dracula.red}20`, color: theme.dracula.red, border: 'none', borderRadius: theme.borderRadius.sm, cursor: 'pointer', fontSize: theme.fontSize.xs }}>+ X+ </button>+ </div>+ <input+ value={config.description}+ onChange={(e) => onChange(fieldName, { ...config, description: e.target.value })}+ placeholder="Description..."+ style={{+ width: '100%',+ padding: '4px 8px',+ borderRadius: theme.borderRadius.sm,+ border: `1px solid ${theme.colors.border}`,+ backgroundColor: theme.colors.background,+ color: theme.colors.text,+ fontSize: theme.fontSize.xs,+ boxSizing: 'border-box'+ }}+ />+ </div>+ );+};++export default ToolSchemaEditor;diff --git a/client/src/contexts/WebSocketContext.tsx b/client/src/contexts/WebSocketContext.tsxindex c4c0f2fa..e173d2a6 100644--- a/client/src/contexts/WebSocketContext.tsx+++ b/client/src/contexts/WebSocketContext.tsx@@ -11,7 +11,6 @@*/import React, { createContext, useContext, useEffect, useState, useCallback, useRef, useMemo } from 'react';-import { flushSync } from 'react-dom';import { API_CONFIG } from '../config/api';import { useAppStore } from '../store/useAppStore';import { useAuth } from './AuthContext';diff --git a/client/src/hooks/useToolSchema.ts b/client/src/hooks/useToolSchema.tsnew file mode 100644index 00000000..1cd6645b--- /dev/null+++ b/client/src/hooks/useToolSchema.ts@@ -0,0 +1,209 @@+/**+ * useToolSchema Hook - WebSocket-based tool schema management+ *+ * Provides tool schema operations for Android Toolkit and other tool nodes.+ * The database-stored schema is the source of truth for LLM tool configurations.+ */++import { useCallback, useState } from 'react';+import { useWebSocket } from '../contexts/WebSocketContext';++/**+ * Schema field configuration for tool arguments+ */+export interface SchemaFieldConfig {+ type: 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array';+ description: string;+ required?: boolean;+ default?: any;+ enum?: string[];+}++/**+ * Full schema configuration stored in database+ */+export interface ToolSchemaConfig {+ description: string;+ fields: Record<string, SchemaFieldConfig>;+}++/**+ * Tool schema as stored in database+ */+export interface ToolSchema {+ node_id: string;+ tool_name: string;+ tool_description: string;+ schema_config: ToolSchemaConfig;+ connected_services?: Record<string, any>[];+ created_at?: string;+ updated_at?: string;+}++export interface UseToolSchemaResult {+ // Get tool schema for a node+ getToolSchema: (nodeId: string) => Promise<ToolSchema | null>;++ // Save tool schema for a node+ saveToolSchema: (+ nodeId: string,+ toolName: string,+ toolDescription: string,+ schemaConfig: ToolSchemaConfig,+ connectedServices?: Record<string, any>[]+ ) => Promise<boolean>;++ // Delete tool schema for a node+ deleteToolSchema: (nodeId: string) => Promise<boolean>;++ // Get all tool schemas+ getAllToolSchemas: () => Promise<ToolSchema[]>;++ // State+ isLoading: boolean;+ error: string | null;+ isConnected: boolean;+}++export const useToolSchema = (): UseToolSchemaResult => {+ const { sendRequest, isConnected } = useWebSocket();++ const [isLoading, setIsLoading] = useState(false);+ const [error, setError] = useState<string | null>(null);++ /**+ * Get tool schema for a node from database+ */+ const getToolSchema = useCallback(async (nodeId: string): Promise<ToolSchema | null> => {+ if (!isConnected) {+ console.warn('[useToolSchema] WebSocket not connected');+ return null;+ }++ setIsLoading(true);+ setError(null);++ try {+ const response = await sendRequest<{ success: boolean; schema: ToolSchema | null }>('get_tool_schema', {+ node_id: nodeId+ });++ if (response.success) {+ return response.schema;+ }+ return null;+ } catch (err) {+ const errorMsg = err instanceof Error ? err.message : 'Failed to get tool schema';+ setError(errorMsg);+ console.error('[useToolSchema] Error getting schema:', errorMsg);+ return null;+ } finally {+ setIsLoading(false);+ }+ }, [isConnected, sendRequest]);++ /**+ * Save tool schema for a node to database+ */+ const saveToolSchema = useCallback(async (+ nodeId: string,+ toolName: string,+ toolDescription: string,+ schemaConfig: ToolSchemaConfig,+ connectedServices?: Record<string, any>[]+ ): Promise<boolean> => {+ if (!isConnected) {+ console.warn('[useToolSchema] WebSocket not connected');+ return false;+ }++ setIsLoading(true);+ setError(null);++ try {+ const response = await sendRequest<{ success: boolean; saved: boolean }>('save_tool_schema', {+ node_id: nodeId,+ tool_name: toolName,+ tool_description: toolDescription,+ schema_config: schemaConfig,+ connected_services: connectedServices+ });++ return response.success && response.saved;+ } catch (err) {+ const errorMsg = err instanceof Error ? err.message : 'Failed to save tool schema';+ setError(errorMsg);+ console.error('[useToolSchema] Error saving schema:', errorMsg);+ return false;+ } finally {+ setIsLoading(false);+ }+ }, [isConnected, sendRequest]);++ /**+ * Delete tool schema for a node from database+ */+ const deleteToolSchema = useCallback(async (nodeId: string): Promise<boolean> => {+ if (!isConnected) {+ console.warn('[useToolSchema] WebSocket not connected');+ return false;+ }++ setIsLoading(true);+ setError(null);++ try {+ const response = await sendRequest<{ success: boolean }>('delete_tool_schema', {+ node_id: nodeId+ });++ return response.success;+ } catch (err) {+ const errorMsg = err instanceof Error ? err.message : 'Failed to delete tool schema';+ setError(errorMsg);+ console.error('[useToolSchema] Error deleting schema:', errorMsg);+ return false;+ } finally {+ setIsLoading(false);+ }+ }, [isConnected, sendRequest]);++ /**+ * Get all tool schemas from database+ */+ const getAllToolSchemas = useCallback(async (): Promise<ToolSchema[]> => {+ if (!isConnected) {+ console.warn('[useToolSchema] WebSocket not connected');+ return [];+ }++ setIsLoading(true);+ setError(null);++ try {+ const response = await sendRequest<{ success: boolean; schemas: ToolSchema[] }>('get_all_tool_schemas', {});++ if (response.success) {+ return response.schemas || [];+ }+ return [];+ } catch (err) {+ const errorMsg = err instanceof Error ? err.message : 'Failed to get tool schemas';+ setError(errorMsg);+ console.error('[useToolSchema] Error getting schemas:', errorMsg);+ return [];+ } finally {+ setIsLoading(false);+ }+ }, [isConnected, sendRequest]);++ return {+ getToolSchema,+ saveToolSchema,+ deleteToolSchema,+ getAllToolSchemas,+ isLoading,+ error,+ isConnected+ };+};diff --git a/client/src/nodeDefinitions/toolNodes.ts b/client/src/nodeDefinitions/toolNodes.tsindex d06f7bc6..d395e30e 100644--- a/client/src/nodeDefinitions/toolNodes.ts+++ b/client/src/nodeDefinitions/toolNodes.ts@@ -185,24 +185,8 @@ export const toolNodes: Record<string, INodeTypeDescription> = {type: 'main' as NodeConnectionType,description: 'Connect to AI Agent tool handle'}],- properties: [- {- displayName: 'Tool Name',- name: 'toolName',- type: 'string',- default: 'android_device',- required: true,- description: 'Name the AI will use to call this tool'- },- {- displayName: 'Description',- name: 'toolDescription',- type: 'string',- default: 'Control Android device. Available services are determined by connected nodes.',- typeOptions: { rows: 2 },- description: 'Base description (connected services auto-appended)'- }- ]+ // No properties - schema is managed by ToolSchemaEditor component+ properties: []}};diff --git a/server/core/database.py b/server/core/database.pyindex 9eba651c..a9e72d00 100644--- a/server/core/database.py+++ b/server/core/database.py@@ -8,7 +8,7 @@ from sqlalchemy.exc import IntegrityErrorfrom contextlib import asynccontextmanagerfrom core.config import Settings-from models.database import NodeParameter, Workflow, Execution, APIKey, APIKeyValidation, NodeOutput, ConversationMessage+from models.database import NodeParameter, Workflow, Execution, APIKey, APIKeyValidation, NodeOutput, ConversationMessage, ToolSchemafrom models.cache import CacheEntry # SQLite-backed cache for Redis alternativefrom models.auth import User # Import User model to ensure table creationfrom core.logging import get_logger@@ -756,4 +756,112 @@ class Database:except Exception as e:logger.error("Failed to check cache exists", key=key, error=str(e))- return False\ No newline at end of file+ return False++ # ============================================================================+ # Tool Schemas (Source of truth for tool node configurations)+ # ============================================================================++ async def save_tool_schema(self, node_id: str, tool_name: str, tool_description: str,+ schema_config: Dict[str, Any],+ connected_services: Optional[Dict[str, Any]] = None) -> bool:+ """Save or update tool schema for a node."""+ try:+ async with self.get_session() as session:+ # Try to get existing schema+ stmt = select(ToolSchema).where(ToolSchema.node_id == node_id)+ result = await session.execute(stmt)+ existing = result.scalar_one_or_none()++ action = "updated"+ if existing:+ existing.tool_name = tool_name+ existing.tool_description = tool_description+ existing.schema_config = schema_config+ existing.connected_services = connected_services+ else:+ action = "created"+ existing = ToolSchema(+ node_id=node_id,+ tool_name=tool_name,+ tool_description=tool_description,+ schema_config=schema_config,+ connected_services=connected_services+ )+ session.add(existing)++ await session.commit()+ logger.info(f"[DB] Tool schema {action}", node_id=node_id, tool_name=tool_name)+ return True++ except Exception as e:+ logger.error("Failed to save tool schema", node_id=node_id, error=str(e))+ return False++ async def get_tool_schema(self, node_id: str) -> Optional[Dict[str, Any]]:+ """Get tool schema for a node."""+ try:+ async with self.get_session() as session:+ stmt = select(ToolSchema).where(ToolSchema.node_id == node_id)+ result = await session.execute(stmt)+ schema = result.scalar_one_or_none()++ if not schema:+ return None++ return {+ "node_id": schema.node_id,+ "tool_name": schema.tool_name,+ "tool_description": schema.tool_description,+ "schema_config": schema.schema_config,+ "connected_services": schema.connected_services,+ "created_at": schema.created_at.isoformat() if schema.created_at else None,+ "updated_at": schema.updated_at.isoformat() if schema.updated_at else None+ }++ except Exception as e:+ logger.error("Failed to get tool schema", node_id=node_id, error=str(e))+ return None++ async def delete_tool_schema(self, node_id: str) -> bool:+ """Delete tool schema for a node."""+ try:+ async with self.get_session() as session:+ stmt = select(ToolSchema).where(ToolSchema.node_id == node_id)+ result = await session.execute(stmt)+ schema = result.scalar_one_or_none()++ if schema:+ await session.delete(schema)+ await session.commit()+ logger.info("[DB] Tool schema deleted", node_id=node_id)++ return True++ except Exception as e:+ logger.error("Failed to delete tool schema", node_id=node_id, error=str(e))+ return False++ async def get_all_tool_schemas(self) -> List[Dict[str, Any]]:+ """Get all tool schemas."""+ try:+ async with self.get_session() as session:+ stmt = select(ToolSchema).order_by(ToolSchema.updated_at.desc())+ result = await session.execute(stmt)+ schemas = result.scalars().all()++ return [+ {+ "node_id": s.node_id,+ "tool_name": s.tool_name,+ "tool_description": s.tool_description,+ "schema_config": s.schema_config,+ "connected_services": s.connected_services,+ "updated_at": s.updated_at.isoformat() if s.updated_at else None+ }+ for s in schemas+ ]++ except Exception as e:+ logger.error("Failed to get all tool schemas", error=str(e))+ return []\ No newline at end of filediff --git a/server/models/database.py b/server/models/database.pyindex 5f54f702..20f1d558 100644--- a/server/models/database.py+++ b/server/models/database.py@@ -133,4 +133,29 @@ class ConversationMessage(SQLModel, table=True):created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc),sa_column=Column(DateTime(timezone=True), server_default=func.now())+ )+++class ToolSchema(SQLModel, table=True):+ """Tool node schema configuration - stores LLM-visible schema for tool nodes.++ This allows Android Toolkit and other aggregator nodes to update the schema+ of connected tool nodes, providing the LLM with accurate capability information.+ """++ __tablename__ = "tool_schemas"++ id: Optional[int] = Field(default=None, primary_key=True)+ node_id: str = Field(index=True, unique=True, max_length=255)+ tool_name: str = Field(max_length=255) # e.g., 'android_device', 'calculator'+ tool_description: str = Field(max_length=2000) # Description shown to LLM+ schema_config: Dict[str, Any] = Field(sa_column=Column(JSON)) # Schema fields and types+ connected_services: Optional[Dict[str, Any]] = Field(default=None, sa_column=Column(JSON)) # For toolkit nodes+ created_at: datetime = Field(+ default_factory=lambda: datetime.now(timezone.utc),+ sa_column=Column(DateTime(timezone=True), server_default=func.now())+ )+ updated_at: datetime = Field(+ default_factory=lambda: datetime.now(timezone.utc),+ sa_column=Column(DateTime(timezone=True), onupdate=func.now()))\ No newline at end of filediff --git a/server/routers/websocket.py b/server/routers/websocket.pyindex ba10a6a2..0c58de9a 100644--- a/server/routers/websocket.py+++ b/server/routers/websocket.py@@ -162,6 +162,69 @@ async def handle_delete_node_parameters(data: Dict[str, Any], websocket: WebSockreturn {"node_id": data["node_id"]}+# ============================================================================+# Tool Schema Handlers (Source of truth for tool node configurations)+# ============================================================================++@ws_handler("node_id")+async def handle_get_tool_schema(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:+ """Get tool schema for a node."""+ database = container.database()+ schema = await database.get_tool_schema(data["node_id"])+ return {"node_id": data["node_id"], "schema": schema}+++@ws_handler("node_id", "tool_name", "tool_description", "schema_config")+async def handle_save_tool_schema(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:+ """Save tool schema for a node. Used by Android Toolkit to update connected service schemas."""+ database = container.database()+ broadcaster = get_status_broadcaster()++ node_id = data["node_id"]+ tool_name = data["tool_name"]+ tool_description = data["tool_description"]+ schema_config = data["schema_config"]+ connected_services = data.get("connected_services")++ success = await database.save_tool_schema(+ node_id=node_id,+ tool_name=tool_name,+ tool_description=tool_description,+ schema_config=schema_config,+ connected_services=connected_services+ )++ if success:+ # Broadcast schema update to all clients+ await broadcaster.broadcast({+ "type": "tool_schema_updated",+ "node_id": node_id,+ "tool_name": tool_name,+ "timestamp": time.time()+ })++ return {+ "node_id": node_id,+ "tool_name": tool_name,+ "saved": success+ }+++@ws_handler("node_id")+async def handle_delete_tool_schema(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:+ """Delete tool schema for a node."""+ database = container.database()+ await database.delete_tool_schema(data["node_id"])+ return {"node_id": data["node_id"]}+++async def handle_get_all_tool_schemas(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:+ """Get all tool schemas."""+ database = container.database()+ schemas = await database.get_all_tool_schemas()+ return {"success": True, "schemas": schemas}++# ============================================================================# Node Execution Handlers# ============================================================================@@ -1335,6 +1398,12 @@ MESSAGE_HANDLERS: Dict[str, MessageHandler] = {"save_node_parameters": handle_save_node_parameters,"delete_node_parameters": handle_delete_node_parameters,+ # Tool schemas (source of truth for tool configurations)+ "get_tool_schema": handle_get_tool_schema,+ "save_tool_schema": handle_save_tool_schema,+ "delete_tool_schema": handle_delete_tool_schema,+ "get_all_tool_schemas": handle_get_all_tool_schemas,+# Node execution"execute_node": handle_execute_node,"execute_workflow": handle_execute_workflow,diff --git a/server/services/ai.py b/server/services/ai.pyindex 275e2f04..fdf90703 100644--- a/server/services/ai.py+++ b/server/services/ai.py@@ -13,7 +13,7 @@ from langchain_google_genai import ChatGoogleGenerativeAIfrom langchain_core.messages import HumanMessage, SystemMessage, AIMessage, BaseMessage, ToolMessagefrom langchain_core.tools import StructuredToolfrom langgraph.graph import StateGraph, END-from pydantic import BaseModel, Field+from pydantic import BaseModel, Field, create_modelimport jsonfrom core.config import Settings@@ -596,7 +596,7 @@ class AIService:})for tool_info in tool_data:- tool, config = self._build_tool_from_node(tool_info)+ tool, config = await self._build_tool_from_node(tool_info)if tool:tools.append(tool)tool_configs[tool.name] = config@@ -763,9 +763,12 @@ class AIService:"timestamp": datetime.now().isoformat()}- def _build_tool_from_node(self, tool_info: Dict[str, Any]) -> tuple:+ async def _build_tool_from_node(self, tool_info: Dict[str, Any]) -> tuple:"""Convert a node configuration into a LangChain StructuredTool.+ Uses database-stored schema as source of truth if available, otherwise+ falls back to dynamic schema generation.+Args:tool_info: Dict containing node_id, node_type, parameters, label, connected_services (for androidTool)@@ -793,17 +796,29 @@ class AIService:node_id = tool_info.get('node_id', '')connected_services = tool_info.get('connected_services', [])- # Get tool name from params, then type-specific default, then generic fallback- tool_name = (- node_params.get('toolName') or- DEFAULT_TOOL_NAMES.get(node_type) or- f"tool_{node_label}".replace(' ', '_').replace('-', '_').lower()- )- tool_description = (- node_params.get('toolDescription') or- DEFAULT_TOOL_DESCRIPTIONS.get(node_type) or- f"Execute {node_label} node"- )+ # Check database for stored schema (source of truth)+ db_schema = await self.database.get_tool_schema(node_id) if node_id else None++ if db_schema:+ # Use database schema as source of truth+ logger.info(f"[LangGraph] Using DB schema for tool node {node_id}")+ tool_name = db_schema.get('tool_name', DEFAULT_TOOL_NAMES.get(node_type, f"tool_{node_label}"))+ tool_description = db_schema.get('tool_description', DEFAULT_TOOL_DESCRIPTIONS.get(node_type, f"Execute {node_label}"))+ # Use stored connected_services if available (for toolkit nodes)+ if db_schema.get('connected_services'):+ connected_services = db_schema['connected_services']+ else:+ # Fall back to dynamic generation from node params+ tool_name = (+ node_params.get('toolName') or+ DEFAULT_TOOL_NAMES.get(node_type) or+ f"tool_{node_label}".replace(' ', '_').replace('-', '_').lower()+ )+ tool_description = (+ node_params.get('toolDescription') or+ DEFAULT_TOOL_DESCRIPTIONS.get(node_type) or+ f"Execute {node_label} node"+ )# For androidTool, enhance description with connected servicesif node_type == 'androidTool' and connected_services:@@ -815,9 +830,12 @@ class AIService:tool_name = re.sub(r'[^a-zA-Z0-9_]', '_', tool_name)# Build schema based on node type - pass connected_services for androidTool+ # If DB has schema_config, use it to build custom schema, otherwise use dynamicschema_params = dict(node_params)if connected_services:schema_params['connected_services'] = connected_services+ if db_schema and db_schema.get('schema_config'):+ schema_params['db_schema_config'] = db_schema['schema_config']schema = self._get_tool_schema(node_type, schema_params)# Create StructuredTool - the func is a placeholder, actual execution via tool_executor@@ -850,13 +868,21 @@ class AIService:def _get_tool_schema(self, node_type: str, params: Dict[str, Any]) -> Type[BaseModel]:"""Get Pydantic schema for tool based on node type.+ Uses db_schema_config from database if available (source of truth),+ otherwise falls back to built-in schema definitions.+Args:node_type: The node type (e.g., 'calculatorTool', 'httpRequest')- params: Node parameters+ params: Node parameters, may include db_schema_config from databaseReturns:Pydantic BaseModel class for the tool's arguments"""+ # Check if we have a database-stored schema config (source of truth)+ db_schema_config = params.get('db_schema_config')+ if db_schema_config:+ return self._build_schema_from_config(db_schema_config)+# Calculator tool schemaif node_type == 'calculatorTool':class CalculatorSchema(BaseModel):@@ -962,4 +988,73 @@ class AIService:"""Generic schema for tool arguments."""input: str = Field(description="Input data for the tool")- return GenericToolSchema\ No newline at end of file+ return GenericToolSchema++ def _build_schema_from_config(self, schema_config: Dict[str, Any]) -> Type[BaseModel]:+ """Build a Pydantic schema from database-stored configuration.++ Schema config format:+ {+ "description": "Schema description",+ "fields": {+ "field_name": {+ "type": "string" | "number" | "boolean" | "object" | "array",+ "description": "Field description",+ "required": True | False,+ "default": <optional default value>,+ "enum": [<optional enum values>]+ }+ }+ }+ """+ fields_config = schema_config.get('fields', {})+ schema_description = schema_config.get('description', 'Tool arguments schema')++ # Build field annotations and defaults+ annotations = {}+ field_defaults = {}++ TYPE_MAP = {+ 'string': str,+ 'number': float,+ 'integer': int,+ 'boolean': bool,+ 'object': Dict[str, Any],+ 'array': list,+ }++ for field_name, field_config in fields_config.items():+ field_type_str = field_config.get('type', 'string')+ field_type = TYPE_MAP.get(field_type_str, str)+ field_description = field_config.get('description', '')+ is_required = field_config.get('required', True)+ default_value = field_config.get('default')+ enum_values = field_config.get('enum')++ # Handle optional fields+ if not is_required:+ field_type = Optional[field_type]++ annotations[field_name] = field_type++ # Build Field with description and enum if provided+ field_kwargs = {'description': field_description}+ if enum_values:+ # For enums, include in description since Pydantic Field doesn't support enum directly+ field_kwargs['description'] = f"{field_description} Options: {', '.join(str(v) for v in enum_values)}"++ if default_value is not None:+ field_defaults[field_name] = Field(default=default_value, **field_kwargs)+ elif not is_required:+ field_defaults[field_name] = Field(default=None, **field_kwargs)+ else:+ field_defaults[field_name] = Field(**field_kwargs)++ # Create dynamic Pydantic model+ DynamicSchema = create_model(+ 'DynamicToolSchema',+ __doc__=schema_description,+ **{name: (annotations[name], field_defaults[name]) for name in annotations}+ )++ return DynamicSchema\ No newline at end of file