orcheo-studio 0.21.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/.bumpversion.cfg +14 -0
- package/.eslintrc +1 -0
- package/CHANGELOG.md +32 -0
- package/README.md +60 -0
- package/bin/orcheo-studio.js +39 -0
- package/components.json +21 -0
- package/dist/assets/arc-BbeTokFd.js +1 -0
- package/dist/assets/architectureDiagram-VXUJARFQ-CN00R9LC.js +36 -0
- package/dist/assets/avatar-01-CIAd4XAq.svg +1 -0
- package/dist/assets/avatar-02-BkgLJWQZ.svg +1 -0
- package/dist/assets/avatar-03-DVVcnD3b.svg +1 -0
- package/dist/assets/avatar-04-ydqFTDdh.svg +1 -0
- package/dist/assets/avatar-05-CSIhgJow.svg +1 -0
- package/dist/assets/avatar-06-B-h1Nz9Y.svg +1 -0
- package/dist/assets/avatar-07-BgkDZuBW.svg +1 -0
- package/dist/assets/avatar-08-C5KZjVH6.svg +1 -0
- package/dist/assets/avatar-09-2EGeSlPh.svg +1 -0
- package/dist/assets/avatar-10-DRf4ZGD2.svg +1 -0
- package/dist/assets/avatar-11-CEzBCpib.svg +1 -0
- package/dist/assets/avatar-12-COVngNEy.svg +1 -0
- package/dist/assets/avatar-13-D1i1tZVO.svg +1 -0
- package/dist/assets/avatar-14-B68CNAEs.svg +1 -0
- package/dist/assets/avatar-15-B9NsRNUX.svg +1 -0
- package/dist/assets/avatar-16-DQ_JJRGR.svg +1 -0
- package/dist/assets/avatar-17-DfDJkGv5.svg +1 -0
- package/dist/assets/avatar-18-BuxiqOaJ.svg +1 -0
- package/dist/assets/avatar-19-C2mJfrwW.svg +1 -0
- package/dist/assets/avatar-20-DPE_yE1a.svg +1 -0
- package/dist/assets/avatar-21-DbB0Lj6t.svg +1 -0
- package/dist/assets/blockDiagram-VD42YOAC-BPpieIRz.js +122 -0
- package/dist/assets/c4Diagram-YG6GDRKO-DAhuY1fj.js +10 -0
- package/dist/assets/channel-DtVQHWfl.js +1 -0
- package/dist/assets/chunk-4BX2VUAB-7RJQCroR.js +1 -0
- package/dist/assets/chunk-55IACEB6-CEN5yOA_.js +1 -0
- package/dist/assets/chunk-B4BG7PRW-vdlAz_3Q.js +165 -0
- package/dist/assets/chunk-DI55MBZ5-BTmKjGVg.js +220 -0
- package/dist/assets/chunk-FMBD7UC4-CwWvFfrg.js +15 -0
- package/dist/assets/chunk-QN33PNHL-XH90lUUN.js +1 -0
- package/dist/assets/chunk-QZHKN3VN-DMoMVES0.js +1 -0
- package/dist/assets/chunk-TZMSLE5B-Bx2XTXDY.js +1 -0
- package/dist/assets/classDiagram-2ON5EDUG-pw6P8q-u.js +1 -0
- package/dist/assets/classDiagram-v2-WZHVMYZB-pw6P8q-u.js +1 -0
- package/dist/assets/clone-DJq6GzHg.js +1 -0
- package/dist/assets/cose-bilkent-S5V4N54A-DS1MNwZB.js +1 -0
- package/dist/assets/cytoscape.esm-BQaXIfA_.js +331 -0
- package/dist/assets/dagre-6UL2VRFP-DdklXSXB.js +4 -0
- package/dist/assets/defaultLocale-C4B-KCzX.js +1 -0
- package/dist/assets/diagram-PSM6KHXK-BKBo8pqg.js +24 -0
- package/dist/assets/diagram-QEK2KX5R-DaavZhFO.js +43 -0
- package/dist/assets/diagram-S2PKOQOG-DkTwknYd.js +24 -0
- package/dist/assets/erDiagram-Q2GNP2WA-ClR5qEsI.js +60 -0
- package/dist/assets/flowDiagram-NV44I4VS-Cxt_sJHB.js +162 -0
- package/dist/assets/ganttDiagram-JELNMOA3-CIbs3JPJ.js +267 -0
- package/dist/assets/gitGraphDiagram-V2S2FVAM-DmqLh_uo.js +65 -0
- package/dist/assets/graph-zo28rS-a.js +1 -0
- package/dist/assets/index-B0_h2wCA.css +1 -0
- package/dist/assets/index-Be29_rJf.js +775 -0
- package/dist/assets/infoDiagram-HS3SLOUP-D9_rMkAf.js +2 -0
- package/dist/assets/init-Gi6I4Gst.js +1 -0
- package/dist/assets/isUndefined-C59bc74c.js +1 -0
- package/dist/assets/journeyDiagram-XKPGCS4Q-4ZuggLXE.js +139 -0
- package/dist/assets/kanban-definition-3W4ZIXB7-BQDNrhHL.js +89 -0
- package/dist/assets/katex-CBSAILhF.js +261 -0
- package/dist/assets/layout-CXbNm-Yo.js +1 -0
- package/dist/assets/linear-DQWATg1F.js +1 -0
- package/dist/assets/min-DJjRzMm8.js +1 -0
- package/dist/assets/mindmap-definition-VGOIOE7T-DiZQmsHT.js +68 -0
- package/dist/assets/ordinal-Cboi1Yqb.js +1 -0
- package/dist/assets/pieDiagram-ADFJNKIX-Bkju7jCD.js +30 -0
- package/dist/assets/quadrantDiagram-AYHSOK5B-CIB47UvU.js +7 -0
- package/dist/assets/requirementDiagram-UZGBJVZJ-BSB3uACk.js +64 -0
- package/dist/assets/sankeyDiagram-TZEHDZUN-rB8wD2kd.js +10 -0
- package/dist/assets/sequenceDiagram-WL72ISMW-Cd9s3Q_1.js +145 -0
- package/dist/assets/stateDiagram-FKZM4ZOC-zAxtjcM9.js +1 -0
- package/dist/assets/stateDiagram-v2-4FDKWEC3-C4DctH65.js +1 -0
- package/dist/assets/timeline-definition-IT6M3QCI-Et89F1F3.js +61 -0
- package/dist/assets/treemap-GDKQZRPO-6mZVX2Gv.js +162 -0
- package/dist/assets/xychartDiagram-PRI3JC2R-CgyY8dNz.js +7 -0
- package/dist/favicon.ico +0 -0
- package/dist/index.html +19 -0
- package/dist/robots.txt +2 -0
- package/eslint.config.js +49 -0
- package/index.html +18 -0
- package/package.json +183 -0
- package/postcss.config.js +6 -0
- package/public/favicon.ico +0 -0
- package/public/robots.txt +2 -0
- package/src/App.tsx +115 -0
- package/src/assets/avatars/avatar-01.svg +1 -0
- package/src/assets/avatars/avatar-02.svg +1 -0
- package/src/assets/avatars/avatar-03.svg +1 -0
- package/src/assets/avatars/avatar-04.svg +1 -0
- package/src/assets/avatars/avatar-05.svg +1 -0
- package/src/assets/avatars/avatar-06.svg +1 -0
- package/src/assets/avatars/avatar-07.svg +1 -0
- package/src/assets/avatars/avatar-08.svg +1 -0
- package/src/assets/avatars/avatar-09.svg +1 -0
- package/src/assets/avatars/avatar-10.svg +1 -0
- package/src/assets/avatars/avatar-11.svg +1 -0
- package/src/assets/avatars/avatar-12.svg +1 -0
- package/src/assets/avatars/avatar-13.svg +1 -0
- package/src/assets/avatars/avatar-14.svg +1 -0
- package/src/assets/avatars/avatar-15.svg +1 -0
- package/src/assets/avatars/avatar-16.svg +1 -0
- package/src/assets/avatars/avatar-17.svg +1 -0
- package/src/assets/avatars/avatar-18.svg +1 -0
- package/src/assets/avatars/avatar-19.svg +1 -0
- package/src/assets/avatars/avatar-20.svg +1 -0
- package/src/assets/avatars/avatar-21.svg +1 -0
- package/src/assets/avatars/index.ts +99 -0
- package/src/design-system/ui/alert-dialog.tsx +141 -0
- package/src/design-system/ui/alert.tsx +59 -0
- package/src/design-system/ui/avatar.tsx +51 -0
- package/src/design-system/ui/badge.tsx +38 -0
- package/src/design-system/ui/button.tsx +59 -0
- package/src/design-system/ui/card.tsx +83 -0
- package/src/design-system/ui/dialog.tsx +122 -0
- package/src/design-system/ui/dropdown-menu.tsx +201 -0
- package/src/design-system/ui/input.tsx +22 -0
- package/src/design-system/ui/label.tsx +26 -0
- package/src/design-system/ui/scroll-area.tsx +48 -0
- package/src/design-system/ui/select.tsx +159 -0
- package/src/design-system/ui/separator.tsx +31 -0
- package/src/design-system/ui/sheet.tsx +141 -0
- package/src/design-system/ui/skeleton.tsx +15 -0
- package/src/design-system/ui/switch.tsx +29 -0
- package/src/design-system/ui/table.tsx +120 -0
- package/src/design-system/ui/tabs.tsx +55 -0
- package/src/design-system/ui/textarea.tsx +22 -0
- package/src/design-system/ui/toast.tsx +132 -0
- package/src/design-system/ui/toaster.tsx +35 -0
- package/src/design-system/ui/toggle-group.tsx +61 -0
- package/src/design-system/ui/toggle.tsx +46 -0
- package/src/design-system/ui/tooltip.tsx +32 -0
- package/src/features/MODULES.md +199 -0
- package/src/features/account/components/settings/appearance-settings-tab.tsx +24 -0
- package/src/features/account/components/theme-settings.tsx +70 -0
- package/src/features/account/components/use-theme-preferences.ts +106 -0
- package/src/features/account/pages/profile/components/profile-general-tab.tsx +89 -0
- package/src/features/account/pages/profile/types.ts +7 -0
- package/src/features/account/pages/profile.tsx +71 -0
- package/src/features/account/pages/service-tokens.tsx +522 -0
- package/src/features/account/pages/settings.tsx +42 -0
- package/src/features/account/pages/workspace-management.tsx +63 -0
- package/src/features/account/pages/workspace-members.tsx +335 -0
- package/src/features/auth/components/auto-login.tsx +51 -0
- package/src/features/auth/components/require-auth.tsx +56 -0
- package/src/features/auth/lib/auth-session.ts +448 -0
- package/src/features/auth/lib/oidc-client.ts +565 -0
- package/src/features/auth/pages/login.tsx +24 -0
- package/src/features/auth/pages/oauth-callback.tsx +63 -0
- package/src/features/chatkit/components/chatkit-surface.tsx +60 -0
- package/src/features/chatkit/components/public-chat-config.ts +70 -0
- package/src/features/chatkit/components/public-chat-error-boundary.tsx +74 -0
- package/src/features/chatkit/components/public-chat-widget.tsx +150 -0
- package/src/features/chatkit/components/studio-chat-bubble.tsx +451 -0
- package/src/features/chatkit/lib/chatkit-attachments.ts +31 -0
- package/src/features/chatkit/lib/chatkit-client.ts +195 -0
- package/src/features/chatkit/lib/chatkit-theme.ts +20 -0
- package/src/features/chatkit/lib/telemetry.ts +29 -0
- package/src/features/chatkit/lib/workflow-session.ts +70 -0
- package/src/features/chatkit/pages/public-chat.tsx +445 -0
- package/src/features/shared/components/chat-interface-options.ts +325 -0
- package/src/features/shared/components/chat-interface.types.ts +47 -0
- package/src/features/shared/components/top-navigation/account-menu.tsx +172 -0
- package/src/features/shared/components/top-navigation/active-workspace-indicator.tsx +280 -0
- package/src/features/shared/components/top-navigation/studio-brand.tsx +59 -0
- package/src/features/shared/components/top-navigation/top-navigation-types.ts +22 -0
- package/src/features/shared/components/top-navigation/version-status.tsx +280 -0
- package/src/features/shared/components/top-navigation.tsx +42 -0
- package/src/features/shared/components/workspace-bootstrap-gate.tsx +235 -0
- package/src/features/workflow/components/dialogs/add-credential-dialog.tsx +245 -0
- package/src/features/workflow/components/dialogs/confirm-delete-workflow-dialog.tsx +52 -0
- package/src/features/workflow/components/dialogs/credential-access-badge.tsx +34 -0
- package/src/features/workflow/components/dialogs/credential-status-badge.tsx +45 -0
- package/src/features/workflow/components/dialogs/credentials-table.tsx +453 -0
- package/src/features/workflow/components/dialogs/credentials-vault.tsx +85 -0
- package/src/features/workflow/components/dialogs/edit-credential-dialog.tsx +264 -0
- package/src/features/workflow/components/dialogs/update-workflow-dialog.tsx +214 -0
- package/src/features/workflow/components/dialogs/upload-workflow-dialog.tsx +288 -0
- package/src/features/workflow/components/forms/schema-config-form.tsx +41 -0
- package/src/features/workflow/components/layouts/sidebar-layout.tsx +288 -0
- package/src/features/workflow/components/layouts/use-sidebar-resize.ts +164 -0
- package/src/features/workflow/components/layouts/workflow-page-layout.tsx +69 -0
- package/src/features/workflow/components/panels/json-object-field.tsx +138 -0
- package/src/features/workflow/components/panels/rjsf-basic-widgets.tsx +21 -0
- package/src/features/workflow/components/panels/rjsf-input-widgets.tsx +105 -0
- package/src/features/workflow/components/panels/rjsf-templates.tsx +147 -0
- package/src/features/workflow/components/panels/rjsf-text-widgets.tsx +139 -0
- package/src/features/workflow/components/panels/rjsf-theme.tsx +10 -0
- package/src/features/workflow/components/panels/schema-dnd.ts +79 -0
- package/src/features/workflow/components/panels/workflow-diff-dialog.tsx +207 -0
- package/src/features/workflow/components/panels/workflow-history-filters.tsx +62 -0
- package/src/features/workflow/components/panels/workflow-history-footer.tsx +28 -0
- package/src/features/workflow/components/panels/workflow-history-header.tsx +47 -0
- package/src/features/workflow/components/panels/workflow-history-table.tsx +148 -0
- package/src/features/workflow/components/panels/workflow-history.tsx +150 -0
- package/src/features/workflow/components/panels/workflow-tabs.tsx +29 -0
- package/src/features/workflow/components/trace/agent-prism/Avatar.tsx +146 -0
- package/src/features/workflow/components/trace/agent-prism/Badge.tsx +95 -0
- package/src/features/workflow/components/trace/agent-prism/BrandLogo.tsx +102 -0
- package/src/features/workflow/components/trace/agent-prism/Button.tsx +124 -0
- package/src/features/workflow/components/trace/agent-prism/CollapseAndExpandControls.tsx +45 -0
- package/src/features/workflow/components/trace/agent-prism/CollapsibleSection.tsx +124 -0
- package/src/features/workflow/components/trace/agent-prism/CopyButton.tsx +63 -0
- package/src/features/workflow/components/trace/agent-prism/DetailsView/DetailsView.tsx +146 -0
- package/src/features/workflow/components/trace/agent-prism/DetailsView/DetailsViewAttributesTab.tsx +125 -0
- package/src/features/workflow/components/trace/agent-prism/DetailsView/DetailsViewContentViewer.tsx +51 -0
- package/src/features/workflow/components/trace/agent-prism/DetailsView/DetailsViewHeader.tsx +100 -0
- package/src/features/workflow/components/trace/agent-prism/DetailsView/DetailsViewInputOutputTab.tsx +401 -0
- package/src/features/workflow/components/trace/agent-prism/DetailsView/DetailsViewJsonOutput.tsx +33 -0
- package/src/features/workflow/components/trace/agent-prism/DetailsView/DetailsViewRawDataTab.tsx +27 -0
- package/src/features/workflow/components/trace/agent-prism/IconButton.tsx +75 -0
- package/src/features/workflow/components/trace/agent-prism/PriceBadge.tsx +14 -0
- package/src/features/workflow/components/trace/agent-prism/SearchInput.tsx +17 -0
- package/src/features/workflow/components/trace/agent-prism/SpanBadge.tsx +54 -0
- package/src/features/workflow/components/trace/agent-prism/SpanCard/SpanCard.tsx +480 -0
- package/src/features/workflow/components/trace/agent-prism/SpanCard/SpanCardBadges.tsx +23 -0
- package/src/features/workflow/components/trace/agent-prism/SpanCard/SpanCardConnector.tsx +36 -0
- package/src/features/workflow/components/trace/agent-prism/SpanCard/SpanCardTimeline.tsx +60 -0
- package/src/features/workflow/components/trace/agent-prism/SpanCard/SpanCardToggle.tsx +39 -0
- package/src/features/workflow/components/trace/agent-prism/SpanStatus.tsx +80 -0
- package/src/features/workflow/components/trace/agent-prism/TabSelector.tsx +35 -0
- package/src/features/workflow/components/trace/agent-prism/Tabs.tsx +140 -0
- package/src/features/workflow/components/trace/agent-prism/TextInput.tsx +143 -0
- package/src/features/workflow/components/trace/agent-prism/TimestampBadge.tsx +22 -0
- package/src/features/workflow/components/trace/agent-prism/TokensBadge.tsx +27 -0
- package/src/features/workflow/components/trace/agent-prism/TraceList/TraceList.tsx +123 -0
- package/src/features/workflow/components/trace/agent-prism/TraceList/TraceListItem.tsx +86 -0
- package/src/features/workflow/components/trace/agent-prism/TraceList/TraceListItemHeader.tsx +37 -0
- package/src/features/workflow/components/trace/agent-prism/TraceViewer/TraceViewer.tsx +208 -0
- package/src/features/workflow/components/trace/agent-prism/TraceViewer/TraceViewerDesktopLayout.tsx +99 -0
- package/src/features/workflow/components/trace/agent-prism/TraceViewer/TraceViewerMobileLayout.tsx +103 -0
- package/src/features/workflow/components/trace/agent-prism/TraceViewer/TraceViewerPlaceholder.tsx +5 -0
- package/src/features/workflow/components/trace/agent-prism/TraceViewer/TraceViewerSearchAndControls.tsx +30 -0
- package/src/features/workflow/components/trace/agent-prism/TraceViewer/TraceViewerTreeViewContainer.tsx +76 -0
- package/src/features/workflow/components/trace/agent-prism/TraceViewer/useTraceSelection.ts +186 -0
- package/src/features/workflow/components/trace/agent-prism/TreeView.tsx +73 -0
- package/src/features/workflow/components/trace/agent-prism/index.ts +7 -0
- package/src/features/workflow/components/trace/agent-prism/shared.ts +170 -0
- package/src/features/workflow/components/trace/agent-prism/theme/index.ts +101 -0
- package/src/features/workflow/components/trace/agent-prism/theme/theme.css +247 -0
- package/src/features/workflow/data/templates/assets/vibe-agent/config.json +5 -0
- package/src/features/workflow/data/templates/candidate-badges.ts +138 -0
- package/src/features/workflow/data/templates/index.ts +29 -0
- package/src/features/workflow/data/templates/template-definition.ts +77 -0
- package/src/features/workflow/data/templates/template-owner.ts +7 -0
- package/src/features/workflow/data/workflow-data.ts +8 -0
- package/src/features/workflow/data/workflow-types.ts +57 -0
- package/src/features/workflow/lib/mermaid-renderer.ts +334 -0
- package/src/features/workflow/lib/workflow-diff.ts +191 -0
- package/src/features/workflow/lib/workflow-execution-builders.ts +103 -0
- package/src/features/workflow/lib/workflow-execution-formatters.ts +145 -0
- package/src/features/workflow/lib/workflow-execution-storage.ts +63 -0
- package/src/features/workflow/lib/workflow-execution.types.ts +80 -0
- package/src/features/workflow/lib/workflow-storage-api.ts +581 -0
- package/src/features/workflow/lib/workflow-storage-helpers.ts +373 -0
- package/src/features/workflow/lib/workflow-storage-versioning.ts +127 -0
- package/src/features/workflow/lib/workflow-storage.constants.ts +21 -0
- package/src/features/workflow/lib/workflow-storage.ts +482 -0
- package/src/features/workflow/lib/workflow-storage.types.ts +261 -0
- package/src/features/workflow/pages/workflow/components/settings-tab-content.tsx +428 -0
- package/src/features/workflow/pages/workflow/components/trace-tab-content.tsx +183 -0
- package/src/features/workflow/pages/workflow/components/workflow-config-sheet.tsx +207 -0
- package/src/features/workflow/pages/workflow/components/workflow-config-sheet.utils.ts +275 -0
- package/src/features/workflow/pages/workflow/components/workflow-layout.tsx +143 -0
- package/src/features/workflow/pages/workflow/components/workflow-tab-content.tsx +766 -0
- package/src/features/workflow/pages/workflow/handlers/credentials.ts +338 -0
- package/src/features/workflow/pages/workflow/helpers/execution.ts +39 -0
- package/src/features/workflow/pages/workflow/helpers/trace.ts +838 -0
- package/src/features/workflow/pages/workflow/helpers/types.ts +28 -0
- package/src/features/workflow/pages/workflow/hooks/controller/build-layout-props.ts +171 -0
- package/src/features/workflow/pages/workflow/hooks/controller/use-workflow-controller.ts +19 -0
- package/src/features/workflow/pages/workflow/hooks/controller/use-workflow-core.ts +84 -0
- package/src/features/workflow/pages/workflow/hooks/controller/use-workflow-execution-controller.ts +167 -0
- package/src/features/workflow/pages/workflow/hooks/controller/use-workflow-lifecycle.ts +37 -0
- package/src/features/workflow/pages/workflow/hooks/controller/use-workflow-resources.ts +57 -0
- package/src/features/workflow/pages/workflow/hooks/execution-log-helpers.ts +75 -0
- package/src/features/workflow/pages/workflow/hooks/execution-node-status.ts +46 -0
- package/src/features/workflow/pages/workflow/hooks/execution-record-updater.ts +119 -0
- package/src/features/workflow/pages/workflow/hooks/execution-record.ts +31 -0
- package/src/features/workflow/pages/workflow/hooks/execution-runtime-updates.ts +96 -0
- package/src/features/workflow/pages/workflow/hooks/use-execution-trace.ts +512 -0
- package/src/features/workflow/pages/workflow/hooks/use-execution-updates.ts +125 -0
- package/src/features/workflow/pages/workflow/hooks/use-pause-workflow.ts +70 -0
- package/src/features/workflow/pages/workflow/hooks/use-studio-ui-state.ts +10 -0
- package/src/features/workflow/pages/workflow/hooks/use-workflow-chat.ts +212 -0
- package/src/features/workflow/pages/workflow/hooks/use-workflow-credential-readiness.ts +72 -0
- package/src/features/workflow/pages/workflow/hooks/use-workflow-credentials.ts +167 -0
- package/src/features/workflow/pages/workflow/hooks/use-workflow-execution-state.ts +20 -0
- package/src/features/workflow/pages/workflow/hooks/use-workflow-listeners.ts +182 -0
- package/src/features/workflow/pages/workflow/hooks/use-workflow-loader.ts +236 -0
- package/src/features/workflow/pages/workflow/hooks/use-workflow-metadata-state.ts +56 -0
- package/src/features/workflow/pages/workflow/hooks/use-workflow-saver.ts +191 -0
- package/src/features/workflow/pages/workflow/hooks/use-workflow-storage-listener.ts +81 -0
- package/src/features/workflow/pages/workflow/hooks/workflow-runner-websocket.ts +150 -0
- package/src/features/workflow/pages/workflow-gallery/types.ts +3 -0
- package/src/features/workflow/pages/workflow-gallery/use-workflow-gallery-actions.ts +223 -0
- package/src/features/workflow/pages/workflow-gallery/use-workflow-gallery-state.ts +206 -0
- package/src/features/workflow/pages/workflow-gallery/use-workflow-gallery.ts +14 -0
- package/src/features/workflow/pages/workflow-gallery/workflow-card-size.ts +8 -0
- package/src/features/workflow/pages/workflow-gallery/workflow-card.tsx +327 -0
- package/src/features/workflow/pages/workflow-gallery/workflow-gallery-tabs.tsx +173 -0
- package/src/features/workflow/pages/workflow-gallery.tsx +96 -0
- package/src/features/workflow/pages/workflow.tsx +119 -0
- package/src/features/workflow/types/credential-vault.ts +52 -0
- package/src/hooks/browser-context-provider.tsx +19 -0
- package/src/hooks/use-browser-context.ts +188 -0
- package/src/hooks/use-color-scheme.ts +77 -0
- package/src/hooks/use-credential-vault.ts +442 -0
- package/src/hooks/use-page-context.ts +39 -0
- package/src/hooks/use-toast.ts +182 -0
- package/src/hooks/use-uploads-allowed.ts +28 -0
- package/src/index.css +95 -0
- package/src/lib/api.ts +445 -0
- package/src/lib/auth-fetch.ts +35 -0
- package/src/lib/config.ts +102 -0
- package/src/lib/theme.ts +109 -0
- package/src/lib/utils.ts +6 -0
- package/src/lib/workspace-routing.ts +67 -0
- package/src/lib/workspace-session.ts +66 -0
- package/src/lib/workspace-slug.ts +10 -0
- package/src/main.tsx +28 -0
- package/src/vite-env.d.ts +17 -0
- package/tailwind.config.js +153 -0
- package/tsconfig.app.json +30 -0
- package/tsconfig.json +16 -0
- package/tsconfig.node.json +21 -0
- package/vite.config.ts +122 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { toast } from "@/hooks/use-toast";
|
|
3
|
+
import { authFetch } from "@/lib/auth-fetch";
|
|
4
|
+
import { buildBackendHttpUrl, getBackendBaseUrl } from "@/lib/config";
|
|
5
|
+
import type {
|
|
6
|
+
Credential,
|
|
7
|
+
CredentialInput,
|
|
8
|
+
CredentialSecretResponse,
|
|
9
|
+
CredentialUpdateInput,
|
|
10
|
+
CredentialVaultEntryResponse,
|
|
11
|
+
} from "@features/workflow/types/credential-vault";
|
|
12
|
+
|
|
13
|
+
interface UseCredentialVaultOptions {
|
|
14
|
+
actorName?: string;
|
|
15
|
+
workflowId?: string | null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface UseCredentialVaultResult {
|
|
19
|
+
credentials: Credential[];
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
onAddCredential: (credential: CredentialInput) => Promise<void>;
|
|
22
|
+
onUpdateCredential: (
|
|
23
|
+
id: string,
|
|
24
|
+
updates: CredentialUpdateInput,
|
|
25
|
+
) => Promise<void>;
|
|
26
|
+
onDeleteCredential: (id: string) => Promise<void>;
|
|
27
|
+
onRevealCredentialSecret: (id: string) => Promise<string | null>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const DEFAULT_ACTOR = "system";
|
|
31
|
+
|
|
32
|
+
const mapEntryToCredential = (
|
|
33
|
+
entry: CredentialVaultEntryResponse,
|
|
34
|
+
): Credential => ({
|
|
35
|
+
id: entry.id,
|
|
36
|
+
name: entry.name,
|
|
37
|
+
provider: entry.provider ?? entry.kind,
|
|
38
|
+
type: entry.provider ?? entry.kind,
|
|
39
|
+
workflowId: entry.workflow_id ?? null,
|
|
40
|
+
createdAt: entry.created_at,
|
|
41
|
+
updatedAt: entry.updated_at,
|
|
42
|
+
owner: entry.owner,
|
|
43
|
+
access: entry.access,
|
|
44
|
+
secrets: undefined,
|
|
45
|
+
status: entry.status,
|
|
46
|
+
secretPreview: entry.secret_preview ?? null,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const resolveCredentialWorkflowId = (
|
|
50
|
+
credentials: Credential[],
|
|
51
|
+
credentialId: string,
|
|
52
|
+
fallbackWorkflowId: string | null,
|
|
53
|
+
): string | null =>
|
|
54
|
+
fallbackWorkflowId ??
|
|
55
|
+
credentials.find((credential) => credential.id === credentialId)
|
|
56
|
+
?.workflowId ??
|
|
57
|
+
null;
|
|
58
|
+
|
|
59
|
+
const getCredentialSecret = (
|
|
60
|
+
secrets: Record<string, string> | undefined,
|
|
61
|
+
): string | null => {
|
|
62
|
+
if (!secrets) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const preferredSecret = secrets.apiKey ?? secrets.secret;
|
|
66
|
+
if (preferredSecret && preferredSecret.trim().length > 0) {
|
|
67
|
+
return preferredSecret.trim();
|
|
68
|
+
}
|
|
69
|
+
for (const value of Object.values(secrets)) {
|
|
70
|
+
const candidate = value.trim();
|
|
71
|
+
if (candidate.length > 0) {
|
|
72
|
+
return candidate;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export function useCredentialVault(
|
|
79
|
+
options: UseCredentialVaultOptions = {},
|
|
80
|
+
): UseCredentialVaultResult {
|
|
81
|
+
const { workflowId = null } = options;
|
|
82
|
+
const backendBaseUrl = useMemo(() => getBackendBaseUrl(), []);
|
|
83
|
+
const actorName = options.actorName?.trim() || DEFAULT_ACTOR;
|
|
84
|
+
|
|
85
|
+
const [credentials, setCredentials] = useState<Credential[]>([]);
|
|
86
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
87
|
+
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const controller = new AbortController();
|
|
90
|
+
let isCancelled = false;
|
|
91
|
+
|
|
92
|
+
const fetchCredentials = async () => {
|
|
93
|
+
setIsLoading(true);
|
|
94
|
+
try {
|
|
95
|
+
const url = new URL(
|
|
96
|
+
buildBackendHttpUrl("/api/credentials", backendBaseUrl),
|
|
97
|
+
);
|
|
98
|
+
if (workflowId) {
|
|
99
|
+
url.searchParams.set("workflow_id", workflowId);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const response = await authFetch(url.toString(), {
|
|
103
|
+
signal: controller.signal,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (!response.ok) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
`Failed to load credentials (status ${response.status})`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const payload =
|
|
113
|
+
(await response.json()) as CredentialVaultEntryResponse[];
|
|
114
|
+
|
|
115
|
+
if (isCancelled) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
setCredentials(payload.map(mapEntryToCredential));
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (controller.signal.aborted || isCancelled) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
console.error("Failed to load credential vault", error);
|
|
126
|
+
toast({
|
|
127
|
+
title: "Unable to load credentials",
|
|
128
|
+
description:
|
|
129
|
+
error instanceof Error
|
|
130
|
+
? error.message
|
|
131
|
+
: "An unexpected error occurred while loading credentials.",
|
|
132
|
+
variant: "destructive",
|
|
133
|
+
});
|
|
134
|
+
} finally {
|
|
135
|
+
if (!isCancelled) {
|
|
136
|
+
setIsLoading(false);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
void fetchCredentials();
|
|
142
|
+
|
|
143
|
+
return () => {
|
|
144
|
+
isCancelled = true;
|
|
145
|
+
controller.abort();
|
|
146
|
+
};
|
|
147
|
+
}, [backendBaseUrl, workflowId]);
|
|
148
|
+
|
|
149
|
+
const onAddCredential = useCallback(
|
|
150
|
+
async (credential: CredentialInput) => {
|
|
151
|
+
const secret = getCredentialSecret(credential.secrets);
|
|
152
|
+
if (!secret) {
|
|
153
|
+
const message = "Credential secret is required to save a credential.";
|
|
154
|
+
toast({
|
|
155
|
+
title: "Missing credential secret",
|
|
156
|
+
description: message,
|
|
157
|
+
variant: "destructive",
|
|
158
|
+
});
|
|
159
|
+
throw new Error(message);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const response = await authFetch(
|
|
163
|
+
buildBackendHttpUrl("/api/credentials", backendBaseUrl),
|
|
164
|
+
{
|
|
165
|
+
method: "POST",
|
|
166
|
+
headers: {
|
|
167
|
+
"Content-Type": "application/json",
|
|
168
|
+
},
|
|
169
|
+
body: JSON.stringify({
|
|
170
|
+
name: credential.name,
|
|
171
|
+
provider: credential.provider?.trim() || "custom",
|
|
172
|
+
secret,
|
|
173
|
+
actor: actorName,
|
|
174
|
+
access: credential.access,
|
|
175
|
+
workflow_id: workflowId,
|
|
176
|
+
scopes: [],
|
|
177
|
+
}),
|
|
178
|
+
},
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
if (!response.ok) {
|
|
182
|
+
let detail = `Failed to save credential (status ${response.status})`;
|
|
183
|
+
try {
|
|
184
|
+
const payload = (await response.json()) as { detail?: unknown };
|
|
185
|
+
if (typeof payload?.detail === "string") {
|
|
186
|
+
detail = payload.detail;
|
|
187
|
+
} else if (
|
|
188
|
+
payload?.detail &&
|
|
189
|
+
typeof (payload.detail as { message?: unknown }).message ===
|
|
190
|
+
"string"
|
|
191
|
+
) {
|
|
192
|
+
detail = (payload.detail as { message?: string }).message as string;
|
|
193
|
+
}
|
|
194
|
+
} catch (parseError) {
|
|
195
|
+
console.warn("Failed to parse credential creation error", parseError);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
toast({
|
|
199
|
+
title: "Unable to save credential",
|
|
200
|
+
description: detail,
|
|
201
|
+
variant: "destructive",
|
|
202
|
+
});
|
|
203
|
+
throw new Error(detail);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const payload = (await response.json()) as CredentialVaultEntryResponse;
|
|
207
|
+
const credentialRecord: Credential = {
|
|
208
|
+
id: payload.id,
|
|
209
|
+
name: payload.name,
|
|
210
|
+
provider: payload.provider ?? payload.kind,
|
|
211
|
+
type: payload.provider ?? payload.kind,
|
|
212
|
+
workflowId: payload.workflow_id ?? null,
|
|
213
|
+
createdAt: payload.created_at,
|
|
214
|
+
updatedAt: payload.updated_at,
|
|
215
|
+
owner: payload.owner,
|
|
216
|
+
access: payload.access,
|
|
217
|
+
secrets: { secret },
|
|
218
|
+
status: payload.status,
|
|
219
|
+
secretPreview: payload.secret_preview ?? null,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
setCredentials((previous) => {
|
|
223
|
+
const withoutDuplicate = previous.filter(
|
|
224
|
+
(existing) => existing.id !== credentialRecord.id,
|
|
225
|
+
);
|
|
226
|
+
return [...withoutDuplicate, credentialRecord];
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
toast({
|
|
230
|
+
title: "Credential added to vault",
|
|
231
|
+
description: `${credentialRecord.name} is now available for nodes that require secure access.`,
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
[actorName, backendBaseUrl, workflowId],
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const onUpdateCredential = useCallback(
|
|
238
|
+
async (id: string, updates: CredentialUpdateInput) => {
|
|
239
|
+
const secret = getCredentialSecret(updates.secrets);
|
|
240
|
+
const credentialWorkflowId = resolveCredentialWorkflowId(
|
|
241
|
+
credentials,
|
|
242
|
+
id,
|
|
243
|
+
workflowId,
|
|
244
|
+
);
|
|
245
|
+
const payload: Record<string, string> = {
|
|
246
|
+
actor: actorName,
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
if (updates.name !== undefined) {
|
|
250
|
+
payload.name = updates.name;
|
|
251
|
+
}
|
|
252
|
+
if (updates.provider !== undefined) {
|
|
253
|
+
payload.provider = updates.provider;
|
|
254
|
+
} else if (updates.type !== undefined) {
|
|
255
|
+
payload.provider = updates.type;
|
|
256
|
+
}
|
|
257
|
+
if (secret !== null) {
|
|
258
|
+
payload.secret = secret;
|
|
259
|
+
}
|
|
260
|
+
if (updates.access !== undefined) {
|
|
261
|
+
payload.access = updates.access;
|
|
262
|
+
}
|
|
263
|
+
if (credentialWorkflowId) {
|
|
264
|
+
payload.workflow_id = credentialWorkflowId;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const hasChanges = Object.keys(payload).some((key) => key !== "actor");
|
|
268
|
+
if (!hasChanges) {
|
|
269
|
+
const message = "No credential changes were provided.";
|
|
270
|
+
toast({
|
|
271
|
+
title: "Nothing to update",
|
|
272
|
+
description: message,
|
|
273
|
+
variant: "destructive",
|
|
274
|
+
});
|
|
275
|
+
throw new Error(message);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const response = await authFetch(
|
|
279
|
+
buildBackendHttpUrl(`/api/credentials/${id}`, backendBaseUrl),
|
|
280
|
+
{
|
|
281
|
+
method: "PATCH",
|
|
282
|
+
headers: {
|
|
283
|
+
"Content-Type": "application/json",
|
|
284
|
+
},
|
|
285
|
+
body: JSON.stringify(payload),
|
|
286
|
+
},
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
if (!response.ok) {
|
|
290
|
+
let detail = `Failed to update credential (status ${response.status})`;
|
|
291
|
+
try {
|
|
292
|
+
const errorPayload = (await response.json()) as { detail?: unknown };
|
|
293
|
+
if (typeof errorPayload?.detail === "string") {
|
|
294
|
+
detail = errorPayload.detail;
|
|
295
|
+
}
|
|
296
|
+
} catch (parseError) {
|
|
297
|
+
console.warn("Failed to parse credential update error", parseError);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
toast({
|
|
301
|
+
title: "Unable to update credential",
|
|
302
|
+
description: detail,
|
|
303
|
+
variant: "destructive",
|
|
304
|
+
});
|
|
305
|
+
throw new Error(detail);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const updated = (await response.json()) as CredentialVaultEntryResponse;
|
|
309
|
+
setCredentials((previous) =>
|
|
310
|
+
previous.map((credential) => {
|
|
311
|
+
if (credential.id !== id) {
|
|
312
|
+
return credential;
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
...credential,
|
|
316
|
+
name: updated.name,
|
|
317
|
+
provider: updated.provider ?? updated.kind,
|
|
318
|
+
type: updated.provider ?? updated.kind,
|
|
319
|
+
workflowId: updated.workflow_id ?? credential.workflowId ?? null,
|
|
320
|
+
access: updated.access,
|
|
321
|
+
status: updated.status,
|
|
322
|
+
updatedAt: updated.updated_at,
|
|
323
|
+
secrets: secret ? { secret } : credential.secrets,
|
|
324
|
+
secretPreview: updated.secret_preview ?? credential.secretPreview,
|
|
325
|
+
};
|
|
326
|
+
}),
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
toast({
|
|
330
|
+
title: "Credential updated",
|
|
331
|
+
description: "Your credential changes were saved successfully.",
|
|
332
|
+
});
|
|
333
|
+
},
|
|
334
|
+
[actorName, backendBaseUrl, credentials, workflowId],
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
const onDeleteCredential = useCallback(
|
|
338
|
+
async (id: string) => {
|
|
339
|
+
const credentialWorkflowId = resolveCredentialWorkflowId(
|
|
340
|
+
credentials,
|
|
341
|
+
id,
|
|
342
|
+
workflowId,
|
|
343
|
+
);
|
|
344
|
+
const url = new URL(
|
|
345
|
+
buildBackendHttpUrl(`/api/credentials/${id}`, backendBaseUrl),
|
|
346
|
+
);
|
|
347
|
+
if (credentialWorkflowId) {
|
|
348
|
+
url.searchParams.set("workflow_id", credentialWorkflowId);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
try {
|
|
352
|
+
const response = await authFetch(url.toString(), {
|
|
353
|
+
method: "DELETE",
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
if (!response.ok && response.status !== 404) {
|
|
357
|
+
throw new Error(
|
|
358
|
+
`Failed to delete credential (status ${response.status})`,
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
setCredentials((previous) =>
|
|
363
|
+
previous.filter((credential) => credential.id !== id),
|
|
364
|
+
);
|
|
365
|
+
toast({
|
|
366
|
+
title: "Credential removed",
|
|
367
|
+
description:
|
|
368
|
+
"Nodes referencing this credential will require reconfiguration before publish.",
|
|
369
|
+
});
|
|
370
|
+
} catch (error) {
|
|
371
|
+
console.error("Failed to delete credential", error);
|
|
372
|
+
const message =
|
|
373
|
+
error instanceof Error ? error.message : "Credential removal failed.";
|
|
374
|
+
toast({
|
|
375
|
+
title: "Unable to delete credential",
|
|
376
|
+
description: message,
|
|
377
|
+
variant: "destructive",
|
|
378
|
+
});
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
[backendBaseUrl, credentials, workflowId],
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
const onRevealCredentialSecret = useCallback(
|
|
386
|
+
async (id: string) => {
|
|
387
|
+
const credentialWorkflowId = resolveCredentialWorkflowId(
|
|
388
|
+
credentials,
|
|
389
|
+
id,
|
|
390
|
+
workflowId,
|
|
391
|
+
);
|
|
392
|
+
const url = new URL(
|
|
393
|
+
buildBackendHttpUrl(`/api/credentials/${id}/secret`, backendBaseUrl),
|
|
394
|
+
);
|
|
395
|
+
if (credentialWorkflowId) {
|
|
396
|
+
url.searchParams.set("workflow_id", credentialWorkflowId);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const response = await authFetch(url.toString());
|
|
400
|
+
if (!response.ok) {
|
|
401
|
+
let detail = `Failed to reveal credential secret (status ${response.status})`;
|
|
402
|
+
try {
|
|
403
|
+
const payload = (await response.json()) as { detail?: unknown };
|
|
404
|
+
if (typeof payload?.detail === "string") {
|
|
405
|
+
detail = payload.detail;
|
|
406
|
+
}
|
|
407
|
+
} catch (parseError) {
|
|
408
|
+
console.warn("Failed to parse credential reveal error", parseError);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
toast({
|
|
412
|
+
title: "Unable to reveal secret",
|
|
413
|
+
description: detail,
|
|
414
|
+
variant: "destructive",
|
|
415
|
+
});
|
|
416
|
+
throw new Error(detail);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const payload = (await response.json()) as CredentialSecretResponse;
|
|
420
|
+
setCredentials((previous) =>
|
|
421
|
+
previous.map((credential) =>
|
|
422
|
+
credential.id === id
|
|
423
|
+
? { ...credential, secrets: { secret: payload.secret } }
|
|
424
|
+
: credential,
|
|
425
|
+
),
|
|
426
|
+
);
|
|
427
|
+
return payload.secret;
|
|
428
|
+
},
|
|
429
|
+
[backendBaseUrl, credentials, workflowId],
|
|
430
|
+
);
|
|
431
|
+
|
|
432
|
+
return {
|
|
433
|
+
credentials,
|
|
434
|
+
isLoading,
|
|
435
|
+
onAddCredential,
|
|
436
|
+
onUpdateCredential,
|
|
437
|
+
onDeleteCredential,
|
|
438
|
+
onRevealCredentialSecret,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export default useCredentialVault;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for accessing the browser context from page components.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { createContext, useContext } from "react";
|
|
6
|
+
|
|
7
|
+
export interface PageContext {
|
|
8
|
+
page:
|
|
9
|
+
| "gallery"
|
|
10
|
+
| "workflow"
|
|
11
|
+
| "execution"
|
|
12
|
+
| "settings"
|
|
13
|
+
| "profile"
|
|
14
|
+
| "workspace"
|
|
15
|
+
| "other";
|
|
16
|
+
workflowId?: string | null;
|
|
17
|
+
workflowName?: string | null;
|
|
18
|
+
executionId?: string | null;
|
|
19
|
+
activeTab?: string | null;
|
|
20
|
+
vaultOpen?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface BrowserContextValue {
|
|
24
|
+
setPageContext: (ctx: PageContext) => void;
|
|
25
|
+
setVaultOpen: (open: boolean) => void;
|
|
26
|
+
pageContext: PageContext;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const DEFAULT_PAGE_CONTEXT: PageContext = { page: "other" };
|
|
30
|
+
|
|
31
|
+
export const BrowserContext = createContext<BrowserContextValue>({
|
|
32
|
+
setPageContext: () => {},
|
|
33
|
+
setVaultOpen: () => {},
|
|
34
|
+
pageContext: DEFAULT_PAGE_CONTEXT,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export function usePageContext(): BrowserContextValue {
|
|
38
|
+
return useContext(BrowserContext);
|
|
39
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// Inspired by react-hot-toast library
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
|
|
6
|
+
import type { ToastActionElement, ToastProps } from "@/design-system/ui/toast";
|
|
7
|
+
|
|
8
|
+
const TOAST_LIMIT = 1;
|
|
9
|
+
const TOAST_REMOVE_DELAY = 1000000;
|
|
10
|
+
|
|
11
|
+
type ToasterToast = ToastProps & {
|
|
12
|
+
id: string;
|
|
13
|
+
title?: React.ReactNode;
|
|
14
|
+
description?: React.ReactNode;
|
|
15
|
+
action?: ToastActionElement;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
let count = 0;
|
|
19
|
+
|
|
20
|
+
function genId() {
|
|
21
|
+
count = (count + 1) % Number.MAX_SAFE_INTEGER;
|
|
22
|
+
return count.toString();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type Action =
|
|
26
|
+
| {
|
|
27
|
+
type: "ADD_TOAST";
|
|
28
|
+
toast: ToasterToast;
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
type: "UPDATE_TOAST";
|
|
32
|
+
toast: Partial<ToasterToast>;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
type: "DISMISS_TOAST";
|
|
36
|
+
toastId?: ToasterToast["id"];
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
type: "REMOVE_TOAST";
|
|
40
|
+
toastId?: ToasterToast["id"];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
interface State {
|
|
44
|
+
toasts: ToasterToast[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>();
|
|
48
|
+
|
|
49
|
+
const addToRemoveQueue = (toastId: string) => {
|
|
50
|
+
if (toastTimeouts.has(toastId)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const timeout = setTimeout(() => {
|
|
55
|
+
toastTimeouts.delete(toastId);
|
|
56
|
+
dispatch({
|
|
57
|
+
type: "REMOVE_TOAST",
|
|
58
|
+
toastId: toastId,
|
|
59
|
+
});
|
|
60
|
+
}, TOAST_REMOVE_DELAY);
|
|
61
|
+
|
|
62
|
+
toastTimeouts.set(toastId, timeout);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const reducer = (state: State, action: Action): State => {
|
|
66
|
+
switch (action.type) {
|
|
67
|
+
case "ADD_TOAST":
|
|
68
|
+
return {
|
|
69
|
+
...state,
|
|
70
|
+
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
case "UPDATE_TOAST":
|
|
74
|
+
return {
|
|
75
|
+
...state,
|
|
76
|
+
toasts: state.toasts.map((t) =>
|
|
77
|
+
t.id === action.toast.id ? { ...t, ...action.toast } : t,
|
|
78
|
+
),
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
case "DISMISS_TOAST": {
|
|
82
|
+
const { toastId } = action;
|
|
83
|
+
|
|
84
|
+
// ! Side effects ! - This could be extracted into a dismissToast() action,
|
|
85
|
+
// but I'll keep it here for simplicity
|
|
86
|
+
if (toastId) {
|
|
87
|
+
addToRemoveQueue(toastId);
|
|
88
|
+
} else {
|
|
89
|
+
state.toasts.forEach((toast) => {
|
|
90
|
+
addToRemoveQueue(toast.id);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
...state,
|
|
96
|
+
toasts: state.toasts.map((t) =>
|
|
97
|
+
t.id === toastId || toastId === undefined
|
|
98
|
+
? {
|
|
99
|
+
...t,
|
|
100
|
+
open: false,
|
|
101
|
+
}
|
|
102
|
+
: t,
|
|
103
|
+
),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
case "REMOVE_TOAST":
|
|
107
|
+
if (action.toastId === undefined) {
|
|
108
|
+
return {
|
|
109
|
+
...state,
|
|
110
|
+
toasts: [],
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
...state,
|
|
115
|
+
toasts: state.toasts.filter((t) => t.id !== action.toastId),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const listeners: Array<(state: State) => void> = [];
|
|
121
|
+
|
|
122
|
+
let memoryState: State = { toasts: [] };
|
|
123
|
+
|
|
124
|
+
function dispatch(action: Action) {
|
|
125
|
+
memoryState = reducer(memoryState, action);
|
|
126
|
+
listeners.forEach((listener) => {
|
|
127
|
+
listener(memoryState);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
type Toast = Omit<ToasterToast, "id">;
|
|
132
|
+
|
|
133
|
+
function toast({ ...props }: Toast) {
|
|
134
|
+
const id = genId();
|
|
135
|
+
|
|
136
|
+
const update = (props: ToasterToast) =>
|
|
137
|
+
dispatch({
|
|
138
|
+
type: "UPDATE_TOAST",
|
|
139
|
+
toast: { ...props, id },
|
|
140
|
+
});
|
|
141
|
+
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });
|
|
142
|
+
|
|
143
|
+
dispatch({
|
|
144
|
+
type: "ADD_TOAST",
|
|
145
|
+
toast: {
|
|
146
|
+
...props,
|
|
147
|
+
id,
|
|
148
|
+
open: true,
|
|
149
|
+
onOpenChange: (open) => {
|
|
150
|
+
if (!open) dismiss();
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
id: id,
|
|
157
|
+
dismiss,
|
|
158
|
+
update,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function useToast() {
|
|
163
|
+
const [state, setState] = React.useState<State>(memoryState);
|
|
164
|
+
|
|
165
|
+
React.useEffect(() => {
|
|
166
|
+
listeners.push(setState);
|
|
167
|
+
return () => {
|
|
168
|
+
const index = listeners.indexOf(setState);
|
|
169
|
+
if (index > -1) {
|
|
170
|
+
listeners.splice(index, 1);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}, [state]);
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
...state,
|
|
177
|
+
toast,
|
|
178
|
+
dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export { useToast, toast };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { getSystemInfo } from "@/lib/api";
|
|
3
|
+
|
|
4
|
+
let _cached: boolean | null = null;
|
|
5
|
+
|
|
6
|
+
export function useUploadsAllowed(): boolean | null {
|
|
7
|
+
const [uploadsAllowed, setUploadsAllowed] = useState<boolean | null>(_cached);
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (_cached !== null) return;
|
|
11
|
+
let active = true;
|
|
12
|
+
getSystemInfo()
|
|
13
|
+
.then((info) => {
|
|
14
|
+
_cached = info.uploads_allowed;
|
|
15
|
+
if (active) setUploadsAllowed(info.uploads_allowed);
|
|
16
|
+
})
|
|
17
|
+
.catch(() => {
|
|
18
|
+
// Fail closed for security - default to disabling uploads on API error
|
|
19
|
+
_cached = false;
|
|
20
|
+
if (active) setUploadsAllowed(false);
|
|
21
|
+
});
|
|
22
|
+
return () => {
|
|
23
|
+
active = false;
|
|
24
|
+
};
|
|
25
|
+
}, []);
|
|
26
|
+
|
|
27
|
+
return uploadsAllowed;
|
|
28
|
+
}
|