-
Workflow 1
+
+ {activeWorkflowId ? workflows[activeWorkflowId].name : 'Workflow'}
+
Saved{' '}
{formatDistanceToNow(history.present.timestamp, { addSuffix: true })}
diff --git a/stores/workflow/workflow-registry.ts b/stores/workflow/workflow-registry.ts
index 45aa3226f..93584c6b1 100644
--- a/stores/workflow/workflow-registry.ts
+++ b/stores/workflow/workflow-registry.ts
@@ -67,10 +67,13 @@ export const useWorkflowRegistry = create()(
},
addWorkflow: (metadata: WorkflowMetadata) => {
+ const uniqueName = generateUniqueName(get().workflows)
+ const updatedMetadata = { ...metadata, name: uniqueName }
+
set((state) => ({
workflows: {
...state.workflows,
- [metadata.id]: metadata
+ [metadata.id]: updatedMetadata
},
error: null
}))
@@ -167,6 +170,24 @@ export const useWorkflowRegistry = create()(
)
)
+const generateUniqueName = (existingWorkflows: Record): string => {
+ // Extract numbers from existing workflow names using regex
+ const numbers = Object.values(existingWorkflows)
+ .map(w => {
+ const match = w.name.match(/Workflow (\d+)/)
+ return match ? parseInt(match[1]) : 0
+ })
+ .filter(n => n > 0)
+
+ if (numbers.length === 0) {
+ return 'Workflow 1'
+ }
+
+ // Find the maximum number and add 1
+ const nextNumber = Math.max(...numbers) + 1
+ return `Workflow ${nextNumber}`
+}
+
// Initialize registry from localStorage
const initializeRegistry = () => {
const savedRegistry = localStorage.getItem('workflow-registry')
@@ -179,4 +200,4 @@ const initializeRegistry = () => {
// Call this in your app's entry point
if (typeof window !== 'undefined') {
initializeRegistry()
-}
\ No newline at end of file
+}