-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
147 lines (133 loc) · 4.96 KB
/
App.tsx
File metadata and controls
147 lines (133 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import React, { useState, useEffect, useCallback } from 'react';
import { FrameworkConfig, GeneratedContent } from './types';
import { FRAMEWORK_MAPPINGS } from './constants';
import { generatePrompts } from './services/geminiService';
import ConfigurationPanel from './components/ConfigurationPanel';
import PreviewPanel from './components/PreviewPanel';
const App: React.FC = () => {
const [config, setConfig] = useState<FrameworkConfig>({
name: 'Sublayer',
domainContext: 'automation',
paradigm: 'agent-based automation',
language: 'Ruby',
componentTypes: 'triggers, commands, actions, tools, agents, generators',
baseClasses: 'Sublayer::Triggers::Base',
frameworkDsl: 'trigger, goal_condition, check_status, step',
integrationPatterns: 'trigger-agent-action coordination',
});
const [workflowDescription, setWorkflowDescription] = useState<string>('');
const [generatedContent, setGeneratedContent] = useState<GeneratedContent | null>(null);
const [isLoading, setIsLoading] = useState<boolean>(false);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const mapping = FRAMEWORK_MAPPINGS[config.name];
if (mapping) {
setConfig(prev => ({
name: prev.name,
...mapping,
}));
}
}, [config.name]);
const handleGenerate = useCallback(async () => {
if (!workflowDescription.trim()) {
setError("Please provide a workflow description.");
return;
}
setIsLoading(true);
setError(null);
setGeneratedContent(null);
try {
const content = await generatePrompts(config, workflowDescription);
setGeneratedContent(content);
} catch (e) {
if (e instanceof Error) {
setError(e.message);
} else {
setError("An unknown error occurred.");
}
} finally {
setIsLoading(false);
}
}, [config, workflowDescription]);
const handleExport = useCallback((format: 'json' | 'md') => {
if (!generatedContent) return;
let fileContent = '';
let fileExtension = format;
let mimeType = 'text/plain';
const fileName = `sfl-component-prompt-output-${Date.now()}`;
if (format === 'json') {
fileContent = JSON.stringify({ config, generatedContent }, null, 2);
mimeType = 'application/json';
} else if (format === 'md') {
const mdParts: string[] = [];
mdParts.push(`# Generated Prompts for ${config.name}`);
mdParts.push(`\n---\n`);
mdParts.push(`## Configuration`);
mdParts.push(`\`\`\`json`);
mdParts.push(JSON.stringify(config, null, 2));
mdParts.push(`\`\`\`\n`);
mdParts.push(`## Component Prompts`);
generatedContent.componentPrompts.forEach(p => {
mdParts.push(`### ${p.componentName}`);
mdParts.push('**Prompt:**');
mdParts.push('```markdown');
mdParts.push(p.prompt);
mdParts.push('```');
mdParts.push('**Usage Example:**');
mdParts.push(`\`\`\`${config.language.toLowerCase()}`);
mdParts.push(p.usageExample);
mdParts.push('```');
mdParts.push('**Integration Example:**');
mdParts.push(`\`\`\`${config.language.toLowerCase()}`);
mdParts.push(p.integrationExample);
mdParts.push('```');
});
mdParts.push(`\n---\n`);
mdParts.push(`## Integration Guidance`);
mdParts.push(generatedContent.integrationGuidance.overview);
mdParts.push(`\n---\n`);
mdParts.push(`## SFL Specification`);
mdParts.push(`### Field`);
mdParts.push(generatedContent.sflSpecification.field);
mdParts.push(`### Tenor`);
mdParts.push(generatedContent.sflSpecification.tenor);
mdParts.push(`### Mode`);
mdParts.push(generatedContent.sflSpecification.mode);
fileContent = mdParts.join('\n\n');
mimeType = 'text/markdown';
}
const blob = new Blob([fileContent], { type: mimeType });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${fileName}.${fileExtension}`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}, [generatedContent, config]);
return (
<div className="flex h-screen bg-[#212934] text-gray-200 font-sans">
<div className="w-1/2 lg:w-2/5 border-r border-[#5c6f7e] flex flex-col">
<ConfigurationPanel
config={config}
setConfig={setConfig}
workflowDescription={workflowDescription}
setWorkflowDescription={setWorkflowDescription}
onGenerate={handleGenerate}
isLoading={isLoading}
/>
</div>
<div className="w-1/2 lg:w-3/5">
<PreviewPanel
content={generatedContent}
isLoading={isLoading}
error={error}
onExport={handleExport}
config={config}
/>
</div>
</div>
);
};
export default App;