@stigmer/react 0.5.0 → 1.0.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/activity/group-activity.d.ts +13 -0
- package/activity/group-activity.d.ts.map +1 -0
- package/activity/group-activity.js +54 -0
- package/activity/group-activity.js.map +1 -0
- package/activity/index.d.ts +4 -0
- package/activity/index.d.ts.map +1 -0
- package/activity/index.js +3 -0
- package/activity/index.js.map +1 -0
- package/activity/types.d.ts +34 -0
- package/activity/types.d.ts.map +1 -0
- package/activity/types.js +2 -0
- package/activity/types.js.map +1 -0
- package/activity/useRecentActivity.d.ts +35 -0
- package/activity/useRecentActivity.d.ts.map +1 -0
- package/activity/useRecentActivity.js +73 -0
- package/activity/useRecentActivity.js.map +1 -0
- package/agent/AgentPicker.d.ts.map +1 -1
- package/agent/AgentPicker.js +4 -2
- package/agent/AgentPicker.js.map +1 -1
- package/billing/BillingSection.d.ts.map +1 -1
- package/billing/BillingSection.js +1 -1
- package/billing/BillingSection.js.map +1 -1
- package/composer/ComposerToolbar.d.ts +5 -1
- package/composer/ComposerToolbar.d.ts.map +1 -1
- package/composer/ComposerToolbar.js +4 -3
- package/composer/ComposerToolbar.js.map +1 -1
- package/composer/ContextChip.d.ts +7 -2
- package/composer/ContextChip.d.ts.map +1 -1
- package/composer/ContextChip.js +2 -1
- package/composer/ContextChip.js.map +1 -1
- package/composer/InteractionModePicker.d.ts +40 -0
- package/composer/InteractionModePicker.d.ts.map +1 -0
- package/composer/InteractionModePicker.js +76 -0
- package/composer/InteractionModePicker.js.map +1 -0
- package/composer/SessionComposer.d.ts +64 -64
- package/composer/SessionComposer.d.ts.map +1 -1
- package/composer/SessionComposer.js +52 -11
- package/composer/SessionComposer.js.map +1 -1
- package/composer/__tests__/SessionComposer-memo.test.js +10 -5
- package/composer/__tests__/SessionComposer-memo.test.js.map +1 -1
- package/composer/index.d.ts +3 -1
- package/composer/index.d.ts.map +1 -1
- package/composer/index.js +1 -0
- package/composer/index.js.map +1 -1
- package/dashboard/DashboardFailedRuns.d.ts +19 -0
- package/dashboard/DashboardFailedRuns.d.ts.map +1 -0
- package/dashboard/DashboardFailedRuns.js +35 -0
- package/dashboard/DashboardFailedRuns.js.map +1 -0
- package/dashboard/DashboardKPICards.d.ts +19 -0
- package/dashboard/DashboardKPICards.d.ts.map +1 -0
- package/dashboard/DashboardKPICards.js +80 -0
- package/dashboard/DashboardKPICards.js.map +1 -0
- package/dashboard/OperationalDashboard.d.ts +37 -0
- package/dashboard/OperationalDashboard.d.ts.map +1 -0
- package/dashboard/OperationalDashboard.js +48 -0
- package/dashboard/OperationalDashboard.js.map +1 -0
- package/dashboard/index.d.ts +8 -0
- package/dashboard/index.d.ts.map +1 -0
- package/dashboard/index.js +9 -0
- package/dashboard/index.js.map +1 -0
- package/dashboard/types.d.ts +49 -0
- package/dashboard/types.d.ts.map +1 -0
- package/dashboard/types.js +2 -0
- package/dashboard/types.js.map +1 -0
- package/dashboard/useAgentExecutionSummary.d.ts +33 -0
- package/dashboard/useAgentExecutionSummary.d.ts.map +1 -0
- package/dashboard/useAgentExecutionSummary.js +32 -0
- package/dashboard/useAgentExecutionSummary.js.map +1 -0
- package/dashboard/useDashboardFailedRuns.d.ts +18 -0
- package/dashboard/useDashboardFailedRuns.d.ts.map +1 -0
- package/dashboard/useDashboardFailedRuns.js +86 -0
- package/dashboard/useDashboardFailedRuns.js.map +1 -0
- package/dashboard/useDashboardSummary.d.ts +32 -0
- package/dashboard/useDashboardSummary.d.ts.map +1 -0
- package/dashboard/useDashboardSummary.js +67 -0
- package/dashboard/useDashboardSummary.js.map +1 -0
- package/environment/usePersonalEnvironment.d.ts.map +1 -1
- package/environment/usePersonalEnvironment.js +1 -0
- package/environment/usePersonalEnvironment.js.map +1 -1
- package/execution/ContextGauge.d.ts +45 -0
- package/execution/ContextGauge.d.ts.map +1 -0
- package/execution/ContextGauge.js +82 -0
- package/execution/ContextGauge.js.map +1 -0
- package/execution/InteractionModeBadge.d.ts +24 -0
- package/execution/InteractionModeBadge.d.ts.map +1 -0
- package/execution/InteractionModeBadge.js +29 -0
- package/execution/InteractionModeBadge.js.map +1 -0
- package/execution/MessageThread.d.ts +33 -3
- package/execution/MessageThread.d.ts.map +1 -1
- package/execution/MessageThread.js +51 -9
- package/execution/MessageThread.js.map +1 -1
- package/execution/PlanCompletionCard.d.ts +23 -0
- package/execution/PlanCompletionCard.d.ts.map +1 -0
- package/execution/PlanCompletionCard.js +28 -0
- package/execution/PlanCompletionCard.js.map +1 -0
- package/execution/SummarizationBadge.d.ts +30 -0
- package/execution/SummarizationBadge.d.ts.map +1 -0
- package/execution/SummarizationBadge.js +61 -0
- package/execution/SummarizationBadge.js.map +1 -0
- package/execution/SummarizationCard.d.ts +27 -0
- package/execution/SummarizationCard.d.ts.map +1 -0
- package/execution/SummarizationCard.js +47 -0
- package/execution/SummarizationCard.js.map +1 -0
- package/execution/__tests__/PlanCompletionCard.test.d.ts +2 -0
- package/execution/__tests__/PlanCompletionCard.test.d.ts.map +1 -0
- package/execution/__tests__/PlanCompletionCard.test.js +53 -0
- package/execution/__tests__/PlanCompletionCard.test.js.map +1 -0
- package/execution/__tests__/buildThreadItems-plan-completion.test.d.ts +2 -0
- package/execution/__tests__/buildThreadItems-plan-completion.test.d.ts.map +1 -0
- package/execution/__tests__/buildThreadItems-plan-completion.test.js +137 -0
- package/execution/__tests__/buildThreadItems-plan-completion.test.js.map +1 -0
- package/execution/__tests__/useContextWindow.test.d.ts +2 -0
- package/execution/__tests__/useContextWindow.test.d.ts.map +1 -0
- package/execution/__tests__/useContextWindow.test.js +121 -0
- package/execution/__tests__/useContextWindow.test.js.map +1 -0
- package/execution/index.d.ts +12 -0
- package/execution/index.d.ts.map +1 -1
- package/execution/index.js +6 -0
- package/execution/index.js.map +1 -1
- package/execution/useContextWindow.d.ts +71 -0
- package/execution/useContextWindow.d.ts.map +1 -0
- package/execution/useContextWindow.js +91 -0
- package/execution/useContextWindow.js.map +1 -0
- package/execution/useCreateAgentExecution.d.ts +9 -0
- package/execution/useCreateAgentExecution.d.ts.map +1 -1
- package/execution/useCreateAgentExecution.js +15 -3
- package/execution/useCreateAgentExecution.js.map +1 -1
- package/index.d.ts +11 -6
- package/index.d.ts.map +1 -1
- package/index.js +13 -3
- package/index.js.map +1 -1
- package/inline-edit/InlineEditKeyValue.d.ts +5 -1
- package/inline-edit/InlineEditKeyValue.d.ts.map +1 -1
- package/inline-edit/InlineEditKeyValue.js +3 -3
- package/inline-edit/InlineEditKeyValue.js.map +1 -1
- package/internal/VirtualizedThread.d.ts +2 -1
- package/internal/VirtualizedThread.d.ts.map +1 -1
- package/internal/VirtualizedThread.js +3 -2
- package/internal/VirtualizedThread.js.map +1 -1
- package/internal/store/index.d.ts +1 -0
- package/internal/store/index.d.ts.map +1 -1
- package/internal/store/index.js +1 -0
- package/internal/store/index.js.map +1 -1
- package/internal/store/workflow-execution-event-store.d.ts +92 -0
- package/internal/store/workflow-execution-event-store.d.ts.map +1 -0
- package/internal/store/workflow-execution-event-store.js +298 -0
- package/internal/store/workflow-execution-event-store.js.map +1 -0
- package/internal/useFetch.js +2 -2
- package/internal/useFetch.js.map +1 -1
- package/library/ScopeToggle.d.ts +13 -9
- package/library/ScopeToggle.d.ts.map +1 -1
- package/library/ScopeToggle.js +43 -22
- package/library/ScopeToggle.js.map +1 -1
- package/library/VisibilityToggle.js +14 -5
- package/library/VisibilityToggle.js.map +1 -1
- package/library/index.d.ts +1 -0
- package/library/index.d.ts.map +1 -1
- package/library/index.js +1 -0
- package/library/index.js.map +1 -1
- package/library/useExportResource.d.ts +3 -2
- package/library/useExportResource.d.ts.map +1 -1
- package/library/useExportResource.js +11 -6
- package/library/useExportResource.js.map +1 -1
- package/mcp-server/McpServerDetailView.d.ts.map +1 -1
- package/mcp-server/McpServerDetailView.js +169 -58
- package/mcp-server/McpServerDetailView.js.map +1 -1
- package/mcp-server/McpServerPicker.d.ts.map +1 -1
- package/mcp-server/McpServerPicker.js +4 -2
- package/mcp-server/McpServerPicker.js.map +1 -1
- package/models/ModelRegistryContext.d.ts +2 -0
- package/models/ModelRegistryContext.d.ts.map +1 -1
- package/models/ModelRegistryContext.js +1 -0
- package/models/ModelRegistryContext.js.map +1 -1
- package/models/ModelSelector.d.ts.map +1 -1
- package/models/ModelSelector.js +2 -2
- package/models/ModelSelector.js.map +1 -1
- package/models/__tests__/useModelRegistry.test.js +4 -3
- package/models/__tests__/useModelRegistry.test.js.map +1 -1
- package/models/useModelRegistry.d.ts +2 -0
- package/models/useModelRegistry.d.ts.map +1 -1
- package/models/useModelRegistry.js +3 -2
- package/models/useModelRegistry.js.map +1 -1
- package/package.json +16 -5
- package/provider.d.ts.map +1 -1
- package/provider.js +232 -22
- package/provider.js.map +1 -1
- package/resource-detail/ResourceDetailShell.d.ts +1 -1
- package/resource-detail/ResourceDetailShell.d.ts.map +1 -1
- package/resource-detail/ResourceDetailShell.js +6 -6
- package/resource-detail/ResourceDetailShell.js.map +1 -1
- package/resource-detail/types.d.ts +23 -0
- package/resource-detail/types.d.ts.map +1 -1
- package/resource-detail/useDeleteResource.d.ts +1 -1
- package/resource-detail/useDeleteResource.d.ts.map +1 -1
- package/resource-detail/useDeleteResource.js +5 -0
- package/resource-detail/useDeleteResource.js.map +1 -1
- package/resource-workbench/components/ResourceWorkbench.d.ts.map +1 -1
- package/resource-workbench/components/ResourceWorkbench.js +2 -1
- package/resource-workbench/components/ResourceWorkbench.js.map +1 -1
- package/session/__tests__/session-spec-converters.test.d.ts +2 -0
- package/session/__tests__/session-spec-converters.test.d.ts.map +1 -0
- package/session/__tests__/session-spec-converters.test.js +162 -0
- package/session/__tests__/session-spec-converters.test.js.map +1 -0
- package/session/__tests__/useNewSessionFlow.test.js +2 -2
- package/session/__tests__/useNewSessionFlow.test.js.map +1 -1
- package/session/__tests__/usePersistedModel.test.js +1 -1
- package/session/__tests__/usePersistedModel.test.js.map +1 -1
- package/session/group-sessions.d.ts +17 -0
- package/session/group-sessions.d.ts.map +1 -1
- package/session/group-sessions.js +46 -0
- package/session/group-sessions.js.map +1 -1
- package/session/index.d.ts +4 -2
- package/session/index.d.ts.map +1 -1
- package/session/index.js +2 -1
- package/session/index.js.map +1 -1
- package/session/session-spec-converters.d.ts +24 -0
- package/session/session-spec-converters.d.ts.map +1 -0
- package/session/session-spec-converters.js +72 -0
- package/session/session-spec-converters.js.map +1 -0
- package/session/useNewSessionFlow.d.ts.map +1 -1
- package/session/useNewSessionFlow.js +1 -0
- package/session/useNewSessionFlow.js.map +1 -1
- package/session/useSessionConversation.d.ts +7 -0
- package/session/useSessionConversation.d.ts.map +1 -1
- package/session/useSessionConversation.js +2 -56
- package/session/useSessionConversation.js.map +1 -1
- package/session/useSessionPageFlow.d.ts +5 -0
- package/session/useSessionPageFlow.d.ts.map +1 -1
- package/session/useSessionPageFlow.js +21 -6
- package/session/useSessionPageFlow.js.map +1 -1
- package/session/useSessionSearch.d.ts +57 -0
- package/session/useSessionSearch.d.ts.map +1 -0
- package/session/useSessionSearch.js +94 -0
- package/session/useSessionSearch.js.map +1 -0
- package/session/useSessionUsage.d.ts.map +1 -1
- package/session/useSessionUsage.js +65 -4
- package/session/useSessionUsage.js.map +1 -1
- package/settings/UsageSection.d.ts.map +1 -1
- package/settings/UsageSection.js +1 -4
- package/settings/UsageSection.js.map +1 -1
- package/skill/SkillPicker.d.ts.map +1 -1
- package/skill/SkillPicker.js +4 -2
- package/skill/SkillPicker.js.map +1 -1
- package/src/activity/group-activity.ts +65 -0
- package/src/activity/index.ts +13 -0
- package/src/activity/types.ts +35 -0
- package/src/activity/useRecentActivity.ts +131 -0
- package/src/agent/AgentPicker.tsx +6 -1
- package/src/billing/BillingSection.tsx +3 -2
- package/src/composer/ComposerToolbar.tsx +19 -1
- package/src/composer/ContextChip.tsx +20 -11
- package/src/composer/InteractionModePicker.tsx +189 -0
- package/src/composer/SessionComposer.tsx +137 -11
- package/src/composer/__tests__/SessionComposer-memo.test.ts +11 -6
- package/src/composer/index.ts +7 -0
- package/src/dashboard/DashboardFailedRuns.tsx +109 -0
- package/src/dashboard/DashboardKPICards.tsx +128 -0
- package/src/dashboard/OperationalDashboard.tsx +96 -0
- package/src/dashboard/index.ts +37 -0
- package/src/dashboard/types.ts +50 -0
- package/src/dashboard/useAgentExecutionSummary.ts +71 -0
- package/src/dashboard/useDashboardFailedRuns.ts +122 -0
- package/src/dashboard/useDashboardSummary.ts +109 -0
- package/src/environment/usePersonalEnvironment.ts +1 -0
- package/src/execution/ContextGauge.tsx +243 -0
- package/src/execution/InteractionModeBadge.tsx +70 -0
- package/src/execution/MessageThread.tsx +88 -3
- package/src/execution/PlanCompletionCard.tsx +105 -0
- package/src/execution/SummarizationBadge.tsx +188 -0
- package/src/execution/SummarizationCard.tsx +126 -0
- package/src/execution/__tests__/PlanCompletionCard.test.tsx +67 -0
- package/src/execution/__tests__/buildThreadItems-plan-completion.test.ts +197 -0
- package/src/execution/__tests__/useContextWindow.test.ts +167 -0
- package/src/execution/index.ts +22 -0
- package/src/execution/useContextWindow.ts +148 -0
- package/src/execution/useCreateAgentExecution.ts +26 -3
- package/src/index.ts +227 -0
- package/src/inline-edit/InlineEditKeyValue.tsx +23 -0
- package/src/internal/VirtualizedThread.tsx +4 -1
- package/src/internal/store/index.ts +6 -0
- package/src/internal/store/workflow-execution-event-store.ts +391 -0
- package/src/internal/useFetch.ts +2 -2
- package/src/library/ScopeToggle.tsx +88 -20
- package/src/library/VisibilityToggle.tsx +54 -13
- package/src/library/index.ts +2 -0
- package/src/library/useExportResource.ts +12 -9
- package/src/mcp-server/McpServerDetailView.tsx +509 -203
- package/src/mcp-server/McpServerPicker.tsx +6 -1
- package/src/models/ModelRegistryContext.ts +3 -0
- package/src/models/ModelSelector.tsx +25 -2
- package/src/models/__tests__/useModelRegistry.test.tsx +5 -3
- package/src/models/useModelRegistry.ts +5 -2
- package/src/provider.tsx +264 -26
- package/src/resource-detail/ResourceDetailShell.tsx +21 -4
- package/src/resource-detail/types.ts +25 -0
- package/src/resource-detail/useDeleteResource.ts +6 -1
- package/src/resource-workbench/components/ResourceWorkbench.tsx +4 -0
- package/src/session/__tests__/session-spec-converters.test.ts +185 -0
- package/src/session/__tests__/useNewSessionFlow.test.tsx +2 -2
- package/src/session/__tests__/usePersistedModel.test.tsx +1 -1
- package/src/session/group-sessions.ts +65 -0
- package/src/session/index.ts +8 -2
- package/src/session/session-spec-converters.ts +86 -0
- package/src/session/useNewSessionFlow.ts +1 -0
- package/src/session/useSessionConversation.ts +13 -64
- package/src/session/useSessionPageFlow.ts +29 -7
- package/src/session/useSessionSearch.ts +149 -0
- package/src/session/useSessionUsage.ts +72 -4
- package/src/settings/UsageSection.tsx +1 -9
- package/src/skill/SkillPicker.tsx +6 -1
- package/src/workflow/ApprovalFormBuilder.tsx +1017 -0
- package/src/workflow/BranchConditionBuilder.tsx +451 -0
- package/src/workflow/CanvasActionsContext.ts +12 -0
- package/src/workflow/CanvasContextMenu.tsx +364 -0
- package/src/workflow/CanvasTaskNode.tsx +372 -0
- package/src/workflow/CanvasTransitionEdge.tsx +122 -0
- package/src/workflow/CostByWorkflowChart.tsx +120 -0
- package/src/workflow/ExecutionSummaryWidget.tsx +194 -0
- package/src/workflow/ExecutionTrendChart.tsx +157 -0
- package/src/workflow/FailedRunsWidget.tsx +109 -0
- package/src/workflow/PendingApprovalsWidget.tsx +115 -0
- package/src/workflow/TaskConfigForm.tsx +618 -0
- package/src/workflow/TaskKindRegistryContext.ts +36 -0
- package/src/workflow/TaskPickerPopover.tsx +326 -0
- package/src/workflow/WorkflowArchitectDialog.tsx +505 -0
- package/src/workflow/WorkflowCanvasEditor.tsx +651 -0
- package/src/workflow/WorkflowCanvasInner.tsx +160 -0
- package/src/workflow/WorkflowDashboard.tsx +124 -0
- package/src/workflow/WorkflowDetailView.tsx +527 -0
- package/src/workflow/WorkflowEditorView.tsx +547 -0
- package/src/workflow/WorkflowExecutionApprovalCard.tsx +129 -0
- package/src/workflow/WorkflowExecutionArtifactPanel.tsx +112 -0
- package/src/workflow/WorkflowExecutionCostPanel.tsx +131 -0
- package/src/workflow/WorkflowExecutionHeader.tsx +194 -0
- package/src/workflow/WorkflowExecutionPhaseBadge.tsx +188 -0
- package/src/workflow/WorkflowExecutionTaskPanel.tsx +135 -0
- package/src/workflow/WorkflowExecutionTimeline.tsx +118 -0
- package/src/workflow/WorkflowExecutionTimelineEvent.tsx +488 -0
- package/src/workflow/WorkflowExecutionViewer.tsx +248 -0
- package/src/workflow/WorkflowInspectorPanel.tsx +568 -0
- package/src/workflow/WorkflowRefinePanel.tsx +411 -0
- package/src/workflow/WorkflowRepairCard.tsx +433 -0
- package/src/workflow/WorkflowRunDialog.tsx +220 -0
- package/src/workflow/WorkflowRunForm.tsx +245 -0
- package/src/workflow/WorkflowTaskList.tsx +177 -0
- package/src/workflow/WorkflowTaskPalette.tsx +248 -0
- package/src/workflow/WorkflowTopologyGraph.tsx +250 -0
- package/src/workflow/WorkflowYamlEditor.tsx +271 -0
- package/src/workflow/__tests__/starter-workflow-yaml.test.ts +57 -0
- package/src/workflow/canvas-constants.ts +87 -0
- package/src/workflow/canvas-icons.tsx +36 -0
- package/src/workflow/extract-workflow-yaml.ts +87 -0
- package/src/workflow/graph-commands.ts +675 -0
- package/src/workflow/index.ts +375 -0
- package/src/workflow/serialize-workflow-yaml.ts +546 -0
- package/src/workflow/starter-workflow-yaml.ts +29 -0
- package/src/workflow/types.ts +99 -0
- package/src/workflow/useCanvasKeyboardShortcuts.ts +134 -0
- package/src/workflow/useDiagnoseExecutionFlow.ts +378 -0
- package/src/workflow/useGraphHistory.ts +138 -0
- package/src/workflow/usePendingApprovals.ts +89 -0
- package/src/workflow/useRefineWorkflowFlow.ts +321 -0
- package/src/workflow/useResolveAgentExecutionSession.ts +57 -0
- package/src/workflow/useRunWorkflowFlow.ts +235 -0
- package/src/workflow/useTaskKindRegistry.ts +135 -0
- package/src/workflow/useWorkflow.ts +78 -0
- package/src/workflow/useWorkflowArchitectFlow.ts +303 -0
- package/src/workflow/useWorkflowCanvas.ts +882 -0
- package/src/workflow/useWorkflowCount.ts +66 -0
- package/src/workflow/useWorkflowDashboardSummary.ts +71 -0
- package/src/workflow/useWorkflowEditor.ts +106 -0
- package/src/workflow/useWorkflowExecution.ts +67 -0
- package/src/workflow/useWorkflowExecutionActions.ts +179 -0
- package/src/workflow/useWorkflowExecutionArtifacts.ts +57 -0
- package/src/workflow/useWorkflowExecutionEventLog.ts +111 -0
- package/src/workflow/useWorkflowExecutionEventStream.ts +244 -0
- package/src/workflow/useWorkflowExecutionList.ts +121 -0
- package/src/workflow/useWorkflowInstances.ts +62 -0
- package/src/workflow/useWorkflowList.ts +79 -0
- package/src/workflow/useWorkflowSave.ts +84 -0
- package/src/workflow/useWorkflowTopology.ts +229 -0
- package/src/workflow/useWorkflowValidation.ts +329 -0
- package/src/workflow/useWorkflowYaml.ts +49 -0
- package/src/workflow/workflow-graph-conversions.ts +796 -0
- package/src/workflow/workflow-graph-model.ts +83 -0
- package/src/workflow/workflow-yaml-diff.ts +132 -0
- package/styles.css +1 -1
- package/workflow/ApprovalFormBuilder.d.ts +24 -0
- package/workflow/ApprovalFormBuilder.d.ts.map +1 -0
- package/workflow/ApprovalFormBuilder.js +347 -0
- package/workflow/ApprovalFormBuilder.js.map +1 -0
- package/workflow/BranchConditionBuilder.d.ts +29 -0
- package/workflow/BranchConditionBuilder.d.ts.map +1 -0
- package/workflow/BranchConditionBuilder.js +170 -0
- package/workflow/BranchConditionBuilder.js.map +1 -0
- package/workflow/CanvasActionsContext.d.ts +8 -0
- package/workflow/CanvasActionsContext.d.ts.map +1 -0
- package/workflow/CanvasActionsContext.js +4 -0
- package/workflow/CanvasActionsContext.js.map +1 -0
- package/workflow/CanvasContextMenu.d.ts +59 -0
- package/workflow/CanvasContextMenu.d.ts.map +1 -0
- package/workflow/CanvasContextMenu.js +98 -0
- package/workflow/CanvasContextMenu.js.map +1 -0
- package/workflow/CanvasTaskNode.d.ts +21 -0
- package/workflow/CanvasTaskNode.d.ts.map +1 -0
- package/workflow/CanvasTaskNode.js +125 -0
- package/workflow/CanvasTaskNode.js.map +1 -0
- package/workflow/CanvasTransitionEdge.d.ts +24 -0
- package/workflow/CanvasTransitionEdge.d.ts.map +1 -0
- package/workflow/CanvasTransitionEdge.js +50 -0
- package/workflow/CanvasTransitionEdge.js.map +1 -0
- package/workflow/CostByWorkflowChart.d.ts +15 -0
- package/workflow/CostByWorkflowChart.d.ts.map +1 -0
- package/workflow/CostByWorkflowChart.js +45 -0
- package/workflow/CostByWorkflowChart.js.map +1 -0
- package/workflow/ExecutionSummaryWidget.d.ts +16 -0
- package/workflow/ExecutionSummaryWidget.d.ts.map +1 -0
- package/workflow/ExecutionSummaryWidget.js +93 -0
- package/workflow/ExecutionSummaryWidget.js.map +1 -0
- package/workflow/ExecutionTrendChart.d.ts +14 -0
- package/workflow/ExecutionTrendChart.d.ts.map +1 -0
- package/workflow/ExecutionTrendChart.js +67 -0
- package/workflow/ExecutionTrendChart.js.map +1 -0
- package/workflow/FailedRunsWidget.d.ts +19 -0
- package/workflow/FailedRunsWidget.d.ts.map +1 -0
- package/workflow/FailedRunsWidget.js +37 -0
- package/workflow/FailedRunsWidget.js.map +1 -0
- package/workflow/PendingApprovalsWidget.d.ts +19 -0
- package/workflow/PendingApprovalsWidget.d.ts.map +1 -0
- package/workflow/PendingApprovalsWidget.js +35 -0
- package/workflow/PendingApprovalsWidget.js.map +1 -0
- package/workflow/TaskConfigForm.d.ts +29 -0
- package/workflow/TaskConfigForm.d.ts.map +1 -0
- package/workflow/TaskConfigForm.js +230 -0
- package/workflow/TaskConfigForm.js.map +1 -0
- package/workflow/TaskKindRegistryContext.d.ts +24 -0
- package/workflow/TaskKindRegistryContext.d.ts.map +1 -0
- package/workflow/TaskKindRegistryContext.js +25 -0
- package/workflow/TaskKindRegistryContext.js.map +1 -0
- package/workflow/TaskPickerPopover.d.ts +33 -0
- package/workflow/TaskPickerPopover.d.ts.map +1 -0
- package/workflow/TaskPickerPopover.js +110 -0
- package/workflow/TaskPickerPopover.js.map +1 -0
- package/workflow/WorkflowArchitectDialog.d.ts +48 -0
- package/workflow/WorkflowArchitectDialog.d.ts.map +1 -0
- package/workflow/WorkflowArchitectDialog.js +129 -0
- package/workflow/WorkflowArchitectDialog.js.map +1 -0
- package/workflow/WorkflowCanvasEditor.d.ts +38 -0
- package/workflow/WorkflowCanvasEditor.d.ts.map +1 -0
- package/workflow/WorkflowCanvasEditor.js +287 -0
- package/workflow/WorkflowCanvasEditor.js.map +1 -0
- package/workflow/WorkflowCanvasInner.d.ts +32 -0
- package/workflow/WorkflowCanvasInner.d.ts.map +1 -0
- package/workflow/WorkflowCanvasInner.js +49 -0
- package/workflow/WorkflowCanvasInner.js.map +1 -0
- package/workflow/WorkflowDashboard.d.ts +35 -0
- package/workflow/WorkflowDashboard.d.ts.map +1 -0
- package/workflow/WorkflowDashboard.js +59 -0
- package/workflow/WorkflowDashboard.js.map +1 -0
- package/workflow/WorkflowDetailView.d.ts +63 -0
- package/workflow/WorkflowDetailView.d.ts.map +1 -0
- package/workflow/WorkflowDetailView.js +202 -0
- package/workflow/WorkflowDetailView.js.map +1 -0
- package/workflow/WorkflowEditorView.d.ts +43 -0
- package/workflow/WorkflowEditorView.d.ts.map +1 -0
- package/workflow/WorkflowEditorView.js +165 -0
- package/workflow/WorkflowEditorView.js.map +1 -0
- package/workflow/WorkflowExecutionApprovalCard.d.ts +27 -0
- package/workflow/WorkflowExecutionApprovalCard.d.ts.map +1 -0
- package/workflow/WorkflowExecutionApprovalCard.js +32 -0
- package/workflow/WorkflowExecutionApprovalCard.js.map +1 -0
- package/workflow/WorkflowExecutionArtifactPanel.d.ts +15 -0
- package/workflow/WorkflowExecutionArtifactPanel.d.ts.map +1 -0
- package/workflow/WorkflowExecutionArtifactPanel.js +53 -0
- package/workflow/WorkflowExecutionArtifactPanel.js.map +1 -0
- package/workflow/WorkflowExecutionCostPanel.d.ts +18 -0
- package/workflow/WorkflowExecutionCostPanel.d.ts.map +1 -0
- package/workflow/WorkflowExecutionCostPanel.js +44 -0
- package/workflow/WorkflowExecutionCostPanel.js.map +1 -0
- package/workflow/WorkflowExecutionHeader.d.ts +26 -0
- package/workflow/WorkflowExecutionHeader.d.ts.map +1 -0
- package/workflow/WorkflowExecutionHeader.js +68 -0
- package/workflow/WorkflowExecutionHeader.js.map +1 -0
- package/workflow/WorkflowExecutionPhaseBadge.d.ts +23 -0
- package/workflow/WorkflowExecutionPhaseBadge.d.ts.map +1 -0
- package/workflow/WorkflowExecutionPhaseBadge.js +99 -0
- package/workflow/WorkflowExecutionPhaseBadge.js.map +1 -0
- package/workflow/WorkflowExecutionTaskPanel.d.ts +24 -0
- package/workflow/WorkflowExecutionTaskPanel.d.ts.map +1 -0
- package/workflow/WorkflowExecutionTaskPanel.js +59 -0
- package/workflow/WorkflowExecutionTaskPanel.js.map +1 -0
- package/workflow/WorkflowExecutionTimeline.d.ts +27 -0
- package/workflow/WorkflowExecutionTimeline.d.ts.map +1 -0
- package/workflow/WorkflowExecutionTimeline.js +51 -0
- package/workflow/WorkflowExecutionTimeline.js.map +1 -0
- package/workflow/WorkflowExecutionTimelineEvent.d.ts +18 -0
- package/workflow/WorkflowExecutionTimelineEvent.d.ts.map +1 -0
- package/workflow/WorkflowExecutionTimelineEvent.js +210 -0
- package/workflow/WorkflowExecutionTimelineEvent.js.map +1 -0
- package/workflow/WorkflowExecutionViewer.d.ts +45 -0
- package/workflow/WorkflowExecutionViewer.d.ts.map +1 -0
- package/workflow/WorkflowExecutionViewer.js +75 -0
- package/workflow/WorkflowExecutionViewer.js.map +1 -0
- package/workflow/WorkflowInspectorPanel.d.ts +46 -0
- package/workflow/WorkflowInspectorPanel.d.ts.map +1 -0
- package/workflow/WorkflowInspectorPanel.js +152 -0
- package/workflow/WorkflowInspectorPanel.js.map +1 -0
- package/workflow/WorkflowRefinePanel.d.ts +30 -0
- package/workflow/WorkflowRefinePanel.d.ts.map +1 -0
- package/workflow/WorkflowRefinePanel.js +107 -0
- package/workflow/WorkflowRefinePanel.js.map +1 -0
- package/workflow/WorkflowRepairCard.d.ts +35 -0
- package/workflow/WorkflowRepairCard.d.ts.map +1 -0
- package/workflow/WorkflowRepairCard.js +113 -0
- package/workflow/WorkflowRepairCard.js.map +1 -0
- package/workflow/WorkflowRunDialog.d.ts +51 -0
- package/workflow/WorkflowRunDialog.d.ts.map +1 -0
- package/workflow/WorkflowRunDialog.js +75 -0
- package/workflow/WorkflowRunDialog.js.map +1 -0
- package/workflow/WorkflowRunForm.d.ts +62 -0
- package/workflow/WorkflowRunForm.d.ts.map +1 -0
- package/workflow/WorkflowRunForm.js +64 -0
- package/workflow/WorkflowRunForm.js.map +1 -0
- package/workflow/WorkflowTaskList.d.ts +25 -0
- package/workflow/WorkflowTaskList.d.ts.map +1 -0
- package/workflow/WorkflowTaskList.js +89 -0
- package/workflow/WorkflowTaskList.js.map +1 -0
- package/workflow/WorkflowTaskPalette.d.ts +22 -0
- package/workflow/WorkflowTaskPalette.d.ts.map +1 -0
- package/workflow/WorkflowTaskPalette.js +83 -0
- package/workflow/WorkflowTaskPalette.js.map +1 -0
- package/workflow/WorkflowTopologyGraph.d.ts +22 -0
- package/workflow/WorkflowTopologyGraph.d.ts.map +1 -0
- package/workflow/WorkflowTopologyGraph.js +123 -0
- package/workflow/WorkflowTopologyGraph.js.map +1 -0
- package/workflow/WorkflowYamlEditor.d.ts +43 -0
- package/workflow/WorkflowYamlEditor.d.ts.map +1 -0
- package/workflow/WorkflowYamlEditor.js +215 -0
- package/workflow/WorkflowYamlEditor.js.map +1 -0
- package/workflow/__tests__/starter-workflow-yaml.test.d.ts +2 -0
- package/workflow/__tests__/starter-workflow-yaml.test.d.ts.map +1 -0
- package/workflow/__tests__/starter-workflow-yaml.test.js +44 -0
- package/workflow/__tests__/starter-workflow-yaml.test.js.map +1 -0
- package/workflow/canvas-constants.d.ts +56 -0
- package/workflow/canvas-constants.d.ts.map +1 -0
- package/workflow/canvas-constants.js +74 -0
- package/workflow/canvas-constants.js.map +1 -0
- package/workflow/canvas-icons.d.ts +13 -0
- package/workflow/canvas-icons.d.ts.map +1 -0
- package/workflow/canvas-icons.js +21 -0
- package/workflow/canvas-icons.js.map +1 -0
- package/workflow/extract-workflow-yaml.d.ts +22 -0
- package/workflow/extract-workflow-yaml.d.ts.map +1 -0
- package/workflow/extract-workflow-yaml.js +63 -0
- package/workflow/extract-workflow-yaml.js.map +1 -0
- package/workflow/graph-commands.d.ts +209 -0
- package/workflow/graph-commands.d.ts.map +1 -0
- package/workflow/graph-commands.js +516 -0
- package/workflow/graph-commands.js.map +1 -0
- package/workflow/index.d.ts +66 -0
- package/workflow/index.d.ts.map +1 -0
- package/workflow/index.js +88 -0
- package/workflow/index.js.map +1 -0
- package/workflow/serialize-workflow-yaml.d.ts +39 -0
- package/workflow/serialize-workflow-yaml.d.ts.map +1 -0
- package/workflow/serialize-workflow-yaml.js +413 -0
- package/workflow/serialize-workflow-yaml.js.map +1 -0
- package/workflow/starter-workflow-yaml.d.ts +12 -0
- package/workflow/starter-workflow-yaml.d.ts.map +1 -0
- package/workflow/starter-workflow-yaml.js +30 -0
- package/workflow/starter-workflow-yaml.js.map +1 -0
- package/workflow/types.d.ts +80 -0
- package/workflow/types.d.ts.map +1 -0
- package/workflow/types.js +2 -0
- package/workflow/types.js.map +1 -0
- package/workflow/useCanvasKeyboardShortcuts.d.ts +34 -0
- package/workflow/useCanvasKeyboardShortcuts.d.ts.map +1 -0
- package/workflow/useCanvasKeyboardShortcuts.js +108 -0
- package/workflow/useCanvasKeyboardShortcuts.js.map +1 -0
- package/workflow/useDiagnoseExecutionFlow.d.ts +87 -0
- package/workflow/useDiagnoseExecutionFlow.d.ts.map +1 -0
- package/workflow/useDiagnoseExecutionFlow.js +257 -0
- package/workflow/useDiagnoseExecutionFlow.js.map +1 -0
- package/workflow/useGraphHistory.d.ts +28 -0
- package/workflow/useGraphHistory.d.ts.map +1 -0
- package/workflow/useGraphHistory.js +106 -0
- package/workflow/useGraphHistory.js.map +1 -0
- package/workflow/usePendingApprovals.d.ts +35 -0
- package/workflow/usePendingApprovals.d.ts.map +1 -0
- package/workflow/usePendingApprovals.js +50 -0
- package/workflow/usePendingApprovals.js.map +1 -0
- package/workflow/useRefineWorkflowFlow.d.ts +75 -0
- package/workflow/useRefineWorkflowFlow.d.ts.map +1 -0
- package/workflow/useRefineWorkflowFlow.js +216 -0
- package/workflow/useRefineWorkflowFlow.js.map +1 -0
- package/workflow/useResolveAgentExecutionSession.d.ts +33 -0
- package/workflow/useResolveAgentExecutionSession.d.ts.map +1 -0
- package/workflow/useResolveAgentExecutionSession.js +37 -0
- package/workflow/useResolveAgentExecutionSession.js.map +1 -0
- package/workflow/useRunWorkflowFlow.d.ts +82 -0
- package/workflow/useRunWorkflowFlow.d.ts.map +1 -0
- package/workflow/useRunWorkflowFlow.js +145 -0
- package/workflow/useRunWorkflowFlow.js.map +1 -0
- package/workflow/useTaskKindRegistry.d.ts +96 -0
- package/workflow/useTaskKindRegistry.d.ts.map +1 -0
- package/workflow/useTaskKindRegistry.js +75 -0
- package/workflow/useTaskKindRegistry.js.map +1 -0
- package/workflow/useWorkflow.d.ts +47 -0
- package/workflow/useWorkflow.d.ts.map +1 -0
- package/workflow/useWorkflow.js +53 -0
- package/workflow/useWorkflow.js.map +1 -0
- package/workflow/useWorkflowArchitectFlow.d.ts +96 -0
- package/workflow/useWorkflowArchitectFlow.d.ts.map +1 -0
- package/workflow/useWorkflowArchitectFlow.js +179 -0
- package/workflow/useWorkflowArchitectFlow.js.map +1 -0
- package/workflow/useWorkflowCanvas.d.ts +66 -0
- package/workflow/useWorkflowCanvas.d.ts.map +1 -0
- package/workflow/useWorkflowCanvas.js +628 -0
- package/workflow/useWorkflowCanvas.js.map +1 -0
- package/workflow/useWorkflowCount.d.ts +47 -0
- package/workflow/useWorkflowCount.d.ts.map +1 -0
- package/workflow/useWorkflowCount.js +26 -0
- package/workflow/useWorkflowCount.js.map +1 -0
- package/workflow/useWorkflowDashboardSummary.d.ts +34 -0
- package/workflow/useWorkflowDashboardSummary.d.ts.map +1 -0
- package/workflow/useWorkflowDashboardSummary.js +33 -0
- package/workflow/useWorkflowDashboardSummary.js.map +1 -0
- package/workflow/useWorkflowEditor.d.ts +45 -0
- package/workflow/useWorkflowEditor.d.ts.map +1 -0
- package/workflow/useWorkflowEditor.js +52 -0
- package/workflow/useWorkflowEditor.js.map +1 -0
- package/workflow/useWorkflowExecution.d.ts +37 -0
- package/workflow/useWorkflowExecution.d.ts.map +1 -0
- package/workflow/useWorkflowExecution.js +43 -0
- package/workflow/useWorkflowExecution.js.map +1 -0
- package/workflow/useWorkflowExecutionActions.d.ts +41 -0
- package/workflow/useWorkflowExecutionActions.d.ts.map +1 -0
- package/workflow/useWorkflowExecutionActions.js +86 -0
- package/workflow/useWorkflowExecutionActions.js.map +1 -0
- package/workflow/useWorkflowExecutionArtifacts.d.ts +26 -0
- package/workflow/useWorkflowExecutionArtifacts.d.ts.map +1 -0
- package/workflow/useWorkflowExecutionArtifacts.js +29 -0
- package/workflow/useWorkflowExecutionArtifacts.js.map +1 -0
- package/workflow/useWorkflowExecutionEventLog.d.ts +47 -0
- package/workflow/useWorkflowExecutionEventLog.d.ts.map +1 -0
- package/workflow/useWorkflowExecutionEventLog.js +59 -0
- package/workflow/useWorkflowExecutionEventLog.js.map +1 -0
- package/workflow/useWorkflowExecutionEventStream.d.ts +61 -0
- package/workflow/useWorkflowExecutionEventStream.d.ts.map +1 -0
- package/workflow/useWorkflowExecutionEventStream.js +161 -0
- package/workflow/useWorkflowExecutionEventStream.js.map +1 -0
- package/workflow/useWorkflowExecutionList.d.ts +49 -0
- package/workflow/useWorkflowExecutionList.d.ts.map +1 -0
- package/workflow/useWorkflowExecutionList.js +65 -0
- package/workflow/useWorkflowExecutionList.js.map +1 -0
- package/workflow/useWorkflowInstances.d.ts +30 -0
- package/workflow/useWorkflowInstances.d.ts.map +1 -0
- package/workflow/useWorkflowInstances.js +33 -0
- package/workflow/useWorkflowInstances.js.map +1 -0
- package/workflow/useWorkflowList.d.ts +57 -0
- package/workflow/useWorkflowList.d.ts.map +1 -0
- package/workflow/useWorkflowList.js +29 -0
- package/workflow/useWorkflowList.js.map +1 -0
- package/workflow/useWorkflowSave.d.ts +25 -0
- package/workflow/useWorkflowSave.d.ts.map +1 -0
- package/workflow/useWorkflowSave.js +61 -0
- package/workflow/useWorkflowSave.js.map +1 -0
- package/workflow/useWorkflowTopology.d.ts +40 -0
- package/workflow/useWorkflowTopology.d.ts.map +1 -0
- package/workflow/useWorkflowTopology.js +163 -0
- package/workflow/useWorkflowTopology.js.map +1 -0
- package/workflow/useWorkflowValidation.d.ts +27 -0
- package/workflow/useWorkflowValidation.d.ts.map +1 -0
- package/workflow/useWorkflowValidation.js +253 -0
- package/workflow/useWorkflowValidation.js.map +1 -0
- package/workflow/useWorkflowYaml.d.ts +26 -0
- package/workflow/useWorkflowYaml.d.ts.map +1 -0
- package/workflow/useWorkflowYaml.js +26 -0
- package/workflow/useWorkflowYaml.js.map +1 -0
- package/workflow/workflow-graph-conversions.d.ts +70 -0
- package/workflow/workflow-graph-conversions.d.ts.map +1 -0
- package/workflow/workflow-graph-conversions.js +634 -0
- package/workflow/workflow-graph-conversions.js.map +1 -0
- package/workflow/workflow-graph-model.d.ts +83 -0
- package/workflow/workflow-graph-model.d.ts.map +1 -0
- package/workflow/workflow-graph-model.js +5 -0
- package/workflow/workflow-graph-model.js.map +1 -0
- package/workflow/workflow-yaml-diff.d.ts +24 -0
- package/workflow/workflow-yaml-diff.d.ts.map +1 -0
- package/workflow/workflow-yaml-diff.js +96 -0
- package/workflow/workflow-yaml-diff.js.map +1 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import type { RefObject } from "react";
|
|
5
|
+
import type { CanvasSelection } from "./useWorkflowCanvas";
|
|
6
|
+
|
|
7
|
+
/** Options for {@link useCanvasKeyboardShortcuts}. */
|
|
8
|
+
export interface UseCanvasKeyboardShortcutsOptions {
|
|
9
|
+
readonly containerRef: RefObject<HTMLDivElement | null>;
|
|
10
|
+
readonly selection: CanvasSelection | null;
|
|
11
|
+
readonly duplicateNode: (nodeId: string) => void;
|
|
12
|
+
readonly selectAll: () => void;
|
|
13
|
+
readonly clearSelection: () => void;
|
|
14
|
+
readonly onRequestTaskPicker: (
|
|
15
|
+
position: { x: number; y: number },
|
|
16
|
+
sourceNodeId?: string,
|
|
17
|
+
) => void;
|
|
18
|
+
readonly onDismiss: () => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isTextInput(target: EventTarget | null): boolean {
|
|
22
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
23
|
+
const tag = target.tagName;
|
|
24
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
25
|
+
if (target.isContentEditable) return true;
|
|
26
|
+
if (target.getAttribute("role") === "textbox") return true;
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isFocusInsideContainer(container: HTMLElement): boolean {
|
|
31
|
+
const active = document.activeElement;
|
|
32
|
+
return active === container || container.contains(active);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Canvas-scoped keyboard shortcuts for the workflow editor.
|
|
37
|
+
*
|
|
38
|
+
* Binds shortcuts that are only active when focus is inside the canvas
|
|
39
|
+
* container, using the same capture-phase listener pattern as
|
|
40
|
+
* {@link useGraphHistory} (undo/redo). Bare-key shortcuts (N, Escape)
|
|
41
|
+
* are suppressed when a text input has focus.
|
|
42
|
+
*
|
|
43
|
+
* | Shortcut | Action |
|
|
44
|
+
* |-------------------|---------------------------------------|
|
|
45
|
+
* | `Ctrl/Cmd+D` | Duplicate selected node |
|
|
46
|
+
* | `Ctrl/Cmd+A` | Select all non-sentinel nodes |
|
|
47
|
+
* | `N` (bare key) | Open task picker |
|
|
48
|
+
* | `Escape` | Clear selection / close open overlays |
|
|
49
|
+
*
|
|
50
|
+
* @internal Not exported from the SDK barrel.
|
|
51
|
+
*/
|
|
52
|
+
export function useCanvasKeyboardShortcuts({
|
|
53
|
+
containerRef,
|
|
54
|
+
selection,
|
|
55
|
+
duplicateNode,
|
|
56
|
+
selectAll,
|
|
57
|
+
clearSelection,
|
|
58
|
+
onRequestTaskPicker,
|
|
59
|
+
onDismiss,
|
|
60
|
+
}: UseCanvasKeyboardShortcutsOptions): void {
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
const container = containerRef.current;
|
|
63
|
+
if (!container) return;
|
|
64
|
+
|
|
65
|
+
function handleKeyDown(e: KeyboardEvent) {
|
|
66
|
+
if (!container || !isFocusInsideContainer(container)) return;
|
|
67
|
+
|
|
68
|
+
const isMod = e.metaKey || e.ctrlKey;
|
|
69
|
+
|
|
70
|
+
// Ctrl/Cmd+D — duplicate selected node
|
|
71
|
+
if (isMod && !e.shiftKey && !e.altKey && e.key.toLowerCase() === "d") {
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
e.stopPropagation();
|
|
74
|
+
if (selection?.type === "node") {
|
|
75
|
+
duplicateNode(selection.id);
|
|
76
|
+
}
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Ctrl/Cmd+A — select all
|
|
81
|
+
if (isMod && !e.shiftKey && !e.altKey && e.key.toLowerCase() === "a") {
|
|
82
|
+
if (isTextInput(e.target)) return;
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
e.stopPropagation();
|
|
85
|
+
selectAll();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Bare-key shortcuts — skip when typing in a text field
|
|
90
|
+
if (isMod || e.altKey) return;
|
|
91
|
+
|
|
92
|
+
// Escape — clear selection, close menus/pickers
|
|
93
|
+
if (e.key === "Escape") {
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
e.stopPropagation();
|
|
96
|
+
onDismiss();
|
|
97
|
+
clearSelection();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// N — open task picker
|
|
102
|
+
if (!e.shiftKey && e.key.toLowerCase() === "n") {
|
|
103
|
+
if (isTextInput(e.target)) return;
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
e.stopPropagation();
|
|
106
|
+
|
|
107
|
+
if (selection?.type === "node") {
|
|
108
|
+
// Position below the selected node — the editor resolves
|
|
109
|
+
// the actual screen coordinates from the node's React Flow position.
|
|
110
|
+
onRequestTaskPicker({ x: 0, y: 0 }, selection.id);
|
|
111
|
+
} else {
|
|
112
|
+
// Viewport center
|
|
113
|
+
const rect = container.getBoundingClientRect();
|
|
114
|
+
onRequestTaskPicker({
|
|
115
|
+
x: rect.left + rect.width / 2,
|
|
116
|
+
y: rect.top + rect.height / 2,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
document.addEventListener("keydown", handleKeyDown, true);
|
|
124
|
+
return () => document.removeEventListener("keydown", handleKeyDown, true);
|
|
125
|
+
}, [
|
|
126
|
+
containerRef,
|
|
127
|
+
selection,
|
|
128
|
+
duplicateNode,
|
|
129
|
+
selectAll,
|
|
130
|
+
clearSelection,
|
|
131
|
+
onRequestTaskPicker,
|
|
132
|
+
onDismiss,
|
|
133
|
+
]);
|
|
134
|
+
}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import type { AgentExecution } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/api_pb";
|
|
5
|
+
import { ExecutionPhase } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
|
|
6
|
+
import { getUserMessage } from "@stigmer/sdk";
|
|
7
|
+
import { useCreateSession } from "../session/useCreateSession";
|
|
8
|
+
import { useCreateAgentExecution } from "../execution/useCreateAgentExecution";
|
|
9
|
+
import { useExecutionStream } from "../execution/useExecutionStream";
|
|
10
|
+
import { isTerminalPhase } from "../execution/execution-phases";
|
|
11
|
+
import { useConversationStoreRef } from "../internal/store";
|
|
12
|
+
import {
|
|
13
|
+
extractWorkflowYaml,
|
|
14
|
+
type ExtractedWorkflowYaml,
|
|
15
|
+
} from "./extract-workflow-yaml";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Lifecycle phases for the workflow execution diagnosis flow.
|
|
19
|
+
*
|
|
20
|
+
* - `idle` — mounted, waiting for auto-start or manual trigger
|
|
21
|
+
* - `starting` — creating session + execution
|
|
22
|
+
* - `streaming` — agent is analyzing (tool calls, reasoning visible)
|
|
23
|
+
* - `complete` — agent finished, YAML fix extracted (diff available)
|
|
24
|
+
* - `ready` — agent finished without YAML (runtime error explanation),
|
|
25
|
+
* or user accepted/discarded a fix; follow-up available
|
|
26
|
+
* - `error` — a failure occurred (RPC, stream)
|
|
27
|
+
*/
|
|
28
|
+
export type DiagnosePhase =
|
|
29
|
+
| "idle"
|
|
30
|
+
| "starting"
|
|
31
|
+
| "streaming"
|
|
32
|
+
| "complete"
|
|
33
|
+
| "ready"
|
|
34
|
+
| "error";
|
|
35
|
+
|
|
36
|
+
/** Options for {@link useDiagnoseExecutionFlow}. */
|
|
37
|
+
export interface UseDiagnoseExecutionFlowOptions {
|
|
38
|
+
/** ID of the failed workflow execution to diagnose. */
|
|
39
|
+
readonly executionId: string;
|
|
40
|
+
/** Organization slug for session and execution creation. */
|
|
41
|
+
readonly org: string;
|
|
42
|
+
/** Current workflow YAML for diff computation (optional). */
|
|
43
|
+
readonly currentWorkflowYaml?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Whether to start diagnosis automatically on mount.
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
readonly autoStart?: boolean;
|
|
49
|
+
/** Called when any step fails. Also available via the `error` return. */
|
|
50
|
+
readonly onError?: (message: string) => void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Return value of {@link useDiagnoseExecutionFlow}. */
|
|
54
|
+
export interface UseDiagnoseExecutionFlowReturn {
|
|
55
|
+
/** Current lifecycle phase. */
|
|
56
|
+
readonly phase: DiagnosePhase;
|
|
57
|
+
/** Completed execution snapshots for MessageThread (chronological). */
|
|
58
|
+
readonly completedExecutions: readonly AgentExecution[];
|
|
59
|
+
/** Currently streaming execution, or null when idle/between turns. */
|
|
60
|
+
readonly activeExecution: AgentExecution | null;
|
|
61
|
+
/** `true` while the agent execution is actively streaming. */
|
|
62
|
+
readonly isStreaming: boolean;
|
|
63
|
+
/** Extracted YAML fix from the latest turn (null unless phase is `complete`). */
|
|
64
|
+
readonly extractedYaml: string | null;
|
|
65
|
+
/** Agent's explanation prose from the latest turn. */
|
|
66
|
+
readonly explanation: string | null;
|
|
67
|
+
/** Human-readable error message, or `null` when healthy. */
|
|
68
|
+
readonly error: string | null;
|
|
69
|
+
/** Start or restart the diagnosis. Callable from `idle` or `error` phases. */
|
|
70
|
+
readonly diagnose: () => Promise<void>;
|
|
71
|
+
/** Send a follow-up question within the same session. */
|
|
72
|
+
readonly sendFollowUp: (message: string) => Promise<void>;
|
|
73
|
+
/** Accept the extracted YAML fix. Returns the YAML string. Transitions to `ready`. */
|
|
74
|
+
readonly acceptFix: () => string | null;
|
|
75
|
+
/** Discard the extracted YAML without applying. Transitions to `ready`. */
|
|
76
|
+
readonly discardFix: () => void;
|
|
77
|
+
/** Reset all state to initial values. Does not delete the server-side session. */
|
|
78
|
+
readonly reset: () => void;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const AGENT_REF = { org: "", slug: "workflow-architect" } as const;
|
|
82
|
+
const MIN_FOLLOWUP_LENGTH = 5;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Behavior hook that orchestrates agent-powered workflow execution
|
|
86
|
+
* diagnosis using the built-in Workflow Architect system agent.
|
|
87
|
+
*
|
|
88
|
+
* Manages a multi-turn conversation within a single Session:
|
|
89
|
+
* - First turn creates a Session + AgentExecution with diagnosis context
|
|
90
|
+
* - Subsequent turns reuse the Session (conversational context)
|
|
91
|
+
* - Each turn streams agent messages via {@link useExecutionStream}
|
|
92
|
+
* - YAML is extracted from agent responses via {@link extractWorkflowYaml}
|
|
93
|
+
* — presence of YAML indicates a definition fix; absence indicates a
|
|
94
|
+
* runtime error with explanation only
|
|
95
|
+
*
|
|
96
|
+
* Auto-starts diagnosis on mount by default (AD-B5-002). The agent uses
|
|
97
|
+
* `get_workflow_execution` and `get_workflow_execution_events` MCP tools
|
|
98
|
+
* to inspect the failure autonomously.
|
|
99
|
+
*
|
|
100
|
+
* Framework-agnostic (DD-004), referentially stable returns (DD-010).
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```tsx
|
|
104
|
+
* const flow = useDiagnoseExecutionFlow({
|
|
105
|
+
* executionId: "wex_abc123",
|
|
106
|
+
* org: "acme",
|
|
107
|
+
* onError: (msg) => toast.error(msg),
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* <WorkflowRepairCard flow={flow} onApplyFix={...} onClose={...} />
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export function useDiagnoseExecutionFlow(
|
|
114
|
+
options: UseDiagnoseExecutionFlowOptions,
|
|
115
|
+
): UseDiagnoseExecutionFlowReturn {
|
|
116
|
+
const { executionId, org, autoStart = true, onError } = options;
|
|
117
|
+
|
|
118
|
+
const [phase, setPhase] = useState<DiagnosePhase>("idle");
|
|
119
|
+
const [activeExecutionId, setActiveExecutionId] = useState<string | null>(
|
|
120
|
+
null,
|
|
121
|
+
);
|
|
122
|
+
const [completedExecutions, setCompletedExecutions] = useState<
|
|
123
|
+
AgentExecution[]
|
|
124
|
+
>([]);
|
|
125
|
+
const [extracted, setExtracted] = useState<ExtractedWorkflowYaml | null>(
|
|
126
|
+
null,
|
|
127
|
+
);
|
|
128
|
+
const [error, setError] = useState<string | null>(null);
|
|
129
|
+
|
|
130
|
+
const orgRef = useRef(org);
|
|
131
|
+
orgRef.current = org;
|
|
132
|
+
const executionIdRef = useRef(executionId);
|
|
133
|
+
executionIdRef.current = executionId;
|
|
134
|
+
const onErrorRef = useRef(onError);
|
|
135
|
+
onErrorRef.current = onError;
|
|
136
|
+
|
|
137
|
+
const sessionIdRef = useRef<string | null>(null);
|
|
138
|
+
const prevTerminalRef = useRef(false);
|
|
139
|
+
const autoStartedRef = useRef(false);
|
|
140
|
+
|
|
141
|
+
const { create: createSession } = useCreateSession();
|
|
142
|
+
const { create: createExecution } = useCreateAgentExecution();
|
|
143
|
+
const conversationStore = useConversationStoreRef();
|
|
144
|
+
const stream = useExecutionStream(activeExecutionId, {
|
|
145
|
+
store: conversationStore,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// ---------------------------------------------------------------------------
|
|
149
|
+
// Build the initial diagnosis message
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
151
|
+
const buildDiagnosisMessage = useCallback((): string => {
|
|
152
|
+
return (
|
|
153
|
+
`Diagnose the failed workflow execution \`${executionIdRef.current}\`.\n\n` +
|
|
154
|
+
"Analyze the failure root cause using the execution status and event log.\n" +
|
|
155
|
+
"If this is a workflow definition error, generate a validated fix.\n" +
|
|
156
|
+
"If this is a runtime error, explain the root cause and suggest operational remediation."
|
|
157
|
+
);
|
|
158
|
+
}, []);
|
|
159
|
+
|
|
160
|
+
// ---------------------------------------------------------------------------
|
|
161
|
+
// Terminal phase detection — extract YAML or transition to ready
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
if (phase !== "streaming") return;
|
|
165
|
+
|
|
166
|
+
const isTerminal =
|
|
167
|
+
stream.phase !== ExecutionPhase.EXECUTION_PHASE_UNSPECIFIED &&
|
|
168
|
+
isTerminalPhase(stream.phase);
|
|
169
|
+
|
|
170
|
+
if (isTerminal && !prevTerminalRef.current) {
|
|
171
|
+
prevTerminalRef.current = true;
|
|
172
|
+
|
|
173
|
+
if (stream.execution) {
|
|
174
|
+
setCompletedExecutions((prev) => [...prev, stream.execution!]);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const result = extractWorkflowYaml(stream.execution);
|
|
178
|
+
if (result) {
|
|
179
|
+
setExtracted(result);
|
|
180
|
+
setPhase("complete");
|
|
181
|
+
} else {
|
|
182
|
+
setPhase("ready");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
setActiveExecutionId(null);
|
|
186
|
+
}
|
|
187
|
+
}, [phase, stream.phase, stream.execution]);
|
|
188
|
+
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
// Stream error surfacing
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
if (stream.error && phase === "streaming") {
|
|
194
|
+
const msg = getUserMessage(stream.error, "Agent stream interrupted");
|
|
195
|
+
setPhase("error");
|
|
196
|
+
setError(msg);
|
|
197
|
+
onErrorRef.current?.(msg);
|
|
198
|
+
}
|
|
199
|
+
}, [stream.error, phase]);
|
|
200
|
+
|
|
201
|
+
// ---------------------------------------------------------------------------
|
|
202
|
+
// Start diagnosis (initial turn)
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
const diagnose = useCallback(async () => {
|
|
205
|
+
if (phase !== "idle" && phase !== "error") return;
|
|
206
|
+
|
|
207
|
+
setPhase("starting");
|
|
208
|
+
setError(null);
|
|
209
|
+
setExtracted(null);
|
|
210
|
+
prevTerminalRef.current = false;
|
|
211
|
+
|
|
212
|
+
try {
|
|
213
|
+
let activeSessionId = sessionIdRef.current;
|
|
214
|
+
|
|
215
|
+
if (!activeSessionId) {
|
|
216
|
+
const { sessionId: newSessionId } = await createSession({
|
|
217
|
+
org: orgRef.current,
|
|
218
|
+
agentRef: { ...AGENT_REF, org: orgRef.current },
|
|
219
|
+
});
|
|
220
|
+
sessionIdRef.current = newSessionId;
|
|
221
|
+
activeSessionId = newSessionId;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const message = buildDiagnosisMessage();
|
|
225
|
+
|
|
226
|
+
const { executionId: newExecutionId } = await createExecution({
|
|
227
|
+
org: orgRef.current,
|
|
228
|
+
sessionId: activeSessionId,
|
|
229
|
+
message,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
setActiveExecutionId(newExecutionId);
|
|
233
|
+
setPhase("streaming");
|
|
234
|
+
} catch (err) {
|
|
235
|
+
const msg = getUserMessage(
|
|
236
|
+
err,
|
|
237
|
+
"Failed to start the Workflow Architect agent",
|
|
238
|
+
);
|
|
239
|
+
setPhase("error");
|
|
240
|
+
setError(msg);
|
|
241
|
+
onErrorRef.current?.(msg);
|
|
242
|
+
}
|
|
243
|
+
}, [phase, createSession, createExecution, buildDiagnosisMessage]);
|
|
244
|
+
|
|
245
|
+
// ---------------------------------------------------------------------------
|
|
246
|
+
// Send a follow-up question
|
|
247
|
+
// ---------------------------------------------------------------------------
|
|
248
|
+
const sendFollowUp = useCallback(
|
|
249
|
+
async (message: string) => {
|
|
250
|
+
const trimmed = message.trim();
|
|
251
|
+
if (trimmed.length < MIN_FOLLOWUP_LENGTH) {
|
|
252
|
+
setError(
|
|
253
|
+
`Follow-up must be at least ${MIN_FOLLOWUP_LENGTH} characters`,
|
|
254
|
+
);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (
|
|
259
|
+
phase !== "ready" &&
|
|
260
|
+
phase !== "complete" &&
|
|
261
|
+
phase !== "error"
|
|
262
|
+
) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
setPhase("starting");
|
|
267
|
+
setError(null);
|
|
268
|
+
setExtracted(null);
|
|
269
|
+
prevTerminalRef.current = false;
|
|
270
|
+
|
|
271
|
+
try {
|
|
272
|
+
let activeSessionId = sessionIdRef.current;
|
|
273
|
+
|
|
274
|
+
if (!activeSessionId) {
|
|
275
|
+
const { sessionId: newSessionId } = await createSession({
|
|
276
|
+
org: orgRef.current,
|
|
277
|
+
agentRef: { ...AGENT_REF, org: orgRef.current },
|
|
278
|
+
});
|
|
279
|
+
sessionIdRef.current = newSessionId;
|
|
280
|
+
activeSessionId = newSessionId;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const { executionId: newExecutionId } = await createExecution({
|
|
284
|
+
org: orgRef.current,
|
|
285
|
+
sessionId: activeSessionId,
|
|
286
|
+
message: trimmed,
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
setActiveExecutionId(newExecutionId);
|
|
290
|
+
setPhase("streaming");
|
|
291
|
+
} catch (err) {
|
|
292
|
+
const msg = getUserMessage(
|
|
293
|
+
err,
|
|
294
|
+
"Failed to send follow-up to the Workflow Architect agent",
|
|
295
|
+
);
|
|
296
|
+
setPhase("error");
|
|
297
|
+
setError(msg);
|
|
298
|
+
onErrorRef.current?.(msg);
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
[phase, createSession, createExecution],
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
// ---------------------------------------------------------------------------
|
|
305
|
+
// Accept / discard extracted YAML fix
|
|
306
|
+
// ---------------------------------------------------------------------------
|
|
307
|
+
const acceptFix = useCallback((): string | null => {
|
|
308
|
+
if (phase !== "complete" || !extracted) return null;
|
|
309
|
+
const yaml = extracted.yaml;
|
|
310
|
+
setExtracted(null);
|
|
311
|
+
setPhase("ready");
|
|
312
|
+
return yaml;
|
|
313
|
+
}, [phase, extracted]);
|
|
314
|
+
|
|
315
|
+
const discardFix = useCallback(() => {
|
|
316
|
+
if (phase !== "complete") return;
|
|
317
|
+
setExtracted(null);
|
|
318
|
+
setPhase("ready");
|
|
319
|
+
}, [phase]);
|
|
320
|
+
|
|
321
|
+
// ---------------------------------------------------------------------------
|
|
322
|
+
// Reset all state
|
|
323
|
+
// ---------------------------------------------------------------------------
|
|
324
|
+
const reset = useCallback(() => {
|
|
325
|
+
setPhase("idle");
|
|
326
|
+
setActiveExecutionId(null);
|
|
327
|
+
setCompletedExecutions([]);
|
|
328
|
+
setExtracted(null);
|
|
329
|
+
setError(null);
|
|
330
|
+
sessionIdRef.current = null;
|
|
331
|
+
prevTerminalRef.current = false;
|
|
332
|
+
autoStartedRef.current = false;
|
|
333
|
+
}, []);
|
|
334
|
+
|
|
335
|
+
// ---------------------------------------------------------------------------
|
|
336
|
+
// Auto-start on mount (AD-B5-002)
|
|
337
|
+
// ---------------------------------------------------------------------------
|
|
338
|
+
useEffect(() => {
|
|
339
|
+
if (autoStart && phase === "idle" && !autoStartedRef.current) {
|
|
340
|
+
autoStartedRef.current = true;
|
|
341
|
+
diagnose();
|
|
342
|
+
}
|
|
343
|
+
}, [autoStart, phase, diagnose]);
|
|
344
|
+
|
|
345
|
+
// ---------------------------------------------------------------------------
|
|
346
|
+
// Referentially stable return (DD-010)
|
|
347
|
+
// ---------------------------------------------------------------------------
|
|
348
|
+
return useMemo(
|
|
349
|
+
() => ({
|
|
350
|
+
phase,
|
|
351
|
+
completedExecutions,
|
|
352
|
+
activeExecution: stream.execution,
|
|
353
|
+
isStreaming: stream.isStreaming || stream.isConnecting,
|
|
354
|
+
extractedYaml: extracted?.yaml ?? null,
|
|
355
|
+
explanation: extracted?.explanation ?? null,
|
|
356
|
+
error,
|
|
357
|
+
diagnose,
|
|
358
|
+
sendFollowUp,
|
|
359
|
+
acceptFix,
|
|
360
|
+
discardFix,
|
|
361
|
+
reset,
|
|
362
|
+
}),
|
|
363
|
+
[
|
|
364
|
+
phase,
|
|
365
|
+
completedExecutions,
|
|
366
|
+
stream.execution,
|
|
367
|
+
stream.isStreaming,
|
|
368
|
+
stream.isConnecting,
|
|
369
|
+
extracted,
|
|
370
|
+
error,
|
|
371
|
+
diagnose,
|
|
372
|
+
sendFollowUp,
|
|
373
|
+
acceptFix,
|
|
374
|
+
discardFix,
|
|
375
|
+
reset,
|
|
376
|
+
],
|
|
377
|
+
);
|
|
378
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, useCallback, useRef, useEffect } from "react";
|
|
4
|
+
import type { RefObject } from "react";
|
|
5
|
+
import type { WorkflowGraphModel } from "./workflow-graph-model";
|
|
6
|
+
import type { GraphCommand } from "./graph-commands";
|
|
7
|
+
import { GraphHistory } from "./graph-commands";
|
|
8
|
+
|
|
9
|
+
/** Return value of {@link useGraphHistory}. */
|
|
10
|
+
export interface UseGraphHistoryReturn {
|
|
11
|
+
readonly currentModel: WorkflowGraphModel;
|
|
12
|
+
readonly canUndo: boolean;
|
|
13
|
+
readonly canRedo: boolean;
|
|
14
|
+
readonly dispatch: (command: GraphCommand) => WorkflowGraphModel;
|
|
15
|
+
readonly undo: () => void;
|
|
16
|
+
readonly redo: () => void;
|
|
17
|
+
readonly reset: (model: WorkflowGraphModel) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* React wrapper around {@link GraphHistory} providing undo/redo state
|
|
22
|
+
* management and keyboard shortcut binding.
|
|
23
|
+
*
|
|
24
|
+
* Keyboard shortcuts (Ctrl/Cmd+Z, Ctrl/Cmd+Shift+Z) are only active
|
|
25
|
+
* when the referenced container element contains the active focus target,
|
|
26
|
+
* preventing conflicts with other editors on the page.
|
|
27
|
+
*
|
|
28
|
+
* @param initialModel - The starting graph model (from YAML parse).
|
|
29
|
+
* @param containerRef - Ref to the DOM element that scopes keyboard shortcuts.
|
|
30
|
+
*
|
|
31
|
+
* @since T15 Batch 2 (Node Authoring)
|
|
32
|
+
*/
|
|
33
|
+
export function useGraphHistory(
|
|
34
|
+
initialModel: WorkflowGraphModel | null,
|
|
35
|
+
containerRef: RefObject<HTMLDivElement | null>,
|
|
36
|
+
): UseGraphHistoryReturn {
|
|
37
|
+
const historyRef = useRef<GraphHistory | null>(null);
|
|
38
|
+
const [model, setModel] = useState<WorkflowGraphModel | null>(null);
|
|
39
|
+
const [, setVersion] = useState(0);
|
|
40
|
+
|
|
41
|
+
if (initialModel && !historyRef.current) {
|
|
42
|
+
historyRef.current = new GraphHistory(initialModel);
|
|
43
|
+
if (!model) {
|
|
44
|
+
setModel(initialModel);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const forceUpdate = useCallback(() => {
|
|
49
|
+
setVersion((v) => v + 1);
|
|
50
|
+
}, []);
|
|
51
|
+
|
|
52
|
+
const dispatch = useCallback(
|
|
53
|
+
(command: GraphCommand): WorkflowGraphModel => {
|
|
54
|
+
const history = historyRef.current;
|
|
55
|
+
if (!history) throw new Error("GraphHistory not initialized.");
|
|
56
|
+
const next = history.dispatch(command);
|
|
57
|
+
setModel(next);
|
|
58
|
+
forceUpdate();
|
|
59
|
+
return next;
|
|
60
|
+
},
|
|
61
|
+
[forceUpdate],
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const undo = useCallback(() => {
|
|
65
|
+
const history = historyRef.current;
|
|
66
|
+
if (!history?.canUndo) return;
|
|
67
|
+
const next = history.undo();
|
|
68
|
+
setModel(next);
|
|
69
|
+
forceUpdate();
|
|
70
|
+
}, [forceUpdate]);
|
|
71
|
+
|
|
72
|
+
const redo = useCallback(() => {
|
|
73
|
+
const history = historyRef.current;
|
|
74
|
+
if (!history?.canRedo) return;
|
|
75
|
+
const next = history.redo();
|
|
76
|
+
setModel(next);
|
|
77
|
+
forceUpdate();
|
|
78
|
+
}, [forceUpdate]);
|
|
79
|
+
|
|
80
|
+
const reset = useCallback(
|
|
81
|
+
(newModel: WorkflowGraphModel) => {
|
|
82
|
+
if (historyRef.current) {
|
|
83
|
+
historyRef.current.reset(newModel);
|
|
84
|
+
} else {
|
|
85
|
+
historyRef.current = new GraphHistory(newModel);
|
|
86
|
+
}
|
|
87
|
+
setModel(newModel);
|
|
88
|
+
forceUpdate();
|
|
89
|
+
},
|
|
90
|
+
[forceUpdate],
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// Keyboard shortcuts: Ctrl/Cmd+Z (undo), Ctrl/Cmd+Shift+Z (redo)
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
const container = containerRef.current;
|
|
96
|
+
if (!container) return;
|
|
97
|
+
|
|
98
|
+
function handleKeyDown(e: KeyboardEvent) {
|
|
99
|
+
if (!container?.contains(document.activeElement) && document.activeElement !== container) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const isMod = e.metaKey || e.ctrlKey;
|
|
104
|
+
if (!isMod || e.key.toLowerCase() !== "z") return;
|
|
105
|
+
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
e.stopPropagation();
|
|
108
|
+
|
|
109
|
+
if (e.shiftKey) {
|
|
110
|
+
redo();
|
|
111
|
+
} else {
|
|
112
|
+
undo();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
document.addEventListener("keydown", handleKeyDown, true);
|
|
117
|
+
return () => document.removeEventListener("keydown", handleKeyDown, true);
|
|
118
|
+
}, [containerRef, undo, redo]);
|
|
119
|
+
|
|
120
|
+
const canUndo = historyRef.current?.canUndo ?? false;
|
|
121
|
+
const canRedo = historyRef.current?.canRedo ?? false;
|
|
122
|
+
|
|
123
|
+
const emptyModel: WorkflowGraphModel = {
|
|
124
|
+
document: { dsl: "1.0.0", namespace: "", name: "", version: "0.0.1" },
|
|
125
|
+
nodes: [],
|
|
126
|
+
edges: [],
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
currentModel: model ?? emptyModel,
|
|
131
|
+
canUndo,
|
|
132
|
+
canRedo,
|
|
133
|
+
dispatch,
|
|
134
|
+
undo,
|
|
135
|
+
redo,
|
|
136
|
+
reset,
|
|
137
|
+
};
|
|
138
|
+
}
|