@marktoflow/gui 2.0.0-alpha.1
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/.turbo/turbo-build.log +26 -0
- package/.turbo/turbo-test.log +22 -0
- package/README.md +179 -0
- package/dist/client/assets/index-DwTI8opO.js +608 -0
- package/dist/client/assets/index-DwTI8opO.js.map +1 -0
- package/dist/client/assets/index-RoEdL6gO.css +1 -0
- package/dist/client/index.html +20 -0
- package/dist/client/vite.svg +9 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +56 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/routes/ai.js +50 -0
- package/dist/server/routes/ai.js.map +1 -0
- package/dist/server/routes/execute.js +62 -0
- package/dist/server/routes/execute.js.map +1 -0
- package/dist/server/routes/workflows.js +99 -0
- package/dist/server/routes/workflows.js.map +1 -0
- package/dist/server/server/index.js +95 -0
- package/dist/server/server/index.js.map +1 -0
- package/dist/server/server/routes/ai.js +87 -0
- package/dist/server/server/routes/ai.js.map +1 -0
- package/dist/server/server/routes/execute.js +63 -0
- package/dist/server/server/routes/execute.js.map +1 -0
- package/dist/server/server/routes/tools.js +518 -0
- package/dist/server/server/routes/tools.js.map +1 -0
- package/dist/server/server/routes/workflows.js +99 -0
- package/dist/server/server/routes/workflows.js.map +1 -0
- package/dist/server/server/services/AIService.js +69 -0
- package/dist/server/server/services/AIService.js.map +1 -0
- package/dist/server/server/services/FileWatcher.js +60 -0
- package/dist/server/server/services/FileWatcher.js.map +1 -0
- package/dist/server/server/services/WorkflowService.js +363 -0
- package/dist/server/server/services/WorkflowService.js.map +1 -0
- package/dist/server/server/services/agents/claude-code-provider.js +250 -0
- package/dist/server/server/services/agents/claude-code-provider.js.map +1 -0
- package/dist/server/server/services/agents/claude-provider.js +204 -0
- package/dist/server/server/services/agents/claude-provider.js.map +1 -0
- package/dist/server/server/services/agents/copilot-provider.js +227 -0
- package/dist/server/server/services/agents/copilot-provider.js.map +1 -0
- package/dist/server/server/services/agents/demo-provider.js +167 -0
- package/dist/server/server/services/agents/demo-provider.js.map +1 -0
- package/dist/server/server/services/agents/index.js +31 -0
- package/dist/server/server/services/agents/index.js.map +1 -0
- package/dist/server/server/services/agents/ollama-provider.js +220 -0
- package/dist/server/server/services/agents/ollama-provider.js.map +1 -0
- package/dist/server/server/services/agents/prompts.js +436 -0
- package/dist/server/server/services/agents/prompts.js.map +1 -0
- package/dist/server/server/services/agents/registry.js +242 -0
- package/dist/server/server/services/agents/registry.js.map +1 -0
- package/dist/server/server/services/agents/types.js +6 -0
- package/dist/server/server/services/agents/types.js.map +1 -0
- package/dist/server/server/websocket/index.js +85 -0
- package/dist/server/server/websocket/index.js.map +1 -0
- package/dist/server/services/AIService.d.ts +30 -0
- package/dist/server/services/AIService.d.ts.map +1 -0
- package/dist/server/services/AIService.js +216 -0
- package/dist/server/services/AIService.js.map +1 -0
- package/dist/server/services/FileWatcher.d.ts +10 -0
- package/dist/server/services/FileWatcher.d.ts.map +1 -0
- package/dist/server/services/FileWatcher.js +62 -0
- package/dist/server/services/FileWatcher.js.map +1 -0
- package/dist/server/services/WorkflowService.d.ts +54 -0
- package/dist/server/services/WorkflowService.d.ts.map +1 -0
- package/dist/server/services/WorkflowService.js +323 -0
- package/dist/server/services/WorkflowService.js.map +1 -0
- package/dist/server/shared/constants.js +175 -0
- package/dist/server/shared/constants.js.map +1 -0
- package/dist/server/shared/types.js +3 -0
- package/dist/server/shared/types.js.map +1 -0
- package/dist/server/websocket/index.d.ts +10 -0
- package/dist/server/websocket/index.d.ts.map +1 -0
- package/dist/server/websocket/index.js +85 -0
- package/dist/server/websocket/index.js.map +1 -0
- package/index.html +19 -0
- package/package.json +96 -0
- package/playwright.config.ts +27 -0
- package/postcss.config.js +6 -0
- package/public/vite.svg +9 -0
- package/src/client/App.tsx +520 -0
- package/src/client/components/Canvas/Canvas.tsx +405 -0
- package/src/client/components/Canvas/ExecutionOverlay.tsx +847 -0
- package/src/client/components/Canvas/NodeContextMenu.tsx +188 -0
- package/src/client/components/Canvas/OutputNode.tsx +111 -0
- package/src/client/components/Canvas/StepNode.tsx +106 -0
- package/src/client/components/Canvas/SubWorkflowNode.tsx +141 -0
- package/src/client/components/Canvas/Toolbar.tsx +189 -0
- package/src/client/components/Canvas/TriggerNode.tsx +128 -0
- package/src/client/components/Editor/InputsEditor.tsx +458 -0
- package/src/client/components/Editor/NewStepWizard.tsx +344 -0
- package/src/client/components/Editor/StepEditor.tsx +532 -0
- package/src/client/components/Editor/YamlEditor.tsx +160 -0
- package/src/client/components/Panels/PropertiesPanel.tsx +589 -0
- package/src/client/components/Prompt/ChangePreview.tsx +281 -0
- package/src/client/components/Prompt/PromptHistoryPanel.tsx +209 -0
- package/src/client/components/Prompt/PromptInput.tsx +108 -0
- package/src/client/components/Sidebar/Sidebar.tsx +343 -0
- package/src/client/components/common/Breadcrumb.tsx +40 -0
- package/src/client/components/common/Button.tsx +68 -0
- package/src/client/components/common/ContextMenu.tsx +202 -0
- package/src/client/components/common/KeyboardShortcuts.tsx +143 -0
- package/src/client/components/common/Modal.tsx +93 -0
- package/src/client/components/common/Tabs.tsx +57 -0
- package/src/client/components/common/ThemeToggle.tsx +63 -0
- package/src/client/components/index.ts +32 -0
- package/src/client/hooks/index.ts +4 -0
- package/src/client/hooks/useAIPrompt.ts +108 -0
- package/src/client/hooks/useCanvas.ts +247 -0
- package/src/client/hooks/useWebSocket.ts +164 -0
- package/src/client/hooks/useWorkflow.ts +138 -0
- package/src/client/main.tsx +10 -0
- package/src/client/stores/canvasStore.ts +348 -0
- package/src/client/stores/editorStore.ts +133 -0
- package/src/client/stores/executionStore.ts +440 -0
- package/src/client/stores/index.ts +4 -0
- package/src/client/stores/layoutStore.ts +103 -0
- package/src/client/stores/navigationStore.ts +49 -0
- package/src/client/stores/promptStore.ts +113 -0
- package/src/client/stores/themeStore.ts +75 -0
- package/src/client/stores/workflowStore.ts +177 -0
- package/src/client/styles/globals.css +346 -0
- package/src/client/utils/cn.ts +9 -0
- package/src/client/utils/index.ts +4 -0
- package/src/client/utils/serviceIcons.tsx +64 -0
- package/src/client/utils/stepValidation.ts +155 -0
- package/src/client/utils/workflowToGraph.ts +299 -0
- package/src/server/index.ts +114 -0
- package/src/server/routes/ai.ts +91 -0
- package/src/server/routes/execute.ts +71 -0
- package/src/server/routes/tools.ts +564 -0
- package/src/server/routes/workflows.ts +106 -0
- package/src/server/services/AIService.ts +105 -0
- package/src/server/services/FileWatcher.ts +69 -0
- package/src/server/services/WorkflowService.ts +441 -0
- package/src/server/services/agents/claude-code-provider.ts +320 -0
- package/src/server/services/agents/claude-provider.ts +248 -0
- package/src/server/services/agents/copilot-provider.ts +311 -0
- package/src/server/services/agents/demo-provider.ts +184 -0
- package/src/server/services/agents/index.ts +31 -0
- package/src/server/services/agents/ollama-provider.ts +267 -0
- package/src/server/services/agents/prompts.ts +482 -0
- package/src/server/services/agents/registry.ts +289 -0
- package/src/server/services/agents/types.ts +146 -0
- package/src/server/websocket/index.ts +104 -0
- package/src/shared/constants.ts +180 -0
- package/src/shared/types.ts +179 -0
- package/tailwind.config.ts +73 -0
- package/tests/e2e/app.spec.ts +90 -0
- package/tests/e2e/canvas.spec.ts +128 -0
- package/tests/e2e/workflow.spec.ts +185 -0
- package/tests/integration/api.test.ts +250 -0
- package/tests/integration/testApp.ts +31 -0
- package/tests/setup.ts +37 -0
- package/tests/unit/canvasStore.test.ts +502 -0
- package/tests/unit/components.test.tsx +151 -0
- package/tests/unit/executionStore.test.ts +527 -0
- package/tests/unit/layoutStore.test.ts +194 -0
- package/tests/unit/navigationStore.test.ts +152 -0
- package/tests/unit/stepValidation.test.ts +226 -0
- package/tests/unit/themeStore.test.ts +141 -0
- package/tests/unit/workflowToGraph.test.ts +289 -0
- package/tsconfig.json +29 -0
- package/tsconfig.server.json +28 -0
- package/vite.config.ts +31 -0
- package/vitest.config.ts +26 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { Modal, ModalFooter } from '../common/Modal';
|
|
3
|
+
import { Button } from '../common/Button';
|
|
4
|
+
import { Tabs, TabsList, TabsTrigger, TabsContent } from '../common/Tabs';
|
|
5
|
+
import Editor from '@monaco-editor/react';
|
|
6
|
+
import { stringify } from 'yaml';
|
|
7
|
+
import { Check, X, Eye, Code, GitCompare } from 'lucide-react';
|
|
8
|
+
import type { Workflow } from '@shared/types';
|
|
9
|
+
|
|
10
|
+
interface ChangePreviewProps {
|
|
11
|
+
open: boolean;
|
|
12
|
+
onOpenChange: (open: boolean) => void;
|
|
13
|
+
originalWorkflow: Workflow | null;
|
|
14
|
+
modifiedWorkflow: Workflow | null;
|
|
15
|
+
explanation: string;
|
|
16
|
+
onAccept: () => void;
|
|
17
|
+
onReject: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function ChangePreview({
|
|
21
|
+
open,
|
|
22
|
+
onOpenChange,
|
|
23
|
+
originalWorkflow,
|
|
24
|
+
modifiedWorkflow,
|
|
25
|
+
explanation,
|
|
26
|
+
onAccept,
|
|
27
|
+
onReject,
|
|
28
|
+
}: ChangePreviewProps) {
|
|
29
|
+
const [activeTab, setActiveTab] = useState('explanation');
|
|
30
|
+
|
|
31
|
+
const originalYaml = originalWorkflow
|
|
32
|
+
? stringify(originalWorkflow, { indent: 2 })
|
|
33
|
+
: '';
|
|
34
|
+
const modifiedYaml = modifiedWorkflow
|
|
35
|
+
? stringify(modifiedWorkflow, { indent: 2 })
|
|
36
|
+
: '';
|
|
37
|
+
|
|
38
|
+
const handleAccept = () => {
|
|
39
|
+
onAccept();
|
|
40
|
+
onOpenChange(false);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const handleReject = () => {
|
|
44
|
+
onReject();
|
|
45
|
+
onOpenChange(false);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Modal
|
|
50
|
+
open={open}
|
|
51
|
+
onOpenChange={onOpenChange}
|
|
52
|
+
title="Review Changes"
|
|
53
|
+
description="The AI has suggested the following changes to your workflow"
|
|
54
|
+
size="xl"
|
|
55
|
+
>
|
|
56
|
+
<Tabs value={activeTab} onValueChange={setActiveTab}>
|
|
57
|
+
<TabsList>
|
|
58
|
+
<TabsTrigger value="explanation">
|
|
59
|
+
<Eye className="w-4 h-4 mr-1.5" />
|
|
60
|
+
Explanation
|
|
61
|
+
</TabsTrigger>
|
|
62
|
+
<TabsTrigger value="diff">
|
|
63
|
+
<GitCompare className="w-4 h-4 mr-1.5" />
|
|
64
|
+
Side by Side
|
|
65
|
+
</TabsTrigger>
|
|
66
|
+
<TabsTrigger value="modified">
|
|
67
|
+
<Code className="w-4 h-4 mr-1.5" />
|
|
68
|
+
Modified YAML
|
|
69
|
+
</TabsTrigger>
|
|
70
|
+
</TabsList>
|
|
71
|
+
|
|
72
|
+
<div className="p-4">
|
|
73
|
+
<TabsContent value="explanation">
|
|
74
|
+
<div className="prose prose-invert max-w-none">
|
|
75
|
+
<div className="p-4 bg-node-bg rounded-lg border border-node-border">
|
|
76
|
+
<p className="text-gray-300 whitespace-pre-wrap">{explanation}</p>
|
|
77
|
+
</div>
|
|
78
|
+
|
|
79
|
+
{modifiedWorkflow && (
|
|
80
|
+
<div className="mt-4">
|
|
81
|
+
<h4 className="text-sm font-medium text-gray-400 mb-2">
|
|
82
|
+
Changes Summary
|
|
83
|
+
</h4>
|
|
84
|
+
<ul className="space-y-2">
|
|
85
|
+
{getChangesSummary(originalWorkflow, modifiedWorkflow).map(
|
|
86
|
+
(change, index) => (
|
|
87
|
+
<li
|
|
88
|
+
key={index}
|
|
89
|
+
className={`flex items-start gap-2 text-sm ${
|
|
90
|
+
change.type === 'added'
|
|
91
|
+
? 'text-success'
|
|
92
|
+
: change.type === 'removed'
|
|
93
|
+
? 'text-error'
|
|
94
|
+
: 'text-warning'
|
|
95
|
+
}`}
|
|
96
|
+
>
|
|
97
|
+
<span className="flex-shrink-0">
|
|
98
|
+
{change.type === 'added'
|
|
99
|
+
? '+'
|
|
100
|
+
: change.type === 'removed'
|
|
101
|
+
? '-'
|
|
102
|
+
: '~'}
|
|
103
|
+
</span>
|
|
104
|
+
<span>{change.description}</span>
|
|
105
|
+
</li>
|
|
106
|
+
)
|
|
107
|
+
)}
|
|
108
|
+
</ul>
|
|
109
|
+
</div>
|
|
110
|
+
)}
|
|
111
|
+
</div>
|
|
112
|
+
</TabsContent>
|
|
113
|
+
|
|
114
|
+
<TabsContent value="diff">
|
|
115
|
+
<div className="grid grid-cols-2 gap-4">
|
|
116
|
+
<div>
|
|
117
|
+
<h4 className="text-sm font-medium text-gray-400 mb-2">
|
|
118
|
+
Original
|
|
119
|
+
</h4>
|
|
120
|
+
<div className="border border-node-border rounded-lg overflow-hidden">
|
|
121
|
+
<Editor
|
|
122
|
+
height="400px"
|
|
123
|
+
language="yaml"
|
|
124
|
+
value={originalYaml}
|
|
125
|
+
theme="vs-dark"
|
|
126
|
+
options={{
|
|
127
|
+
readOnly: true,
|
|
128
|
+
minimap: { enabled: false },
|
|
129
|
+
fontSize: 12,
|
|
130
|
+
lineNumbers: 'on',
|
|
131
|
+
scrollBeyondLastLine: false,
|
|
132
|
+
}}
|
|
133
|
+
/>
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
<div>
|
|
137
|
+
<h4 className="text-sm font-medium text-gray-400 mb-2">
|
|
138
|
+
Modified
|
|
139
|
+
</h4>
|
|
140
|
+
<div className="border border-node-border rounded-lg overflow-hidden">
|
|
141
|
+
<Editor
|
|
142
|
+
height="400px"
|
|
143
|
+
language="yaml"
|
|
144
|
+
value={modifiedYaml}
|
|
145
|
+
theme="vs-dark"
|
|
146
|
+
options={{
|
|
147
|
+
readOnly: true,
|
|
148
|
+
minimap: { enabled: false },
|
|
149
|
+
fontSize: 12,
|
|
150
|
+
lineNumbers: 'on',
|
|
151
|
+
scrollBeyondLastLine: false,
|
|
152
|
+
}}
|
|
153
|
+
/>
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
</div>
|
|
157
|
+
</TabsContent>
|
|
158
|
+
|
|
159
|
+
<TabsContent value="modified">
|
|
160
|
+
<div className="border border-node-border rounded-lg overflow-hidden">
|
|
161
|
+
<Editor
|
|
162
|
+
height="500px"
|
|
163
|
+
language="yaml"
|
|
164
|
+
value={modifiedYaml}
|
|
165
|
+
theme="vs-dark"
|
|
166
|
+
options={{
|
|
167
|
+
readOnly: true,
|
|
168
|
+
minimap: { enabled: false },
|
|
169
|
+
fontSize: 13,
|
|
170
|
+
fontFamily: 'JetBrains Mono, Consolas, monospace',
|
|
171
|
+
lineNumbers: 'on',
|
|
172
|
+
scrollBeyondLastLine: false,
|
|
173
|
+
}}
|
|
174
|
+
/>
|
|
175
|
+
</div>
|
|
176
|
+
</TabsContent>
|
|
177
|
+
</div>
|
|
178
|
+
</Tabs>
|
|
179
|
+
|
|
180
|
+
<ModalFooter>
|
|
181
|
+
<Button
|
|
182
|
+
variant="secondary"
|
|
183
|
+
onClick={handleReject}
|
|
184
|
+
icon={<X className="w-4 h-4" />}
|
|
185
|
+
>
|
|
186
|
+
Reject
|
|
187
|
+
</Button>
|
|
188
|
+
<Button onClick={handleAccept} icon={<Check className="w-4 h-4" />}>
|
|
189
|
+
Accept Changes
|
|
190
|
+
</Button>
|
|
191
|
+
</ModalFooter>
|
|
192
|
+
</Modal>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
interface Change {
|
|
197
|
+
type: 'added' | 'removed' | 'modified';
|
|
198
|
+
description: string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function getChangesSummary(
|
|
202
|
+
original: Workflow | null,
|
|
203
|
+
modified: Workflow | null
|
|
204
|
+
): Change[] {
|
|
205
|
+
const changes: Change[] = [];
|
|
206
|
+
|
|
207
|
+
if (!original || !modified) return changes;
|
|
208
|
+
|
|
209
|
+
// Check steps
|
|
210
|
+
const originalStepIds = new Set(original.steps.map((s) => s.id));
|
|
211
|
+
const modifiedStepIds = new Set(modified.steps.map((s) => s.id));
|
|
212
|
+
|
|
213
|
+
// Added steps
|
|
214
|
+
for (const step of modified.steps) {
|
|
215
|
+
if (!originalStepIds.has(step.id)) {
|
|
216
|
+
changes.push({
|
|
217
|
+
type: 'added',
|
|
218
|
+
description: `Added step "${step.name || step.id}"`,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Removed steps
|
|
224
|
+
for (const step of original.steps) {
|
|
225
|
+
if (!modifiedStepIds.has(step.id)) {
|
|
226
|
+
changes.push({
|
|
227
|
+
type: 'removed',
|
|
228
|
+
description: `Removed step "${step.name || step.id}"`,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Modified steps
|
|
234
|
+
for (const modStep of modified.steps) {
|
|
235
|
+
if (originalStepIds.has(modStep.id)) {
|
|
236
|
+
const origStep = original.steps.find((s) => s.id === modStep.id);
|
|
237
|
+
if (origStep) {
|
|
238
|
+
// Check for modifications
|
|
239
|
+
if (JSON.stringify(origStep) !== JSON.stringify(modStep)) {
|
|
240
|
+
const modifications: string[] = [];
|
|
241
|
+
|
|
242
|
+
if (origStep.action !== modStep.action) {
|
|
243
|
+
modifications.push('action');
|
|
244
|
+
}
|
|
245
|
+
if (JSON.stringify(origStep.inputs) !== JSON.stringify(modStep.inputs)) {
|
|
246
|
+
modifications.push('inputs');
|
|
247
|
+
}
|
|
248
|
+
if (
|
|
249
|
+
JSON.stringify(origStep.errorHandling) !==
|
|
250
|
+
JSON.stringify(modStep.errorHandling)
|
|
251
|
+
) {
|
|
252
|
+
modifications.push('error handling');
|
|
253
|
+
}
|
|
254
|
+
if (
|
|
255
|
+
JSON.stringify(origStep.conditions) !==
|
|
256
|
+
JSON.stringify(modStep.conditions)
|
|
257
|
+
) {
|
|
258
|
+
modifications.push('conditions');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (modifications.length > 0) {
|
|
262
|
+
changes.push({
|
|
263
|
+
type: 'modified',
|
|
264
|
+
description: `Modified "${modStep.name || modStep.id}": ${modifications.join(', ')}`,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Check metadata changes
|
|
273
|
+
if (original.metadata.name !== modified.metadata.name) {
|
|
274
|
+
changes.push({
|
|
275
|
+
type: 'modified',
|
|
276
|
+
description: `Renamed workflow to "${modified.metadata.name}"`,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return changes;
|
|
281
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
History,
|
|
4
|
+
ChevronDown,
|
|
5
|
+
ChevronUp,
|
|
6
|
+
CheckCircle,
|
|
7
|
+
XCircle,
|
|
8
|
+
RefreshCw,
|
|
9
|
+
Trash2,
|
|
10
|
+
Clock,
|
|
11
|
+
Copy,
|
|
12
|
+
Check,
|
|
13
|
+
X,
|
|
14
|
+
} from 'lucide-react';
|
|
15
|
+
import { usePromptStore, type PromptHistoryItem } from '../../stores/promptStore';
|
|
16
|
+
import { Button } from '../common/Button';
|
|
17
|
+
|
|
18
|
+
interface PromptHistoryPanelProps {
|
|
19
|
+
onSelectPrompt?: (prompt: string) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function PromptHistoryPanel({ onSelectPrompt }: PromptHistoryPanelProps) {
|
|
23
|
+
const [isExpanded, setIsExpanded] = useState(false);
|
|
24
|
+
const [selectedItem, setSelectedItem] = useState<PromptHistoryItem | null>(null);
|
|
25
|
+
const [copiedId, setCopiedId] = useState<string | null>(null);
|
|
26
|
+
|
|
27
|
+
const { history, clearHistory, sendPrompt, isProcessing } = usePromptStore();
|
|
28
|
+
|
|
29
|
+
const handleRerun = async (prompt: string) => {
|
|
30
|
+
if (isProcessing) return;
|
|
31
|
+
await sendPrompt(prompt);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const handleCopy = async (text: string, id: string) => {
|
|
35
|
+
try {
|
|
36
|
+
await navigator.clipboard.writeText(text);
|
|
37
|
+
setCopiedId(id);
|
|
38
|
+
setTimeout(() => setCopiedId(null), 2000);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error('Failed to copy:', error);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const formatTime = (date: Date) => {
|
|
45
|
+
const now = new Date();
|
|
46
|
+
const diff = now.getTime() - new Date(date).getTime();
|
|
47
|
+
|
|
48
|
+
if (diff < 60000) return 'Just now';
|
|
49
|
+
if (diff < 3600000) return `${Math.floor(diff / 60000)}m ago`;
|
|
50
|
+
if (diff < 86400000) return `${Math.floor(diff / 3600000)}h ago`;
|
|
51
|
+
return new Date(date).toLocaleDateString();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
if (history.length === 0) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div className="border-t border-node-border">
|
|
60
|
+
{/* Header - always visible */}
|
|
61
|
+
<button
|
|
62
|
+
onClick={() => setIsExpanded(!isExpanded)}
|
|
63
|
+
className="w-full flex items-center justify-between px-4 py-2 bg-panel-bg hover:bg-white/5 transition-colors"
|
|
64
|
+
>
|
|
65
|
+
<div className="flex items-center gap-2">
|
|
66
|
+
<History className="w-4 h-4 text-gray-400" />
|
|
67
|
+
<span className="text-sm text-gray-300">Prompt History</span>
|
|
68
|
+
<span className="text-xs text-gray-500">({history.length})</span>
|
|
69
|
+
</div>
|
|
70
|
+
{isExpanded ? (
|
|
71
|
+
<ChevronDown className="w-4 h-4 text-gray-400" />
|
|
72
|
+
) : (
|
|
73
|
+
<ChevronUp className="w-4 h-4 text-gray-400" />
|
|
74
|
+
)}
|
|
75
|
+
</button>
|
|
76
|
+
|
|
77
|
+
{/* Expanded content */}
|
|
78
|
+
{isExpanded && (
|
|
79
|
+
<div className="bg-panel-bg">
|
|
80
|
+
{/* Action bar */}
|
|
81
|
+
<div className="flex items-center justify-between px-4 py-2 border-b border-node-border">
|
|
82
|
+
<span className="text-xs text-gray-500">
|
|
83
|
+
{history.filter((h) => h.success).length} successful,{' '}
|
|
84
|
+
{history.filter((h) => !h.success).length} failed
|
|
85
|
+
</span>
|
|
86
|
+
<Button
|
|
87
|
+
variant="ghost"
|
|
88
|
+
size="sm"
|
|
89
|
+
onClick={clearHistory}
|
|
90
|
+
icon={<Trash2 className="w-3 h-3" />}
|
|
91
|
+
>
|
|
92
|
+
Clear
|
|
93
|
+
</Button>
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
{/* History list */}
|
|
97
|
+
<div className="max-h-64 overflow-y-auto">
|
|
98
|
+
{history.map((item, index) => {
|
|
99
|
+
const itemId = `${index}-${item.timestamp}`;
|
|
100
|
+
const isSelected = selectedItem === item;
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<div
|
|
104
|
+
key={itemId}
|
|
105
|
+
className="border-b border-node-border last:border-b-0"
|
|
106
|
+
>
|
|
107
|
+
{/* Item header */}
|
|
108
|
+
<div
|
|
109
|
+
className={`flex items-start gap-3 px-4 py-3 cursor-pointer transition-colors ${
|
|
110
|
+
isSelected ? 'bg-primary/10' : 'hover:bg-white/5'
|
|
111
|
+
}`}
|
|
112
|
+
onClick={() => setSelectedItem(isSelected ? null : item)}
|
|
113
|
+
>
|
|
114
|
+
{/* Status icon */}
|
|
115
|
+
{item.success ? (
|
|
116
|
+
<CheckCircle className="w-4 h-4 text-success flex-shrink-0 mt-0.5" />
|
|
117
|
+
) : (
|
|
118
|
+
<XCircle className="w-4 h-4 text-error flex-shrink-0 mt-0.5" />
|
|
119
|
+
)}
|
|
120
|
+
|
|
121
|
+
{/* Content */}
|
|
122
|
+
<div className="flex-1 min-w-0">
|
|
123
|
+
<div className="text-sm text-gray-300 line-clamp-2">
|
|
124
|
+
{item.prompt}
|
|
125
|
+
</div>
|
|
126
|
+
<div className="flex items-center gap-2 mt-1">
|
|
127
|
+
<Clock className="w-3 h-3 text-gray-500" />
|
|
128
|
+
<span className="text-xs text-gray-500">
|
|
129
|
+
{formatTime(item.timestamp)}
|
|
130
|
+
</span>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
{/* Actions */}
|
|
135
|
+
<div className="flex items-center gap-1 flex-shrink-0">
|
|
136
|
+
<button
|
|
137
|
+
onClick={(e) => {
|
|
138
|
+
e.stopPropagation();
|
|
139
|
+
handleCopy(item.prompt, itemId);
|
|
140
|
+
}}
|
|
141
|
+
className="p-1.5 hover:bg-white/10 rounded transition-colors"
|
|
142
|
+
title="Copy prompt"
|
|
143
|
+
>
|
|
144
|
+
{copiedId === itemId ? (
|
|
145
|
+
<Check className="w-3.5 h-3.5 text-success" />
|
|
146
|
+
) : (
|
|
147
|
+
<Copy className="w-3.5 h-3.5 text-gray-400" />
|
|
148
|
+
)}
|
|
149
|
+
</button>
|
|
150
|
+
<button
|
|
151
|
+
onClick={(e) => {
|
|
152
|
+
e.stopPropagation();
|
|
153
|
+
handleRerun(item.prompt);
|
|
154
|
+
}}
|
|
155
|
+
disabled={isProcessing}
|
|
156
|
+
className="p-1.5 hover:bg-white/10 rounded transition-colors disabled:opacity-50"
|
|
157
|
+
title="Re-run prompt"
|
|
158
|
+
>
|
|
159
|
+
<RefreshCw className={`w-3.5 h-3.5 text-gray-400 ${isProcessing ? 'animate-spin' : ''}`} />
|
|
160
|
+
</button>
|
|
161
|
+
{onSelectPrompt && (
|
|
162
|
+
<button
|
|
163
|
+
onClick={(e) => {
|
|
164
|
+
e.stopPropagation();
|
|
165
|
+
onSelectPrompt(item.prompt);
|
|
166
|
+
}}
|
|
167
|
+
className="p-1.5 hover:bg-white/10 rounded transition-colors"
|
|
168
|
+
title="Edit prompt"
|
|
169
|
+
>
|
|
170
|
+
<span className="text-xs text-gray-400">Edit</span>
|
|
171
|
+
</button>
|
|
172
|
+
)}
|
|
173
|
+
</div>
|
|
174
|
+
</div>
|
|
175
|
+
|
|
176
|
+
{/* Expanded details */}
|
|
177
|
+
{isSelected && (
|
|
178
|
+
<div className="px-4 pb-3 pl-11">
|
|
179
|
+
<div className="bg-node-bg rounded-lg p-3">
|
|
180
|
+
<div className="flex items-center justify-between mb-2">
|
|
181
|
+
<span className="text-xs font-medium text-gray-500 uppercase">
|
|
182
|
+
Response
|
|
183
|
+
</span>
|
|
184
|
+
<button
|
|
185
|
+
onClick={() => handleCopy(item.response, `${itemId}-response`)}
|
|
186
|
+
className="p-1 hover:bg-white/10 rounded transition-colors"
|
|
187
|
+
>
|
|
188
|
+
{copiedId === `${itemId}-response` ? (
|
|
189
|
+
<Check className="w-3 h-3 text-success" />
|
|
190
|
+
) : (
|
|
191
|
+
<Copy className="w-3 h-3 text-gray-400" />
|
|
192
|
+
)}
|
|
193
|
+
</button>
|
|
194
|
+
</div>
|
|
195
|
+
<div className={`text-xs font-mono ${item.success ? 'text-gray-300' : 'text-error'}`}>
|
|
196
|
+
{item.response || 'No response'}
|
|
197
|
+
</div>
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
)}
|
|
201
|
+
</div>
|
|
202
|
+
);
|
|
203
|
+
})}
|
|
204
|
+
</div>
|
|
205
|
+
</div>
|
|
206
|
+
)}
|
|
207
|
+
</div>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { useState, useRef, useEffect } from 'react';
|
|
2
|
+
import { Send, Loader2, Sparkles } from 'lucide-react';
|
|
3
|
+
import { usePromptStore } from '../../stores/promptStore';
|
|
4
|
+
import { PromptHistoryPanel } from './PromptHistoryPanel';
|
|
5
|
+
|
|
6
|
+
export function PromptInput() {
|
|
7
|
+
const [prompt, setPrompt] = useState('');
|
|
8
|
+
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
9
|
+
|
|
10
|
+
const { isProcessing, history, sendPrompt } = usePromptStore();
|
|
11
|
+
|
|
12
|
+
// Auto-resize textarea
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (textareaRef.current) {
|
|
15
|
+
textareaRef.current.style.height = 'auto';
|
|
16
|
+
textareaRef.current.style.height = `${Math.min(textareaRef.current.scrollHeight, 200)}px`;
|
|
17
|
+
}
|
|
18
|
+
}, [prompt]);
|
|
19
|
+
|
|
20
|
+
const handleSubmit = async () => {
|
|
21
|
+
if (!prompt.trim() || isProcessing) return;
|
|
22
|
+
|
|
23
|
+
await sendPrompt(prompt);
|
|
24
|
+
setPrompt('');
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
28
|
+
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
handleSubmit();
|
|
31
|
+
}
|
|
32
|
+
if (e.key === 'ArrowUp' && !prompt && history.length > 0) {
|
|
33
|
+
setPrompt(history[0].prompt);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const suggestions = [
|
|
38
|
+
'Add a Slack notification step',
|
|
39
|
+
'Add error handling with 3 retries',
|
|
40
|
+
'Convert to a sub-workflow',
|
|
41
|
+
'Add a condition to skip if draft',
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className="bg-panel-bg">
|
|
46
|
+
{/* History Panel */}
|
|
47
|
+
<PromptHistoryPanel onSelectPrompt={setPrompt} />
|
|
48
|
+
|
|
49
|
+
{/* Suggestions */}
|
|
50
|
+
{!prompt && !isProcessing && (
|
|
51
|
+
<div className="px-4 py-2 border-t border-node-border/50">
|
|
52
|
+
<div className="flex items-center gap-2 overflow-x-auto pb-1">
|
|
53
|
+
<Sparkles className="w-4 h-4 text-primary flex-shrink-0" />
|
|
54
|
+
{suggestions.map((suggestion) => (
|
|
55
|
+
<button
|
|
56
|
+
key={suggestion}
|
|
57
|
+
onClick={() => setPrompt(suggestion)}
|
|
58
|
+
className="px-3 py-1 bg-node-bg border border-node-border rounded-full text-xs text-gray-300 hover:border-primary hover:text-primary transition-colors whitespace-nowrap"
|
|
59
|
+
>
|
|
60
|
+
{suggestion}
|
|
61
|
+
</button>
|
|
62
|
+
))}
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
)}
|
|
66
|
+
|
|
67
|
+
{/* Input area */}
|
|
68
|
+
<div className="p-4 flex items-end gap-3 border-t border-node-border">
|
|
69
|
+
<div className="flex-1 relative">
|
|
70
|
+
<textarea
|
|
71
|
+
ref={textareaRef}
|
|
72
|
+
value={prompt}
|
|
73
|
+
onChange={(e) => setPrompt(e.target.value)}
|
|
74
|
+
onKeyDown={handleKeyDown}
|
|
75
|
+
placeholder="Describe the changes you want to make to the workflow..."
|
|
76
|
+
disabled={isProcessing}
|
|
77
|
+
rows={1}
|
|
78
|
+
className="w-full px-4 py-3 bg-node-bg border border-node-border rounded-lg text-sm text-white placeholder-gray-500 focus:outline-none focus:border-primary resize-none disabled:opacity-50"
|
|
79
|
+
/>
|
|
80
|
+
{isProcessing && (
|
|
81
|
+
<div className="absolute right-3 top-1/2 -translate-y-1/2">
|
|
82
|
+
<Loader2 className="w-5 h-5 text-primary animate-spin" />
|
|
83
|
+
</div>
|
|
84
|
+
)}
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
<button
|
|
88
|
+
onClick={handleSubmit}
|
|
89
|
+
disabled={!prompt.trim() || isProcessing}
|
|
90
|
+
className="w-10 h-10 rounded-lg bg-primary hover:bg-primary-dark disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center transition-colors"
|
|
91
|
+
>
|
|
92
|
+
<Send className="w-5 h-5 text-white" />
|
|
93
|
+
</button>
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
{/* Keyboard hint */}
|
|
97
|
+
<div className="px-4 pb-2 text-xs text-gray-500">
|
|
98
|
+
Press <kbd className="px-1.5 py-0.5 bg-node-bg rounded text-gray-400">⌘</kbd> +{' '}
|
|
99
|
+
<kbd className="px-1.5 py-0.5 bg-node-bg rounded text-gray-400">Enter</kbd> to send
|
|
100
|
+
{history.length > 0 && (
|
|
101
|
+
<span className="ml-4">
|
|
102
|
+
<kbd className="px-1.5 py-0.5 bg-node-bg rounded text-gray-400">↑</kbd> for last prompt
|
|
103
|
+
</span>
|
|
104
|
+
)}
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
}
|