snow-flow 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +49 -0
- package/.mcp.json +106 -0
- package/.mcp.json.template +106 -0
- package/LICENSE +21 -0
- package/README.md +236 -0
- package/bin/snow-flow +4 -0
- package/bin/snow-flow.js +3 -0
- package/claude-flow +79 -0
- package/claude-flow.bat +18 -0
- package/claude-flow.config.json +20 -0
- package/claude-flow.ps1 +24 -0
- package/dist/agents/app-creator.agent.d.ts +55 -0
- package/dist/agents/app-creator.agent.d.ts.map +1 -0
- package/dist/agents/app-creator.agent.js +1292 -0
- package/dist/agents/app-creator.agent.js.map +1 -0
- package/dist/agents/base-snow-agent.d.ts +63 -0
- package/dist/agents/base-snow-agent.d.ts.map +1 -0
- package/dist/agents/base-snow-agent.js +296 -0
- package/dist/agents/base-snow-agent.js.map +1 -0
- package/dist/agents/script-generator.agent.d.ts +32 -0
- package/dist/agents/script-generator.agent.d.ts.map +1 -0
- package/dist/agents/script-generator.agent.js +772 -0
- package/dist/agents/script-generator.agent.js.map +1 -0
- package/dist/agents/ui-builder.agent.d.ts +50 -0
- package/dist/agents/ui-builder.agent.d.ts.map +1 -0
- package/dist/agents/ui-builder.agent.js +1539 -0
- package/dist/agents/ui-builder.agent.js.map +1 -0
- package/dist/agents/widget-builder.agent.d.ts +32 -0
- package/dist/agents/widget-builder.agent.d.ts.map +1 -0
- package/dist/agents/widget-builder.agent.js +439 -0
- package/dist/agents/widget-builder.agent.js.map +1 -0
- package/dist/agents/workflow-designer.agent.d.ts +31 -0
- package/dist/agents/workflow-designer.agent.d.ts.map +1 -0
- package/dist/agents/workflow-designer.agent.js +583 -0
- package/dist/agents/workflow-designer.agent.js.map +1 -0
- package/dist/api/error-handling.d.ts +214 -0
- package/dist/api/error-handling.d.ts.map +1 -0
- package/dist/api/error-handling.js +594 -0
- package/dist/api/error-handling.js.map +1 -0
- package/dist/api/flow-designer-api.d.ts +167 -0
- package/dist/api/flow-designer-api.d.ts.map +1 -0
- package/dist/api/flow-designer-api.js +555 -0
- package/dist/api/flow-designer-api.js.map +1 -0
- package/dist/api/natural-language-mapper.d.ts +126 -0
- package/dist/api/natural-language-mapper.d.ts.map +1 -0
- package/dist/api/natural-language-mapper.js +498 -0
- package/dist/api/natural-language-mapper.js.map +1 -0
- package/dist/api/performance-optimizer.d.ts +240 -0
- package/dist/api/performance-optimizer.d.ts.map +1 -0
- package/dist/api/performance-optimizer.js +701 -0
- package/dist/api/performance-optimizer.js.map +1 -0
- package/dist/api/transaction-manager.d.ts +189 -0
- package/dist/api/transaction-manager.d.ts.map +1 -0
- package/dist/api/transaction-manager.js +576 -0
- package/dist/api/transaction-manager.js.map +1 -0
- package/dist/cli/deploy-artifact.d.ts +7 -0
- package/dist/cli/deploy-artifact.d.ts.map +1 -0
- package/dist/cli/deploy-artifact.js +279 -0
- package/dist/cli/deploy-artifact.js.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +2057 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/managers/scope-manager.d.ts +75 -0
- package/dist/managers/scope-manager.d.ts.map +1 -0
- package/dist/managers/scope-manager.js +448 -0
- package/dist/managers/scope-manager.js.map +1 -0
- package/dist/mcp/mcp-wrapper.d.ts +8 -0
- package/dist/mcp/mcp-wrapper.d.ts.map +1 -0
- package/dist/mcp/mcp-wrapper.js +77 -0
- package/dist/mcp/mcp-wrapper.js.map +1 -0
- package/dist/mcp/servicenow-automation-mcp.d.ts +8 -0
- package/dist/mcp/servicenow-automation-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-automation-mcp.js +683 -0
- package/dist/mcp/servicenow-automation-mcp.js.map +1 -0
- package/dist/mcp/servicenow-deployment-mcp.d.ts +7 -0
- package/dist/mcp/servicenow-deployment-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-deployment-mcp.js +972 -0
- package/dist/mcp/servicenow-deployment-mcp.js.map +1 -0
- package/dist/mcp/servicenow-flow-composer-mcp.d.ts +7 -0
- package/dist/mcp/servicenow-flow-composer-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-flow-composer-mcp.js +1121 -0
- package/dist/mcp/servicenow-flow-composer-mcp.js.map +1 -0
- package/dist/mcp/servicenow-graph-memory-mcp.d.ts +7 -0
- package/dist/mcp/servicenow-graph-memory-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-graph-memory-mcp.js +703 -0
- package/dist/mcp/servicenow-graph-memory-mcp.js.map +1 -0
- package/dist/mcp/servicenow-integration-mcp.d.ts +8 -0
- package/dist/mcp/servicenow-integration-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-integration-mcp.js +689 -0
- package/dist/mcp/servicenow-integration-mcp.js.map +1 -0
- package/dist/mcp/servicenow-intelligent-mcp.d.ts +7 -0
- package/dist/mcp/servicenow-intelligent-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-intelligent-mcp.js +1138 -0
- package/dist/mcp/servicenow-intelligent-mcp.js.map +1 -0
- package/dist/mcp/servicenow-mcp-server.d.ts +37 -0
- package/dist/mcp/servicenow-mcp-server.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-server.js +648 -0
- package/dist/mcp/servicenow-mcp-server.js.map +1 -0
- package/dist/mcp/servicenow-operations-mcp.d.ts +15 -0
- package/dist/mcp/servicenow-operations-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-operations-mcp.js +1287 -0
- package/dist/mcp/servicenow-operations-mcp.js.map +1 -0
- package/dist/mcp/servicenow-platform-development-mcp.d.ts +8 -0
- package/dist/mcp/servicenow-platform-development-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-platform-development-mcp.js +557 -0
- package/dist/mcp/servicenow-platform-development-mcp.js.map +1 -0
- package/dist/mcp/servicenow-progressive-indexer.d.ts +79 -0
- package/dist/mcp/servicenow-progressive-indexer.d.ts.map +1 -0
- package/dist/mcp/servicenow-progressive-indexer.js +320 -0
- package/dist/mcp/servicenow-progressive-indexer.js.map +1 -0
- package/dist/mcp/servicenow-reporting-analytics-mcp.d.ts +8 -0
- package/dist/mcp/servicenow-reporting-analytics-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-reporting-analytics-mcp.js +888 -0
- package/dist/mcp/servicenow-reporting-analytics-mcp.js.map +1 -0
- package/dist/mcp/servicenow-security-compliance-mcp.d.ts +8 -0
- package/dist/mcp/servicenow-security-compliance-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-security-compliance-mcp.js +812 -0
- package/dist/mcp/servicenow-security-compliance-mcp.js.map +1 -0
- package/dist/mcp/servicenow-update-set-mcp.d.ts +7 -0
- package/dist/mcp/servicenow-update-set-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-update-set-mcp.js +599 -0
- package/dist/mcp/servicenow-update-set-mcp.js.map +1 -0
- package/dist/mcp/start-all-mcp-servers.d.ts +6 -0
- package/dist/mcp/start-all-mcp-servers.d.ts.map +1 -0
- package/dist/mcp/start-all-mcp-servers.js +65 -0
- package/dist/mcp/start-all-mcp-servers.js.map +1 -0
- package/dist/mcp/start-servicenow-mcp.d.ts +7 -0
- package/dist/mcp/start-servicenow-mcp.d.ts.map +1 -0
- package/dist/mcp/start-servicenow-mcp.js +64 -0
- package/dist/mcp/start-servicenow-mcp.js.map +1 -0
- package/dist/mcp/test-simple-mcp.d.ts +6 -0
- package/dist/mcp/test-simple-mcp.d.ts.map +1 -0
- package/dist/mcp/test-simple-mcp.js +64 -0
- package/dist/mcp/test-simple-mcp.js.map +1 -0
- package/dist/orchestrator/flow-composer.d.ts +269 -0
- package/dist/orchestrator/flow-composer.d.ts.map +1 -0
- package/dist/orchestrator/flow-composer.js +2221 -0
- package/dist/orchestrator/flow-composer.js.map +1 -0
- package/dist/orchestrator/flow-pattern-templates.d.ts +260 -0
- package/dist/orchestrator/flow-pattern-templates.d.ts.map +1 -0
- package/dist/orchestrator/flow-pattern-templates.js +906 -0
- package/dist/orchestrator/flow-pattern-templates.js.map +1 -0
- package/dist/orchestrator/flow-subflow-decision-engine.d.ts +202 -0
- package/dist/orchestrator/flow-subflow-decision-engine.d.ts.map +1 -0
- package/dist/orchestrator/flow-subflow-decision-engine.js +769 -0
- package/dist/orchestrator/flow-subflow-decision-engine.js.map +1 -0
- package/dist/orchestrator/flow-validation-engine.d.ts +145 -0
- package/dist/orchestrator/flow-validation-engine.d.ts.map +1 -0
- package/dist/orchestrator/flow-validation-engine.js +663 -0
- package/dist/orchestrator/flow-validation-engine.js.map +1 -0
- package/dist/orchestrator/snow-orchestrator.d.ts +49 -0
- package/dist/orchestrator/snow-orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/snow-orchestrator.js +235 -0
- package/dist/orchestrator/snow-orchestrator.js.map +1 -0
- package/dist/orchestrator/subflow-creation-handler.d.ts +230 -0
- package/dist/orchestrator/subflow-creation-handler.d.ts.map +1 -0
- package/dist/orchestrator/subflow-creation-handler.js +791 -0
- package/dist/orchestrator/subflow-creation-handler.js.map +1 -0
- package/dist/strategies/global-scope-strategy.d.ts +123 -0
- package/dist/strategies/global-scope-strategy.d.ts.map +1 -0
- package/dist/strategies/global-scope-strategy.js +585 -0
- package/dist/strategies/global-scope-strategy.js.map +1 -0
- package/dist/types/index.d.ts +138 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/servicenow.types.d.ts +260 -0
- package/dist/types/servicenow.types.d.ts.map +1 -0
- package/dist/types/servicenow.types.js +3 -0
- package/dist/types/servicenow.types.js.map +1 -0
- package/dist/types/snow-flow.types.d.ts +114 -0
- package/dist/types/snow-flow.types.d.ts.map +1 -0
- package/dist/types/snow-flow.types.js +3 -0
- package/dist/types/snow-flow.types.js.map +1 -0
- package/dist/utils/action-type-cache.d.ts +66 -0
- package/dist/utils/action-type-cache.d.ts.map +1 -0
- package/dist/utils/action-type-cache.js +237 -0
- package/dist/utils/action-type-cache.js.map +1 -0
- package/dist/utils/agent-detector.d.ts +35 -0
- package/dist/utils/agent-detector.d.ts.map +1 -0
- package/dist/utils/agent-detector.js +353 -0
- package/dist/utils/agent-detector.js.map +1 -0
- package/dist/utils/flow-api-discovery.d.ts +151 -0
- package/dist/utils/flow-api-discovery.d.ts.map +1 -0
- package/dist/utils/flow-api-discovery.js +440 -0
- package/dist/utils/flow-api-discovery.js.map +1 -0
- package/dist/utils/flow-xml-generator.d.ts +41 -0
- package/dist/utils/flow-xml-generator.d.ts.map +1 -0
- package/dist/utils/flow-xml-generator.js +258 -0
- package/dist/utils/flow-xml-generator.js.map +1 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +51 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/mcp-auth-middleware.d.ts +58 -0
- package/dist/utils/mcp-auth-middleware.d.ts.map +1 -0
- package/dist/utils/mcp-auth-middleware.js +227 -0
- package/dist/utils/mcp-auth-middleware.js.map +1 -0
- package/dist/utils/mcp-config-manager.d.ts +126 -0
- package/dist/utils/mcp-config-manager.d.ts.map +1 -0
- package/dist/utils/mcp-config-manager.js +209 -0
- package/dist/utils/mcp-config-manager.js.map +1 -0
- package/dist/utils/mcp-server-manager.d.ts +91 -0
- package/dist/utils/mcp-server-manager.d.ts.map +1 -0
- package/dist/utils/mcp-server-manager.js +338 -0
- package/dist/utils/mcp-server-manager.js.map +1 -0
- package/dist/utils/scope-utils.d.ts +72 -0
- package/dist/utils/scope-utils.d.ts.map +1 -0
- package/dist/utils/scope-utils.js +386 -0
- package/dist/utils/scope-utils.js.map +1 -0
- package/dist/utils/servicenow-client.d.ts +233 -0
- package/dist/utils/servicenow-client.d.ts.map +1 -0
- package/dist/utils/servicenow-client.js +1465 -0
- package/dist/utils/servicenow-client.js.map +1 -0
- package/dist/utils/snow-oauth-old.d.ts +65 -0
- package/dist/utils/snow-oauth-old.d.ts.map +1 -0
- package/dist/utils/snow-oauth-old.js +345 -0
- package/dist/utils/snow-oauth-old.js.map +1 -0
- package/dist/utils/snow-oauth.d.ts +85 -0
- package/dist/utils/snow-oauth.d.ts.map +1 -0
- package/dist/utils/snow-oauth.js +512 -0
- package/dist/utils/snow-oauth.js.map +1 -0
- package/dist/utils/template-engine.d.ts +76 -0
- package/dist/utils/template-engine.d.ts.map +1 -0
- package/dist/utils/template-engine.js +391 -0
- package/dist/utils/template-engine.js.map +1 -0
- package/dist/version.d.ts +35 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +72 -0
- package/dist/version.js.map +1 -0
- package/mcp-wrapper.sh +12 -0
- package/package.json +77 -0
- package/reports/swarm-auto-centralized-1752649029776.json +13 -0
- package/scripts/postinstall.js +30 -0
- package/scripts/setup-mcp.js +89 -0
|
@@ -0,0 +1,1539 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* UI Builder Agent for UI Pages and UI Actions
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.UIBuilderAgent = void 0;
|
|
7
|
+
const base_agent_js_1 = require("../core/base-agent.js");
|
|
8
|
+
class UIBuilderAgent extends base_agent_js_1.BaseServiceNowAgent {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super('ui-builder', servicenow_types_js_1.AgentType.UI_BUILDER, [
|
|
11
|
+
'create_ui_page',
|
|
12
|
+
'create_ui_action',
|
|
13
|
+
'generate_form_layout',
|
|
14
|
+
'create_ui_macro',
|
|
15
|
+
'generate_responsive_ui',
|
|
16
|
+
'create_ui_components',
|
|
17
|
+
'validate_ui_code'
|
|
18
|
+
], config);
|
|
19
|
+
}
|
|
20
|
+
async execute(task) {
|
|
21
|
+
this.logger.info(`Executing UI building task: ${task.description}`);
|
|
22
|
+
try {
|
|
23
|
+
switch (task.type) {
|
|
24
|
+
case 'create_ui_page':
|
|
25
|
+
return await this.createUIPage(task);
|
|
26
|
+
case 'create_ui_action':
|
|
27
|
+
return await this.createUIAction(task);
|
|
28
|
+
case 'generate_ui_from_spec':
|
|
29
|
+
return await this.generateUIFromSpec(task);
|
|
30
|
+
case 'create_form_layout':
|
|
31
|
+
return await this.createFormLayout(task);
|
|
32
|
+
case 'create_ui_components':
|
|
33
|
+
return await this.createUIComponents(task);
|
|
34
|
+
default:
|
|
35
|
+
throw new Error(`Unknown task type: ${task.type}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
this.logger.error(`UI building task failed: ${error.message}`);
|
|
40
|
+
return {
|
|
41
|
+
taskId: task.id,
|
|
42
|
+
success: false,
|
|
43
|
+
error: error.message
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async createUIPage(task) {
|
|
48
|
+
const { name, description, layout, components, directAccess } = task.payload;
|
|
49
|
+
const uiPage = {
|
|
50
|
+
name,
|
|
51
|
+
html: this.generateUIPageHTML(name, layout, components),
|
|
52
|
+
processingScript: this.generateProcessingScript(components),
|
|
53
|
+
clientScript: this.generateUIPageClientScript(components),
|
|
54
|
+
directAccess: directAccess ?? false
|
|
55
|
+
};
|
|
56
|
+
// Generate CSS file
|
|
57
|
+
const css = this.generateUIPageCSS(name, layout);
|
|
58
|
+
// Generate orchestration commands
|
|
59
|
+
const commands = [
|
|
60
|
+
this.generateCommand('Bash', 'create', {
|
|
61
|
+
command: `mkdir -p /Users/nielsvanderwerf/Projects/servicenow_multiagent/output/ui_pages/${this.sanitizeName(name)}`,
|
|
62
|
+
description: `Create UI Page directory for ${name}`
|
|
63
|
+
}, 'Create directory'),
|
|
64
|
+
this.generateCommand('Write', 'create', {
|
|
65
|
+
file_path: `/Users/nielsvanderwerf/Projects/servicenow_multiagent/output/ui_pages/${this.sanitizeName(name)}/page.html`,
|
|
66
|
+
content: uiPage.html
|
|
67
|
+
}, `Create UI Page HTML: ${name}`),
|
|
68
|
+
this.generateCommand('Write', 'create', {
|
|
69
|
+
file_path: `/Users/nielsvanderwerf/Projects/servicenow_multiagent/output/ui_pages/${this.sanitizeName(name)}/processing.js`,
|
|
70
|
+
content: uiPage.processingScript || '// No processing script required'
|
|
71
|
+
}, 'Create processing script'),
|
|
72
|
+
this.generateCommand('Write', 'create', {
|
|
73
|
+
file_path: `/Users/nielsvanderwerf/Projects/servicenow_multiagent/output/ui_pages/${this.sanitizeName(name)}/client.js`,
|
|
74
|
+
content: uiPage.clientScript || '// No client script required'
|
|
75
|
+
}, 'Create client script'),
|
|
76
|
+
this.generateCommand('Write', 'create', {
|
|
77
|
+
file_path: `/Users/nielsvanderwerf/Projects/servicenow_multiagent/output/ui_pages/${this.sanitizeName(name)}/styles.css`,
|
|
78
|
+
content: css
|
|
79
|
+
}, 'Create CSS styles'),
|
|
80
|
+
this.generateCommand('Write', 'create', {
|
|
81
|
+
file_path: `/Users/nielsvanderwerf/Projects/servicenow_multiagent/output/ui_pages/${this.sanitizeName(name)}/config.json`,
|
|
82
|
+
content: JSON.stringify({
|
|
83
|
+
name,
|
|
84
|
+
description: description || `UI Page: ${name}`,
|
|
85
|
+
directAccess,
|
|
86
|
+
created: new Date().toISOString()
|
|
87
|
+
}, null, 2)
|
|
88
|
+
}, 'Create UI Page configuration')
|
|
89
|
+
];
|
|
90
|
+
// Store in memory
|
|
91
|
+
await this.storeInMemory(`ui_pages:${this.sanitizeName(name)}`, uiPage);
|
|
92
|
+
return {
|
|
93
|
+
taskId: task.id,
|
|
94
|
+
success: true,
|
|
95
|
+
output: uiPage,
|
|
96
|
+
artifacts: [
|
|
97
|
+
this.createArtifact('ui_page', name, uiPage, {
|
|
98
|
+
hasProcessingScript: !!uiPage.processingScript,
|
|
99
|
+
hasClientScript: !!uiPage.clientScript,
|
|
100
|
+
directAccess
|
|
101
|
+
})
|
|
102
|
+
],
|
|
103
|
+
commands
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async createUIAction(task) {
|
|
107
|
+
const { name, table, label, formButton, listButton, conditions, action } = task.payload;
|
|
108
|
+
const uiAction = {
|
|
109
|
+
name,
|
|
110
|
+
table,
|
|
111
|
+
formButton: formButton ?? true,
|
|
112
|
+
listButton: listButton ?? false,
|
|
113
|
+
conditions: conditions || '',
|
|
114
|
+
clientScript: action.clientSide ? this.generateUIActionClientScript(action) : undefined,
|
|
115
|
+
serverScript: action.serverSide ? this.generateUIActionServerScript(action) : undefined
|
|
116
|
+
};
|
|
117
|
+
const commands = [
|
|
118
|
+
this.generateCommand('Bash', 'create', {
|
|
119
|
+
command: `mkdir -p /Users/nielsvanderwerf/Projects/servicenow_multiagent/output/ui_actions/${table}`,
|
|
120
|
+
description: `Create UI Actions directory for ${table}`
|
|
121
|
+
}, 'Create directory'),
|
|
122
|
+
this.generateCommand('Write', 'create', {
|
|
123
|
+
file_path: `/Users/nielsvanderwerf/Projects/servicenow_multiagent/output/ui_actions/${table}/${this.sanitizeName(name)}.js`,
|
|
124
|
+
content: this.combineUIActionScripts(uiAction)
|
|
125
|
+
}, `Create UI Action: ${name}`),
|
|
126
|
+
this.generateCommand('Write', 'create', {
|
|
127
|
+
file_path: `/Users/nielsvanderwerf/Projects/servicenow_multiagent/output/ui_actions/${table}/${this.sanitizeName(name)}.json`,
|
|
128
|
+
content: JSON.stringify({
|
|
129
|
+
...uiAction,
|
|
130
|
+
label: label || name,
|
|
131
|
+
order: action.order || 100,
|
|
132
|
+
active: true
|
|
133
|
+
}, null, 2)
|
|
134
|
+
}, 'Create UI Action metadata')
|
|
135
|
+
];
|
|
136
|
+
await this.storeInMemory(`ui_actions:${table}:${this.sanitizeName(name)}`, uiAction);
|
|
137
|
+
return {
|
|
138
|
+
taskId: task.id,
|
|
139
|
+
success: true,
|
|
140
|
+
output: uiAction,
|
|
141
|
+
artifacts: [
|
|
142
|
+
this.createArtifact('ui_action', name, uiAction, {
|
|
143
|
+
table,
|
|
144
|
+
type: action.clientSide ? 'client' : 'server'
|
|
145
|
+
})
|
|
146
|
+
],
|
|
147
|
+
commands
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
async generateUIFromSpec(task) {
|
|
151
|
+
const { spec, type } = task.payload;
|
|
152
|
+
let result;
|
|
153
|
+
switch (type) {
|
|
154
|
+
case 'dashboard':
|
|
155
|
+
result = await this.generateDashboard(spec);
|
|
156
|
+
break;
|
|
157
|
+
case 'form':
|
|
158
|
+
result = await this.generateForm(spec);
|
|
159
|
+
break;
|
|
160
|
+
case 'report':
|
|
161
|
+
result = await this.generateReport(spec);
|
|
162
|
+
break;
|
|
163
|
+
case 'wizard':
|
|
164
|
+
result = await this.generateWizard(spec);
|
|
165
|
+
break;
|
|
166
|
+
default:
|
|
167
|
+
result = await this.generateGenericUI(spec);
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
...result,
|
|
171
|
+
taskId: task.id
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
async createFormLayout(task) {
|
|
175
|
+
const { formName, sections, fields, responsive } = task.payload;
|
|
176
|
+
const formHTML = this.generateFormHTML(sections, fields, responsive);
|
|
177
|
+
const formCSS = this.generateFormCSS(formName, responsive);
|
|
178
|
+
const formJS = this.generateFormJavaScript(fields);
|
|
179
|
+
const commands = [
|
|
180
|
+
this.generateCommand('Bash', 'create', {
|
|
181
|
+
command: `mkdir -p /Users/nielsvanderwerf/Projects/servicenow_multiagent/output/forms/${this.sanitizeName(formName)}`,
|
|
182
|
+
description: `Create form directory for ${formName}`
|
|
183
|
+
}, 'Create directory'),
|
|
184
|
+
this.generateCommand('Write', 'create', {
|
|
185
|
+
file_path: `/Users/nielsvanderwerf/Projects/servicenow_multiagent/output/forms/${this.sanitizeName(formName)}/form.html`,
|
|
186
|
+
content: formHTML
|
|
187
|
+
}, 'Create form HTML'),
|
|
188
|
+
this.generateCommand('Write', 'create', {
|
|
189
|
+
file_path: `/Users/nielsvanderwerf/Projects/servicenow_multiagent/output/forms/${this.sanitizeName(formName)}/styles.css`,
|
|
190
|
+
content: formCSS
|
|
191
|
+
}, 'Create form CSS'),
|
|
192
|
+
this.generateCommand('Write', 'create', {
|
|
193
|
+
file_path: `/Users/nielsvanderwerf/Projects/servicenow_multiagent/output/forms/${this.sanitizeName(formName)}/script.js`,
|
|
194
|
+
content: formJS
|
|
195
|
+
}, 'Create form JavaScript')
|
|
196
|
+
];
|
|
197
|
+
return {
|
|
198
|
+
taskId: task.id,
|
|
199
|
+
success: true,
|
|
200
|
+
output: {
|
|
201
|
+
html: formHTML,
|
|
202
|
+
css: formCSS,
|
|
203
|
+
javascript: formJS
|
|
204
|
+
},
|
|
205
|
+
artifacts: [
|
|
206
|
+
this.createArtifact('form_layout', formName, {
|
|
207
|
+
sections: sections.length,
|
|
208
|
+
fields: fields.length,
|
|
209
|
+
responsive
|
|
210
|
+
})
|
|
211
|
+
],
|
|
212
|
+
commands
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
async createUIComponents(task) {
|
|
216
|
+
const { components, theme } = task.payload;
|
|
217
|
+
const generatedComponents = components.map((comp) => ({
|
|
218
|
+
name: comp.name,
|
|
219
|
+
type: comp.type,
|
|
220
|
+
html: this.generateComponentHTML(comp),
|
|
221
|
+
css: this.generateComponentCSS(comp, theme),
|
|
222
|
+
javascript: this.generateComponentJS(comp)
|
|
223
|
+
}));
|
|
224
|
+
const commands = [];
|
|
225
|
+
generatedComponents.forEach((comp) => {
|
|
226
|
+
const compDir = `/Users/nielsvanderwerf/Projects/servicenow_multiagent/output/components/${this.sanitizeName(comp.name)}`;
|
|
227
|
+
commands.push(this.generateCommand('Bash', 'create', {
|
|
228
|
+
command: `mkdir -p ${compDir}`,
|
|
229
|
+
description: `Create component directory for ${comp.name}`
|
|
230
|
+
}, 'Create directory'), this.generateCommand('Write', 'create', {
|
|
231
|
+
file_path: `${compDir}/component.html`,
|
|
232
|
+
content: comp.html
|
|
233
|
+
}, `Create ${comp.name} HTML`), this.generateCommand('Write', 'create', {
|
|
234
|
+
file_path: `${compDir}/component.css`,
|
|
235
|
+
content: comp.css
|
|
236
|
+
}, `Create ${comp.name} CSS`), this.generateCommand('Write', 'create', {
|
|
237
|
+
file_path: `${compDir}/component.js`,
|
|
238
|
+
content: comp.javascript
|
|
239
|
+
}, `Create ${comp.name} JavaScript`));
|
|
240
|
+
});
|
|
241
|
+
return {
|
|
242
|
+
taskId: task.id,
|
|
243
|
+
success: true,
|
|
244
|
+
output: generatedComponents,
|
|
245
|
+
artifacts: generatedComponents.map((comp) => this.createArtifact('ui_component', comp.name, comp)),
|
|
246
|
+
commands
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
// Helper methods
|
|
250
|
+
generateUIPageHTML(name, layout, components) {
|
|
251
|
+
const layoutClass = layout?.type || 'standard';
|
|
252
|
+
return `<?xml version="1.0" encoding="utf-8" ?>
|
|
253
|
+
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
|
|
254
|
+
<g:requires name="styles/${this.sanitizeName(name)}.css" />
|
|
255
|
+
|
|
256
|
+
<div class="ui-page-container ${layoutClass}-layout">
|
|
257
|
+
<header class="ui-page-header">
|
|
258
|
+
<h1>${name}</h1>
|
|
259
|
+
</header>
|
|
260
|
+
|
|
261
|
+
<main class="ui-page-content">
|
|
262
|
+
${this.generateLayoutHTML(layout, components)}
|
|
263
|
+
</main>
|
|
264
|
+
|
|
265
|
+
<footer class="ui-page-footer">
|
|
266
|
+
<p>Generated by ServiceNow UI Builder</p>
|
|
267
|
+
</footer>
|
|
268
|
+
</div>
|
|
269
|
+
|
|
270
|
+
<script>
|
|
271
|
+
${this.generateUIPageClientScript(components)}
|
|
272
|
+
</script>
|
|
273
|
+
</j:jelly>`;
|
|
274
|
+
}
|
|
275
|
+
generateLayoutHTML(layout, components) {
|
|
276
|
+
if (!layout || !components) {
|
|
277
|
+
return '<div class="placeholder">Add your content here</div>';
|
|
278
|
+
}
|
|
279
|
+
switch (layout.type) {
|
|
280
|
+
case 'grid':
|
|
281
|
+
return this.generateGridLayout(layout, components);
|
|
282
|
+
case 'flex':
|
|
283
|
+
return this.generateFlexLayout(layout, components);
|
|
284
|
+
case 'tabs':
|
|
285
|
+
return this.generateTabsLayout(layout, components);
|
|
286
|
+
default:
|
|
287
|
+
return this.generateStandardLayout(components);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
generateGridLayout(layout, components) {
|
|
291
|
+
const columns = layout.columns || 3;
|
|
292
|
+
return `<div class="grid-container" style="grid-template-columns: repeat(${columns}, 1fr);">
|
|
293
|
+
${components.map((comp, index) => `
|
|
294
|
+
<div class="grid-item" data-component="${comp.type}">
|
|
295
|
+
${this.generateComponentHTML(comp)}
|
|
296
|
+
</div>
|
|
297
|
+
`).join('')}
|
|
298
|
+
</div>`;
|
|
299
|
+
}
|
|
300
|
+
generateFlexLayout(layout, components) {
|
|
301
|
+
return `<div class="flex-container" style="flex-direction: ${layout.direction || 'row'};">
|
|
302
|
+
${components.map(comp => `
|
|
303
|
+
<div class="flex-item" data-component="${comp.type}">
|
|
304
|
+
${this.generateComponentHTML(comp)}
|
|
305
|
+
</div>
|
|
306
|
+
`).join('')}
|
|
307
|
+
</div>`;
|
|
308
|
+
}
|
|
309
|
+
generateTabsLayout(layout, components) {
|
|
310
|
+
return `<div class="tabs-container">
|
|
311
|
+
<ul class="tab-headers">
|
|
312
|
+
${components.map((comp, index) => `
|
|
313
|
+
<li class="tab-header ${index === 0 ? 'active' : ''}" data-tab="${index}">
|
|
314
|
+
${comp.label || comp.name}
|
|
315
|
+
</li>
|
|
316
|
+
`).join('')}
|
|
317
|
+
</ul>
|
|
318
|
+
<div class="tab-contents">
|
|
319
|
+
${components.map((comp, index) => `
|
|
320
|
+
<div class="tab-content ${index === 0 ? 'active' : ''}" data-tab="${index}">
|
|
321
|
+
${this.generateComponentHTML(comp)}
|
|
322
|
+
</div>
|
|
323
|
+
`).join('')}
|
|
324
|
+
</div>
|
|
325
|
+
</div>`;
|
|
326
|
+
}
|
|
327
|
+
generateStandardLayout(components) {
|
|
328
|
+
return components.map(comp => `
|
|
329
|
+
<section class="ui-section">
|
|
330
|
+
${this.generateComponentHTML(comp)}
|
|
331
|
+
</section>
|
|
332
|
+
`).join('');
|
|
333
|
+
}
|
|
334
|
+
generateComponentHTML(component) {
|
|
335
|
+
switch (component.type) {
|
|
336
|
+
case 'chart':
|
|
337
|
+
return `<div class="chart-container" id="${component.id || 'chart'}">
|
|
338
|
+
<canvas id="${component.id}-canvas"></canvas>
|
|
339
|
+
</div>`;
|
|
340
|
+
case 'table':
|
|
341
|
+
return `<div class="table-container">
|
|
342
|
+
<table class="data-table" id="${component.id || 'table'}">
|
|
343
|
+
<thead>
|
|
344
|
+
<tr>${(component.columns || []).map((col) => `<th>${col.label}</th>`).join('')}</tr>
|
|
345
|
+
</thead>
|
|
346
|
+
<tbody>
|
|
347
|
+
<!-- Data will be loaded dynamically -->
|
|
348
|
+
</tbody>
|
|
349
|
+
</table>
|
|
350
|
+
</div>`;
|
|
351
|
+
case 'form':
|
|
352
|
+
return this.generateFormHTML(component.sections || [], component.fields || [], false);
|
|
353
|
+
case 'metric':
|
|
354
|
+
return `<div class="metric-widget">
|
|
355
|
+
<h3>${component.label}</h3>
|
|
356
|
+
<div class="metric-value" id="${component.id}-value">--</div>
|
|
357
|
+
<div class="metric-trend" id="${component.id}-trend"></div>
|
|
358
|
+
</div>`;
|
|
359
|
+
default:
|
|
360
|
+
return `<div class="custom-component" id="${component.id}">
|
|
361
|
+
${component.content || '<!-- Custom component -->'}
|
|
362
|
+
</div>`;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
generateProcessingScript(components) {
|
|
366
|
+
return `<%
|
|
367
|
+
// Server-side processing script
|
|
368
|
+
|
|
369
|
+
// Initialize response object
|
|
370
|
+
var response = {
|
|
371
|
+
success: true,
|
|
372
|
+
data: {}
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
try {
|
|
376
|
+
${components?.map(comp => this.generateComponentDataFetch(comp)).join('\n ') || '// Add data fetching logic'}
|
|
377
|
+
|
|
378
|
+
// Set response data
|
|
379
|
+
g_response.setContentType('application/json');
|
|
380
|
+
g_response.getWriter().write(JSON.stringify(response));
|
|
381
|
+
} catch (e) {
|
|
382
|
+
response.success = false;
|
|
383
|
+
response.error = e.message;
|
|
384
|
+
g_response.getWriter().write(JSON.stringify(response));
|
|
385
|
+
}
|
|
386
|
+
%>`;
|
|
387
|
+
}
|
|
388
|
+
generateComponentDataFetch(component) {
|
|
389
|
+
switch (component.type) {
|
|
390
|
+
case 'table':
|
|
391
|
+
return `// Fetch data for table: ${component.id}
|
|
392
|
+
var gr = new GlideRecord('${component.table || 'incident'}');
|
|
393
|
+
gr.setLimit(${component.limit || 100});
|
|
394
|
+
gr.query();
|
|
395
|
+
response.data.${component.id} = [];
|
|
396
|
+
while (gr.next()) {
|
|
397
|
+
response.data.${component.id}.push({
|
|
398
|
+
sys_id: gr.getUniqueValue(),
|
|
399
|
+
display_value: gr.getDisplayValue()
|
|
400
|
+
});
|
|
401
|
+
}`;
|
|
402
|
+
case 'metric':
|
|
403
|
+
return `// Calculate metric: ${component.id}
|
|
404
|
+
var count = new GlideAggregate('${component.table || 'incident'}');
|
|
405
|
+
count.addAggregate('COUNT');
|
|
406
|
+
count.query();
|
|
407
|
+
if (count.next()) {
|
|
408
|
+
response.data.${component.id} = count.getAggregate('COUNT');
|
|
409
|
+
}`;
|
|
410
|
+
default:
|
|
411
|
+
return `// Custom data fetch for ${component.id}`;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
generateUIPageClientScript(components) {
|
|
415
|
+
return `(function() {
|
|
416
|
+
// UI Page client-side script
|
|
417
|
+
|
|
418
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
419
|
+
initializePage();
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
function initializePage() {
|
|
423
|
+
${components?.map(comp => this.generateComponentInitialization(comp)).join('\n ') || '// Add initialization logic'}
|
|
424
|
+
|
|
425
|
+
// Setup event handlers
|
|
426
|
+
setupEventHandlers();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function setupEventHandlers() {
|
|
430
|
+
// Tab navigation
|
|
431
|
+
var tabHeaders = document.querySelectorAll('.tab-header');
|
|
432
|
+
tabHeaders.forEach(function(header) {
|
|
433
|
+
header.addEventListener('click', function() {
|
|
434
|
+
switchTab(this.getAttribute('data-tab'));
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function switchTab(tabIndex) {
|
|
440
|
+
// Hide all tabs
|
|
441
|
+
document.querySelectorAll('.tab-content').forEach(function(content) {
|
|
442
|
+
content.classList.remove('active');
|
|
443
|
+
});
|
|
444
|
+
document.querySelectorAll('.tab-header').forEach(function(header) {
|
|
445
|
+
header.classList.remove('active');
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
// Show selected tab
|
|
449
|
+
document.querySelector('.tab-content[data-tab="' + tabIndex + '"]').classList.add('active');
|
|
450
|
+
document.querySelector('.tab-header[data-tab="' + tabIndex + '"]').classList.add('active');
|
|
451
|
+
}
|
|
452
|
+
})();`;
|
|
453
|
+
}
|
|
454
|
+
generateComponentInitialization(component) {
|
|
455
|
+
switch (component.type) {
|
|
456
|
+
case 'chart':
|
|
457
|
+
return `// Initialize chart: ${component.id}
|
|
458
|
+
initializeChart('${component.id}-canvas', ${JSON.stringify(component.config || {})});`;
|
|
459
|
+
case 'table':
|
|
460
|
+
return `// Initialize table: ${component.id}
|
|
461
|
+
loadTableData('${component.id}');`;
|
|
462
|
+
default:
|
|
463
|
+
return `// Initialize component: ${component.id}`;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
generateUIPageCSS(name, layout) {
|
|
467
|
+
return `.ui-page-container {
|
|
468
|
+
max-width: 1200px;
|
|
469
|
+
margin: 0 auto;
|
|
470
|
+
padding: 20px;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
.ui-page-header {
|
|
474
|
+
margin-bottom: 30px;
|
|
475
|
+
padding-bottom: 20px;
|
|
476
|
+
border-bottom: 2px solid #e0e0e0;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
.ui-page-header h1 {
|
|
480
|
+
margin: 0;
|
|
481
|
+
color: #333;
|
|
482
|
+
font-size: 28px;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
.ui-page-content {
|
|
486
|
+
min-height: 400px;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/* Grid Layout */
|
|
490
|
+
.grid-container {
|
|
491
|
+
display: grid;
|
|
492
|
+
gap: 20px;
|
|
493
|
+
margin-bottom: 20px;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
.grid-item {
|
|
497
|
+
background: #f9f9f9;
|
|
498
|
+
padding: 20px;
|
|
499
|
+
border-radius: 4px;
|
|
500
|
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/* Flex Layout */
|
|
504
|
+
.flex-container {
|
|
505
|
+
display: flex;
|
|
506
|
+
gap: 20px;
|
|
507
|
+
flex-wrap: wrap;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
.flex-item {
|
|
511
|
+
flex: 1;
|
|
512
|
+
min-width: 300px;
|
|
513
|
+
background: #f9f9f9;
|
|
514
|
+
padding: 20px;
|
|
515
|
+
border-radius: 4px;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/* Tabs Layout */
|
|
519
|
+
.tab-headers {
|
|
520
|
+
list-style: none;
|
|
521
|
+
padding: 0;
|
|
522
|
+
margin: 0;
|
|
523
|
+
display: flex;
|
|
524
|
+
border-bottom: 2px solid #ddd;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
.tab-header {
|
|
528
|
+
padding: 10px 20px;
|
|
529
|
+
cursor: pointer;
|
|
530
|
+
border-bottom: 2px solid transparent;
|
|
531
|
+
transition: all 0.3s;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
.tab-header:hover {
|
|
535
|
+
background: #f0f0f0;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
.tab-header.active {
|
|
539
|
+
border-bottom-color: #0078d4;
|
|
540
|
+
color: #0078d4;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
.tab-content {
|
|
544
|
+
display: none;
|
|
545
|
+
padding: 20px 0;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
.tab-content.active {
|
|
549
|
+
display: block;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/* Components */
|
|
553
|
+
.chart-container {
|
|
554
|
+
position: relative;
|
|
555
|
+
height: 400px;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
.data-table {
|
|
559
|
+
width: 100%;
|
|
560
|
+
border-collapse: collapse;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
.data-table th,
|
|
564
|
+
.data-table td {
|
|
565
|
+
padding: 10px;
|
|
566
|
+
text-align: left;
|
|
567
|
+
border-bottom: 1px solid #ddd;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
.data-table th {
|
|
571
|
+
background: #f5f5f5;
|
|
572
|
+
font-weight: bold;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
.metric-widget {
|
|
576
|
+
text-align: center;
|
|
577
|
+
padding: 20px;
|
|
578
|
+
background: #fff;
|
|
579
|
+
border-radius: 8px;
|
|
580
|
+
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
.metric-value {
|
|
584
|
+
font-size: 48px;
|
|
585
|
+
font-weight: bold;
|
|
586
|
+
color: #0078d4;
|
|
587
|
+
margin: 20px 0;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
.ui-page-footer {
|
|
591
|
+
margin-top: 40px;
|
|
592
|
+
padding-top: 20px;
|
|
593
|
+
border-top: 1px solid #e0e0e0;
|
|
594
|
+
text-align: center;
|
|
595
|
+
color: #666;
|
|
596
|
+
}`;
|
|
597
|
+
}
|
|
598
|
+
generateUIActionClientScript(action) {
|
|
599
|
+
const confirmMessage = action.confirmMessage || 'Are you sure you want to perform this action?';
|
|
600
|
+
return `function ${this.sanitizeName(action.name)}() {
|
|
601
|
+
// Client-side UI Action
|
|
602
|
+
|
|
603
|
+
if (!confirm('${confirmMessage}')) {
|
|
604
|
+
return false;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// Show loading indicator
|
|
608
|
+
g_form.showLoadingMessage('Processing...');
|
|
609
|
+
|
|
610
|
+
// Prepare data
|
|
611
|
+
var data = {
|
|
612
|
+
sys_id: g_form.getUniqueValue(),
|
|
613
|
+
table: '${action.table || 'current'}',
|
|
614
|
+
${action.parameters?.map((p) => `${p.name}: g_form.getValue('${p.field}')`).join(',\n ') || ''}
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
// Make AJAX call to server
|
|
618
|
+
var ga = new GlideAjax('${action.ajaxProcessor || 'UIActionProcessor'}');
|
|
619
|
+
ga.addParam('sysparm_name', '${action.name}');
|
|
620
|
+
ga.addParam('sysparm_data', JSON.stringify(data));
|
|
621
|
+
|
|
622
|
+
ga.getXMLAnswer(function(response) {
|
|
623
|
+
g_form.hideLoadingMessage();
|
|
624
|
+
|
|
625
|
+
try {
|
|
626
|
+
var result = JSON.parse(response);
|
|
627
|
+
if (result.success) {
|
|
628
|
+
g_form.addInfoMessage(result.message || 'Action completed successfully');
|
|
629
|
+
${action.refresh ? 'g_form.reload();' : ''}
|
|
630
|
+
} else {
|
|
631
|
+
g_form.addErrorMessage(result.error || 'Action failed');
|
|
632
|
+
}
|
|
633
|
+
} catch (e) {
|
|
634
|
+
g_form.addErrorMessage('Error processing response');
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
return false; // Prevent default form submission
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// Execute the action
|
|
642
|
+
${this.sanitizeName(action.name)}();`;
|
|
643
|
+
}
|
|
644
|
+
generateUIActionServerScript(action) {
|
|
645
|
+
return `// Server-side UI Action
|
|
646
|
+
(function() {
|
|
647
|
+
try {
|
|
648
|
+
${this.generateServerActionLogic(action)}
|
|
649
|
+
|
|
650
|
+
// Set success message
|
|
651
|
+
gs.addInfoMessage('${action.successMessage || 'Action completed successfully'}');
|
|
652
|
+
|
|
653
|
+
// Redirect if specified
|
|
654
|
+
${action.redirect ? `action.setRedirectURL('${action.redirect}');` : '// No redirect'}
|
|
655
|
+
|
|
656
|
+
} catch (e) {
|
|
657
|
+
gs.addErrorMessage('Error: ' + e.message);
|
|
658
|
+
action.setRedirectURL(current);
|
|
659
|
+
}
|
|
660
|
+
})();`;
|
|
661
|
+
}
|
|
662
|
+
generateServerActionLogic(action) {
|
|
663
|
+
switch (action.type) {
|
|
664
|
+
case 'create_related':
|
|
665
|
+
return `// Create related record
|
|
666
|
+
var gr = new GlideRecord('${action.targetTable}');
|
|
667
|
+
gr.initialize();
|
|
668
|
+
${action.fieldMappings?.map((m) => `gr.${m.target} = current.${m.source};`).join('\n ') || ''}
|
|
669
|
+
gr.insert();`;
|
|
670
|
+
case 'update_field':
|
|
671
|
+
return `// Update field
|
|
672
|
+
current.${action.field} = '${action.value}';
|
|
673
|
+
current.update();`;
|
|
674
|
+
case 'execute_flow':
|
|
675
|
+
return `// Execute flow
|
|
676
|
+
sn_fd.FlowAPI.startFlow('${action.flowId}', {
|
|
677
|
+
table: current.getTableName(),
|
|
678
|
+
sys_id: current.getUniqueValue()
|
|
679
|
+
});`;
|
|
680
|
+
default:
|
|
681
|
+
return '// Custom action logic\n ' + (action.customCode || '// Add implementation');
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
combineUIActionScripts(uiAction) {
|
|
685
|
+
let combined = '// UI Action: ' + uiAction.name + '\n\n';
|
|
686
|
+
if (uiAction.clientScript) {
|
|
687
|
+
combined += '// CLIENT SCRIPT\n' + uiAction.clientScript + '\n\n';
|
|
688
|
+
}
|
|
689
|
+
if (uiAction.serverScript) {
|
|
690
|
+
combined += '// SERVER SCRIPT\n' + uiAction.serverScript;
|
|
691
|
+
}
|
|
692
|
+
return combined;
|
|
693
|
+
}
|
|
694
|
+
generateFormHTML(sections, fields, responsive) {
|
|
695
|
+
const formClass = responsive ? 'responsive-form' : 'standard-form';
|
|
696
|
+
return `<form class="${formClass}" id="custom-form">
|
|
697
|
+
${sections.map(section => `
|
|
698
|
+
<fieldset class="form-section">
|
|
699
|
+
<legend>${section.title}</legend>
|
|
700
|
+
<div class="form-fields">
|
|
701
|
+
${fields
|
|
702
|
+
.filter(field => field.section === section.id)
|
|
703
|
+
.map(field => this.generateFieldHTML(field))
|
|
704
|
+
.join('')}
|
|
705
|
+
</div>
|
|
706
|
+
</fieldset>
|
|
707
|
+
`).join('')}
|
|
708
|
+
|
|
709
|
+
<div class="form-actions">
|
|
710
|
+
<button type="submit" class="btn btn-primary">Submit</button>
|
|
711
|
+
<button type="button" class="btn btn-secondary" onclick="resetForm()">Reset</button>
|
|
712
|
+
</div>
|
|
713
|
+
</form>`;
|
|
714
|
+
}
|
|
715
|
+
generateFieldHTML(field) {
|
|
716
|
+
const required = field.required ? 'required' : '';
|
|
717
|
+
switch (field.type) {
|
|
718
|
+
case 'text':
|
|
719
|
+
case 'email':
|
|
720
|
+
case 'number':
|
|
721
|
+
return `<div class="form-field">
|
|
722
|
+
<label for="${field.id}">${field.label}</label>
|
|
723
|
+
<input type="${field.type}" id="${field.id}" name="${field.name}" ${required} />
|
|
724
|
+
</div>`;
|
|
725
|
+
case 'textarea':
|
|
726
|
+
return `<div class="form-field">
|
|
727
|
+
<label for="${field.id}">${field.label}</label>
|
|
728
|
+
<textarea id="${field.id}" name="${field.name}" rows="4" ${required}></textarea>
|
|
729
|
+
</div>`;
|
|
730
|
+
case 'select':
|
|
731
|
+
return `<div class="form-field">
|
|
732
|
+
<label for="${field.id}">${field.label}</label>
|
|
733
|
+
<select id="${field.id}" name="${field.name}" ${required}>
|
|
734
|
+
<option value="">-- Select --</option>
|
|
735
|
+
${field.options?.map((opt) => `<option value="${opt.value}">${opt.label}</option>`).join('')}
|
|
736
|
+
</select>
|
|
737
|
+
</div>`;
|
|
738
|
+
case 'checkbox':
|
|
739
|
+
return `<div class="form-field checkbox-field">
|
|
740
|
+
<input type="checkbox" id="${field.id}" name="${field.name}" />
|
|
741
|
+
<label for="${field.id}">${field.label}</label>
|
|
742
|
+
</div>`;
|
|
743
|
+
case 'reference':
|
|
744
|
+
return `<div class="form-field">
|
|
745
|
+
<label for="${field.id}">${field.label}</label>
|
|
746
|
+
<input type="text" id="${field.id}" name="${field.name}"
|
|
747
|
+
data-reference="${field.reference}" ${required} />
|
|
748
|
+
<button type="button" class="reference-lookup" onclick="lookupReference('${field.id}')">
|
|
749
|
+
🔍
|
|
750
|
+
</button>
|
|
751
|
+
</div>`;
|
|
752
|
+
default:
|
|
753
|
+
return `<div class="form-field">
|
|
754
|
+
<label for="${field.id}">${field.label}</label>
|
|
755
|
+
<input type="text" id="${field.id}" name="${field.name}" ${required} />
|
|
756
|
+
</div>`;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
generateFormCSS(formName, responsive) {
|
|
760
|
+
return `.${responsive ? 'responsive-form' : 'standard-form'} {
|
|
761
|
+
max-width: ${responsive ? '100%' : '800px'};
|
|
762
|
+
margin: 0 auto;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
.form-section {
|
|
766
|
+
margin-bottom: 30px;
|
|
767
|
+
padding: 20px;
|
|
768
|
+
border: 1px solid #e0e0e0;
|
|
769
|
+
border-radius: 4px;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
.form-section legend {
|
|
773
|
+
font-weight: bold;
|
|
774
|
+
color: #333;
|
|
775
|
+
padding: 0 10px;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
.form-fields {
|
|
779
|
+
display: ${responsive ? 'grid' : 'block'};
|
|
780
|
+
${responsive ? 'grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));' : ''}
|
|
781
|
+
gap: 20px;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
.form-field {
|
|
785
|
+
margin-bottom: 20px;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
.form-field label {
|
|
789
|
+
display: block;
|
|
790
|
+
margin-bottom: 5px;
|
|
791
|
+
font-weight: 600;
|
|
792
|
+
color: #555;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
.form-field input,
|
|
796
|
+
.form-field textarea,
|
|
797
|
+
.form-field select {
|
|
798
|
+
width: 100%;
|
|
799
|
+
padding: 8px 12px;
|
|
800
|
+
border: 1px solid #ddd;
|
|
801
|
+
border-radius: 4px;
|
|
802
|
+
font-size: 14px;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
.form-field input:focus,
|
|
806
|
+
.form-field textarea:focus,
|
|
807
|
+
.form-field select:focus {
|
|
808
|
+
outline: none;
|
|
809
|
+
border-color: #0078d4;
|
|
810
|
+
box-shadow: 0 0 0 2px rgba(0, 120, 212, 0.2);
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
.checkbox-field {
|
|
814
|
+
display: flex;
|
|
815
|
+
align-items: center;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
.checkbox-field input {
|
|
819
|
+
width: auto;
|
|
820
|
+
margin-right: 8px;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
.reference-lookup {
|
|
824
|
+
display: inline-block;
|
|
825
|
+
margin-left: 8px;
|
|
826
|
+
padding: 6px 10px;
|
|
827
|
+
border: 1px solid #ddd;
|
|
828
|
+
background: #f5f5f5;
|
|
829
|
+
cursor: pointer;
|
|
830
|
+
border-radius: 4px;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
.form-actions {
|
|
834
|
+
margin-top: 30px;
|
|
835
|
+
text-align: center;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
.btn {
|
|
839
|
+
padding: 10px 20px;
|
|
840
|
+
margin: 0 5px;
|
|
841
|
+
border: none;
|
|
842
|
+
border-radius: 4px;
|
|
843
|
+
font-size: 16px;
|
|
844
|
+
cursor: pointer;
|
|
845
|
+
transition: background-color 0.3s;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
.btn-primary {
|
|
849
|
+
background: #0078d4;
|
|
850
|
+
color: white;
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
.btn-primary:hover {
|
|
854
|
+
background: #005a9e;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
.btn-secondary {
|
|
858
|
+
background: #e0e0e0;
|
|
859
|
+
color: #333;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
.btn-secondary:hover {
|
|
863
|
+
background: #d0d0d0;
|
|
864
|
+
}`;
|
|
865
|
+
}
|
|
866
|
+
generateFormJavaScript(fields) {
|
|
867
|
+
return `// Form JavaScript
|
|
868
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
869
|
+
initializeForm();
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
function initializeForm() {
|
|
873
|
+
// Setup form validation
|
|
874
|
+
var form = document.getElementById('custom-form');
|
|
875
|
+
form.addEventListener('submit', handleSubmit);
|
|
876
|
+
|
|
877
|
+
// Initialize reference fields
|
|
878
|
+
${fields.filter(f => f.type === 'reference').map(field => `
|
|
879
|
+
initializeReferenceField('${field.id}', '${field.reference}');`).join('')}
|
|
880
|
+
|
|
881
|
+
// Setup field dependencies
|
|
882
|
+
setupFieldDependencies();
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
function handleSubmit(event) {
|
|
886
|
+
event.preventDefault();
|
|
887
|
+
|
|
888
|
+
if (!validateForm()) {
|
|
889
|
+
return false;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// Collect form data
|
|
893
|
+
var formData = new FormData(event.target);
|
|
894
|
+
var data = {};
|
|
895
|
+
|
|
896
|
+
for (var [key, value] of formData.entries()) {
|
|
897
|
+
data[key] = value;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// Submit form via AJAX
|
|
901
|
+
submitForm(data);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
function validateForm() {
|
|
905
|
+
var isValid = true;
|
|
906
|
+
var errors = [];
|
|
907
|
+
|
|
908
|
+
// Validate required fields
|
|
909
|
+
document.querySelectorAll('[required]').forEach(function(field) {
|
|
910
|
+
if (!field.value.trim()) {
|
|
911
|
+
errors.push(field.previousElementSibling.textContent + ' is required');
|
|
912
|
+
isValid = false;
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
|
|
916
|
+
// Custom validations
|
|
917
|
+
${fields.filter(f => f.validation).map(field => `
|
|
918
|
+
if (!validate${field.name}()) {
|
|
919
|
+
errors.push('${field.validationMessage || 'Invalid ' + field.label}');
|
|
920
|
+
isValid = false;
|
|
921
|
+
}`).join('')}
|
|
922
|
+
|
|
923
|
+
if (!isValid) {
|
|
924
|
+
showErrors(errors);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
return isValid;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
function submitForm(data) {
|
|
931
|
+
// Show loading
|
|
932
|
+
showLoading();
|
|
933
|
+
|
|
934
|
+
// Make AJAX request
|
|
935
|
+
var xhr = new XMLHttpRequest();
|
|
936
|
+
xhr.open('POST', '/api/form/submit', true);
|
|
937
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
938
|
+
|
|
939
|
+
xhr.onload = function() {
|
|
940
|
+
hideLoading();
|
|
941
|
+
|
|
942
|
+
if (xhr.status === 200) {
|
|
943
|
+
var response = JSON.parse(xhr.responseText);
|
|
944
|
+
if (response.success) {
|
|
945
|
+
showSuccess('Form submitted successfully');
|
|
946
|
+
resetForm();
|
|
947
|
+
} else {
|
|
948
|
+
showError(response.error || 'Submission failed');
|
|
949
|
+
}
|
|
950
|
+
} else {
|
|
951
|
+
showError('Server error occurred');
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
xhr.send(JSON.stringify(data));
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
function resetForm() {
|
|
959
|
+
document.getElementById('custom-form').reset();
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
function lookupReference(fieldId) {
|
|
963
|
+
// Open reference lookup dialog
|
|
964
|
+
var field = document.getElementById(fieldId);
|
|
965
|
+
var table = field.getAttribute('data-reference');
|
|
966
|
+
|
|
967
|
+
// Implement reference lookup logic
|
|
968
|
+
console.log('Opening reference lookup for', table);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
function initializeReferenceField(fieldId, table) {
|
|
972
|
+
// Setup autocomplete for reference field
|
|
973
|
+
var field = document.getElementById(fieldId);
|
|
974
|
+
|
|
975
|
+
// Add autocomplete functionality
|
|
976
|
+
// This would integrate with ServiceNow's reference field behavior
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
function setupFieldDependencies() {
|
|
980
|
+
// Setup any field dependencies or conditional display logic
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
function showLoading() {
|
|
984
|
+
// Show loading indicator
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
function hideLoading() {
|
|
988
|
+
// Hide loading indicator
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
function showSuccess(message) {
|
|
992
|
+
alert('Success: ' + message);
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
function showError(message) {
|
|
996
|
+
alert('Error: ' + message);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
function showErrors(errors) {
|
|
1000
|
+
alert('Please fix the following errors:\\n\\n' + errors.join('\\n'));
|
|
1001
|
+
}`;
|
|
1002
|
+
}
|
|
1003
|
+
generateComponentCSS(component, theme) {
|
|
1004
|
+
const primaryColor = theme?.primaryColor || '#0078d4';
|
|
1005
|
+
const secondaryColor = theme?.secondaryColor || '#e0e0e0';
|
|
1006
|
+
return `.component-${this.sanitizeName(component.name)} {
|
|
1007
|
+
padding: 20px;
|
|
1008
|
+
background: ${theme?.background || '#fff'};
|
|
1009
|
+
border: 1px solid ${secondaryColor};
|
|
1010
|
+
border-radius: 4px;
|
|
1011
|
+
margin-bottom: 20px;
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
.component-${this.sanitizeName(component.name)} h3 {
|
|
1015
|
+
color: ${primaryColor};
|
|
1016
|
+
margin-bottom: 15px;
|
|
1017
|
+
}`;
|
|
1018
|
+
}
|
|
1019
|
+
generateComponentJS(component) {
|
|
1020
|
+
return `// Component: ${component.name}
|
|
1021
|
+
(function() {
|
|
1022
|
+
var component = {
|
|
1023
|
+
init: function() {
|
|
1024
|
+
console.log('Initializing ${component.name}');
|
|
1025
|
+
${component.initialization || '// Add initialization code'}
|
|
1026
|
+
},
|
|
1027
|
+
|
|
1028
|
+
refresh: function() {
|
|
1029
|
+
${component.refreshCode || '// Add refresh logic'}
|
|
1030
|
+
},
|
|
1031
|
+
|
|
1032
|
+
destroy: function() {
|
|
1033
|
+
${component.cleanupCode || '// Add cleanup code'}
|
|
1034
|
+
}
|
|
1035
|
+
};
|
|
1036
|
+
|
|
1037
|
+
// Auto-initialize if DOM is ready
|
|
1038
|
+
if (document.readyState === 'loading') {
|
|
1039
|
+
document.addEventListener('DOMContentLoaded', component.init);
|
|
1040
|
+
} else {
|
|
1041
|
+
component.init();
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// Export for external use
|
|
1045
|
+
window['${this.sanitizeName(component.name)}Component'] = component;
|
|
1046
|
+
})();`;
|
|
1047
|
+
}
|
|
1048
|
+
async generateDashboard(spec) {
|
|
1049
|
+
// Generate dashboard UI
|
|
1050
|
+
const dashboardHTML = this.generateDashboardHTML(spec);
|
|
1051
|
+
const dashboardCSS = this.generateDashboardCSS(spec);
|
|
1052
|
+
const dashboardJS = this.generateDashboardJS(spec);
|
|
1053
|
+
return {
|
|
1054
|
+
taskId: '',
|
|
1055
|
+
success: true,
|
|
1056
|
+
output: {
|
|
1057
|
+
html: dashboardHTML,
|
|
1058
|
+
css: dashboardCSS,
|
|
1059
|
+
javascript: dashboardJS
|
|
1060
|
+
},
|
|
1061
|
+
artifacts: [
|
|
1062
|
+
this.createArtifact('dashboard', spec.name, {
|
|
1063
|
+
html: dashboardHTML,
|
|
1064
|
+
css: dashboardCSS,
|
|
1065
|
+
javascript: dashboardJS
|
|
1066
|
+
})
|
|
1067
|
+
]
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
generateDashboardHTML(spec) {
|
|
1071
|
+
return `<div class="dashboard-container">
|
|
1072
|
+
<header class="dashboard-header">
|
|
1073
|
+
<h1>${spec.title || 'Dashboard'}</h1>
|
|
1074
|
+
<div class="dashboard-controls">
|
|
1075
|
+
<button onclick="refreshDashboard()">Refresh</button>
|
|
1076
|
+
</div>
|
|
1077
|
+
</header>
|
|
1078
|
+
|
|
1079
|
+
<div class="dashboard-grid">
|
|
1080
|
+
${spec.widgets?.map((widget) => `
|
|
1081
|
+
<div class="dashboard-widget ${widget.size || 'medium'}" id="widget-${widget.id}">
|
|
1082
|
+
${this.generateWidgetHTML(widget)}
|
|
1083
|
+
</div>
|
|
1084
|
+
`).join('') || ''}
|
|
1085
|
+
</div>
|
|
1086
|
+
</div>`;
|
|
1087
|
+
}
|
|
1088
|
+
generateWidgetHTML(widget) {
|
|
1089
|
+
switch (widget.type) {
|
|
1090
|
+
case 'metric':
|
|
1091
|
+
return `<div class="metric-widget">
|
|
1092
|
+
<h3>${widget.title}</h3>
|
|
1093
|
+
<div class="metric-value">${widget.value || '--'}</div>
|
|
1094
|
+
<div class="metric-change">${widget.change || ''}</div>
|
|
1095
|
+
</div>`;
|
|
1096
|
+
case 'chart':
|
|
1097
|
+
return `<div class="chart-widget">
|
|
1098
|
+
<h3>${widget.title}</h3>
|
|
1099
|
+
<canvas id="chart-${widget.id}"></canvas>
|
|
1100
|
+
</div>`;
|
|
1101
|
+
case 'list':
|
|
1102
|
+
return `<div class="list-widget">
|
|
1103
|
+
<h3>${widget.title}</h3>
|
|
1104
|
+
<ul class="widget-list">
|
|
1105
|
+
<!-- Items will be loaded dynamically -->
|
|
1106
|
+
</ul>
|
|
1107
|
+
</div>`;
|
|
1108
|
+
default:
|
|
1109
|
+
return `<div class="custom-widget">
|
|
1110
|
+
<h3>${widget.title}</h3>
|
|
1111
|
+
<div class="widget-content">
|
|
1112
|
+
<!-- Custom content -->
|
|
1113
|
+
</div>
|
|
1114
|
+
</div>`;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
generateDashboardCSS(spec) {
|
|
1118
|
+
return `.dashboard-container {
|
|
1119
|
+
padding: 20px;
|
|
1120
|
+
background: #f5f5f5;
|
|
1121
|
+
min-height: 100vh;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
.dashboard-header {
|
|
1125
|
+
display: flex;
|
|
1126
|
+
justify-content: space-between;
|
|
1127
|
+
align-items: center;
|
|
1128
|
+
margin-bottom: 30px;
|
|
1129
|
+
padding: 20px;
|
|
1130
|
+
background: white;
|
|
1131
|
+
border-radius: 8px;
|
|
1132
|
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
.dashboard-grid {
|
|
1136
|
+
display: grid;
|
|
1137
|
+
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
|
1138
|
+
gap: 20px;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
.dashboard-widget {
|
|
1142
|
+
background: white;
|
|
1143
|
+
padding: 20px;
|
|
1144
|
+
border-radius: 8px;
|
|
1145
|
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
.dashboard-widget.small {
|
|
1149
|
+
grid-column: span 1;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
.dashboard-widget.medium {
|
|
1153
|
+
grid-column: span 2;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
.dashboard-widget.large {
|
|
1157
|
+
grid-column: span 3;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
.metric-widget {
|
|
1161
|
+
text-align: center;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
.metric-value {
|
|
1165
|
+
font-size: 48px;
|
|
1166
|
+
font-weight: bold;
|
|
1167
|
+
color: #0078d4;
|
|
1168
|
+
margin: 20px 0;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
.metric-change {
|
|
1172
|
+
color: #666;
|
|
1173
|
+
font-size: 14px;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
.chart-widget canvas {
|
|
1177
|
+
max-width: 100%;
|
|
1178
|
+
height: 300px;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
.list-widget .widget-list {
|
|
1182
|
+
list-style: none;
|
|
1183
|
+
padding: 0;
|
|
1184
|
+
margin: 0;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
.list-widget .widget-list li {
|
|
1188
|
+
padding: 10px;
|
|
1189
|
+
border-bottom: 1px solid #e0e0e0;
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
.list-widget .widget-list li:last-child {
|
|
1193
|
+
border-bottom: none;
|
|
1194
|
+
}`;
|
|
1195
|
+
}
|
|
1196
|
+
generateDashboardJS(spec) {
|
|
1197
|
+
return `// Dashboard JavaScript
|
|
1198
|
+
var dashboard = {
|
|
1199
|
+
widgets: {},
|
|
1200
|
+
refreshInterval: ${spec.refreshInterval || 30000},
|
|
1201
|
+
|
|
1202
|
+
init: function() {
|
|
1203
|
+
console.log('Initializing dashboard');
|
|
1204
|
+
this.loadWidgets();
|
|
1205
|
+
this.startAutoRefresh();
|
|
1206
|
+
},
|
|
1207
|
+
|
|
1208
|
+
loadWidgets: function() {
|
|
1209
|
+
${spec.widgets?.map((widget) => `
|
|
1210
|
+
this.loadWidget('${widget.id}', ${JSON.stringify(widget)});`).join('')}
|
|
1211
|
+
},
|
|
1212
|
+
|
|
1213
|
+
loadWidget: function(widgetId, config) {
|
|
1214
|
+
console.log('Loading widget:', widgetId);
|
|
1215
|
+
|
|
1216
|
+
switch (config.type) {
|
|
1217
|
+
case 'metric':
|
|
1218
|
+
this.loadMetricWidget(widgetId, config);
|
|
1219
|
+
break;
|
|
1220
|
+
case 'chart':
|
|
1221
|
+
this.loadChartWidget(widgetId, config);
|
|
1222
|
+
break;
|
|
1223
|
+
case 'list':
|
|
1224
|
+
this.loadListWidget(widgetId, config);
|
|
1225
|
+
break;
|
|
1226
|
+
}
|
|
1227
|
+
},
|
|
1228
|
+
|
|
1229
|
+
loadMetricWidget: function(widgetId, config) {
|
|
1230
|
+
// Fetch metric data
|
|
1231
|
+
fetch('/api/metrics/' + config.metric)
|
|
1232
|
+
.then(response => response.json())
|
|
1233
|
+
.then(data => {
|
|
1234
|
+
var widget = document.getElementById('widget-' + widgetId);
|
|
1235
|
+
widget.querySelector('.metric-value').textContent = data.value;
|
|
1236
|
+
widget.querySelector('.metric-change').textContent = data.change;
|
|
1237
|
+
});
|
|
1238
|
+
},
|
|
1239
|
+
|
|
1240
|
+
loadChartWidget: function(widgetId, config) {
|
|
1241
|
+
// Initialize chart
|
|
1242
|
+
var ctx = document.getElementById('chart-' + widgetId).getContext('2d');
|
|
1243
|
+
// Chart.js initialization would go here
|
|
1244
|
+
},
|
|
1245
|
+
|
|
1246
|
+
loadListWidget: function(widgetId, config) {
|
|
1247
|
+
// Fetch list data
|
|
1248
|
+
fetch('/api/list/' + config.source)
|
|
1249
|
+
.then(response => response.json())
|
|
1250
|
+
.then(data => {
|
|
1251
|
+
var list = document.querySelector('#widget-' + widgetId + ' .widget-list');
|
|
1252
|
+
list.innerHTML = data.items.map(item =>
|
|
1253
|
+
'<li>' + item.display_value + '</li>'
|
|
1254
|
+
).join('');
|
|
1255
|
+
});
|
|
1256
|
+
},
|
|
1257
|
+
|
|
1258
|
+
refresh: function() {
|
|
1259
|
+
console.log('Refreshing dashboard');
|
|
1260
|
+
this.loadWidgets();
|
|
1261
|
+
},
|
|
1262
|
+
|
|
1263
|
+
startAutoRefresh: function() {
|
|
1264
|
+
var self = this;
|
|
1265
|
+
setInterval(function() {
|
|
1266
|
+
self.refresh();
|
|
1267
|
+
}, this.refreshInterval);
|
|
1268
|
+
}
|
|
1269
|
+
};
|
|
1270
|
+
|
|
1271
|
+
// Initialize on load
|
|
1272
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
1273
|
+
dashboard.init();
|
|
1274
|
+
});
|
|
1275
|
+
|
|
1276
|
+
function refreshDashboard() {
|
|
1277
|
+
dashboard.refresh();
|
|
1278
|
+
}`;
|
|
1279
|
+
}
|
|
1280
|
+
async generateForm(spec) {
|
|
1281
|
+
return this.createFormLayout({
|
|
1282
|
+
id: '',
|
|
1283
|
+
type: 'create_form_layout',
|
|
1284
|
+
description: 'Generate form from spec',
|
|
1285
|
+
payload: {
|
|
1286
|
+
formName: spec.name,
|
|
1287
|
+
sections: spec.sections || [{ id: 'main', title: 'Main Section' }],
|
|
1288
|
+
fields: spec.fields || [],
|
|
1289
|
+
responsive: spec.responsive !== false
|
|
1290
|
+
},
|
|
1291
|
+
priority: 'medium'
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
async generateReport(spec) {
|
|
1295
|
+
// Generate report UI
|
|
1296
|
+
const reportHTML = `<div class="report-container">
|
|
1297
|
+
<h1>${spec.title}</h1>
|
|
1298
|
+
<div class="report-filters">
|
|
1299
|
+
<!-- Filters will be added here -->
|
|
1300
|
+
</div>
|
|
1301
|
+
<div class="report-content">
|
|
1302
|
+
<!-- Report content will be loaded here -->
|
|
1303
|
+
</div>
|
|
1304
|
+
</div>`;
|
|
1305
|
+
return {
|
|
1306
|
+
taskId: '',
|
|
1307
|
+
success: true,
|
|
1308
|
+
output: { html: reportHTML },
|
|
1309
|
+
artifacts: [
|
|
1310
|
+
this.createArtifact('report', spec.name, { html: reportHTML })
|
|
1311
|
+
]
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
async generateWizard(spec) {
|
|
1315
|
+
// Generate wizard UI
|
|
1316
|
+
const wizardHTML = this.generateWizardHTML(spec);
|
|
1317
|
+
const wizardCSS = this.generateWizardCSS();
|
|
1318
|
+
const wizardJS = this.generateWizardJS(spec);
|
|
1319
|
+
return {
|
|
1320
|
+
taskId: '',
|
|
1321
|
+
success: true,
|
|
1322
|
+
output: {
|
|
1323
|
+
html: wizardHTML,
|
|
1324
|
+
css: wizardCSS,
|
|
1325
|
+
javascript: wizardJS
|
|
1326
|
+
},
|
|
1327
|
+
artifacts: [
|
|
1328
|
+
this.createArtifact('wizard', spec.name, {
|
|
1329
|
+
html: wizardHTML,
|
|
1330
|
+
css: wizardCSS,
|
|
1331
|
+
javascript: wizardJS
|
|
1332
|
+
})
|
|
1333
|
+
]
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
generateWizardHTML(spec) {
|
|
1337
|
+
return `<div class="wizard-container">
|
|
1338
|
+
<div class="wizard-progress">
|
|
1339
|
+
${spec.steps?.map((step, index) => `
|
|
1340
|
+
<div class="wizard-step ${index === 0 ? 'active' : ''}" data-step="${index}">
|
|
1341
|
+
<div class="step-number">${index + 1}</div>
|
|
1342
|
+
<div class="step-title">${step.title}</div>
|
|
1343
|
+
</div>
|
|
1344
|
+
`).join('') || ''}
|
|
1345
|
+
</div>
|
|
1346
|
+
|
|
1347
|
+
<div class="wizard-content">
|
|
1348
|
+
${spec.steps?.map((step, index) => `
|
|
1349
|
+
<div class="wizard-panel ${index === 0 ? 'active' : ''}" data-step="${index}">
|
|
1350
|
+
<h2>${step.title}</h2>
|
|
1351
|
+
${step.content || '<!-- Step content -->'}
|
|
1352
|
+
</div>
|
|
1353
|
+
`).join('') || ''}
|
|
1354
|
+
</div>
|
|
1355
|
+
|
|
1356
|
+
<div class="wizard-actions">
|
|
1357
|
+
<button class="btn btn-secondary" onclick="previousStep()" id="prevBtn" disabled>Previous</button>
|
|
1358
|
+
<button class="btn btn-primary" onclick="nextStep()" id="nextBtn">Next</button>
|
|
1359
|
+
<button class="btn btn-success" onclick="finishWizard()" id="finishBtn" style="display:none;">Finish</button>
|
|
1360
|
+
</div>
|
|
1361
|
+
</div>`;
|
|
1362
|
+
}
|
|
1363
|
+
generateWizardCSS() {
|
|
1364
|
+
return `.wizard-container {
|
|
1365
|
+
max-width: 800px;
|
|
1366
|
+
margin: 0 auto;
|
|
1367
|
+
padding: 20px;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
.wizard-progress {
|
|
1371
|
+
display: flex;
|
|
1372
|
+
justify-content: space-between;
|
|
1373
|
+
margin-bottom: 40px;
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
.wizard-step {
|
|
1377
|
+
text-align: center;
|
|
1378
|
+
flex: 1;
|
|
1379
|
+
position: relative;
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
.wizard-step:not(:last-child)::after {
|
|
1383
|
+
content: '';
|
|
1384
|
+
position: absolute;
|
|
1385
|
+
top: 20px;
|
|
1386
|
+
left: 50%;
|
|
1387
|
+
width: 100%;
|
|
1388
|
+
height: 2px;
|
|
1389
|
+
background: #e0e0e0;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
.wizard-step.active::after,
|
|
1393
|
+
.wizard-step.completed::after {
|
|
1394
|
+
background: #0078d4;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
.step-number {
|
|
1398
|
+
width: 40px;
|
|
1399
|
+
height: 40px;
|
|
1400
|
+
border-radius: 50%;
|
|
1401
|
+
background: #e0e0e0;
|
|
1402
|
+
color: #666;
|
|
1403
|
+
display: flex;
|
|
1404
|
+
align-items: center;
|
|
1405
|
+
justify-content: center;
|
|
1406
|
+
margin: 0 auto 10px;
|
|
1407
|
+
position: relative;
|
|
1408
|
+
z-index: 1;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
.wizard-step.active .step-number,
|
|
1412
|
+
.wizard-step.completed .step-number {
|
|
1413
|
+
background: #0078d4;
|
|
1414
|
+
color: white;
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
.wizard-panel {
|
|
1418
|
+
display: none;
|
|
1419
|
+
min-height: 300px;
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
.wizard-panel.active {
|
|
1423
|
+
display: block;
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
.wizard-actions {
|
|
1427
|
+
margin-top: 40px;
|
|
1428
|
+
text-align: center;
|
|
1429
|
+
}`;
|
|
1430
|
+
}
|
|
1431
|
+
generateWizardJS(spec) {
|
|
1432
|
+
return `// Wizard JavaScript
|
|
1433
|
+
var wizard = {
|
|
1434
|
+
currentStep: 0,
|
|
1435
|
+
totalSteps: ${spec.steps?.length || 0},
|
|
1436
|
+
|
|
1437
|
+
init: function() {
|
|
1438
|
+
this.updateButtons();
|
|
1439
|
+
},
|
|
1440
|
+
|
|
1441
|
+
nextStep: function() {
|
|
1442
|
+
if (this.validateStep(this.currentStep)) {
|
|
1443
|
+
this.currentStep++;
|
|
1444
|
+
this.showStep(this.currentStep);
|
|
1445
|
+
}
|
|
1446
|
+
},
|
|
1447
|
+
|
|
1448
|
+
previousStep: function() {
|
|
1449
|
+
this.currentStep--;
|
|
1450
|
+
this.showStep(this.currentStep);
|
|
1451
|
+
},
|
|
1452
|
+
|
|
1453
|
+
showStep: function(step) {
|
|
1454
|
+
// Hide all panels
|
|
1455
|
+
document.querySelectorAll('.wizard-panel').forEach(function(panel) {
|
|
1456
|
+
panel.classList.remove('active');
|
|
1457
|
+
});
|
|
1458
|
+
document.querySelectorAll('.wizard-step').forEach(function(stepEl) {
|
|
1459
|
+
stepEl.classList.remove('active');
|
|
1460
|
+
});
|
|
1461
|
+
|
|
1462
|
+
// Show current panel
|
|
1463
|
+
document.querySelector('.wizard-panel[data-step="' + step + '"]').classList.add('active');
|
|
1464
|
+
document.querySelector('.wizard-step[data-step="' + step + '"]').classList.add('active');
|
|
1465
|
+
|
|
1466
|
+
// Mark completed steps
|
|
1467
|
+
for (var i = 0; i < step; i++) {
|
|
1468
|
+
document.querySelector('.wizard-step[data-step="' + i + '"]').classList.add('completed');
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
this.updateButtons();
|
|
1472
|
+
},
|
|
1473
|
+
|
|
1474
|
+
updateButtons: function() {
|
|
1475
|
+
var prevBtn = document.getElementById('prevBtn');
|
|
1476
|
+
var nextBtn = document.getElementById('nextBtn');
|
|
1477
|
+
var finishBtn = document.getElementById('finishBtn');
|
|
1478
|
+
|
|
1479
|
+
prevBtn.disabled = this.currentStep === 0;
|
|
1480
|
+
|
|
1481
|
+
if (this.currentStep === this.totalSteps - 1) {
|
|
1482
|
+
nextBtn.style.display = 'none';
|
|
1483
|
+
finishBtn.style.display = 'inline-block';
|
|
1484
|
+
} else {
|
|
1485
|
+
nextBtn.style.display = 'inline-block';
|
|
1486
|
+
finishBtn.style.display = 'none';
|
|
1487
|
+
}
|
|
1488
|
+
},
|
|
1489
|
+
|
|
1490
|
+
validateStep: function(step) {
|
|
1491
|
+
// Add validation logic for each step
|
|
1492
|
+
return true;
|
|
1493
|
+
},
|
|
1494
|
+
|
|
1495
|
+
finish: function() {
|
|
1496
|
+
if (this.validateStep(this.currentStep)) {
|
|
1497
|
+
// Collect all data and submit
|
|
1498
|
+
console.log('Wizard completed');
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
};
|
|
1502
|
+
|
|
1503
|
+
// Global functions
|
|
1504
|
+
function nextStep() {
|
|
1505
|
+
wizard.nextStep();
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
function previousStep() {
|
|
1509
|
+
wizard.previousStep();
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
function finishWizard() {
|
|
1513
|
+
wizard.finish();
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
// Initialize
|
|
1517
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
1518
|
+
wizard.init();
|
|
1519
|
+
});`;
|
|
1520
|
+
}
|
|
1521
|
+
async generateGenericUI(spec) {
|
|
1522
|
+
// Generate generic UI based on spec
|
|
1523
|
+
return {
|
|
1524
|
+
taskId: '',
|
|
1525
|
+
success: true,
|
|
1526
|
+
output: {
|
|
1527
|
+
html: '<div>Generic UI Component</div>'
|
|
1528
|
+
},
|
|
1529
|
+
artifacts: [
|
|
1530
|
+
this.createArtifact('ui_component', spec.name, spec)
|
|
1531
|
+
]
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
sanitizeName(name) {
|
|
1535
|
+
return name.toLowerCase().replace(/[^a-z0-9]/g, '_');
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
exports.UIBuilderAgent = UIBuilderAgent;
|
|
1539
|
+
//# sourceMappingURL=ui-builder.agent.js.map
|