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,451 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lazy,
|
|
3
|
+
Suspense,
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
type PointerEvent as ReactPointerEvent,
|
|
10
|
+
} from "react";
|
|
11
|
+
import { Alert, AlertDescription, AlertTitle } from "@/design-system/ui/alert";
|
|
12
|
+
import { Button } from "@/design-system/ui/button";
|
|
13
|
+
import { Skeleton } from "@/design-system/ui/skeleton";
|
|
14
|
+
import { cn } from "@/lib/utils";
|
|
15
|
+
import { Loader2, MessageSquare } from "lucide-react";
|
|
16
|
+
import type { UseChatKitOptions } from "@openai/chatkit-react";
|
|
17
|
+
import { useChatInterfaceOptions } from "@features/shared/components/chat-interface-options";
|
|
18
|
+
import type { ChatParticipant } from "@features/shared/components/chat-interface.types";
|
|
19
|
+
import type { ChatSessionStatus } from "@features/workflow/pages/workflow/hooks/use-workflow-chat";
|
|
20
|
+
import { recordChatTelemetry } from "@features/chatkit/lib/telemetry";
|
|
21
|
+
import { useColorScheme } from "@/hooks/use-color-scheme";
|
|
22
|
+
import { buildChatTheme } from "@features/chatkit/lib/chatkit-theme";
|
|
23
|
+
import {
|
|
24
|
+
buildModelOptions,
|
|
25
|
+
buildStartScreenPrompts,
|
|
26
|
+
} from "@features/chatkit/components/public-chat-config";
|
|
27
|
+
import type {
|
|
28
|
+
ChatKitStartScreenPrompt,
|
|
29
|
+
ChatKitSupportedModel,
|
|
30
|
+
} from "@features/workflow/lib/workflow-storage.types";
|
|
31
|
+
|
|
32
|
+
const ChatKitSurfaceLazy = lazy(() =>
|
|
33
|
+
import("@features/chatkit/components/chatkit-surface").then((module) => ({
|
|
34
|
+
default: module.ChatKitSurface,
|
|
35
|
+
})),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const MINIMAP_SELECTOR = ".react-flow__panel.react-flow__minimap";
|
|
39
|
+
const DEFAULT_FLOATING_OFFSET = 96;
|
|
40
|
+
const MINIMAP_GAP = 16;
|
|
41
|
+
|
|
42
|
+
const DEFAULT_PANEL_WIDTH = 448;
|
|
43
|
+
const DEFAULT_PANEL_HEIGHT = 520;
|
|
44
|
+
const MIN_PANEL_WIDTH = 320;
|
|
45
|
+
const MIN_PANEL_HEIGHT = 360;
|
|
46
|
+
const PANEL_VIEWPORT_MARGIN = 24;
|
|
47
|
+
|
|
48
|
+
interface StudioChatBubbleProps {
|
|
49
|
+
title: string;
|
|
50
|
+
user: ChatParticipant;
|
|
51
|
+
ai: ChatParticipant;
|
|
52
|
+
workflowId: string | null;
|
|
53
|
+
chatkitWorkflowId?: string | null;
|
|
54
|
+
sessionPayload?: Record<string, unknown>;
|
|
55
|
+
backendBaseUrl?: string | null;
|
|
56
|
+
startScreenPrompts?: ChatKitStartScreenPrompt[] | null;
|
|
57
|
+
supportedModels?: ChatKitSupportedModel[] | null;
|
|
58
|
+
getClientSecret: (currentSecret: string | null) => Promise<string>;
|
|
59
|
+
sessionStatus: ChatSessionStatus;
|
|
60
|
+
sessionError: string | null;
|
|
61
|
+
onRetry: () => Promise<string>;
|
|
62
|
+
onResponseStart?: () => void;
|
|
63
|
+
onResponseEnd?: () => void;
|
|
64
|
+
onClientTool?: (tool: {
|
|
65
|
+
name: string;
|
|
66
|
+
params: Record<string, unknown>;
|
|
67
|
+
}) => Promise<Record<string, unknown>>;
|
|
68
|
+
onDismiss?: () => void;
|
|
69
|
+
onOpen?: () => void;
|
|
70
|
+
isExternallyOpen: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function StudioChatBubble({
|
|
74
|
+
title,
|
|
75
|
+
user,
|
|
76
|
+
ai,
|
|
77
|
+
workflowId,
|
|
78
|
+
chatkitWorkflowId,
|
|
79
|
+
sessionPayload,
|
|
80
|
+
backendBaseUrl,
|
|
81
|
+
startScreenPrompts,
|
|
82
|
+
supportedModels,
|
|
83
|
+
getClientSecret,
|
|
84
|
+
sessionStatus,
|
|
85
|
+
sessionError,
|
|
86
|
+
onRetry,
|
|
87
|
+
onResponseStart,
|
|
88
|
+
onResponseEnd,
|
|
89
|
+
onClientTool,
|
|
90
|
+
onDismiss,
|
|
91
|
+
onOpen,
|
|
92
|
+
isExternallyOpen,
|
|
93
|
+
}: StudioChatBubbleProps) {
|
|
94
|
+
const [isPanelOpen, setIsPanelOpen] = useState(false);
|
|
95
|
+
const [shouldLoadChat, setShouldLoadChat] = useState(false);
|
|
96
|
+
const [isRetrying, setIsRetrying] = useState(false);
|
|
97
|
+
const [floatingOffset, setFloatingOffset] = useState(DEFAULT_FLOATING_OFFSET);
|
|
98
|
+
const [panelSize, setPanelSize] = useState({
|
|
99
|
+
width: DEFAULT_PANEL_WIDTH,
|
|
100
|
+
height: DEFAULT_PANEL_HEIGHT,
|
|
101
|
+
});
|
|
102
|
+
const resizeStateRef = useRef<{
|
|
103
|
+
pointerId: number;
|
|
104
|
+
startX: number;
|
|
105
|
+
startY: number;
|
|
106
|
+
startWidth: number;
|
|
107
|
+
startHeight: number;
|
|
108
|
+
} | null>(null);
|
|
109
|
+
const colorScheme = useColorScheme();
|
|
110
|
+
const modelOptions = useMemo(
|
|
111
|
+
() => buildModelOptions(supportedModels),
|
|
112
|
+
[supportedModels],
|
|
113
|
+
);
|
|
114
|
+
const prompts = useMemo(
|
|
115
|
+
() => buildStartScreenPrompts(title, startScreenPrompts),
|
|
116
|
+
[startScreenPrompts, title],
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (isExternallyOpen) {
|
|
121
|
+
setIsPanelOpen(true);
|
|
122
|
+
setShouldLoadChat(true);
|
|
123
|
+
} else {
|
|
124
|
+
setIsPanelOpen(false);
|
|
125
|
+
}
|
|
126
|
+
}, [isExternallyOpen]);
|
|
127
|
+
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let resizeObserver: ResizeObserver | null = null;
|
|
134
|
+
let mutationObserver: MutationObserver | null = null;
|
|
135
|
+
let observedElement: Element | null = null;
|
|
136
|
+
|
|
137
|
+
const updateOffset = () => {
|
|
138
|
+
if (typeof window === "undefined") {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const minimap = document.querySelector<HTMLElement>(MINIMAP_SELECTOR);
|
|
143
|
+
|
|
144
|
+
if (!minimap) {
|
|
145
|
+
setFloatingOffset(DEFAULT_FLOATING_OFFSET);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const rect = minimap.getBoundingClientRect();
|
|
150
|
+
const offset = window.innerHeight - rect.top + MINIMAP_GAP;
|
|
151
|
+
setFloatingOffset(Math.max(offset, DEFAULT_FLOATING_OFFSET));
|
|
152
|
+
|
|
153
|
+
if (
|
|
154
|
+
typeof ResizeObserver !== "undefined" &&
|
|
155
|
+
minimap !== observedElement
|
|
156
|
+
) {
|
|
157
|
+
resizeObserver?.disconnect();
|
|
158
|
+
resizeObserver = new ResizeObserver(() => updateOffset());
|
|
159
|
+
resizeObserver.observe(minimap);
|
|
160
|
+
observedElement = minimap;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const handleResize = () => updateOffset();
|
|
165
|
+
|
|
166
|
+
updateOffset();
|
|
167
|
+
window.addEventListener("resize", handleResize);
|
|
168
|
+
|
|
169
|
+
if (typeof MutationObserver !== "undefined" && document.body) {
|
|
170
|
+
mutationObserver = new MutationObserver(() => updateOffset());
|
|
171
|
+
mutationObserver.observe(document.body, {
|
|
172
|
+
childList: true,
|
|
173
|
+
subtree: true,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return () => {
|
|
178
|
+
window.removeEventListener("resize", handleResize);
|
|
179
|
+
resizeObserver?.disconnect();
|
|
180
|
+
mutationObserver?.disconnect();
|
|
181
|
+
};
|
|
182
|
+
}, []);
|
|
183
|
+
|
|
184
|
+
const floatingPositionStyle = useMemo(
|
|
185
|
+
() => ({
|
|
186
|
+
bottom: floatingOffset,
|
|
187
|
+
}),
|
|
188
|
+
[floatingOffset],
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const handleResizePointerDown = useCallback(
|
|
192
|
+
(event: ReactPointerEvent<HTMLDivElement>) => {
|
|
193
|
+
// Only react to the primary (left) button.
|
|
194
|
+
if (event.button !== 0) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
// Route every subsequent pointer event to this element until release, so
|
|
199
|
+
// fast moves over the ChatKit iframe / off-window can't drop the pointerup.
|
|
200
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
201
|
+
resizeStateRef.current = {
|
|
202
|
+
pointerId: event.pointerId,
|
|
203
|
+
startX: event.clientX,
|
|
204
|
+
startY: event.clientY,
|
|
205
|
+
startWidth: panelSize.width,
|
|
206
|
+
startHeight: panelSize.height,
|
|
207
|
+
};
|
|
208
|
+
},
|
|
209
|
+
[panelSize],
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
const handleResizePointerMove = useCallback(
|
|
213
|
+
(event: ReactPointerEvent<HTMLDivElement>) => {
|
|
214
|
+
const state = resizeStateRef.current;
|
|
215
|
+
if (!state || event.pointerId !== state.pointerId) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Panel is anchored bottom-right, so dragging the handle up/left grows it.
|
|
220
|
+
const deltaX = state.startX - event.clientX;
|
|
221
|
+
const deltaY = state.startY - event.clientY;
|
|
222
|
+
|
|
223
|
+
const maxWidth =
|
|
224
|
+
typeof window === "undefined"
|
|
225
|
+
? Number.POSITIVE_INFINITY
|
|
226
|
+
: window.innerWidth - PANEL_VIEWPORT_MARGIN * 2;
|
|
227
|
+
const maxHeight =
|
|
228
|
+
typeof window === "undefined"
|
|
229
|
+
? Number.POSITIVE_INFINITY
|
|
230
|
+
: window.innerHeight - PANEL_VIEWPORT_MARGIN * 2;
|
|
231
|
+
|
|
232
|
+
const nextWidth = Math.min(
|
|
233
|
+
Math.max(state.startWidth + deltaX, MIN_PANEL_WIDTH),
|
|
234
|
+
Math.max(maxWidth, MIN_PANEL_WIDTH),
|
|
235
|
+
);
|
|
236
|
+
const nextHeight = Math.min(
|
|
237
|
+
Math.max(state.startHeight + deltaY, MIN_PANEL_HEIGHT),
|
|
238
|
+
Math.max(maxHeight, MIN_PANEL_HEIGHT),
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
setPanelSize({ width: nextWidth, height: nextHeight });
|
|
242
|
+
},
|
|
243
|
+
[],
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
const handleResizePointerEnd = useCallback(
|
|
247
|
+
(event: ReactPointerEvent<HTMLDivElement>) => {
|
|
248
|
+
const state = resizeStateRef.current;
|
|
249
|
+
if (!state || event.pointerId !== state.pointerId) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
resizeStateRef.current = null;
|
|
253
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
254
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
[],
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const handleFabClick = () => {
|
|
261
|
+
setIsPanelOpen(true);
|
|
262
|
+
setShouldLoadChat(true);
|
|
263
|
+
recordChatTelemetry("studio.chat.open", {
|
|
264
|
+
workflowId,
|
|
265
|
+
source: "bubble",
|
|
266
|
+
});
|
|
267
|
+
onOpen?.();
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const handleCollapse = () => {
|
|
271
|
+
setIsPanelOpen(false);
|
|
272
|
+
recordChatTelemetry("studio.chat.close", {
|
|
273
|
+
workflowId,
|
|
274
|
+
source: "bubble",
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const handleDismiss = () => {
|
|
279
|
+
handleCollapse();
|
|
280
|
+
onDismiss?.();
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const handleRetry = useCallback(async () => {
|
|
284
|
+
setIsRetrying(true);
|
|
285
|
+
try {
|
|
286
|
+
await onRetry();
|
|
287
|
+
} finally {
|
|
288
|
+
setIsRetrying(false);
|
|
289
|
+
}
|
|
290
|
+
}, [onRetry]);
|
|
291
|
+
|
|
292
|
+
const chatKitOptions: UseChatKitOptions = useChatInterfaceOptions({
|
|
293
|
+
chatkitOptions: {
|
|
294
|
+
header: {
|
|
295
|
+
enabled: true,
|
|
296
|
+
title: {
|
|
297
|
+
enabled: true,
|
|
298
|
+
text: title,
|
|
299
|
+
},
|
|
300
|
+
rightAction: {
|
|
301
|
+
icon: "close",
|
|
302
|
+
onClick: handleDismiss,
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
composer: {
|
|
306
|
+
placeholder: `Ask ${title} a question`,
|
|
307
|
+
...(modelOptions ? { models: modelOptions } : {}),
|
|
308
|
+
},
|
|
309
|
+
startScreen: {
|
|
310
|
+
greeting: `You're chatting with ${title}.`,
|
|
311
|
+
prompts,
|
|
312
|
+
},
|
|
313
|
+
onClientTool,
|
|
314
|
+
theme: buildChatTheme(colorScheme),
|
|
315
|
+
},
|
|
316
|
+
getClientSecret,
|
|
317
|
+
backendBaseUrl: backendBaseUrl ?? undefined,
|
|
318
|
+
sessionPayload: {
|
|
319
|
+
...sessionPayload,
|
|
320
|
+
workflowId: chatkitWorkflowId ?? workflowId,
|
|
321
|
+
workflowLabel: title,
|
|
322
|
+
},
|
|
323
|
+
workflowId: chatkitWorkflowId ?? workflowId,
|
|
324
|
+
title,
|
|
325
|
+
user,
|
|
326
|
+
ai,
|
|
327
|
+
initialMessages: [
|
|
328
|
+
{
|
|
329
|
+
id: "studio-chat-greeting",
|
|
330
|
+
content: `You're chatting with ${title}.`,
|
|
331
|
+
sender: {
|
|
332
|
+
...ai,
|
|
333
|
+
isAI: true,
|
|
334
|
+
},
|
|
335
|
+
timestamp: new Date(),
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
onResponseStart,
|
|
339
|
+
onResponseEnd,
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
const statusView = useMemo(() => {
|
|
343
|
+
if (sessionStatus === "loading") {
|
|
344
|
+
return (
|
|
345
|
+
<div className="flex h-full flex-col items-center justify-center space-y-3 text-sm text-muted-foreground">
|
|
346
|
+
<Loader2 className="h-5 w-5 animate-spin" />
|
|
347
|
+
<p>Starting a secure chat session…</p>
|
|
348
|
+
</div>
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (sessionStatus === "error") {
|
|
353
|
+
return (
|
|
354
|
+
<Alert variant="destructive" className="mt-4 text-left">
|
|
355
|
+
<AlertTitle>Chat unavailable</AlertTitle>
|
|
356
|
+
<AlertDescription className="mt-1 text-sm">
|
|
357
|
+
{sessionError ||
|
|
358
|
+
"We couldn't reach the chat service. Try again in a moment."}
|
|
359
|
+
</AlertDescription>
|
|
360
|
+
<div className="mt-3 flex gap-2">
|
|
361
|
+
<Button
|
|
362
|
+
variant="outline"
|
|
363
|
+
size="sm"
|
|
364
|
+
onClick={handleRetry}
|
|
365
|
+
disabled={isRetrying}
|
|
366
|
+
>
|
|
367
|
+
{isRetrying && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
|
368
|
+
Retry
|
|
369
|
+
</Button>
|
|
370
|
+
</div>
|
|
371
|
+
</Alert>
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return null;
|
|
376
|
+
}, [handleRetry, isRetrying, sessionError, sessionStatus]);
|
|
377
|
+
|
|
378
|
+
return (
|
|
379
|
+
<>
|
|
380
|
+
{!isPanelOpen && (
|
|
381
|
+
<Button
|
|
382
|
+
className="fixed right-6 z-50 h-14 w-14 rounded-full shadow-xl"
|
|
383
|
+
style={floatingPositionStyle}
|
|
384
|
+
size="icon"
|
|
385
|
+
onClick={handleFabClick}
|
|
386
|
+
>
|
|
387
|
+
<MessageSquare className="h-5 w-5" />
|
|
388
|
+
<span className="sr-only">Open ChatKit</span>
|
|
389
|
+
</Button>
|
|
390
|
+
)}
|
|
391
|
+
|
|
392
|
+
{isPanelOpen && (
|
|
393
|
+
<div
|
|
394
|
+
className="fixed right-6 z-50 flex max-h-[calc(100vh-2rem)] max-w-[calc(100vw-2rem)] flex-col rounded-2xl border border-border bg-card text-foreground shadow-2xl"
|
|
395
|
+
style={{
|
|
396
|
+
...floatingPositionStyle,
|
|
397
|
+
width: panelSize.width,
|
|
398
|
+
height: panelSize.height,
|
|
399
|
+
}}
|
|
400
|
+
>
|
|
401
|
+
<div
|
|
402
|
+
role="separator"
|
|
403
|
+
aria-orientation="vertical"
|
|
404
|
+
aria-label="Resize chat window"
|
|
405
|
+
onPointerDown={handleResizePointerDown}
|
|
406
|
+
onPointerMove={handleResizePointerMove}
|
|
407
|
+
onPointerUp={handleResizePointerEnd}
|
|
408
|
+
onPointerCancel={handleResizePointerEnd}
|
|
409
|
+
className="group absolute left-0 top-0 z-10 flex h-7 w-7 cursor-nwse-resize touch-none items-center justify-center rounded-tl-2xl"
|
|
410
|
+
>
|
|
411
|
+
<span className="pointer-events-none flex h-4 w-4 -translate-x-px -translate-y-px items-center justify-center">
|
|
412
|
+
<svg
|
|
413
|
+
viewBox="0 0 16 16"
|
|
414
|
+
fill="none"
|
|
415
|
+
className="h-full w-full text-muted-foreground/40 transition-colors group-hover:text-muted-foreground"
|
|
416
|
+
>
|
|
417
|
+
<path
|
|
418
|
+
d="M14 2H5a3 3 0 0 0-3 3v9"
|
|
419
|
+
stroke="currentColor"
|
|
420
|
+
strokeWidth="2"
|
|
421
|
+
strokeLinecap="round"
|
|
422
|
+
/>
|
|
423
|
+
</svg>
|
|
424
|
+
</span>
|
|
425
|
+
</div>
|
|
426
|
+
<div className="flex-1 overflow-hidden px-2 py-2">
|
|
427
|
+
{statusView}
|
|
428
|
+
{sessionStatus !== "error" && shouldLoadChat && (
|
|
429
|
+
<Suspense
|
|
430
|
+
fallback={
|
|
431
|
+
<div className="flex h-full w-full flex-col gap-3">
|
|
432
|
+
<Skeleton className="h-10 w-1/2 self-center" />
|
|
433
|
+
<Skeleton className="h-full w-full" />
|
|
434
|
+
</div>
|
|
435
|
+
}
|
|
436
|
+
>
|
|
437
|
+
<ChatKitSurfaceLazy
|
|
438
|
+
options={chatKitOptions}
|
|
439
|
+
className={cn(
|
|
440
|
+
sessionStatus !== "ready" &&
|
|
441
|
+
"pointer-events-none opacity-50",
|
|
442
|
+
)}
|
|
443
|
+
/>
|
|
444
|
+
</Suspense>
|
|
445
|
+
)}
|
|
446
|
+
</div>
|
|
447
|
+
</div>
|
|
448
|
+
)}
|
|
449
|
+
</>
|
|
450
|
+
);
|
|
451
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { UseChatKitOptions } from "@openai/chatkit-react";
|
|
2
|
+
|
|
3
|
+
type ChatKitComposerAttachments = NonNullable<
|
|
4
|
+
NonNullable<UseChatKitOptions["composer"]>["attachments"]
|
|
5
|
+
>;
|
|
6
|
+
|
|
7
|
+
export const CHATKIT_ATTACHMENT_MAX_SIZE_BYTES = 5 * 1024 * 1024;
|
|
8
|
+
export const CHATKIT_ATTACHMENT_MAX_COUNT = 10;
|
|
9
|
+
|
|
10
|
+
export const CHATKIT_ATTACHMENT_ACCEPT: NonNullable<
|
|
11
|
+
ChatKitComposerAttachments["accept"]
|
|
12
|
+
> = {
|
|
13
|
+
"text/plain": [".txt"],
|
|
14
|
+
"application/json": [".json"],
|
|
15
|
+
"text/markdown": [".md"],
|
|
16
|
+
"text/csv": [".csv"],
|
|
17
|
+
"text/x-log": [".log"],
|
|
18
|
+
"application/pdf": [".pdf"],
|
|
19
|
+
"image/png": [".png"],
|
|
20
|
+
"image/jpeg": [".jpg", ".jpeg"],
|
|
21
|
+
"image/webp": [".webp"],
|
|
22
|
+
"image/gif": [".gif"],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const buildChatKitAttachmentOptions =
|
|
26
|
+
(): ChatKitComposerAttachments => ({
|
|
27
|
+
enabled: true,
|
|
28
|
+
accept: CHATKIT_ATTACHMENT_ACCEPT,
|
|
29
|
+
maxSize: CHATKIT_ATTACHMENT_MAX_SIZE_BYTES,
|
|
30
|
+
maxCount: CHATKIT_ATTACHMENT_MAX_COUNT,
|
|
31
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
export interface PublicChatHttpError {
|
|
2
|
+
status: number;
|
|
3
|
+
message: string;
|
|
4
|
+
code?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface PublicChatFetchOptions {
|
|
8
|
+
workflowId: string;
|
|
9
|
+
onHttpError?: (error: PublicChatHttpError) => void;
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type RuntimeConfig = {
|
|
14
|
+
chatkitDomainKey?: unknown;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const safeString = (value: unknown): string | undefined => {
|
|
18
|
+
if (typeof value === "string" && value.trim()) {
|
|
19
|
+
return value.trim();
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const DEFAULT_DOMAIN_KEY =
|
|
25
|
+
safeString(import.meta.env?.VITE_ORCHEO_CHATKIT_DEFAULT_DOMAIN_KEY) ??
|
|
26
|
+
"domain_pk_localhost_dev";
|
|
27
|
+
|
|
28
|
+
const getRuntimeDomainKey = (): string | undefined => {
|
|
29
|
+
if (typeof window === "undefined") {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const runtimeConfig = (
|
|
33
|
+
window as typeof window & {
|
|
34
|
+
__ORCHEO_CONFIG__?: RuntimeConfig;
|
|
35
|
+
}
|
|
36
|
+
).__ORCHEO_CONFIG__;
|
|
37
|
+
return safeString(runtimeConfig?.chatkitDomainKey);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const parseErrorPayload = async (
|
|
41
|
+
response: Response,
|
|
42
|
+
): Promise<Pick<PublicChatHttpError, "message" | "code">> => {
|
|
43
|
+
try {
|
|
44
|
+
const body = await response.json();
|
|
45
|
+
if (!body) {
|
|
46
|
+
return {
|
|
47
|
+
message: response.statusText || "ChatKit request failed.",
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (typeof body === "string") {
|
|
51
|
+
return { message: body };
|
|
52
|
+
}
|
|
53
|
+
if (typeof body === "object") {
|
|
54
|
+
const detail =
|
|
55
|
+
(("detail" in body ? body.detail : undefined) as Record<
|
|
56
|
+
string,
|
|
57
|
+
unknown
|
|
58
|
+
>) ?? (body as Record<string, unknown>);
|
|
59
|
+
const message =
|
|
60
|
+
safeString(detail?.message) ??
|
|
61
|
+
safeString((body as Record<string, unknown>).message);
|
|
62
|
+
const code =
|
|
63
|
+
safeString(detail?.code) ??
|
|
64
|
+
safeString((body as Record<string, unknown>).code);
|
|
65
|
+
return {
|
|
66
|
+
message:
|
|
67
|
+
message ??
|
|
68
|
+
(response.statusText ||
|
|
69
|
+
"ChatKit request failed. Please retry shortly."),
|
|
70
|
+
code,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
message: response.statusText || "ChatKit request failed.",
|
|
75
|
+
};
|
|
76
|
+
} catch {
|
|
77
|
+
return {
|
|
78
|
+
message: response.statusText || "ChatKit request failed.",
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const getChatKitDomainKey = (): string => {
|
|
84
|
+
const fromEnv = safeString(import.meta.env?.VITE_ORCHEO_CHATKIT_DOMAIN_KEY);
|
|
85
|
+
const fromRuntime = getRuntimeDomainKey();
|
|
86
|
+
return fromEnv ?? fromRuntime ?? DEFAULT_DOMAIN_KEY;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const buildPublicChatFetch = ({
|
|
90
|
+
workflowId,
|
|
91
|
+
onHttpError,
|
|
92
|
+
metadata,
|
|
93
|
+
}: PublicChatFetchOptions): typeof fetch => {
|
|
94
|
+
// Use plain fetch to avoid attaching Studio access tokens to public requests.
|
|
95
|
+
const baseFetch = fetch;
|
|
96
|
+
|
|
97
|
+
const emitError = async (response: Response) => {
|
|
98
|
+
if (!onHttpError) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const detail = await parseErrorPayload(response);
|
|
102
|
+
onHttpError({
|
|
103
|
+
status: response.status,
|
|
104
|
+
message: detail.message,
|
|
105
|
+
code: detail.code,
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
return async (input: RequestInfo | URL, init: RequestInit = {}) => {
|
|
110
|
+
const nextInit: RequestInit = {
|
|
111
|
+
...init,
|
|
112
|
+
credentials: "include",
|
|
113
|
+
};
|
|
114
|
+
// Ensure OAuth HttpOnly cookies are sent with every ChatKit request.
|
|
115
|
+
|
|
116
|
+
const requestIsRequest = input instanceof Request;
|
|
117
|
+
const requestHeaders = new Headers(
|
|
118
|
+
requestIsRequest ? input.headers : undefined,
|
|
119
|
+
);
|
|
120
|
+
for (const [key, value] of new Headers(nextInit.headers ?? {})) {
|
|
121
|
+
requestHeaders.set(key, value);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const contentType = requestHeaders.get("Content-Type") ?? "";
|
|
125
|
+
const expectsJson = contentType.includes("application/json");
|
|
126
|
+
const stringBody = typeof nextInit.body === "string";
|
|
127
|
+
|
|
128
|
+
const serializedBody = async (): Promise<string | null> => {
|
|
129
|
+
if (stringBody) {
|
|
130
|
+
return nextInit.body as string;
|
|
131
|
+
}
|
|
132
|
+
if (requestIsRequest) {
|
|
133
|
+
try {
|
|
134
|
+
return await input.clone().text();
|
|
135
|
+
} catch {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const augmentPayload = (serialized: string | null) => {
|
|
143
|
+
if (!serialized) {
|
|
144
|
+
return JSON.stringify({
|
|
145
|
+
workflow_id: workflowId,
|
|
146
|
+
metadata: {
|
|
147
|
+
...(metadata ?? {}),
|
|
148
|
+
workflow_id: workflowId,
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
const payload = JSON.parse(serialized) as Record<string, unknown>;
|
|
154
|
+
if (payload.workflow_id !== workflowId) {
|
|
155
|
+
payload.workflow_id = workflowId;
|
|
156
|
+
}
|
|
157
|
+
const payloadMetadata =
|
|
158
|
+
payload.metadata && typeof payload.metadata === "object"
|
|
159
|
+
? { ...(payload.metadata as Record<string, unknown>) }
|
|
160
|
+
: {};
|
|
161
|
+
if (metadata) {
|
|
162
|
+
Object.assign(payloadMetadata, metadata);
|
|
163
|
+
}
|
|
164
|
+
payloadMetadata.workflow_id = workflowId;
|
|
165
|
+
payload.metadata = payloadMetadata;
|
|
166
|
+
return JSON.stringify(payload);
|
|
167
|
+
} catch {
|
|
168
|
+
return serialized;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const rawBody = await serializedBody();
|
|
173
|
+
const shouldInjectWorkflowId =
|
|
174
|
+
expectsJson ||
|
|
175
|
+
stringBody ||
|
|
176
|
+
!nextInit.body ||
|
|
177
|
+
(requestIsRequest && (rawBody?.trim().startsWith("{") ?? false));
|
|
178
|
+
if (shouldInjectWorkflowId) {
|
|
179
|
+
nextInit.body = augmentPayload(rawBody);
|
|
180
|
+
requestHeaders.set("Content-Type", "application/json");
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
nextInit.headers = requestHeaders;
|
|
184
|
+
|
|
185
|
+
const response = requestIsRequest
|
|
186
|
+
? await baseFetch(new Request(input, nextInit))
|
|
187
|
+
: await baseFetch(input, nextInit);
|
|
188
|
+
|
|
189
|
+
if (!response.ok) {
|
|
190
|
+
await emitError(response.clone());
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return response;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { UseChatKitOptions } from "@openai/chatkit-react";
|
|
2
|
+
import type { ColorScheme } from "@/hooks/use-color-scheme";
|
|
3
|
+
|
|
4
|
+
export const buildChatTheme = (
|
|
5
|
+
scheme: ColorScheme,
|
|
6
|
+
): NonNullable<UseChatKitOptions["theme"]> => ({
|
|
7
|
+
colorScheme: scheme,
|
|
8
|
+
color: {
|
|
9
|
+
grayscale: {
|
|
10
|
+
hue: 220,
|
|
11
|
+
tint: 6,
|
|
12
|
+
shade: scheme === "dark" ? -1 : -4,
|
|
13
|
+
},
|
|
14
|
+
accent: {
|
|
15
|
+
primary: scheme === "dark" ? "#f1f5f9" : "#0f172a",
|
|
16
|
+
level: 1,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
radius: "round",
|
|
20
|
+
});
|