@vertesia/ui 1.5.0-dev.20260807.073259Z → 1.5.0-dev.20260826.064249Z
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/README.md +1 -7
- package/lib/core/components/shadcn/filters/comboBox/DateCombobox.js +1 -1
- package/lib/core/components/shadcn/filters/comboBox/DateCombobox.js.map +1 -1
- package/lib/core/components/shadcn/filters/filter/dateFilter.d.ts.map +1 -1
- package/lib/core/components/shadcn/filters/filter/dateFilter.js +1 -1
- package/lib/core/components/shadcn/filters/filter/dateFilter.js.map +1 -1
- package/lib/core/components/shadcn/filters/filters.d.ts.map +1 -1
- package/lib/core/components/shadcn/filters/filters.js +1 -1
- package/lib/core/components/shadcn/filters/filters.js.map +1 -1
- package/lib/core/components/shadcn/index.d.ts +1 -0
- package/lib/core/components/shadcn/index.d.ts.map +1 -1
- package/lib/core/components/shadcn/index.js +1 -0
- package/lib/core/components/shadcn/index.js.map +1 -1
- package/lib/core/components/shadcn/modal/dialog.d.ts.map +1 -1
- package/lib/core/components/shadcn/modal/dialog.js +1 -3
- package/lib/core/components/shadcn/modal/dialog.js.map +1 -1
- package/lib/core/components/shadcn/overflowTabs.d.ts +59 -0
- package/lib/core/components/shadcn/overflowTabs.d.ts.map +1 -0
- package/lib/core/components/shadcn/overflowTabs.js +173 -0
- package/lib/core/components/shadcn/overflowTabs.js.map +1 -0
- package/lib/core/components/shadcn/selectBox.js +2 -2
- package/lib/core/components/shadcn/selectBox.js.map +1 -1
- package/lib/core/components/shadcn/theme/ThemeProvider.d.ts +3 -1
- package/lib/core/components/shadcn/theme/ThemeProvider.d.ts.map +1 -1
- package/lib/core/components/shadcn/theme/ThemeProvider.js +8 -9
- package/lib/core/components/shadcn/theme/ThemeProvider.js.map +1 -1
- package/lib/core/utils/dayjs.d.ts +12 -0
- package/lib/core/utils/dayjs.d.ts.map +1 -0
- package/lib/core/utils/dayjs.js +16 -0
- package/lib/core/utils/dayjs.js.map +1 -0
- package/lib/env/index.d.ts +17 -0
- package/lib/env/index.d.ts.map +1 -1
- package/lib/env/index.js +18 -1
- package/lib/env/index.js.map +1 -1
- package/lib/features/agent/PayloadBuilder.d.ts +1 -0
- package/lib/features/agent/PayloadBuilder.d.ts.map +1 -1
- package/lib/features/agent/PayloadBuilder.js +22 -5
- package/lib/features/agent/PayloadBuilder.js.map +1 -1
- package/lib/features/agent/chat/AgentRightPanel.d.ts.map +1 -1
- package/lib/features/agent/chat/AgentRightPanel.js +3 -135
- package/lib/features/agent/chat/AgentRightPanel.js.map +1 -1
- package/lib/features/agent/chat/ArtifactsTab.d.ts.map +1 -1
- package/lib/features/agent/chat/ArtifactsTab.js +1 -1
- package/lib/features/agent/chat/ArtifactsTab.js.map +1 -1
- package/lib/features/agent/chat/AskUserWidget.d.ts.map +1 -1
- package/lib/features/agent/chat/AskUserWidget.js +19 -4
- package/lib/features/agent/chat/AskUserWidget.js.map +1 -1
- package/lib/features/agent/chat/ModernAgentConversation.d.ts +6 -0
- package/lib/features/agent/chat/ModernAgentConversation.d.ts.map +1 -1
- package/lib/features/agent/chat/ModernAgentConversation.js +99 -29
- package/lib/features/agent/chat/ModernAgentConversation.js.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/ActiveWorkstreamsSummary.d.ts.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/ActiveWorkstreamsSummary.js +10 -9
- package/lib/features/agent/chat/ModernAgentOutput/ActiveWorkstreamsSummary.js.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/AllMessagesMixed.d.ts.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/AllMessagesMixed.js +5 -8
- package/lib/features/agent/chat/ModernAgentOutput/AllMessagesMixed.js.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/AttachmentPreview.d.ts.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/AttachmentPreview.js +45 -4
- package/lib/features/agent/chat/ModernAgentOutput/AttachmentPreview.js.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/BatchProgressPanel.js +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/BatchProgressPanel.js.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/Header.d.ts.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/Header.js +3 -3
- package/lib/features/agent/chat/ModernAgentOutput/Header.js.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/MessageItem.d.ts.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/MessageItem.js +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/MessageItem.js.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/StreamingMessage.d.ts.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/StreamingMessage.js +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/StreamingMessage.js.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/ToolCallGroup.js +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/ToolCallGroup.js.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/WorkstreamTabs.d.ts.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/WorkstreamTabs.js +9 -121
- package/lib/features/agent/chat/ModernAgentOutput/WorkstreamTabs.js.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/utils.d.ts +6 -0
- package/lib/features/agent/chat/ModernAgentOutput/utils.d.ts.map +1 -1
- package/lib/features/agent/chat/ModernAgentOutput/utils.js +19 -11
- package/lib/features/agent/chat/ModernAgentOutput/utils.js.map +1 -1
- package/lib/features/agent/chat/VegaLiteChart.d.ts.map +1 -1
- package/lib/features/agent/chat/VegaLiteChart.js +11 -3
- package/lib/features/agent/chat/VegaLiteChart.js.map +1 -1
- package/lib/features/agent/chat/hooks/useAgentStream.d.ts.map +1 -1
- package/lib/features/agent/chat/hooks/useAgentStream.js +3 -0
- package/lib/features/agent/chat/hooks/useAgentStream.js.map +1 -1
- package/lib/features/document-viewer/UniversalDocumentViewer.d.ts.map +1 -1
- package/lib/features/document-viewer/UniversalDocumentViewer.js +1 -1
- package/lib/features/document-viewer/UniversalDocumentViewer.js.map +1 -1
- package/lib/features/facets/AgentRunnerFacetsNav.d.ts +14 -2
- package/lib/features/facets/AgentRunnerFacetsNav.d.ts.map +1 -1
- package/lib/features/facets/AgentRunnerFacetsNav.js +20 -2
- package/lib/features/facets/AgentRunnerFacetsNav.js.map +1 -1
- package/lib/features/facets/CollectionsFacetsNav.d.ts +3 -3
- package/lib/features/facets/CollectionsFacetsNav.d.ts.map +1 -1
- package/lib/features/facets/CollectionsFacetsNav.js +6 -1
- package/lib/features/facets/CollectionsFacetsNav.js.map +1 -1
- package/lib/features/facets/DocumentsFacetsNav.d.ts +3 -3
- package/lib/features/facets/DocumentsFacetsNav.d.ts.map +1 -1
- package/lib/features/facets/DocumentsFacetsNav.js +20 -8
- package/lib/features/facets/DocumentsFacetsNav.js.map +1 -1
- package/lib/features/facets/InteractionsFacetsNav.d.ts +3 -3
- package/lib/features/facets/InteractionsFacetsNav.d.ts.map +1 -1
- package/lib/features/facets/InteractionsFacetsNav.js +11 -1
- package/lib/features/facets/InteractionsFacetsNav.js.map +1 -1
- package/lib/features/facets/PromptsFacetsNav.d.ts +3 -3
- package/lib/features/facets/PromptsFacetsNav.d.ts.map +1 -1
- package/lib/features/facets/PromptsFacetsNav.js +6 -1
- package/lib/features/facets/PromptsFacetsNav.js.map +1 -1
- package/lib/features/facets/RunsFacetsNav.d.ts +4 -14
- package/lib/features/facets/RunsFacetsNav.d.ts.map +1 -1
- package/lib/features/facets/RunsFacetsNav.js +26 -15
- package/lib/features/facets/RunsFacetsNav.js.map +1 -1
- package/lib/features/facets/WorkflowExecutionsFacetsNav.d.ts +4 -3
- package/lib/features/facets/WorkflowExecutionsFacetsNav.d.ts.map +1 -1
- package/lib/features/facets/WorkflowExecutionsFacetsNav.js +18 -10
- package/lib/features/facets/WorkflowExecutionsFacetsNav.js.map +1 -1
- package/lib/features/facets/index.d.ts +1 -1
- package/lib/features/facets/index.d.ts.map +1 -1
- package/lib/features/facets/index.js.map +1 -1
- package/lib/features/facets/utils/SearchInterface.d.ts +4 -3
- package/lib/features/facets/utils/SearchInterface.d.ts.map +1 -1
- package/lib/features/facets/utils/SearchInterface.js +4 -0
- package/lib/features/facets/utils/SearchInterface.js.map +1 -1
- package/lib/features/layout/GenericPageNavHeader.d.ts +8 -1
- package/lib/features/layout/GenericPageNavHeader.d.ts.map +1 -1
- package/lib/features/layout/GenericPageNavHeader.js +9 -1
- package/lib/features/layout/GenericPageNavHeader.js.map +1 -1
- package/lib/features/magic-pdf/DownloadPopover.d.ts +3 -2
- package/lib/features/magic-pdf/DownloadPopover.d.ts.map +1 -1
- package/lib/features/magic-pdf/DownloadPopover.js.map +1 -1
- package/lib/features/magic-pdf/GroundedExtractionView.d.ts.map +1 -1
- package/lib/features/magic-pdf/GroundedExtractionView.js +51 -64
- package/lib/features/magic-pdf/GroundedExtractionView.js.map +1 -1
- package/lib/features/oauth/McpConnectionsButton.d.ts +1 -1
- package/lib/features/oauth/McpConnectionsButton.d.ts.map +1 -1
- package/lib/features/oauth/McpConnectionsButton.js +2 -2
- package/lib/features/oauth/McpConnectionsButton.js.map +1 -1
- package/lib/features/oauth/McpConnectionsDialog.d.ts +1 -1
- package/lib/features/oauth/McpConnectionsDialog.js +2 -2
- package/lib/features/oauth/McpConnectionsDialog.js.map +1 -1
- package/lib/features/oauth/useMcpConnections.d.ts +4 -5
- package/lib/features/oauth/useMcpConnections.d.ts.map +1 -1
- package/lib/features/oauth/useMcpConnections.js +20 -4
- package/lib/features/oauth/useMcpConnections.js.map +1 -1
- package/lib/features/pdf-viewer/PdfPageRenderer.d.ts.map +1 -1
- package/lib/features/pdf-viewer/PdfPageRenderer.js +9 -11
- package/lib/features/pdf-viewer/PdfPageRenderer.js.map +1 -1
- package/lib/features/pdf-viewer/lazyReactPdf.d.ts +10 -0
- package/lib/features/pdf-viewer/lazyReactPdf.d.ts.map +1 -0
- package/lib/features/pdf-viewer/lazyReactPdf.js +25 -0
- package/lib/features/pdf-viewer/lazyReactPdf.js.map +1 -0
- package/lib/features/store/collections/CollectionsTable.d.ts.map +1 -1
- package/lib/features/store/collections/CollectionsTable.js +1 -3
- package/lib/features/store/collections/CollectionsTable.js.map +1 -1
- package/lib/features/store/collections/EditCollectionView.js +1 -1
- package/lib/features/store/collections/EditCollectionView.js.map +1 -1
- package/lib/features/store/objects/ExportPropertiesModal.d.ts +3 -1
- package/lib/features/store/objects/ExportPropertiesModal.d.ts.map +1 -1
- package/lib/features/store/objects/ExportPropertiesModal.js +5 -5
- package/lib/features/store/objects/ExportPropertiesModal.js.map +1 -1
- package/lib/features/store/objects/components/ContentOverview.d.ts.map +1 -1
- package/lib/features/store/objects/components/ContentOverview.js +4 -10
- package/lib/features/store/objects/components/ContentOverview.js.map +1 -1
- package/lib/features/store/objects/components/TextEditorPanel.d.ts.map +1 -1
- package/lib/features/store/objects/components/TextEditorPanel.js +8 -3
- package/lib/features/store/objects/components/TextEditorPanel.js.map +1 -1
- package/lib/features/store/objects/layout/renderers.d.ts.map +1 -1
- package/lib/features/store/objects/layout/renderers.js +1 -5
- package/lib/features/store/objects/layout/renderers.js.map +1 -1
- package/lib/features/store/objects/search/DocumentSearchContext.d.ts +29 -62
- package/lib/features/store/objects/search/DocumentSearchContext.d.ts.map +1 -1
- package/lib/features/store/objects/search/DocumentSearchContext.js +2 -0
- package/lib/features/store/objects/search/DocumentSearchContext.js.map +1 -1
- package/lib/features/store/objects/upload/DocumentUploadModal.d.ts +6 -1
- package/lib/features/store/objects/upload/DocumentUploadModal.d.ts.map +1 -1
- package/lib/features/store/objects/upload/DocumentUploadModal.js +4 -3
- package/lib/features/store/objects/upload/DocumentUploadModal.js.map +1 -1
- package/lib/features/store/objects/upload/useSmartFileUploadProcessing.d.ts.map +1 -1
- package/lib/features/store/objects/upload/useSmartFileUploadProcessing.js +2 -2
- package/lib/features/store/objects/upload/useSmartFileUploadProcessing.js.map +1 -1
- package/lib/features/store/types/ContentObjectTypesTable.d.ts.map +1 -1
- package/lib/features/store/types/ContentObjectTypesTable.js +1 -3
- package/lib/features/store/types/ContentObjectTypesTable.js.map +1 -1
- package/lib/features/store/types/IntakePolicyEditor.d.ts.map +1 -1
- package/lib/features/store/types/IntakePolicyEditor.js +11 -1
- package/lib/features/store/types/IntakePolicyEditor.js.map +1 -1
- package/lib/features/store/types/ObjectSchemaEditor.d.ts.map +1 -1
- package/lib/features/store/types/ObjectSchemaEditor.js +6 -2
- package/lib/features/store/types/ObjectSchemaEditor.js.map +1 -1
- package/lib/features/store/types/TableLayoutEditor.d.ts.map +1 -1
- package/lib/features/store/types/TableLayoutEditor.js +2 -0
- package/lib/features/store/types/TableLayoutEditor.js.map +1 -1
- package/lib/features/store/types/TypeRegistry.d.ts +272 -0
- package/lib/features/store/types/TypeRegistry.d.ts.map +1 -1
- package/lib/features/store/types/search/ObjectTypeSearchContext.d.ts +271 -0
- package/lib/features/store/types/search/ObjectTypeSearchContext.d.ts.map +1 -1
- package/lib/features/user/UserInfo.d.ts.map +1 -1
- package/lib/features/user/UserInfo.js +2 -4
- package/lib/features/user/UserInfo.js.map +1 -1
- package/lib/features/views/ViewActions.d.ts +32 -0
- package/lib/features/views/ViewActions.d.ts.map +1 -0
- package/lib/features/views/ViewActions.js +186 -0
- package/lib/features/views/ViewActions.js.map +1 -0
- package/lib/features/views/ViewDropTarget.d.ts +15 -0
- package/lib/features/views/ViewDropTarget.d.ts.map +1 -0
- package/lib/features/views/ViewDropTarget.js +79 -0
- package/lib/features/views/ViewDropTarget.js.map +1 -0
- package/lib/features/views/ViewExperience.d.ts +3 -2
- package/lib/features/views/ViewExperience.d.ts.map +1 -1
- package/lib/features/views/ViewExperience.js +103 -12
- package/lib/features/views/ViewExperience.js.map +1 -1
- package/lib/features/views/ViewNavigation.d.ts +1 -1
- package/lib/features/views/ViewNavigation.d.ts.map +1 -1
- package/lib/features/views/ViewNavigation.js +14 -5
- package/lib/features/views/ViewNavigation.js.map +1 -1
- package/lib/features/views/ViewResults.d.ts +1 -1
- package/lib/features/views/ViewResults.d.ts.map +1 -1
- package/lib/features/views/ViewResults.js +124 -34
- package/lib/features/views/ViewResults.js.map +1 -1
- package/lib/features/views/index.d.ts +1 -0
- package/lib/features/views/index.d.ts.map +1 -1
- package/lib/features/views/index.js +1 -0
- package/lib/features/views/index.js.map +1 -1
- package/lib/features/views/types.d.ts +46 -1
- package/lib/features/views/types.d.ts.map +1 -1
- package/lib/features/views/viewState.d.ts.map +1 -1
- package/lib/features/views/viewState.js +34 -0
- package/lib/features/views/viewState.js.map +1 -1
- package/lib/i18n/LanguageProvider.d.ts +3 -1
- package/lib/i18n/LanguageProvider.d.ts.map +1 -1
- package/lib/i18n/LanguageProvider.js +9 -7
- package/lib/i18n/LanguageProvider.js.map +1 -1
- package/lib/i18n/instance.d.ts +2 -0
- package/lib/i18n/instance.d.ts.map +1 -1
- package/lib/i18n/instance.js +45 -26
- package/lib/i18n/instance.js.map +1 -1
- package/lib/i18n/locales/ar.json +261 -15
- package/lib/i18n/locales/de.json +259 -13
- package/lib/i18n/locales/en.json +30 -4
- package/lib/i18n/locales/es.json +260 -14
- package/lib/i18n/locales/fr.json +259 -13
- package/lib/i18n/locales/it.json +259 -13
- package/lib/i18n/locales/ja.json +257 -10
- package/lib/i18n/locales/ko.json +257 -10
- package/lib/i18n/locales/pt.json +259 -13
- package/lib/i18n/locales/ru.json +256 -10
- package/lib/i18n/locales/tr.json +256 -10
- package/lib/i18n/locales/zh-TW.json +257 -10
- package/lib/i18n/locales/zh.json +257 -10
- package/lib/session/UserSessionProvider.d.ts.map +1 -1
- package/lib/session/UserSessionProvider.js +8 -16
- package/lib/session/UserSessionProvider.js.map +1 -1
- package/lib/session/auth/composable.d.ts.map +1 -1
- package/lib/session/auth/composable.js +25 -19
- package/lib/session/auth/composable.js.map +1 -1
- package/lib/session/auth/firebase.js +1 -1
- package/lib/session/auth/firebase.js.map +1 -1
- package/lib/shell/VertesiaShell.d.ts.map +1 -1
- package/lib/shell/VertesiaShell.js +2 -1
- package/lib/shell/VertesiaShell.js.map +1 -1
- package/lib/shell/apps/AppInstallationProvider.d.ts +4 -2
- package/lib/shell/apps/AppInstallationProvider.d.ts.map +1 -1
- package/lib/shell/apps/IframeAppContextSync.d.ts +3 -0
- package/lib/shell/apps/IframeAppContextSync.d.ts.map +1 -0
- package/lib/shell/apps/IframeAppContextSync.js +95 -0
- package/lib/shell/apps/IframeAppContextSync.js.map +1 -0
- package/lib/shell/apps/iframe-auth.d.ts +55 -0
- package/lib/shell/apps/iframe-auth.d.ts.map +1 -0
- package/lib/shell/apps/iframe-auth.js +154 -0
- package/lib/shell/apps/iframe-auth.js.map +1 -0
- package/lib/shell/apps/index.d.ts +2 -0
- package/lib/shell/apps/index.d.ts.map +1 -1
- package/lib/shell/apps/index.js +2 -0
- package/lib/shell/apps/index.js.map +1 -1
- package/lib/vertesia-ui-core.js +4 -4
- package/lib/vertesia-ui-core.js.map +1 -1
- package/lib/vertesia-ui-env.js +1 -1
- package/lib/vertesia-ui-env.js.map +1 -1
- package/lib/vertesia-ui-features.js +32 -34
- package/lib/vertesia-ui-features.js.map +1 -1
- package/lib/vertesia-ui-i18n.js +16 -16
- package/lib/vertesia-ui-i18n.js.map +1 -1
- package/lib/vertesia-ui-rich-text.js +4 -4
- package/lib/vertesia-ui-rich-text.js.map +1 -1
- package/lib/vertesia-ui-router.js +1 -1
- package/lib/vertesia-ui-router.js.map +1 -1
- package/lib/vertesia-ui-session.js +1 -1
- package/lib/vertesia-ui-session.js.map +1 -1
- package/lib/vertesia-ui-shell.js +1 -1
- package/lib/vertesia-ui-shell.js.map +1 -1
- package/lib/vertesia-ui-widgets.js +20 -20
- package/lib/vertesia-ui-widgets.js.map +1 -1
- package/lib/widgets/markdown/MarkdownRenderer.d.ts.map +1 -1
- package/lib/widgets/markdown/MarkdownRenderer.js +43 -2
- package/lib/widgets/markdown/MarkdownRenderer.js.map +1 -1
- package/lib/widgets/markdown/MermaidDiagram.d.ts.map +1 -1
- package/lib/widgets/markdown/MermaidDiagram.js +35 -22
- package/lib/widgets/markdown/MermaidDiagram.js.map +1 -1
- package/lib/widgets/monacoEditor/MonacoEditor.d.ts.map +1 -1
- package/lib/widgets/monacoEditor/MonacoEditor.js +14 -10
- package/lib/widgets/monacoEditor/MonacoEditor.js.map +1 -1
- package/lib/widgets/xml-viewer/hooks/useCollapsible.d.ts +1 -1
- package/package.json +24 -29
- package/src/core/components/shadcn/filters/comboBox/DateCombobox.tsx +1 -1
- package/src/core/components/shadcn/filters/filter/dateFilter.tsx +1 -1
- package/src/core/components/shadcn/filters/filters.tsx +1 -1
- package/src/core/components/shadcn/index.ts +1 -0
- package/src/core/components/shadcn/modal/dialog.test.tsx +35 -0
- package/src/core/components/shadcn/modal/dialog.tsx +0 -4
- package/src/core/components/shadcn/overflowTabs.tsx +320 -0
- package/src/core/components/shadcn/selectBox.tsx +2 -2
- package/src/core/components/shadcn/theme/ThemeProvider.tsx +10 -9
- package/src/core/utils/dayjs.ts +17 -0
- package/src/css/base.css +78 -0
- package/src/env/index.test.ts +94 -0
- package/src/env/index.ts +36 -1
- package/src/features/agent/PayloadBuilder.test.ts +68 -0
- package/src/features/agent/PayloadBuilder.tsx +28 -4
- package/src/features/agent/chat/AgentRightPanel.tsx +2 -252
- package/src/features/agent/chat/ArtifactsTab.tsx +1 -0
- package/src/features/agent/chat/AskUserWidget.test.tsx +20 -1
- package/src/features/agent/chat/AskUserWidget.tsx +22 -6
- package/src/features/agent/chat/ModernAgentConversation.test.tsx +160 -0
- package/src/features/agent/chat/ModernAgentConversation.tsx +111 -31
- package/src/features/agent/chat/ModernAgentOutput/ActiveWorkstreamsSummary.tsx +86 -67
- package/src/features/agent/chat/ModernAgentOutput/AllMessagesMixed.test.tsx +90 -7
- package/src/features/agent/chat/ModernAgentOutput/AllMessagesMixed.tsx +4 -6
- package/src/features/agent/chat/ModernAgentOutput/AttachmentPreview.test.ts +103 -1
- package/src/features/agent/chat/ModernAgentOutput/AttachmentPreview.tsx +50 -4
- package/src/features/agent/chat/ModernAgentOutput/BatchProgressPanel.tsx +1 -1
- package/src/features/agent/chat/ModernAgentOutput/Header.tsx +18 -1
- package/src/features/agent/chat/ModernAgentOutput/MessageItem.tsx +1 -1
- package/src/features/agent/chat/ModernAgentOutput/StreamingMessage.tsx +1 -1
- package/src/features/agent/chat/ModernAgentOutput/ToolCallGroup.tsx +1 -1
- package/src/features/agent/chat/ModernAgentOutput/WorkstreamTabs.tsx +37 -167
- package/src/features/agent/chat/ModernAgentOutput/utils.test.ts +94 -0
- package/src/features/agent/chat/ModernAgentOutput/utils.ts +19 -10
- package/src/features/agent/chat/VegaLiteChart.tsx +32 -14
- package/src/features/agent/chat/hooks/useAgentStream.test.tsx +18 -0
- package/src/features/agent/chat/hooks/useAgentStream.ts +3 -0
- package/src/features/document-viewer/UniversalDocumentViewer.tsx +1 -1
- package/src/features/facets/AgentRunnerFacetsNav.tsx +44 -4
- package/src/features/facets/CollectionsFacetsNav.tsx +15 -4
- package/src/features/facets/DocumentsFacetsNav.tsx +25 -8
- package/src/features/facets/FacetQueryHandlers.test.ts +84 -0
- package/src/features/facets/InteractionsFacetsNav.tsx +20 -4
- package/src/features/facets/PromptsFacetsNav.tsx +15 -4
- package/src/features/facets/RunsFacetsNav.test.ts +59 -0
- package/src/features/facets/RunsFacetsNav.tsx +40 -30
- package/src/features/facets/WorkflowExecutionsFacetsNav.test.ts +57 -0
- package/src/features/facets/WorkflowExecutionsFacetsNav.tsx +36 -16
- package/src/features/facets/index.ts +1 -0
- package/src/features/facets/utils/SearchInterface.tsx +12 -3
- package/src/features/layout/GenericPageNavHeader.tsx +16 -0
- package/src/features/magic-pdf/DownloadPopover.tsx +1 -2
- package/src/features/magic-pdf/GroundedExtractionView.test.tsx +7 -1
- package/src/features/magic-pdf/GroundedExtractionView.tsx +162 -242
- package/src/features/oauth/McpConnectionsButton.test.tsx +18 -1
- package/src/features/oauth/McpConnectionsButton.tsx +6 -2
- package/src/features/oauth/McpConnectionsDialog.tsx +3 -3
- package/src/features/oauth/useMcpConnections.test.ts +1 -0
- package/src/features/oauth/useMcpConnections.ts +24 -7
- package/src/features/pdf-viewer/PdfPageRenderer.tsx +76 -71
- package/src/features/pdf-viewer/lazyReactPdf.ts +33 -0
- package/src/features/store/collections/CollectionsTable.tsx +1 -4
- package/src/features/store/collections/EditCollectionView.tsx +1 -1
- package/src/features/store/objects/ExportPropertiesModal.tsx +25 -16
- package/src/features/store/objects/components/ContentOverview.tsx +2 -28
- package/src/features/store/objects/components/TextEditorPanel.tsx +13 -3
- package/src/features/store/objects/layout/renderers.tsx +1 -6
- package/src/features/store/objects/search/DocumentSearchContext.ts +4 -2
- package/src/features/store/objects/upload/DocumentUploadModal.tsx +10 -3
- package/src/features/store/objects/upload/useSmartFileUploadProcessing.ts +15 -6
- package/src/features/store/types/ContentObjectTypesTable.tsx +1 -4
- package/src/features/store/types/IntakePolicyEditor.tsx +11 -1
- package/src/features/store/types/ObjectSchemaEditor.tsx +6 -2
- package/src/features/store/types/TableLayoutEditor.tsx +2 -0
- package/src/features/user/UserInfo.test.tsx +10 -0
- package/src/features/user/UserInfo.tsx +2 -7
- package/src/features/views/ViewActions.test.tsx +80 -0
- package/src/features/views/ViewActions.tsx +352 -0
- package/src/features/views/ViewDropTarget.test.tsx +150 -0
- package/src/features/views/ViewDropTarget.tsx +140 -0
- package/src/features/views/ViewExperience.test.tsx +72 -0
- package/src/features/views/ViewExperience.tsx +189 -22
- package/src/features/views/ViewMedia.test.tsx +180 -0
- package/src/features/views/ViewNavigation.test.tsx +42 -0
- package/src/features/views/ViewNavigation.tsx +43 -5
- package/src/features/views/ViewResults.tsx +243 -26
- package/src/features/views/index.ts +1 -0
- package/src/features/views/types.ts +50 -0
- package/src/features/views/viewState.test.ts +7 -1
- package/src/features/views/viewState.ts +32 -0
- package/src/i18n/LanguageProvider.tsx +15 -8
- package/src/i18n/instance.test.ts +30 -0
- package/src/i18n/instance.ts +67 -40
- package/src/i18n/locales/ar.json +1157 -911
- package/src/i18n/locales/de.json +1113 -867
- package/src/i18n/locales/en.json +30 -4
- package/src/i18n/locales/es.json +1124 -878
- package/src/i18n/locales/fr.json +1124 -878
- package/src/i18n/locales/it.json +1124 -878
- package/src/i18n/locales/ja.json +1113 -866
- package/src/i18n/locales/ko.json +1113 -866
- package/src/i18n/locales/pt.json +1124 -878
- package/src/i18n/locales/ru.json +1135 -889
- package/src/i18n/locales/tr.json +1113 -867
- package/src/i18n/locales/zh-TW.json +1113 -866
- package/src/i18n/locales/zh.json +1113 -866
- package/src/i18n/rtl.test.ts +16 -7
- package/src/rich-text/VertesiaRichTextEditor.test.tsx +33 -1
- package/src/session/UserSessionProvider.tsx +8 -20
- package/src/session/auth/composable.scope.test.ts +1 -1
- package/src/session/auth/composable.test.ts +61 -1
- package/src/session/auth/composable.ts +29 -23
- package/src/session/auth/firebase.ts +1 -1
- package/src/shell/VertesiaShell.tsx +2 -0
- package/src/shell/apps/IframeAppContextSync.test.tsx +196 -0
- package/src/shell/apps/IframeAppContextSync.tsx +101 -0
- package/src/shell/apps/iframe-auth.test.ts +118 -0
- package/src/shell/apps/iframe-auth.ts +193 -0
- package/src/shell/apps/index.ts +2 -0
- package/src/widgets/markdown/ArtifactEditingSurface.test.tsx +12 -3
- package/src/widgets/markdown/MarkdownRenderer.tsx +50 -2
- package/src/widgets/markdown/MermaidDiagram.tsx +38 -22
- package/src/widgets/monacoEditor/MonacoEditor.tsx +27 -20
- package/lib/features/magic-pdf/GroundedExtractionAssistantPanel.d.ts +0 -25
- package/lib/features/magic-pdf/GroundedExtractionAssistantPanel.d.ts.map +0 -1
- package/lib/features/magic-pdf/GroundedExtractionAssistantPanel.js +0 -42
- package/lib/features/magic-pdf/GroundedExtractionAssistantPanel.js.map +0 -1
- package/src/features/magic-pdf/GroundedExtractionAssistantPanel.tsx +0 -86
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
import{Fragment as e,jsx as t,jsxs as n}from"react/jsx-runtime";import{Avatar as r,Badge as i,Breadcrumbs as a,Button as o,Card as s,CardContent as c,CardDescription as l,CardFooter as u,CardHeader as d,CardTitle as f,Center as p,Checkbox as m,Command as h,CommandEmpty as g,CommandGroup as _,CommandInput as v,CommandItem as y,ConfirmModal as b,CopyButton as x,DialogDescription as S,Divider as C,Dropdown as w,DropdownMenu as T,DropdownMenuContent as E,DropdownMenuItem as D,DropdownMenuRadioGroup as O,DropdownMenuRadioItem as k,DropdownMenuTrigger as A,EmptyCollection as j,ErrorBox as M,FilterBar as N,FilterBtn as P,FilterClear as F,FilterProvider as I,FormItem as L,Heading as ee,Input as R,InputList as te,Label as z,MenuGroup as ne,MenuItem as B,MessageBox as re,Modal as ie,ModalBody as ae,ModalFooter as oe,ModalTitle as se,NumberInput as ce,Panel as V,Popover as le,PopoverContent as ue,PopoverTrigger as de,Portal as fe,RadioGroup as pe,RadioGroupAdapter as me,ResizableHandle as he,ResizablePanel as ge,ResizablePanelGroup as _e,SelectBox as ve,SelectList as ye,Separator as be,SharedState as xe,SidePanel as Se,Slider as Ce,SortableTableHeaderCell as we,Spinner as Te,Styles as Ee,Switch as De,TBody as Oe,THead as ke,TR as Ae,Table as je,TableHeaderCell as Me,Tabs as Ne,TabsBar as Pe,TabsPanel as Fe,TagsInput as Ie,Textarea as Le,VTooltip as Re,cn as H,errorMessage as ze,insertNewlineAtCursor as Be,onActivateKey as Ve,useDebounce as He,useFetch as Ue,useFetchOnce as We,useFlag as Ge,useIntersectionObserver as Ke,useIsInModal as qe,useTheme as Je,useToast as Ye,useWatchSharedState as Xe}from"@vertesia/ui/core";import Ze,{clsx as Qe}from"clsx";import{AnimatePresence as $e,motion as et}from"motion/react";import*as U from"react";import W,{Component as tt,createContext as nt,forwardRef as rt,memo as it,useCallback as G,useContext as at,useEffect as K,useId as ot,useLayoutEffect as st,useMemo as q,useRef as J,useState as Y,useSyncExternalStore as ct}from"react";import{AgentResourceResolverProvider as lt,AgentResourceResolverProvider as ut,ArtifactEditingSurface as dt,CodeBlockErrorBoundary as ft,CodeBlockPlaceholder as pt,CodeBlockRendererProvider as mt,DropZone as ht,GeneratedForm as gt,JSONCode as _t,JSONDisplay as vt,ManagedObject as yt,MarkdownRenderer as bt,MonacoEditor as xt,Progress as St,SchemaEditor as Ct,UploadSummary as wt,XMLViewer as Tt,createUnifiedLineDiff as Et,diffTextSegments as Dt,diffWordSegments as Ot,isArtifactRefreshEvent as kt,isIncompleteJson as At,useAgentResourceResolver as jt,useAgentResourceResolver as Mt,useCodeBlockContext as Nt,useSchema as Pt}from"@vertesia/ui/widgets";import{NAMESPACE as Ft,i18nInstance as It,useLocaleFormat as Lt,useUITranslation as X}from"@vertesia/ui/i18n";import{Activity as Rt,AlertCircle as zt,AlertCircleIcon as Bt,AlertTriangle as Vt,ArrowLeft as Ht,ArrowLeftIcon as Ut,ArrowUpIcon as Wt,BarChart3 as Gt,Bot as Kt,Boxes as qt,Braces as Jt,Brain as Yt,BrainCircuit as Xt,Bug as Zt,Check as Qt,CheckCheck as $t,CheckCircle as en,CheckCircle2 as tn,CheckCircleIcon as nn,CheckIcon as rn,ChevronDown as an,ChevronDownIcon as on,ChevronLeft as sn,ChevronRight as cn,ChevronRightIcon as ln,ChevronUp as un,ChevronsDown as dn,ChevronsLeft as fn,ChevronsRight as pn,ChevronsUp as mn,ChevronsUpDown as hn,Circle as gn,ClipboardCopyIcon as _n,ClipboardList as vn,Clock as yn,Code as bn,Copy as xn,CopyIcon as Sn,Cpu as Cn,Database as wn,Download as Tn,DownloadCloudIcon as En,DownloadIcon as Dn,EllipsisVertical as On,ExternalLink as kn,ExternalLinkIcon as An,Eye as jn,FileDown as Mn,FileIcon as Nn,FileJson2 as Pn,FilePenLine as Fn,FileSearch as In,FileText as Ln,FileTextIcon as Rn,FileType as zn,Filter as Bn,FolderClosed as Vn,FolderIcon as Hn,FolderOpenIcon as Un,GitBranch as Wn,GitCompareArrows as Gn,GitFork as Kn,Grid3X3 as qn,HandIcon as Jn,HelpCircle as Yn,Image as Xn,ImageIcon as Zn,Info as Qn,InfoIcon as $n,Layers as er,LayoutGrid as tr,LayoutListIcon as nr,Link as rr,Link2 as ir,Link2Off as ar,ListChecks as or,Loader2 as sr,Loader2Icon as cr,LockKeyhole as lr,LockOpen as ur,Maximize as dr,Maximize2 as fr,MessageSquare as pr,MessageSquareText as mr,MessagesSquare as hr,Minimize2 as gr,Minus as _r,MonitorIcon as vr,MoreVertical as yr,PackageIcon as br,PanelsTopLeft as xr,PaperclipIcon as Sr,Pause as Cr,PenLineIcon as wr,Pencil as Tr,PencilLine as Er,Play as Dr,PlayCircle as Or,Plus as kr,PlusIcon as Ar,Radio as jr,RefreshCcw as Mr,RefreshCw as Nr,RefreshCwIcon as Pr,RotateCcw as Fr,Rows3 as Ir,Rows3Icon as Lr,Save as Rr,ScanSearch as zr,Search as Br,Send as Vr,Settings as Hr,ShieldAlertIcon as Ur,ShieldCheckIcon as Wr,SlidersHorizontal as Gr,Sparkles as Kr,SquareIcon as qr,SquarePen as Jr,SquareTerminal as Yr,Table as Xr,TableProperties as Zr,Terminal as Qr,Trash2 as $r,Unlink2 as ei,UploadIcon as ti,User as ni,Users as ri,Users2 as ii,WandSparkles as ai,Workflow as oi,Wrench as si,X as ci,XCircle as li,XCircleIcon as ui,XIcon as di}from"lucide-react";import*as fi from"@radix-ui/react-dialog";import{UserSessionContext as pi,useUserSession as Z}from"@vertesia/ui/session";import mi from"papaparse";import{VegaEmbed as hi}from"react-vega";import{twMerge as gi}from"tailwind-merge";import{AUDIO_RENDITION_NAME as _i,AgentMessageType as Q,AgentSearchScope as vi,ContentNature as yi,ContentObjectStatus as bi,ContentTypeIntakePolicySchema as xi,FileProcessingStatus as Si,ImageRenditionFormat as Ci,InteractionStatus as wi,MarkdownRenditionFormat as Ti,PDF_RENDITION_NAME as Ei,POSTER_RENDITION_NAME as Di,Permission as Oi,PrincipalType as ki,SearchTypes as Ai,SecurityLevelLabels as ji,SupportedEmbeddingTypes as Mi,WorkflowExecutionStatus as Ni,getContentTypeRefId as Pi,getResourcesFromMessage as Fi,mergeInCodePromptSchemas as Ii,normalizeAgentToolApprovalMode as Li,normalizeToolCollection as Ri,supportsToolUse as zi}from"@vertesia/common";import"react-dom";import{Slot as Bi}from"@radix-ui/react-slot";import{cva as Vi}from"class-variance-authority";import*as Hi from"@radix-ui/react-tooltip";import"@vertesia/ui/env";import"framer-motion";import*as Ui from"@radix-ui/react-checkbox";import"@radix-ui/react-collapsible";import{Command as Wi}from"cmdk";import*as Gi from"@radix-ui/react-dropdown-menu";import Ki from"dayjs";import"react-calendar";import*as qi from"@radix-ui/react-popover";import{capitalize as Ji}from"lodash-es";import*as Yi from"@radix-ui/react-label";import"@radix-ui/react-radio-group";import"react-resizable-panels";import*as Xi from"@radix-ui/react-separator";import*as Zi from"@radix-ui/react-slider";import*as Qi from"@radix-ui/react-switch";import*as $i from"@radix-ui/react-tabs";import ea,{defaultUrlTransform as ta}from"react-markdown";import na from"rehype-katex";import{defListHastHandlers as ra,remarkDefinitionList as ia}from"remark-definition-list";import aa from"remark-directive";import oa from"remark-gfm";import sa from"remark-github-blockquote-alert";import ca from"remark-math";import la from"remark-supersub";import{SKIP as ua,visit as da}from"unist-util-visit";import{FusionFragmentHandler as fa,FusionFragmentProvider as pa}from"@vertesia/fusion-ux";import ma from"dompurify";import ha from"mermaid";import{NavLink as ga,useNavigate as _a,useRouterContext as va}from"@vertesia/ui/router";import ya,{Ajv as ba}from"ajv";import xa from"dayjs/plugin/localizedFormat";import Sa from"dayjs/plugin/relativeTime";import{Md5 as Ca}from"ts-md5";import{Document as wa,Page as Ta,pdfjs as Ea}from"react-pdf";import{ErrorBoundary as Da}from"react-error-boundary";import{FullHeightLayout as Oa,SidebarItem as ka}from"@vertesia/ui/layout";import{VertesiaMarkdownDocumentEditor as Aa}from"@vertesia/ui/rich-text";import ja from"ajv-formats";var Ma=Object.defineProperty,Na=(e,t)=>{let n={};for(var r in e)Ma(n,r,{get:e[r],enumerable:!0});return t||Ma(n,Symbol.toStringTag,{value:`Module`}),n};function Pa({children:e,secondary:n=!1}){return t(`span`,{className:n?`bg-secondary text-primary`:`text-foreground bg-muted`,children:e})}function Fa(e){if(e)return e.name===`array`?Fa(e.innerType):e}function Ia({property:e}){return n(`div`,{className:`flex items-center gap-x-2`,children:[t(`div`,{className:`font-semibold text-gray-600`,children:e.name}),e.optional&&t(Pa,{children:`optional`}),t(Pa,{children:e.type.value})]})}function La({activities:e}){return t(`div`,{className:`flex flex-col gap-y-4 divide-y divide-gray-200`,children:e.map(e=>t(za,{activity:e},e.name))})}function Ra({code:e,children:r}){return n(`div`,{className:`flex gap-2 items-center border-b border-b-gray-200 mb-2`,children:[t(`div`,{className:`text-lg font-medium text-gray-900 py-2 `,children:r}),e&&t(`div`,{children:t(Pa,{children:e})})]})}function za({activity:e,headingClass:r,headingRef:i}){return n(`div`,{className:r,id:e.name,ref:i,children:[t(`div`,{className:`text-xl font-semibold pt-8`,children:e.title}),t(`div`,{className:`pb-4`,children:t(Pa,{children:e.name})}),e.doc&&t(`div`,{className:`text-gray-700 pb-2`,children:e.doc}),n(`div`,{className:`pb-4`,children:[t(Ra,{code:e.paramsType,children:`Parameters`}),t(`div`,{className:`divide-y divide-gray-100`,children:e.params.map(e=>t(Ba,{property:e},e.name))})]}),n(`div`,{className:`pb-4`,children:[t(Ra,{children:`Returns`}),t(`div`,{children:e.returnType?e.returnType.value:`void`})]})]})}function Ba({property:e,className:r}){let i=q(()=>{let n=Fa(e.type.innerType)??e.type;return n.name===`object`&&n.members?t(Ha,{members:n.members}):n.name===`enum`&&n.enum?t(Va,{values:n.enum}):null},[e.type]);return n(`div`,{className:Ze(`py-2`,r),children:[t(Ia,{property:e}),e.doc&&t(`div`,{className:`text-gray-700 text-sm pt-2`,children:e.doc}),i&&t(`div`,{className:`my-2 overflow-hidden`,children:i})]})}function Va({values:e}){return t(`div`,{className:`flex flex-wrap items-center gap-2`,children:e.map(e=>t(Pa,{secondary:!0,children:e},e))})}function Ha({members:e}){return t(Wa,{className:`rounded-md border border-gray-200`,button:e=>n(`div`,{className:`px-4 py-2 flex items-center gap-x-2 text-sm font-medium hover:text-blue-600`,children:[t(Ga,{isOpen:e}),e?t(`div`,{children:`Hide child properties`}):t(`div`,{children:`Show child properties`})]}),body:t(Ua,{properties:e})})}function Ua({properties:e}){return t(`div`,{className:`border-s-2 border-s-blue-200 flex flex-col divide-y divide-gray-100 border-t border-t-gray-200`,children:e.map(e=>t(Ba,{property:e,className:`px-4 py-2`},e.name))})}function Wa({button:e,body:r,className:i,isInitiallyOpen:a}){let[s,c]=Y(a||!1);return n(`div`,{className:Ze(s?`block`:`inline-block`,i),children:[t(o,{variant:`unstyled`,className:`p-0 m-0 bg-transparent`,onClick:()=>c(!s),children:t($e,{children:e(s)})}),t($e,{children:s&&t(et.div,{className:`overflow-hidden`,initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},transition:{duration:.3,ease:`easeOut`},children:r})})]})}function Ga({isOpen:e}){return t($e,{propagate:!0,mode:`wait`,children:t(et.div,{className:`font-mono font-semibold text-gray-400 text-lg`,initial:{rotate:0},animate:{rotate:e?45:0},transition:{duration:.2},children:`+`},`closeIcon`)})}function Ka(e){return e===`full_control`?`text-attention`:e===`auto_review`?`text-info`:`text-muted`}function qa(e){return t(e===`full_control`?Ur:e===`ask`?Jn:Wr,{className:`size-4`})}function Ja({mode:e,onChange:r,disabled:i=!1,className:a}){let{t:s}=X(),c=q(()=>[{mode:`ask`,label:s(`agent.approvalMode.ask`),description:s(`agent.approvalMode.askDescription`),icon:t(Jn,{className:`size-4`})},{mode:`auto_review`,label:s(`agent.approvalMode.autoReview`),description:s(`agent.approvalMode.autoReviewDescription`),icon:t(Wr,{className:`size-4`})},{mode:`full_control`,label:s(`agent.approvalMode.fullControl`),description:s(`agent.approvalMode.fullControlDescription`),icon:t(Ur,{className:`size-4`})}],[s]),l=c.find(t=>t.mode===e)??c[2],u=t=>{t!==e&&r(t)};return n(T,{children:[t(A,{asChild:!0,children:n(o,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,className:H(`h-8 max-w-[13rem] rounded-full px-2.5 font-medium`,`bg-mixer-muted/15 text-muted hover:bg-muted hover:text-foreground disabled:opacity-60`,a),"aria-label":s(`agent.approvalMode.selectorLabel`),children:[t(`span`,{className:H(`shrink-0`,Ka(e)),children:qa(e)}),t(`span`,{className:`min-w-0 truncate`,children:l.label}),t(on,{className:`size-4 shrink-0 opacity-70`})]})}),n(E,{align:`start`,className:`z-[1000000] w-[min(28rem,calc(100vw-1rem))] p-2`,children:[t(`div`,{className:`px-2 pb-1.5 pt-1 text-sm font-medium text-foreground`,children:s(`agent.approvalMode.dropdownTitle`)}),t(O,{value:e,onValueChange:e=>u(e),children:c.map(e=>n(k,{value:e.mode,className:`min-h-14 items-start gap-3 rounded-md py-2 pe-8 ps-2 text-start`,children:[t(`span`,{className:H(`mt-0.5 shrink-0`,Ka(e.mode)),children:e.icon}),n(`span`,{className:`min-w-0 flex-1`,children:[t(`span`,{className:`block text-sm font-medium text-foreground`,children:e.label}),t(`span`,{className:`mt-0.5 block whitespace-normal text-sm leading-5 text-muted`,children:e.description})]})]},e.mode))})]})]})}function $(...e){return gi(Qe(e))}const Ya=nt(null);function Xa({children:e}){let n=J(new Map),r=J(new Map),i=G(e=>n.current.get(e),[]),a=G((e,t)=>{n.current.set(e,t)},[]),o=G(async(e,t)=>{let i=n.current.get(e);if(i)return i;let a=r.current.get(e);if(a)return a;let o=t().then(t=>(n.current.set(e,t),r.current.delete(e),t)).catch(t=>{throw r.current.delete(e),t});return r.current.set(e,o),o},[]),s=W.useMemo(()=>({getUrl:i,setUrl:a,getOrFetch:o}),[i,a,o]);return t(Ya.Provider,{value:s,children:e})}function Za(){return at(Ya)}function Qa(e){return e.startsWith(`agents/`)||e.startsWith(`documents/`)}function $a(e,t,n=`inline`){return`artifact:${e}:${t}:${n}`}function eo(e){return`file:${e}`}function to({error:e,chartTitle:r}){return t(`div`,{className:`flex items-center justify-center h-full bg-red-50 dark:bg-red-950 rounded-md p-4`,children:n(`div`,{className:`text-center`,children:[n(`p`,{className:`text-sm font-medium text-red-600 dark:text-red-400`,children:[`Cannot render `,r||`Vega-Lite`,` chart`]}),t(`p`,{className:`text-xs text-red-500 dark:text-red-500 mt-1 max-w-xs truncate`,children:e})]})})}function no({isOpen:e,onClose:r,title:i,description:a,children:s}){let{t:c}=X();return t(fi.Root,{open:e,onOpenChange:e=>!e&&r(),children:n(fi.Portal,{children:[t(fi.Overlay,{className:`fixed inset-0 z-50 bg-black/80 backdrop-blur-sm transition-all duration-300 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`}),n(fi.Content,{className:`fixed inset-2 sm:inset-4 z-50 flex flex-col bg-white dark:bg-gray-900 rounded-xl shadow-2xl transition-all duration-300 ease-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-98 data-[state=open]:zoom-in-98 data-[state=closed]:slide-out-to-bottom-2 data-[state=open]:slide-in-from-bottom-2`,onEscapeKeyDown:r,children:[t(fi.Close,{asChild:!0,children:t(o,{variant:`unstyled`,onClick:r,className:`absolute top-3 end-3 z-10 p-2 rounded-lg bg-white/80 dark:bg-gray-800/80 backdrop-blur-sm hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors duration-150 shadow-sm`,"aria-label":c(`agent.closeFullscreen`),children:t(ci,{className:`w-5 h-5 text-gray-600 dark:text-gray-300`})})}),t(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6 animate-in fade-in-0 duration-500 delay-150`,children:s}),t(`div`,{className:`flex items-center justify-between px-4 sm:px-6 py-3 border-t border-gray-200 dark:border-gray-800 bg-gray-50/50 dark:bg-gray-800/50 rounded-b-xl`,children:n(`div`,{className:`flex flex-col`,children:[t(fi.Title,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:i||c(`agent.dashboard`)}),a&&t(fi.Description,{className:`text-sm text-gray-500 dark:text-gray-400 mt-0.5`,children:a})]})})]})]})})}function ro(e,t){if(t===`chart`)return 280;let n=1;if(e.vconcat)n=Array.isArray(e.vconcat)?e.vconcat.length:1;else if(e.concat){let t=e.columns||2,r=Array.isArray(e.concat)?e.concat.length:1;n=Math.ceil(r/t)}else e.facet&&(n=2);return Math.max(500,n*280+40)}const io={categorical:[`#6366f1`,`#8b5cf6`,`#ec4899`,`#f43f5e`,`#f97316`,`#eab308`,`#22c55e`,`#14b8a6`,`#06b6d4`,`#3b82f6`],blues:[`#dbeafe`,`#93c5fd`,`#3b82f6`,`#1d4ed8`,`#1e3a8a`],purples:[`#f3e8ff`,`#c4b5fd`,`#8b5cf6`,`#6d28d9`,`#4c1d95`],greens:[`#dcfce7`,`#86efac`,`#22c55e`,`#15803d`,`#14532d`],diverging:[`#ef4444`,`#fca5a5`,`#fef3c7`,`#86efac`,`#22c55e`]};function ao(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function oo(e){return ao(e)}function so(e){let t=JSON.parse(JSON.stringify(e)),n=[`vconcat`,`hconcat`,`concat`];if(!n.some(e=>Array.isArray(t[e])))return t;let r=[];if(Array.isArray(t.params))for(let e of t.params)e&&typeof e==`object`&&e.name&&e.select&&r.push({name:e.name,param:e});if(r.length===0)return t;for(let{name:e,param:i}of r){let r=i.select?.fields||[],a=i.select?.bind===`legend`,o=null;for(let e of n)if(Array.isArray(t[e])){o=t[e];break}if(!o||o.length===0)continue;let s=0;for(let e=0;e<o.length;e++){let t=o[e];if(lo(t,r)||a&&uo(t,r)){s=e;break}}let c=o[s];c.params||=[],c.params.push(i),t.params=(t.params??[]).filter(t=>t.name!==e)}return Array.isArray(t.params)&&t.params.length===0&&delete t.params,t}function co(e,t){if(!t||Object.keys(t).length===0)return e;let n=JSON.parse(JSON.stringify(e)),r=e=>{for(let n of e)n.name&&n.name in t&&(n.value=t[n.name])};Array.isArray(n.params)&&r(n.params);let i=e=>{if(Array.isArray(e)){for(let t of e)if(Array.isArray(t.params)&&r(t.params),t.vconcat&&i(t.vconcat),t.hconcat&&i(t.hconcat),t.concat&&i(t.concat),Array.isArray(t.layer))for(let e of t.layer)Array.isArray(e.params)&&r(e.params)}};if(n.vconcat&&i(n.vconcat),n.hconcat&&i(n.hconcat),n.concat&&i(n.concat),Array.isArray(n.layer))for(let e of n.layer)e&&Array.isArray(e.params)&&r(e.params);return n}function lo(e,t){if(!e?.encoding)return!1;for(let n of t)for(let t of Object.values(e.encoding))if(t.field===n)return!0;if(Array.isArray(e.layer)){for(let n of e.layer)if(lo(n,t))return!0}return!1}function uo(e,t){if(!e)return!1;let n=e=>{if(!e)return!1;let n=e.color?.field;return!!n&&t.includes(n)};if(n(e.encoding))return!0;if(Array.isArray(e.layer)){for(let t of e.layer)if(n(t.encoding))return!0}return!1}function fo(e,t=[]){let n=[];if(!e||typeof e!=`object`)return n;if(e.data&&typeof e.data==`object`){let r=e.data.url;typeof r==`string`&&r.startsWith(`artifact:`)&&n.push({path:[...t,`data`],artifactPath:r.replace(/^artifact:/,``).trim()})}for(let r of[`layer`,`vconcat`,`hconcat`,`concat`,`spec`,`repeat`,`facet`])if(r in e){let i=e[r];Array.isArray(i)?i.forEach((e,i)=>{oo(e)&&n.push(...fo(e,[...t,r,String(i)]))}):oo(i)&&n.push(...fo(i,[...t,r]))}return n}function po(e,t){let n=JSON.parse(JSON.stringify(e));for(let[e,r]of t){let t=e.split(`.`),i=n;for(let e=0;e<t.length-1;e++){let n=i[t[e]];if(!ao(n))break;i=n}let a=t[t.length-1],o=i[a];ao(o)&&(delete o.url,o.values=r)}return n}function mo(e){let t={background:`transparent`,view:{stroke:`transparent`},range:{category:io.categorical,diverging:io.diverging,heatmap:io.purples,ramp:io.blues},mark:{tooltip:!0},bar:{tooltip:!0,cornerRadiusTopLeft:4,cornerRadiusTopRight:4},line:{tooltip:!0,strokeWidth:2.5,strokeCap:`round`},point:{tooltip:!0,size:60,filled:!0},area:{tooltip:!0,fillOpacity:.7,line:!0},rect:{tooltip:!0,cornerRadius:2},arc:{tooltip:!0,cornerRadius:4},circle:{tooltip:!0,size:80}};return e?{...t,axis:{labelColor:`#a1a1aa`,titleColor:`#e4e4e7`,gridColor:`#3f3f46`,domainColor:`#52525b`,tickColor:`#52525b`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,titleFontWeight:500},legend:{labelColor:`#a1a1aa`,titleColor:`#e4e4e7`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,symbolSize:100},title:{color:`#fafafa`,font:`Inter, system-ui, sans-serif`,fontSize:14,fontWeight:600}}:{...t,axis:{labelColor:`#71717a`,titleColor:`#3f3f46`,gridColor:`#e4e4e7`,domainColor:`#d4d4d8`,tickColor:`#d4d4d8`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,titleFontWeight:500},legend:{labelColor:`#71717a`,titleColor:`#3f3f46`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,symbolSize:100},title:{color:`#18181b`,font:`Inter, system-ui, sans-serif`,fontSize:14,fontWeight:600}}}const ho=it(function({spec:r,artifactRunId:i}){let{t:a}=X(),{title:s,description:c,options:l}=r,u=r.spec,[d,f]=Y(!1),[p,m]=Y(!1),[h,g]=Y(null),[_,v]=Y(!1),y=J(null),b=J(null),x=J(null),{client:S}=Z(),C=Za(),w=J(S);w.current=S;let T=J(C);T.current=C;let[E,D]=Y(null),[O,k]=Y(!1),[A,j]=Y(null),M=l?.mode||`chart`,N=M===`dashboard`,P=l?.enableFullscreen??N,F=l?.height||ro(u,M);K(()=>{let e=fo(u);if(e.length===0){D(u),k(!1),j(null);return}i?console.info(`[VegaLiteChart] resolving artifacts with runId:`,i,e.map(e=>e.artifactPath)):console.warn(`[VegaLiteChart] artifact references found but artifactRunId is missing!`,{references:e.map(e=>e.artifactPath),artifactRunId:i});let t=!1;return k(!0),j(null),(async()=>{let n=new Map,r=w.current,a=T.current;for(let o of e)try{let e=o.path.join(`.`),t;if(i&&!Qa(o.artifactPath)){let e=$a(i,o.artifactPath,`inline`);t=a?await a.getOrFetch(e,async()=>(await r.files.getArtifactDownloadUrl(i,o.artifactPath,`inline`)).url):(await r.files.getArtifactDownloadUrl(i,o.artifactPath,`inline`)).url}else{let e=eo(o.artifactPath);t=a?await a.getOrFetch(e,async()=>(await r.files.getDownloadUrl(o.artifactPath)).url):(await r.files.getDownloadUrl(o.artifactPath)).url}let s=await fetch(t);if(!s.ok)throw Error(`Failed to fetch artifact data: ${s.statusText}`);let c=o.artifactPath.toLowerCase().endsWith(`.csv`),l;if(c){let e=await s.text();l=mi.parse(e,{header:!0,skipEmptyLines:!0,dynamicTyping:!0}).data}else{let e=await s.json();l=Array.isArray(e)?e:[e]}n.set(e,l)}catch(e){console.error(`Failed to resolve artifact: ${o.artifactPath}`,e),t||j(`Failed to load data from artifact: ${o.artifactPath}`);return}if(!t){let e=po(u,n);D(e),k(!1)}})(),()=>{t=!0}},[u,i]);let[I,L]=Y(!1),ee=J(!1);K(()=>{let e=()=>{let e=document.documentElement.classList.contains(`dark`);e!==ee.current&&(ee.current=e,L(e))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]);let[R,te]=Y(0),z=J(0);K(()=>{if(!x.current)return;let e,t=new ResizeObserver(t=>{clearTimeout(e),e=setTimeout(()=>{let e=t[0]?.contentRect.width;e&&e!==z.current&&(z.current=e,te(e))},100)});t.observe(x.current);let n=x.current.clientWidth;return z.current=n,te(n),()=>{clearTimeout(e),t.disconnect()}},[]);let ne=q(()=>fo(u).length>0,[u]),B=q(()=>{if(ne&&!E)return null;let e=E||u;return e?(l?.parameterValues&&(e=co(e,l.parameterValues)),so(e)):null},[E,u,ne,l?.parameterValues]),re=G((e,t)=>{if(!e||typeof e!=`object`)return e;if(e.hconcat&&Array.isArray(e.hconcat)){let n=e.hconcat.length,r=(e.spacing??10)*(n-1),i=Math.floor((t-r)/n);return{...e,hconcat:e.hconcat.map(e=>re(e,i))}}if(e.vconcat&&Array.isArray(e.vconcat))return{...e,vconcat:e.vconcat.map(e=>re(e,t))};if(e.concat&&Array.isArray(e.concat)){let n=e.columns??e.concat.length,r=(e.spacing??10)*(n-1),i=Math.floor((t-r)/n);return{...e,concat:e.concat.map(e=>re(e,i))}}let n=e.width;return n===`container`||typeof n==`number`&&n>t?{...e,width:t}:e},[]),ie=G((e,t=!1)=>{if(!B)return null;let n=mo(I),r=t?typeof window<`u`?Math.min(window.innerWidth-80,1400):1200:R>0?R-24:500,i=`vconcat`in B||`hconcat`in B||`concat`in B,a=i?{type:`pad`,contains:`padding`}:{type:`fit`,contains:`padding`},o=B;i&&r&&(o=re(B,r));let c=o.width,l=i?void 0:c===`container`?r:c??r,{width:u,...d}=o;return{$schema:`https://vega.github.io/schema/vega-lite/v6.json`,...!i&&l?{width:l}:{},height:t?void 0:e,autosize:a,...i?o:d,...s&&!B.title?{title:s}:{},config:{...n,...B.config}}},[B,s,I,R,re]),ae=G(async()=>{let e=_?b.current:y.current;if(!(!e||p))try{(await e.toCanvas(2)).toBlob(async e=>{e&&(await navigator.clipboard.write([new ClipboardItem({"image/png":e})]),m(!0),setTimeout(()=>m(!1),2e3))},`image/png`)}catch(e){console.error(`Failed to copy chart:`,e)}},[p,_]),oe=G(async()=>{let e=_?b.current:y.current;if(!(!e||d)){f(!0);try{let t=await e.toImageURL(`png`,2),n=document.createElement(`a`);n.download=`${s||`chart`}.png`,n.href=t,n.click()}catch(e){console.error(`Failed to export chart:`,e)}finally{f(!1)}}},[s,d,_]),se=G(e=>{y.current=e,g(null)},[]),ce=G(e=>{b.current=e},[]),V=G(e=>{console.error(`Vega-Lite rendering error:`,e),g(e instanceof Error?e.message:`Unknown error`)},[]),le=G(()=>{v(e=>!e)},[]);K(()=>{g(null)},[u]);let ue=({className:e})=>n(`div`,{className:$(`flex items-center gap-2`,e),children:[n(o,{variant:`unstyled`,onClick:ae,disabled:p,className:`text-xs px-2 py-1 rounded border border-gray-300 dark:border-gray-700 bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 cursor-pointer transition-colors disabled:opacity-50 flex items-center gap-1`,title:a(`agent.copyToClipboard`),children:[t(p?Qt:xn,{className:`w-3 h-3`}),a(p?`agent.copied`:`agent.copy`)]}),n(o,{variant:`unstyled`,onClick:oe,disabled:d,className:`text-xs px-2 py-1 rounded border border-gray-300 dark:border-gray-700 bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 cursor-pointer transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-1`,title:a(`agent.exportAsPng`),children:[t(Tn,{className:`w-3 h-3`}),a(d?`agent.exporting`:`agent.export`)]}),P&&n(o,{variant:`unstyled`,onClick:le,className:`text-xs px-2 py-1 rounded border border-gray-300 dark:border-gray-700 bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 cursor-pointer transition-colors flex items-center gap-1`,title:a(_?`agent.exitFullscreen`:`agent.fullscreen`),children:[t(_?gr:fr,{className:`w-3 h-3`}),a(_?`agent.exit`:`agent.fullscreen`)]})]});if(O||ne&&!E)return t(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||`Chart`})}),t(`div`,{className:`flex items-center justify-center bg-gray-50 dark:bg-gray-800 rounded`,style:{width:`100%`,height:F},children:n(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[t(sr,{className:`w-5 h-5 animate-spin`}),t(`span`,{className:`text-sm`,children:`Loading data from artifacts...`})]})})]})});if(A)return t(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||`Chart`})}),t(`div`,{style:{width:`100%`,height:F},children:t(to,{error:A,chartTitle:s})})]})});if(h)return t(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||`Chart`})}),t(`div`,{style:{width:`100%`,height:F},children:t(to,{error:h,chartTitle:s})})]})});let de=ie(F),fe=ie(0,!0);return de?(typeof window<`u`&&localStorage.getItem(`DEBUG_VEGA_RENDERS`)&&console.log(`VegaLite rendering with spec:`,{title:s,hasData:!!de.data?.values,dataLength:de.data?.values?.length}),n(e,{children:[t(`div`,{className:$(`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,N&&`border-2`),children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[n(`div`,{className:`flex items-center justify-between`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||(N?`Dashboard`:`Chart`)}),N&&t(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-indigo-100 dark:bg-indigo-900 text-indigo-700 dark:text-indigo-300`,children:`Interactive`})]}),t(ue,{})]}),c&&t(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:c}),t(`div`,{ref:x,className:`bg-white dark:bg-gray-900 rounded overflow-hidden`,style:{width:`100%`,height:F,minWidth:0},children:t(hi,{spec:de,onEmbed:e=>se(e.view),onError:V,options:{renderer:l?.renderer||`canvas`,actions:!1}})})]})}),n(no,{isOpen:_,onClose:()=>v(!1),title:s||(N?`Dashboard`:`Chart`),description:c,children:[t(`div`,{className:`w-full h-full min-h-[calc(100vh-200px)]`,children:fe&&t(hi,{spec:fe,onEmbed:e=>ce(e.view),onError:V,options:{renderer:l?.renderer||`canvas`,actions:!1}})}),t(`div`,{className:`absolute bottom-6 end-6`,children:t(ue,{className:`bg-white dark:bg-gray-800 rounded-lg shadow-lg p-2 border border-gray-200 dark:border-gray-700`})})]})]})):null},(e,t)=>JSON.stringify(e.spec)===JSON.stringify(t.spec)&&e.artifactRunId===t.artifactRunId);function go(e){return e.library===`vega-lite`&&typeof e.spec==`object`}function _o(e){return e.library===`recharts`||e.library===void 0}function vo(e){return typeof e.$schema==`string`&&e.$schema.includes(`vega`)}const yo=it(function({spec:e,artifactRunId:r}){return go(e)?t(ho,{spec:e,artifactRunId:r}):vo(e)?t(ho,{spec:{library:`vega-lite`,spec:e},artifactRunId:r}):n(`div`,{className:`my-5 rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-200`,children:[`Recharts chart rendering has been retired. Use a Vega-Lite chart spec (`,t(`code`,{children:`library: "vega-lite"`}),` with `,t(`code`,{children:`spec`}),`).`]})},(e,t)=>JSON.stringify(e.spec)===JSON.stringify(t.spec)&&e.artifactRunId===t.artifactRunId);function bo(e,t){return e===`live`?e:t===0?`live`:Math.min(Math.max(e,0),t-1)}function xo(e,t){return t===0?-1:e===`live`?t-1:Math.min(Math.max(e,0),t-1)}function So(e,t){if(e.length===0)return null;let n=t===`live`?e.length:xo(t,e.length);for(let t=Math.min(n-1,e.length-1);t>=0;t--)if(e[t].type===Q.QUESTION)return t;return null}function Co(e,t){if(e.length===0||t===`live`)return null;let n=xo(t,e.length);for(let t=n+1;t<e.length;t++)if(e[t].type===Q.QUESTION)return t;return`live`}function wo(e,t,n){let r=n?bo(t,e.length):`live`,i=xo(r,e.length),a=!n||r===`live`,o=a?e:e.slice(0,i+1);return{cursor:r,cursorIndex:i,isLive:a,renderedMessageCount:o.length,displayedMessages:o}}function To(e){let t=e.indexOf(`?`);return t===-1?new URLSearchParams:new URLSearchParams(e.slice(t+1))}function Eo(){return!(typeof window>`u`)}function Do(){if(!Eo())return!1;let e=new URLSearchParams(window.location.search),t=To(window.location.hash),n=e.get(`agentChatPlayback`)??t.get(`agentChatPlayback`);return n===`1`||n===`true`}const Oo=Eo,ko=Do;function Ao({cursor:e,messages:r,onChangeCursor:i,className:a}){let{t:s}=X(),c=r.length,l=e===`live`,u=xo(e,c),d=c>0&&(l||u>0),f=!l&&c>0,p=c>0&&(l||u>0),m=!l&&c>0&&u<c-1,h=c===0?0:u+1,[g,_]=Y(String(h));K(()=>{_(String(h))},[h]);let v=()=>{if(c!==0){if(e===`live`){i(c-1);return}i(Math.max(0,u-1))}},y=()=>{if(c!==0&&e!==`live`){if(u>=c-1){i(`live`);return}i(u+1)}},b=()=>{c!==0&&i(0)},x=()=>{c!==0&&i(c-1)},S=()=>{_(String(h))},C=(e,t=!1)=>{if(c===0){_(`0`);return}let n=Number.parseInt(e,10);if(!Number.isFinite(n)){t&&S();return}let r=Math.min(Math.max(n,1),c);_(String(r)),i(r-1)},w=e=>{c!==0&&C(e)},T=c>1,E=+!!T,D=Math.max(1,c),O=`size-7 rounded-lg text-muted hover:text-foreground disabled:opacity-35`,k=`${Math.max(3,String(c).length+1)}ch`;return n(`div`,{className:H(`inline-flex max-w-full flex-col gap-1 rounded-xl border border-border/70 bg-background/95 px-2 py-1 text-sm leading-none text-muted shadow-lg shadow-black/10 backdrop-blur`,a),"data-testid":`agent-test-playback-controls`,"data-playback-cursor":e,"data-live-message-count":c,"data-rendered-message-count":l?c:u+1,children:[n(`div`,{className:`flex max-w-full items-center gap-1`,children:[t(`span`,{className:`ms-2 me-1 font-medium leading-none text-foreground/80`,children:s(`agent.rewind.label`)}),t(o,{type:`button`,variant:`ghost`,size:`icon`,title:s(`agent.rewind.jumpToStart`),disabled:!p,onClick:b,className:O,children:t(fn,{className:`size-4`})}),t(o,{type:`button`,variant:`ghost`,size:`icon`,title:s(`agent.rewind.previousMessage`),disabled:!d,onClick:v,className:O,children:t(sn,{className:`size-4`})}),n(`span`,{className:`inline-flex min-w-16 items-center justify-center gap-0.5 px-1 font-medium leading-none tabular-nums text-foreground/80`,"data-testid":`agent-test-playback-position`,children:[t(R,{type:`text`,variant:`unstyled`,size:`sm`,clearable:!1,inputMode:`numeric`,pattern:`[0-9]*`,value:g,"aria-label":s(`agent.rewind.positionInput`),disabled:c===0,onChange:e=>{let t=e.replace(/\D/g,``);_(t)},onBlur:e=>C(e.currentTarget.value,!0),onKeyDown:e=>{e.key===`Enter`&&(C(e.currentTarget.value,!0),e.currentTarget.blur())},style:{width:k},className:`h-7 w-auto rounded-md border border-transparent bg-transparent px-1 text-center text-sm font-medium leading-none tabular-nums text-foreground outline-none transition-colors hover:border-border focus:border-ring focus:bg-muted/30 disabled:opacity-50`}),t(`span`,{"aria-hidden":`true`,className:`text-muted`,children:`/`}),t(`span`,{className:`text-muted`,children:c})]}),t(o,{type:`button`,variant:`ghost`,size:`icon`,title:s(`agent.rewind.nextMessage`),disabled:!f,onClick:y,className:O,children:t(cn,{className:`size-4`})}),t(o,{type:`button`,variant:`ghost`,size:`icon`,title:s(`agent.rewind.jumpToLatest`),disabled:!m,onClick:x,className:O,children:t(pn,{className:`size-4`})}),t(o,{type:`button`,variant:l?`secondary`:`ghost`,size:`icon`,title:s(`agent.rewind.jumpToLive`),disabled:l,onClick:()=>i(`live`),className:H(O,l&&`bg-muted text-foreground`),children:t(jr,{className:`size-4`})})]}),t(`div`,{className:`px-2 pb-1`,children:t(Ce,{min:E,max:D,step:1,value:[h],"aria-label":s(`agent.rewind.positionInput`),disabled:!T,onValueChange:([e])=>w(String(e)),className:`h-2`})})]})}nt(void 0);var jo=class{filter(e,t){let n=t.toLowerCase();return e.filter(e=>this.valueOf(e).toLowerCase().includes(n))}renderOption(e){return this.valueOf(e)}findById(e,t){return e.find(e=>this.idOf(e)===t)}createItem(e){return null}},Mo=class e extends jo{valueOf(e){return String(e)}idOf(e){return String(e)}static instance=new e};(class e extends Mo{createItem(e){return e}static instance=new e});const No=W.createContext(void 0);function Po(){return W.useContext(No)}const Fo=Hi.Provider,Io=Hi.Root,Lo=Hi.Trigger,Ro=U.forwardRef(({className:e,sideOffset:n=4,side:r=`top`,...i},a)=>{let o=Po();return t(Hi.Portal,{container:o,children:t(Hi.Content,{ref:a,sideOffset:n,side:r,style:{zIndex:100},className:$(`max-w-[90vw]`,`z-50 overflow-hidden rounded-md bg-tooltips border border-border px-3 py-1.5 text-xs animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...i})})});Ro.displayName=Hi.Content.displayName;function zo({description:e,children:r,size:i=`sm`,placement:a=`top`,className:o,asChild:s}){let[c,l]=U.useState(!1),u=U.useRef(!1);return U.useEffect(()=>{let e=()=>{l(!1),u.current=!0,requestAnimationFrame(()=>{u.current=!1})};return window.addEventListener(`blur`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`blur`,e),document.removeEventListener(`visibilitychange`,e)}},[]),t(Fo,{delayDuration:0,children:n(Io,{open:c,onOpenChange:e=>{u.current||l(e)},children:[t(Lo,{className:`cursor-pointer`,asChild:s,children:r}),t(Ro,{side:a,className:`px-3 py-1.5 max-w-${i} text-${i} px-3 ${o}`,children:e})]})})}const Bo=new Set;function Vo(e,t,n){K(()=>{t&&!Bo.has(e)&&(Bo.add(e),console.warn(`[@vertesia/ui] ${e} is deprecated: ${n}`))},[t,n,e])}function Ho(e){return U.Children.toArray(e).some(e=>{if(typeof e==`string`)return e.trim().length>0;if(typeof e==`number`)return!0;if(U.isValidElement(e)){let t=e.props;return t[`aria-hidden`]===!0||t[`aria-hidden`]===`true`?!1:Ho(t.children)}return!1})}const Uo=Vi(`hover:cursor-pointer inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`,{variants:{variant:{destructive:`bg-destructive dark:bg-destructive/10 text-destructive ring-1 ring-inset ring-destructive-muted/50 dark:ring-destructive-muted/50 shadow-xs hover:bg-destructive/50`,outline:`border border-input bg-background shadow-xs hover:bg-muted ring-inset`,secondary:`bg-primary/5 dark:bg-primary/10 text-primary shadow-xs hover:bg-primary/10 dark:hover:bg-primary/20 ring-inset`,ghost:`hover:bg-muted/50 dark:hover:bg-muted/20 ring-inset`,link:`text-foreground underline-offset-4 hover:underline ring-inset`,primary:`bg-primary text-white shadow-xs hover:bg-primary/90 ring-inset`,unstyled:``},size:{xs:`h-7 rounded px-2 py-1 text-xs gap-x-1`,sm:`h-8 rounded px-3 text-xs`,md:`h-9 rounded-md px-4 py-2`,lg:`h-10 rounded-md px-3`,xl:`rounded-md px-3.5 py-2.5 text-sm gap-x-2`,icon:`p-0 m-0 rounded-full`,none:``}},defaultVariants:{variant:`primary`,size:`md`}}),Wo=U.forwardRef(({className:r,variant:i,size:a,asChild:o=!1,alt:s,isDisabled:c,isLoading:l,title:u,tooltipPlacement:d=`top`,onClick:f,type:p,...m},h)=>{Vo(`Button.alt`,s!==void 0,"use `title` instead — it drives the same tooltip and the accessible name. `alt` remains an alias for one release.");let g=o?Bi:`button`,_=o?p:p??`button`,v=u??s,y=m[`aria-label`]??s??(Ho(m.children)?void 0:u),b=o?m.children:n(e,{children:[l&&t(sr,{className:`animate-spin`}),m.children]}),x=t(g,{className:Ze($(Uo({variant:i,size:a})),r),disabled:c||l||m.disabled,ref:h,onClick:f,type:_,autoFocus:!1,...m,"aria-label":y,children:b});return v?t(zo,{description:v,asChild:!0,className:`cursor-pointer`,size:`xs`,placement:d,children:x}):x});Wo.displayName=`Button`;const Go=U.forwardRef(({size:e,content:n,toast:r,className:i,alt:a,"aria-label":o,...s},c)=>{let[l,u]=Y(!1),{t:d}=X();Vo(`CopyButton.alt`,a!==void 0,"use aria-label for the accessible name. `alt` is forwarded for one release.");let f=e=>{e.stopPropagation(),navigator.clipboard.writeText(n).then(()=>{u(!0),setTimeout(()=>u(!1),2e3),r?.toast&&r.toast({status:`success`,title:r.message||d(`misc.copiedToClipboard`),duration:2e3})}).catch(e=>{console.error(`Failed to copy text: `,e),r?.toast&&r.toast({status:`error`,title:d(`misc.failedToCopy`),duration:2e3})})},p=o??a??d(`misc.copy`);return t(Wo,{ref:c,className:$(i),variant:`unstyled`,size:e||`sm`,onClick:f,...s,title:p,children:l?t(Qt,{className:`text-success`}):t(Sn,{className:`size-4`})})});Go.displayName=`CopyButton`;function Ko(e){return t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e(t))}}const qo=Vi(`inline-flex items-center rounded-md px-2 py-1 text-xs font-medium`,{variants:{variant:{default:`text-foreground bg-muted`,secondary:`bg-secondary text-primary`,destructive:`bg-destructive text-destructive`,attention:`bg-attention text-attention`,success:`bg-success text-success`,info:`bg-info text-info`,done:`bg-done text-done`,outline:`bg-transparent border border-border text-foreground`}},defaultVariants:{variant:`default`}});function Jo({className:e,variant:n,children:r,onClick:i,...a}){let o=i?{role:`button`,tabIndex:0,onClick:i,onKeyDown:Ko(i)}:{};return t(`span`,{className:$(qo({variant:n}),e),...o,...a,children:r})}Vi(`inline-flex items-center gap-x-1.5 rounded-md px-2 py-1 text-xs font-medium ring-1 ring-inset ring-border`,{variants:{variant:{default:``,success:``,destructive:``,attention:``,done:``,info:``,outline:``}},defaultVariants:{variant:`default`}}),Vi(`h-1.5 w-1.5`,{variants:{variant:{default:`fill-foreground`,success:`fill-success`,destructive:`fill-destructive`,attention:`fill-attention`,done:`fill-done`,info:`fill-info`,outline:`fill-foreground`}},defaultVariants:{variant:`default`}}),rt(function(e,n){let{current:r,children:i,className:a,href:o=`#`,onClick:s,...c}=e;return t(`li`,{className:Ze(a,r?`bg-muted`:``,`w-full p-2 ps-3 text-sm leading-6 font-semibold hover:bg-muted`),children:t(`a`,{ref:n,href:o,onClick:e=>{s?(e.preventDefault(),s(e)):o===`#`&&e.preventDefault()},className:`w-full flex items-center gap-x-3`,...c,children:i})})});const Yo=`rounded-md text-sm flex w-full rounded-md border border-input bg-background ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 ring-inset focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`,Xo={INPUT_UNSTYLED:`block m-0 p-0 w-full border-0 focus:outline-hidden focus:ring-0 bg-transparent`,INPUT_NO_PADDING:Yo,INPUT:`${Yo} py-1.5`};function Zo(e){return e==null||Number.isNaN(e)?``:e.toString()}W.forwardRef(({value:e,onChange:n,className:r,noScroll:i=!1,noSpinners:a=!1,...o},s)=>{let[c,l]=W.useState(Zo(e));return K(()=>{if(e==null||!Number.isNaN(e)){let t=Zo(e);l(t)}},[e]),t(`input`,{onWheel:i?e=>{e.currentTarget.blur()}:o.onWheel,type:`number`,value:c,onChange:e=>{let t=e.target.value;l(t),t===``?n?.(void 0,t):n?.(parseFloat(t),t)},className:Ze(r,Xo.INPUT,{"no-spinners":a},a&&`[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`),ref:s,...o})});const Qo=U.forwardRef(({...e},n)=>t(`nav`,{ref:n,"aria-label":`breadcrumb`,...e}));Qo.displayName=`Breadcrumb`;const $o=U.forwardRef(({className:e,...n},r)=>t(`ol`,{ref:r,className:$(`flex flex-wrap items-center gap-1.5 break-words text-sm text-muted sm:gap-2.5`,e),...n}));$o.displayName=`BreadcrumbList`;const es=U.forwardRef(({className:e,...n},r)=>t(`li`,{ref:r,className:$(`inline-flex items-center gap-1.5 text-muted`,e),...n}));es.displayName=`BreadcrumbItem`;const ts=U.forwardRef(({asChild:e,className:n,...r},i)=>t(`a`,{ref:i,className:$(`transition-colors hover:text-muted`,n),...r}));ts.displayName=`BreadcrumbLink`;const ns=U.forwardRef(({className:e,href:n,onClick:r,...i},a)=>t(Wo,{variant:`ghost`,size:`md`,ref:a,className:$(`p-0! hover:underline! hover:bg-background!`,e),onClick:e=>{e.preventDefault(),r&&r(e)},...i}));ns.displayName=`BreadcrumbButton`;const rs=U.forwardRef(({className:e,...n},r)=>t(`span`,{ref:r,"aria-current":`page`,className:$(`font-normal text-foreground`,e),...n}));rs.displayName=`BreadcrumbPage`;const is=U.forwardRef(({className:e,...n},r)=>t(`div`,{ref:r,className:$(`rounded-xl border bg-card text-card-foreground shadow`,e),...n}));is.displayName=`Card`;const as=U.forwardRef(({className:e,...n},r)=>t(`div`,{ref:r,className:$(`flex flex-col p-6`,e),...n}));as.displayName=`CardHeader`;const os=U.forwardRef(({className:e,...n},r)=>t(`div`,{ref:r,className:$(`font-semibold leading-none tracking-tight`,e),...n}));os.displayName=`CardTitle`;const ss=U.forwardRef(({className:e,...n},r)=>t(`div`,{ref:r,className:$(`text-sm text-muted-foreground`,e),...n}));ss.displayName=`CardDescription`;const cs=U.forwardRef(({className:e,...n},r)=>t(`div`,{ref:r,className:$(`p-6 pt-0`,e),...n}));cs.displayName=`CardContent`;const ls=U.forwardRef(({className:e,...n},r)=>t(`div`,{ref:r,className:$(`flex items-center p-6 pt-0`,e),...n}));ls.displayName=`CardFooter`;const us=U.forwardRef(({className:e,...n},r)=>t(Ui.Root,{ref:r,className:$(`peer size-4 shrink-0 rounded-sm border border-1 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-white`,e),...n,children:t(Ui.Indicator,{className:$(`flex items-center justify-center text-current`),children:t(Qt,{className:`size-4`})})}));us.displayName=Ui.Root.displayName;function ds({children:e}){return t(`span`,{style:{border:0,clip:`rect(0 0 0 0)`,height:`1px`,margin:`-1px`,overflow:`hidden`,padding:0,position:`absolute`,width:`1px`,whiteSpace:`nowrap`,wordWrap:`normal`},children:e})}const fs=nt(!1);function ps({children:e}){return t(fs.Provider,{value:!0,children:e})}function ms({className:e,children:r,isOpen:i,onClose:a,description:o=`Modal Description`,noCloseButton:s=!1,allowOverflow:c=!1,disableCloseOnClickOutside:l=!1,size:u=`md`,action:d}){let f=e=>{e||a()};function p(){switch(u){case`sm`:return`max-w-[20vw]`;case`md`:return`max-w-[60vw] lg:max-w-[40vw]`;case`lg`:return`max-w-[80vw] md:max-w-[60vw]`;case`xl`:return`max-w-[95vw] lg:max-w-[80vw]`;case`full`:return`h-[calc(100vh-2rem)] max-w-[calc(100vw-2rem)]`;default:return`max-w-[60vw] lg:max-w-[40vw]`}}return n(_s,{open:i,onOpenChange:e=>{(!l||e)&&f(e)},children:[c&&t(bs,{className:`z-50 fixed inset-0 bg-black/80`}),t(ds,{children:t(Ss,{children:o})}),n(xs,{className:$(`min-h-20 p-4`,`fixed left-[50%] top-[50%] z-50 grid w-full translate-x-[-50%] translate-y-[-50%] border bg-background shadow-lg duration-200 sm:rounded-lg`,p(),e),children:[t(`div`,{className:`top-4 end-4 absolute`,children:n(`div`,{className:`flex gap-2`,children:[d&&d,!s&&t(ys,{onClick:()=>f(!1),asChild:!0,autoFocus:!1,children:t(Wo,{variant:`outline`,title:`Close`,className:`data-[state=open]:bg-accent opacity-70 hover:opacity-100 rounded-sm focus:outline-none focus:ring-2 focus:ring-ring ring-offset-background focus:ring-offset-2 data-[state=open]:text-muted-foreground transition-opacity disabled:pointer-events-none`,children:t(ci,{className:`size-4`})})})]})}),t(ps,{children:r})]})]})}const hs=({children:e,show:r=!0,className:i,description:a,showDivider:o=!1,...s})=>r?n(Cs,{className:$(o?`border-b-solid border-b border-b-1 pb-2 mb-4`:``,`text-lg font-semibold leading-6 tracking-tight`,{"py-2":!a},i),...s,children:[e,a&&t(Ss,{className:`text-sm !font-normal text-muted-foreground pb-2`,children:a})]}):n(ds,{children:[t(Cs,{children:e}),a&&t(Ss,{children:a})]}),gs=({children:e,className:n,...r})=>t(`div`,{className:$(`text-sm max-h-[80vh] overflow-y-auto`,n),...r,children:e}),_s=fi.Root,vs=fi.Portal,ys=fi.Close,bs=U.forwardRef(({className:e,...n},r)=>t(fi.Overlay,{ref:r,className:$(`fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...n}));bs.displayName=fi.Overlay.displayName;const xs=U.forwardRef(({className:e,children:r,...i},a)=>{let o=Po();return n(vs,{container:o,children:[t(bs,{}),t(fi.Content,{ref:a,autoFocus:!1,onOpenAutoFocus:e=>{e.preventDefault()},className:$(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] border bg-background shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg`,e),...i,children:r})]})});xs.displayName=fi.Content.displayName;const Ss=U.forwardRef(({className:e,...n},r)=>t(fi.Description,{ref:r,className:$(`text-sm text-muted`,e),...n}));Ss.displayName=fi.Description.displayName;const Cs=U.forwardRef(({className:e,...n},r)=>t(fi.Title,{ref:r,className:$(`text-lg font-semibold leading-none tracking-tight`,e),...n}));Cs.displayName=fi.Title.displayName;const ws=U.forwardRef(({className:e,...n},r)=>t(Wi,{ref:r,className:$(`flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground`,e),...n}));ws.displayName=Wi.displayName;const Ts=U.forwardRef(({className:e,...r},i)=>n(`div`,{className:`flex items-center px-3 border-b`,"cmdk-input-wrapper":``,children:[t(Br,{className:`opacity-50 size-4 shrink-0`}),t(Wi.Input,{ref:i,className:$(`focus:ring-0`,`border-0 flex h-8 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50`,e),...r})]}));Ts.displayName=Wi.Input.displayName;const Es=U.forwardRef(({className:e,...n},r)=>t(Wi.List,{ref:r,className:$(`overflow-y-auto overflow-x-hidden`,e),...n}));Es.displayName=Wi.List.displayName;const Ds=U.forwardRef((e,n)=>t(Wi.Empty,{ref:n,className:`py-2 text-sm text-center`,...e}));Ds.displayName=Wi.Empty.displayName;const Os=U.forwardRef(({className:e,...n},r)=>t(Wi.Group,{ref:r,className:$(`overflow-y-auto overflow-x-hidden p-1 text-foreground`,`[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground`,e),...n}));Os.displayName=Wi.Group.displayName;const ks=U.forwardRef(({className:e,...n},r)=>t(Wi.Separator,{ref:r,className:$(`-mx-1 h-px bg-border`,e),...n}));ks.displayName=Wi.Separator.displayName;const As=U.forwardRef(({className:e,...n},r)=>t(Wi.Item,{ref:r,className:$(`hover:bg-muted cursor-pointer relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`,e),...n}));As.displayName=Wi.Item.displayName;const js=U.createContext(!1);function Ms({...e}){return t(Gi.Root,{"data-slot":`dropdown-menu`,...e})}function Ns({...e}){return t(Gi.Trigger,{"data-slot":`dropdown-menu-trigger`,...e})}function Ps({className:e,align:n=`start`,sideOffset:r=4,...i}){return t(Gi.Portal,{children:t(Gi.Content,{"data-slot":`dropdown-menu-content`,sideOffset:r,align:n,className:$(`data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 bg-popover text-popover-foreground min-w-32 rounded-lg p-1 shadow-md ring-1 duration-100 z-50 max-h-(--radix-dropdown-menu-content-available-height) w-(--radix-dropdown-menu-trigger-width) origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto data-[state=closed]:overflow-hidden`,e),...i})})}function Fs({className:e,inset:n,variant:r=`default`,...i}){return t(Gi.Item,{"data-slot":`dropdown-menu-item`,"data-inset":n,"data-variant":r,className:$(`hover:bg-muted focus:bg-muted data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:text-destructive gap-2 rounded-md px-1.5 py-1 text-sm data-inset:ps-7 [&_svg:not([class*='size-'])]:size-4 group/dropdown-menu-item relative flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0`,e),...i})}const Is={left:`start`,center:`center`,right:`end`};function Ls({trigger:e,children:r,align:i=`right`,hover:a}){let[o,s]=U.useState(!1),c=U.useRef(null);return a?n(`div`,{className:`relative inline-flex`,onMouseEnter:()=>{c.current&&clearTimeout(c.current),s(!0)},onMouseLeave:()=>{c.current=setTimeout(()=>s(!1),80)},children:[e,o&&t(`div`,{className:$(`absolute top-full pt-1 z-50`,i===`right`?`end-0`:i===`center`?`left-1/2 -translate-x-1/2`:`start-0`),children:t(`div`,{className:`min-w-32 rounded-lg p-1 shadow-md ring-1 ring-foreground/10 bg-popover text-popover-foreground`,children:t(js.Provider,{value:!0,children:r})})})]}):n(Ms,{children:[t(Ns,{asChild:!0,children:t(`span`,{className:`-m-1.5 flex items-center p-1.5`,children:e})}),t(Ps,{align:Is[i],className:`w-max`,children:r})]})}function Rs({children:e,href:n,onClick:r,isDisabled:i=!1,variant:a=`default`,className:o}){let s=U.useContext(js),c=$(`w-full gap-2 rounded-md px-1.5 py-1 text-sm text-nowrap [&_svg:not([class*='size-'])]:size-4 flex cursor-default items-center select-none [&_svg]:pointer-events-none [&_svg]:shrink-0`,a===`destructive`?`text-destructive`:``,i?`pointer-events-none opacity-50`:`hover:bg-muted focus:bg-muted`,o);return s?n?t(`a`,{href:n,className:c,children:e}):t(`button`,{type:`button`,className:c,disabled:i,onClick:e=>{e.stopPropagation(),r?.(e)},children:e}):t(Fs,{className:$(`data-[disabled]:pointer-events-none data-[disabled]:opacity-50 text-nowrap`,o),disabled:i,variant:a,onClick:e=>{e.stopPropagation(),r?.(e)},asChild:!!n,children:n?t(`a`,{href:n,children:e}):e})}const zs=U.createContext(null);function Bs(e=!1,t=()=>{},n){e&&t(n===`enter`)}const Vs=U.forwardRef(({children:e,...n},r)=>{let i=U.useContext(zs);if(!i)throw Error(`PopoverTrigger must be used within a Popover`);let{setOpen:a,hover:o,click:s}=i;return t(qi.Trigger,{ref:r,asChild:!0,onMouseEnter:()=>Bs(o,a,`enter`),onMouseLeave:()=>Bs(o,a,`leave`),onClick:()=>{s&&a(e=>!e)},...n,children:e})});Vs.displayName=qi.Trigger.displayName;const Hs=U.forwardRef(({className:e,align:n=`center`,side:r=`bottom`,...i},a)=>{let o=U.useContext(zs);if(!o)throw Error(`PopoverContent must be used within a Popover`);let{setOpen:s,hover:c}=o,l=Po();return t(qi.Portal,{container:l,children:t(qi.Content,{ref:a,align:n,side:r,onMouseEnter:()=>Bs(c,s,`enter`),onMouseLeave:()=>Bs(c,s,`leave`),className:$(`z-50 w-72 rounded-md border-popover bg-popover text-popover-foreground ring-1 ring-gray-200 dark:ring-slate-700 shadow-md focus:outline-none animate-in`,`data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...i})})});Hs.displayName=qi.Content.displayName;const Us=qi.Close;Us.displayName=qi.Close.displayName;const Ws=Vi(``,{variants:{size:{xs:`rounded py-1 text-xs rounded-xs`,sm:`rounded text-xs rounded-sm`,md:`rounded-md py-2 text-sm`,lg:`rounded-md text-base`,xl:`rounded-md py-2.5 text-lg`},variant:{default:`flex w-full rounded-md border border-input bg-background ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 ring-inset focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`,unstyled:`block m-0 p-0 w-full border-0 focus:outline-hidden focus:ring-0 bg-transparent`,noPadding:`block rounded-md border-0 bg-background shadow-2xs ring-1 ring-inset ring-ring placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-ring ring-offset-background`,legacy:`py-1.5 block rounded-md border-0 bg-background shadow-2xs ring-1 ring-inset ring-ring placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-ring ring-offset-background`}},defaultVariants:{size:`md`,variant:`default`}}),Gs=U.forwardRef(({className:e,type:r,size:i=`md`,variant:a=`default`,clearable:o=!0,onChange:s,value:c,invalid:l,...u},d)=>{let f=()=>{s?.(``)},p=e=>{s?.(e.target.value)},m=u[`aria-invalid`]??(l?!0:void 0);return n(`div`,{className:`w-full relative inline-block [&:hover_.clear-button]:opacity-100`,children:[t(`input`,{type:r,className:$(Ws({size:i,variant:a}),e,o&&c?`pe-8`:``),ref:d,value:c??``,onChange:p,...u,"aria-invalid":m}),o&&c&&!u.readOnly&&!u.disabled&&t(Wo,{variant:`link`,size:`icon`,type:`button`,onClick:f,className:`clear-button opacity-0 transition-opacity duration-200
|
|
2
|
-
absolute top-1/2 -translate-y-1/2 text-muted !hover:text-destructive cursor-pointer
|
|
3
|
-
flex items-center justify-center size-6 rounded end-2`,"aria-label":`Clear input`,children:t(ci,{size:16})})]})});Gs.displayName=`Input`,W.createContext({filters:[],setFilters:()=>void 0,filterGroups:[]});var Ks;(function(e){e.IS=`is`,e.IS_NOT=`is_not`,e.CONTAINS=`contains`,e.BEFORE=`before`,e.AFTER=`after`,e.IS_ANY_OF=`is_any_of`})(Ks||={});const qs=rt(({className:e,level:n=3,...r},i)=>t(`h${n}`,{ref:i,className:$({h1:`text-2xl font-medium tracking-tight`,h2:`text-xl font-medium tracking-tight`,h3:`text-lg font-medium`,h4:`text-base font-medium`,h5:`text-sm font-medium`,h6:`text-xs font-medium`}[`h${n}`],`mb-2`,e),...r}));qs.displayName=`Heading`;const Js=Vi(`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`),Ys=U.forwardRef(({className:e,required:r,...i},a)=>n(Yi.Root,{ref:a,className:$(Js(),e),...i,children:[i.children,r&&t(`span`,{className:`text-destructive-foreground ms-1`,children:`*`})]}));Ys.displayName=Yi.Root.displayName,nt(()=>{});const Xs=U.forwardRef(({className:e,orientation:n=`horizontal`,decorative:r=!0,...i},a)=>t(Xi.Root,{ref:a,decorative:r,orientation:n,className:$(`shrink-0 bg-border`,n===`horizontal`?`h-[1px] w-full`:`h-full w-[1px]`,e),...i}));Xs.displayName=Xi.Root.displayName;const Zs=U.forwardRef(({className:e,trackClassName:r,rangeClassName:i,thumbClassName:a,value:o,defaultValue:s,min:c=0,max:l=100,"aria-label":u,...d},f)=>{let p=U.useId(),m=Array.isArray(o)?o.length:Array.isArray(s)?s.length:1,h=U.useMemo(()=>Array.from({length:Math.max(1,m)},(e,t)=>`${p}-thumb-${t}`),[p,m]);return n(Zi.Root,{ref:f,"data-slot":`slider`,value:o,defaultValue:s,min:c,max:l,...d,className:$(`relative flex w-full touch-none select-none items-center data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col`,e),children:[t(Zi.Track,{"data-slot":`slider-track`,className:$(`relative h-1.5 w-full grow overflow-hidden rounded-full bg-muted data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5`,r),children:t(Zi.Range,{"data-slot":`slider-range`,className:$(`absolute h-full bg-primary data-[orientation=vertical]:w-full`,i)})}),h.map(e=>t(Zi.Thumb,{"data-slot":`slider-thumb`,"aria-label":u,className:$(`block size-3.5 rounded-full border border-primary bg-background shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50`,a)},e))]})});Zs.displayName=Zi.Root.displayName;const Qs={sm:[`h-5 w-8`,`size-3`,`translate-x-4 rtl:-translate-x-4`],md:[`h-6 w-11`,`size-4`,`translate-x-6 rtl:-translate-x-6`],lg:[`h-8 w-16`,`size-6`,`translate-x-9 rtl:-translate-x-9`]};function $s({className:e,size:r=`md`,value:i,onChange:a,children:o,disabled:s,...c}){let[l,u,d]=Qs[r],f=t(Qi.Root,{"data-slot":`switch`,checked:i,onCheckedChange:a,disabled:s,...c,className:$(`data-[state=checked]:bg-primary data-[state=unchecked]:bg-muted focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 shrink-0 rounded-full border focus-visible:ring-3 aria-invalid:ring-3 peer group/switch relative inline-flex items-center transition-all outline-none after:absolute after:-inset-x-3 after:-inset-y-2 data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50`,l,!o&&e),children:t(Qi.Thumb,{"data-slot":`switch-thumb`,className:$(`bg-white rounded-full pointer-events-none block ring-0 transition-transform`,u,i?d:`translate-x-1 rtl:-translate-x-1`)})});return o?n(`div`,{className:$(`flex items-center`,e),children:[f,t(`span`,{className:`px-2`,children:o})]}):f}const ec=U.createContext({size:void 0,tabs:void 0,current:void 0,setTab:void 0,responsive:!1,variant:`tabs`,updateHash:!0}),tc=U.forwardRef(({className:e,size:n,variant:r=`tabs`,...i},a)=>t(ec.Provider,{value:{size:n,variant:r},children:t($i.List,{ref:a,className:$(r===`tabs`?`border-b -mb-px flex gap-4`:`flex gap-2 p-1 rounded-md`,e),...i})}));tc.displayName=$i.List.displayName;const nc=U.forwardRef(({className:e,href:n,variant:r=`tabs`,...i},a)=>{let{size:o}=U.useContext(ec),s=U.useCallback(e=>{if(n){e.preventDefault();let t=window.history.state;window.history.pushState(t,``,n)}i.onClick&&i.onClick(e)},[n,i.onClick]);return t($i.Trigger,{ref:a,className:$(r===`tabs`?$(`border-b-2 px-2 py-1.5 text-sm font-medium whitespace-nowrap cursor-pointer`,`border-transparent text-muted-foreground hover:border-border hover:text-foreground`,`data-[state=active]:border-primary data-[state=active]:text-primary`,`disabled:pointer-events-none disabled:opacity-50`):$(`px-3 py-1.5 text-sm font-medium whitespace-nowrap cursor-pointer rounded-sm transition-colors`,`tborder border-input bg-muted shadow-xs hover:bg-muted ring-inset`,`data-[state=active]:bg-primary data-[state=active]:text-white data-[state=active]:shadow-sm`,`disabled:pointer-events-none disabled:opacity-50`),e,o?`w-1/${o}`:``),onClick:s,...i})});nc.displayName=$i.Trigger.displayName;const rc=U.forwardRef(({className:e,...n},r)=>t($i.Content,{ref:r,className:$(`focus-visible:outline-none`,`flex-1 overflow-y-auto min-h-0 pt-2 pb-4`,e),...n}));rc.displayName=$i.Content.displayName;const ic=Vi(`text-foreground`,{variants:{size:{xl:`text-base md:text-lg leading-relaxed`,lg:`text-base leading-relaxed`,default:`text-sm leading-normal`,sm:`text-sm leading-normal`,xs:`text-xs leading-normal`},weight:{normal:`font-normal`,medium:`font-medium`,semibold:`font-semibold`}},defaultVariants:{size:`default`,weight:`normal`}}),ac=rt(({className:e,size:n,weight:r,...i},a)=>t(`p`,{ref:a,className:$(ic({size:n,weight:r,className:e})),...i}));ac.displayName=`Text`,nt({theme:`system`,setTheme:()=>null});function oc(e){switch(e){case`xs`:return`size-2`;case`sm`:return`size-3`;case`md`:return`size-4`;case`lg`:return`size-5`;case`xl`:return`size-7`;case`2xl`:return`size-10`;default:throw Error(`Unexpected size: ${e}`)}}function sc({size:e,className:r}){return n(`svg`,{className:Ze(`animate-[spin_0.8s_linear_infinite] text-indigo-500`,oc(e||`md`),r),xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,role:`img`,"aria-label":`Loading`,children:[t(`title`,{children:`Loading`}),t(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),t(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z`})]})}function cc(e){return typeof e==`object`&&!!e&&`type`in e&&e.type===`oauth-complete`&&`success`in e&&typeof e.success==`boolean`}function lc({onComplete:e,onError:t}){let n=J(null),r=J(e),i=J(t);return K(()=>{r.current=e,i.current=t},[e,t]),K(()=>()=>{n.current&&=(n.current(),null)},[]),{openOAuthPopup:e=>{n.current&&=(n.current(),null);let t=window.screenX+(window.outerWidth-600)/2,a=window.screenY+(window.outerHeight-700)/2,o=window.open(e,`oauth_popup`,`width=600,height=700,left=${t},top=${a},popup=yes`),s=!1,c=null,l=new BroadcastChannel(`oauth-callback`);l.addEventListener(`message`,e=>{cc(e.data)&&(s=!0,l.close(),c&&clearInterval(c),r.current(),!e.data.success&&e.data.error&&i.current?.(e.data.error),n.current=null)}),o&&(c=setInterval(()=>{o.closed&&(c&&clearInterval(c),l.close(),s||r.current(),n.current=null)},1e3)),n.current=()=>{l.close(),c&&clearInterval(c)}}}}function uc({appId:r,collectionId:i,collectionName:a,authenticated:o,onAuthChange:s,onError:c,variant:l=`default`,showLabel:u=!1,showDisconnect:d=!1,readOnly:f=!1}){let{client:p}=Z(),{t:m}=X(),[h,g]=Y(null),[_,v]=Y(o===void 0&&!f),[y,b]=Y(!1),[x,S]=Y(!1),C=o??h?.authenticated??!1,w=a??i,T=`h-6 w-32 justify-center px-2 text-xs`,E=G(async()=>{if(o!==void 0){v(!1);return}if(f){v(!1);return}try{v(!0);let e=await p.remoteMcpConnections.getCollectionStatus(r,i);g(e)}catch(e){console.error(`[RemoteMcpConnectionButton] Failed to load OAuth status:`,e)}finally{v(!1)}},[p,r,i,o,f]);K(()=>{E()},[E]);let{openOAuthPopup:D}=lc({onComplete:()=>{b(!1),E(),s?.()},onError:e=>{console.error(`OAuth failed:`,e),b(!1)}}),O=async()=>{try{b(!0),c?.(null);let e=await p.remoteMcpConnections.authorize(r,i);e.connected?(b(!1),await E(),s?.()):e.authorization_url?D(e.authorization_url):(c?.(`${w}: Authorization URL not provided by server`),b(!1))}catch(e){console.error(`Failed to authorize:`,e);let t=(e instanceof Error?e.original_message??e.message:`Failed to connect`).replace(/^[A-Za-z\s]+:\s/,``);c?.(`${w}: ${t}`),b(!1)}},k=async()=>{try{S(!0),await p.remoteMcpConnections.disconnect(r,i),await E(),s?.()}catch(e){console.error(`Failed to disconnect:`,e)}finally{S(!1)}};return _?l===`compact`?t(Wo,{variant:`outline`,size:`sm`,disabled:!0,className:T,title:m(`mcpConnections.checkingStatus`),children:t(sc,{className:`size-3`})}):t(`div`,{className:`flex items-center gap-2 text-sm`,children:t(sc,{className:`size-4`})}):l===`full`?C?n(`div`,{className:`flex items-center gap-2`,children:[u&&n(`span`,{className:`font-medium text-sm text-foreground`,children:[w,`:`]}),n(`div`,{className:`flex items-center gap-1 text-success text-sm`,children:[t(tn,{className:`size-4`}),t(`span`,{children:m(`mcpOAuth.connected`)})]}),d&&t(Wo,{variant:`ghost`,size:`sm`,onClick:k,disabled:x,children:x?t(sc,{className:`size-4`}):m(`mcpOAuth.disconnect`)})]}):n(`div`,{className:`flex items-center gap-2 text-sm`,children:[u&&n(`span`,{className:`font-medium text-foreground`,children:[w,`:`]}),t(Wo,{variant:`ghost`,size:`sm`,onClick:O,disabled:y,children:y?n(e,{children:[t(sc,{className:`size-4`}),t(`span`,{children:m(`mcpOAuth.authenticating`)})]}):n(e,{children:[t(Ur,{className:`size-4`}),t(`span`,{children:m(`mcpOAuth.authenticate`)})]})})]}):C?l===`compact`?n(`div`,{className:`flex items-center gap-2`,children:[u&&n(`span`,{className:`font-medium text-xs text-foreground`,children:[w,`:`]}),!f&&d&&t(Wo,{variant:`outline`,size:`sm`,onClick:k,disabled:x,className:T,children:x?t(sc,{className:`size-3`}):n(e,{children:[t(ei,{className:`size-3`}),t(`span`,{children:m(`mcpOAuth.disconnect`)})]})})]}):n(`div`,{className:`flex items-center gap-1 text-success`,children:[t(tn,{className:`size-4`}),t(`span`,{className:`text-sm`,children:m(`mcpOAuth.connected`)})]}):l===`compact`?f?n(`div`,{className:`flex items-center gap-2`,children:[u&&n(`span`,{className:`font-medium text-xs text-foreground`,children:[a,`:`]}),t(`div`,{className:`flex items-center gap-1 text-muted`,children:t(`span`,{className:`text-xs`,children:m(`mcpOAuth.notConnected`)})})]}):n(`div`,{className:`flex items-center gap-2`,children:[u&&n(`span`,{className:`font-medium text-xs text-foreground`,children:[w,`:`]}),t(Wo,{variant:`outline`,size:`sm`,onClick:O,disabled:y,className:T,children:y?n(e,{children:[t(sc,{className:`size-3`}),t(`span`,{children:m(`mcpOAuth.connecting`)})]}):n(e,{children:[t(ir,{className:`size-3`}),t(`span`,{children:m(`mcpOAuth.connect`)})]})})]}):t(Wo,{variant:`outline`,size:`sm`,onClick:O,disabled:f||y,children:y?n(e,{children:[t(sc,{className:`size-4`}),t(`span`,{children:m(`mcpOAuth.connecting`)})]}):n(e,{children:[t(ir,{className:`size-4 me-1`}),t(`span`,{children:m(`mcpOAuth.connect`)})]})})}const dc=W.createContext({});function fc({children:e,artifactRunId:n,onProposalSelect:r,onProposalSubmit:i,MarkdownRenderer:a}){let o=q(()=>({artifactRunId:n,onProposalSelect:r,onProposalSubmit:i,MarkdownRenderer:a}),[n,r,i,a]);return t(dc.Provider,{value:o,children:e})}function pc(){return W.useContext(dc)}const mc=nt(null);function hc(){return at(mc)}const gc={chart:{icon:Gt,label:`chart`,defaultHeight:200},mermaid:{icon:Wn,label:`diagram`,defaultHeight:150},proposal:{icon:pr,label:`options`,defaultHeight:100},code:{icon:bn,label:`code`,defaultHeight:80},image:{icon:Xn,label:`image`,defaultHeight:150},link:{icon:rr,label:`link`,defaultHeight:24},expand:{icon:Tn,label:`content`,defaultHeight:100},table:{icon:Xr,label:`table`,defaultHeight:150},markdown:{icon:Ln,label:`content`,defaultHeight:100},"fusion-fragment":{icon:bn,label:`fragment`,defaultHeight:150}};function _c({type:e,error:r,onRetry:i,message:a,height:s}){let c=gc[e],l=s??c.defaultHeight,u=e===`link`;if(r)return n(`div`,{className:`flex items-center gap-2 rounded border border-destructive/30 bg-destructive/5 text-destructive ${u?`inline-flex px-2 py-1 text-sm`:`p-4`}`,style:u?void 0:{minHeight:l},children:[n(`span`,{className:`text-destructive`,children:[`Failed to load `,c.label]}),i&&t(o,{variant:`unstyled`,onClick:i,className:`ms-2 rounded bg-destructive/10 px-2 py-1 text-xs hover:bg-destructive/20 transition-colors text-destructive`,children:`Retry`})]});let d=c.icon;return u?n(`span`,{className:`inline-flex items-center gap-1 text-muted animate-pulse`,children:[t(d,{className:`h-3 w-3`}),t(`span`,{children:a||`Loading ${c.label}...`})]}):n(`div`,{className:`flex flex-col items-center justify-center gap-3 rounded border border-border bg-muted/30 animate-pulse`,style:{minHeight:l},children:[t(d,{className:`h-8 w-8 text-muted`}),t(`span`,{className:`text-sm text-muted`,children:a||`Loading ${c.label}...`}),t(`div`,{className:`flex gap-1`,children:[...[,,,]].map((e,n)=>t(`div`,{className:`h-2 w-2 rounded-full bg-muted animate-bounce`,style:{animationDelay:`${n*150}ms`}},`dot-${n}`))})]})}var vc=class extends W.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`CodeBlock rendering error (${this.props.type}):`,e,t),this.props.onError?.(e)}handleRetry=()=>{this.setState({hasError:!1,error:void 0})};render(){if(this.state.hasError){let{type:e,fallbackCode:r}=this.props;return n(`div`,{className:`space-y-2`,children:[t(_c,{type:e,error:this.state.error?.message||`Rendering failed`,onRetry:this.handleRetry}),r&&n(`details`,{className:`text-sm`,children:[t(`summary`,{className:`cursor-pointer text-muted hover:text-foreground`,children:`Show raw content`}),t(`pre`,{className:`mt-2 overflow-x-auto rounded bg-muted/50 p-2 text-xs`,children:t(`code`,{children:r})})]})]})}return this.props.children}};function yc(e,t,n){let r=t.split(`.`).pop()?.toLowerCase();if(r===`svg`)return`mockup`;if([`png`,`jpg`,`jpeg`,`gif`,`webp`].includes(r||``))return`image`;if(r===`md`)return`markdown`;if(r===`csv`)return`table`;if(n===`json`&&typeof e==`object`&&e){let t=e;if(typeof t.$schema==`string`&&t.$schema.includes(`vega`)||t.library===`vega-lite`&&`spec`in t)return`vega-lite`;if(`template`in t&&`data`in t)return`fusion-fragment`;if(Array.isArray(e)&&e.length>0&&typeof e[0]==`object`)return`table`}return`code`}function bc(e){if(typeof e!=`object`||!e)return null;let t=e;return t.library===`vega-lite`&&`spec`in t&&typeof t.spec==`object`&&t.spec!==null?t:typeof t.$schema==`string`&&t.$schema.includes(`vega`)?{library:`vega-lite`,spec:t}:null}function xc({content:e}){let{headers:r,rows:i}=q(()=>{if(!Array.isArray(e)||e.length===0)return{headers:[],rows:[]};let t=e[0];if(typeof t!=`object`||!t)return{headers:[],rows:[]};let n=Object.keys(t);return{headers:n,rows:e.map(e=>n.map(t=>{let n=e[t];return n==null?``:typeof n==`object`?JSON.stringify(n):String(n)}))}},[e]);return r.length===0?t(_c,{type:`table`,error:`No table data found`}):n(`div`,{className:`overflow-x-auto`,children:[n(`table`,{className:`min-w-full text-sm border-collapse`,children:[t(`thead`,{children:t(`tr`,{className:`border-b`,children:r.map(e=>t(`th`,{className:`px-3 py-2 text-start font-medium text-muted`,children:e},e))})}),t(`tbody`,{children:i.slice(0,100).map((e,n)=>t(`tr`,{className:`border-b border-muted/20`,children:e.map((e,n)=>t(`td`,{className:`px-3 py-2`,children:e},`cell-${n}`))},`row-${n}`))})]}),i.length>100&&n(`div`,{className:`text-sm text-muted py-2`,children:[`Showing 100 of `,i.length,` rows`]})]})}function Sc({content:e,path:n}){let r=n.split(`.`).pop()?.toLowerCase()||``,i=typeof e==`string`?e:JSON.stringify(e,null,2);return t(`pre`,{className:`overflow-x-auto p-3 bg-muted/10 rounded text-sm`,children:t(`code`,{className:`language-${r}`,children:i})})}function Cc(e){return ma.sanitize(e,{USE_PROFILES:{svg:!0,svgFilters:!0},ADD_TAGS:[`use`],FORBID_TAGS:[`foreignObject`]})}function wc(e){return e.replace(/<svg([^>]*)>/i,(e,t)=>{let n=t;if(!/viewBox/i.test(n)){let e=/\swidth\s*=\s*["']?(\d+(?:\.\d+)?)/i.exec(n),t=/\sheight\s*=\s*["']?(\d+(?:\.\d+)?)/i.exec(n);e&&t&&(n+=` viewBox="0 0 ${e[1]} ${t[1]}"`)}return n=n.replace(/\swidth\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/i,``).replace(/\sheight\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/i,``),/style="/i.test(n)?n=n.replace(/style="([^"]*)"/i,(e,t)=>`style="${t};width:100%;height:auto;display:block;max-width:100%;"`):n+=` style="width:100%;height:auto;display:block;max-width:100%;"`,/preserveAspectRatio=/i.test(n)||(n+=` preserveAspectRatio="xMidYMid meet"`),`<svg${n}>`})}function Tc({content:e}){let n=q(()=>{let t=typeof e==`string`?e.trim():``;return t?wc(Cc(t)):null},[e]);return n?t(`div`,{style:{margin:`16px 0`,width:`100%`,overflowX:`auto`},dangerouslySetInnerHTML:{__html:n}}):t(_c,{type:`expand`,error:`Empty mockup`})}function Ec({content:e,path:n}){return t(`img`,{src:typeof e==`string`?e:``,alt:n.split(`/`).pop()||`Artifact image`,className:`max-w-full h-auto rounded`,loading:`lazy`})}function Dc({content:e,renderType:n,path:r,runId:i,contentType:a}){let{MarkdownRenderer:o}=pc();switch(q(()=>n===`auto`?yc(e,r,a):n,[e,r,a,n])){case`chart`:{let n=bc(e);return n?t(vc,{type:`chart`,fallbackCode:JSON.stringify(e,null,2),children:t(ho,{spec:n,artifactRunId:i})}):t(_c,{type:`chart`,error:`Only Vega-Lite charts are supported. Recharts rendering has been retired.`})}case`vega-lite`:{let n=bc(e);return n?t(vc,{type:`chart`,fallbackCode:JSON.stringify(e,null,2),children:t(ho,{spec:n,artifactRunId:i})}):t(_c,{type:`chart`,error:`Invalid Vega-Lite specification`})}case`fusion-fragment`:{let n=e;return console.log(`[ArtifactContentRenderer] fusion-fragment:`,{hasTemplate:!!n.template,hasData:!!n.data,runId:i,hasVegaLiteChart:!!ho}),n.template&&n.data?t(vc,{type:`fusion-fragment`,fallbackCode:JSON.stringify(e,null,2),children:t(pa,{data:n.data,ChartComponent:ho,artifactRunId:i,children:t(fa,{code:JSON.stringify(n.template),data:n.data})})}):t(vc,{type:`fusion-fragment`,fallbackCode:JSON.stringify(e,null,2),children:t(fa,{code:JSON.stringify(e)})})}case`table`:return t(vc,{type:`table`,fallbackCode:JSON.stringify(e,null,2),children:t(xc,{content:e})});case`markdown`:{let n=typeof e==`string`?e:String(e);return t(vc,{type:`markdown`,fallbackCode:n,children:o?t(o,{artifactRunId:i,children:n}):t(`pre`,{className:`overflow-x-auto p-3 bg-muted/10 rounded text-sm`,children:t(`code`,{children:n})})})}case`mockup`:return t(vc,{type:`expand`,fallbackCode:typeof e==`string`?e:r,children:t(Tc,{content:e})});case`image`:return t(vc,{type:`image`,fallbackCode:r,children:t(Ec,{content:e,path:r})});default:return t(Sc,{content:e,path:r})}}const Oc=`Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif`;function kc(e){let t=e.trim(),n=``,r=!1,i=!1;for(let e=0;e<t.length;e++){let a=t[e],o=e>0?t[e-1]:``;if(a===`"`&&!i&&o!==`\\`){r=!r,n+=a;continue}if(a===`'`&&!r&&o!==`\\`){i=!i,n+=a;continue}if((r||i)&&a===`\\`){let r=e;for(;t[r]===`\\`;)r++;if(t[r]===`n`){n+=`<br/>`,e=r;continue}}n+=a}return n}function Ac(e){return e.replace(/<svg([^<>]*)>/i,(e,t)=>{let n=t.replace(/\swidth="[^"]*"/i,``).replace(/\sheight="[^"]*"/i,``);return/style="/i.test(n)?n=n.replace(/style="([^"]*)"/i,(e,t)=>`style="${t};width:100%;height:auto;display:block;max-width:100%;"`):n+=` style="width:100%;height:auto;display:block;max-width:100%;"`,/preserveAspectRatio=/i.test(n)||(n+=` preserveAspectRatio="xMidYMid meet"`),`<svg${n}>`})}ha.initialize({startOnLoad:!1,theme:`default`,securityLevel:`loose`,fontFamily:Oc,suppressErrorRendering:!0,flowchart:{htmlLabels:!0,useMaxWidth:!0,nodeSpacing:40,rankSpacing:50,padding:12},sequence:{useMaxWidth:!0},themeVariables:{fontFamily:Oc}});function jc({code:e,className:n}){let r=J(null),[i,a]=Y(null),[o,s]=Y(null),c=ot().replace(/:/g,`_`);return K(()=>{let t=!1;return(async()=>{if(!e.trim()){a(null),s(null);return}try{s(null);let n=`mermaid-${c}-${Date.now()}`,r=kc(e),{svg:i}=await ha.render(n,r),o=Ac(i);t||a(o)}catch(e){if(!t){let t=e instanceof Error?e.message:`Failed to render mermaid diagram`;s(t),a(null)}}})(),()=>{t=!0}},[e,c]),o?null:i?t(`div`,{ref:r,className:`my-4 w-full overflow-x-auto [&_svg]:mx-auto [&_svg]:w-full [&_svg]:h-auto [&_svg]:max-w-full ${n||``}`,dangerouslySetInnerHTML:{__html:i}}):t(`div`,{className:`my-4 p-4 bg-gray-50 dark:bg-gray-800 rounded-lg animate-pulse ${n||``}`,children:t(`div`,{className:`h-32 bg-gray-200 dark:bg-gray-700 rounded`})})}function Mc(e){switch(e.split(`.`).pop()?.toLowerCase()){case`json`:return`json`;case`md`:case`txt`:case`csv`:case`yaml`:case`yml`:return`text`;case`png`:case`jpg`:case`jpeg`:case`gif`:case`webp`:case`pdf`:return`binary`;default:return`text`}}function Nc({runId:e,path:t,parseJson:n=!0}){let{client:r}=Z(),i=Za(),a=J(r);a.current=r;let o=J(i);o.current=i;let[s,c]=Y({data:void 0,rawContent:void 0,isLoading:!0,error:void 0,contentType:void 0}),l=G(async()=>{if(!e){c({data:void 0,rawContent:void 0,isLoading:!1,error:`No run ID provided`,contentType:void 0});return}if(!t){c({data:void 0,rawContent:void 0,isLoading:!1,error:`No artifact path provided`,contentType:void 0});return}c(e=>({...e,isLoading:!0,error:void 0}));let r=a.current,i=o.current,s=Mc(t);try{let a=$a(e,t,`inline`),o;o=i?await i.getOrFetch(a,async()=>(await r.files.getArtifactDownloadUrl(e,t,`inline`)).url):(await r.files.getArtifactDownloadUrl(e,t,`inline`)).url;let l=await fetch(o);if(!l.ok)throw Error(`Failed to fetch artifact: ${l.status} ${l.statusText}`);if(s===`binary`){c({data:o,rawContent:void 0,isLoading:!1,error:void 0,contentType:s,etag:l.headers.get(`etag`)?.replace(/^"(.*)"$/,`$1`)});return}let u=await l.text(),d;if(n&&s===`json`)try{d=JSON.parse(u)}catch{d=u}else d=u;c({data:d,rawContent:u,isLoading:!1,error:void 0,contentType:s,etag:l.headers.get(`etag`)?.replace(/^"(.*)"$/,`$1`)})}catch(e){let n=e instanceof Error?e.message:`Failed to fetch artifact`;console.error(`Failed to fetch artifact content:`,t,e),c({data:void 0,rawContent:void 0,isLoading:!1,error:n,contentType:s})}},[e,t,n]);K(()=>{l()},[l]);let u=G(()=>{c({data:void 0,rawContent:void 0,isLoading:!0,error:void 0,contentType:void 0}),l()},[l]);return{data:s.data,rawContent:s.rawContent,isLoading:s.isLoading,error:s.error,contentType:s.contentType,etag:s.etag,retry:u}}function Pc(e){let t=e.trim();if(t.length<2)return!0;if(!t.startsWith(`{`))return!1;try{return JSON.parse(t),!1}catch(e){let n=e instanceof Error?e.message:``,r=[`unexpected end`,`unterminated string`,`expected`,`unexpected token`],i=n.toLowerCase();if(r.some(e=>i.includes(e))){let e=0,n=0,r=!1,i=!1;for(let a of t){if(i){i=!1;continue}if(a===`\\`){i=!0;continue}if(a===`"`){r=!r;continue}r||(a===`{`?e++:a===`}`?e--:a===`[`?n++:a===`]`&&n--)}return e>0||n>0||r}return!1}}function Fc(e){try{let t=e.trim(),n=t.indexOf(`{`),r=t.lastIndexOf(`}`);return n!==-1&&r>n&&(t=t.slice(n,r+1)),JSON.parse(t)}catch{return null}}function Ic(e){let t=typeof e.$schema==`string`&&e.$schema.includes(`vega`),n=e.library===`vega-lite`&&`spec`in e;return t||n?`vega-lite`:null}function Lc({code:e}){let{artifactRunId:n}=pc();n||console.warn(`[VegaLiteCodeBlockHandler] artifactRunId is missing from CodeBlockContext`);let r=q(()=>Pc(e),[e]),i=q(()=>{if(r)return null;let t=Fc(e);return t?{library:`vega-lite`,spec:t}:null},[e,r]);return r?t(_c,{type:`chart`,message:`Loading chart...`}):i?t(vc,{type:`chart`,fallbackCode:e,children:t(ho,{spec:i,artifactRunId:n})}):t(_c,{type:`chart`,error:`Invalid Vega-Lite specification`})}function Rc({code:e}){let{artifactRunId:n}=pc();n||console.warn(`[ChartCodeBlockHandler] artifactRunId is missing from CodeBlockContext`);let r=q(()=>Pc(e),[e]),i=q(()=>{if(r)return null;let t=Fc(e);return!t||!Ic(t)?null:t.library===`vega-lite`&&`spec`in t&&typeof t.spec==`object`?t:{library:`vega-lite`,spec:t}},[e,r]);return r?t(_c,{type:`chart`,message:`Loading chart...`}):i?t(vc,{type:`chart`,fallbackCode:e,children:t(ho,{spec:i,artifactRunId:n})}):t(_c,{type:`chart`,error:`Invalid Vega-Lite chart specification`})}function zc({code:e}){let n=e.trim();return n?t(vc,{type:`mermaid`,fallbackCode:e,children:t(jc,{code:n})}):t(_c,{type:`mermaid`,error:`Empty diagram`})}function Bc({code:e}){let n=q(()=>{let t=e.trim();return t?wc(Cc(t)):null},[e]);return n?t(vc,{type:`code`,fallbackCode:e,children:t(`div`,{style:{margin:`16px 0`,width:`100%`,overflowX:`auto`},dangerouslySetInnerHTML:{__html:n}})}):t(_c,{type:`code`,error:`Empty mockup`})}function Vc({code:e,language:n}){let{artifactRunId:r}=pc(),i=e.trim(),a=q(()=>{if(!n?.includes(`:`))return`auto`;let e=n.split(`:`)[1];return[`chart`,`vega-lite`,`table`,`markdown`,`fusion-fragment`,`mockup`,`code`,`image`,`auto`].includes(e)?e:`auto`},[n]),{data:o,isLoading:s,error:c,contentType:l}=Nc({runId:r,path:i});return r?s?t(_c,{type:`expand`,message:`Loading ${i}...`}):c?t(_c,{type:`expand`,error:`Failed to load artifact: ${c}`}):o===void 0?t(_c,{type:`expand`,error:`No content found in artifact`}):t(Dc,{content:o,renderType:a,path:i,runId:r,contentType:l}):t(_c,{type:`expand`,error:`No artifact run ID available`})}function Hc(e){return e?.startsWith(`expand`)??!1}function Uc(){return{chart:Rc,"vega-lite":Lc,vegalite:Lc,mermaid:zc,mockup:Bc,svg:Bc}}const Wc=new Set([`store`,`document`,`collection`,`interaction`,`prompt`,`agent`,`workflow`,`process`,`run`]);function Gc(e){return e.trim().replace(/^\/+/,``)}function Kc(e){if(e.startsWith(`artifact:`))return{scheme:`artifact`,path:e.slice(9).trim()};if(e.startsWith(`image:`))return{scheme:`image`,path:e.slice(6).trim()};let t=e.indexOf(`:`);if(t>0){let n=e.slice(0,t);if(Wc.has(n))return{scheme:n,path:Gc(e.slice(t+1))}}return{scheme:`standard`,path:e}}function qc({rawUrl:e,artifactRunId:t,disposition:n=`inline`}){let{client:r}=Z(),i=Za(),a=J(r);a.current=r;let o=J(i);o.current=i;let{scheme:s,path:c}=Kc(e),[l,u]=Y(()=>{if(s===`standard`)return{url:e,isLoading:!1,error:void 0};if(i&&(s===`artifact`||s===`image`)){let e;e=s===`artifact`&&t&&!Qa(c)?$a(t,c,n):eo(c);let r=i.getUrl(e);if(r)return{url:r,isLoading:!1,error:void 0}}return{url:void 0,isLoading:!0,error:void 0}}),d=G(async()=>{if(s===`standard`)return;if(s!==`artifact`&&s!==`image`){u({url:void 0,isLoading:!1,error:`Unknown scheme: ${s}`});return}u(e=>({...e,isLoading:!0,error:void 0}));let e=a.current,r=o.current;try{let i;if(s===`artifact`)if(t&&!Qa(c)){let a=$a(t,c,n);i=r?await r.getOrFetch(a,async()=>(await e.files.getArtifactDownloadUrl(t,c,n)).url):(await e.files.getArtifactDownloadUrl(t,c,n)).url}else{let t=eo(c);i=r?await r.getOrFetch(t,async()=>(await e.files.getDownloadUrl(c)).url):(await e.files.getDownloadUrl(c)).url}else{let t=eo(c);i=r?await r.getOrFetch(t,async()=>(await e.files.getDownloadUrl(c)).url):(await e.files.getDownloadUrl(c)).url}u({url:i,isLoading:!1,error:void 0})}catch(e){let t=e instanceof Error?e.message:`Failed to resolve URL`;console.error(`Failed to resolve URL:`,c,e),u({url:void 0,isLoading:!1,error:t})}},[s,c,t,n]);K(()=>{if(l.url&&!l.error)return;let e=!1;return e||(async()=>{await d()})(),()=>{e=!0}},[d,l.url,l.error]);let f=G(()=>{u({url:void 0,isLoading:!0,error:void 0}),d()},[d]);return{url:l.url,isLoading:l.isLoading,error:l.error,scheme:s,retry:f}}function Jc({src:e,alt:r,caption:i,className:a,artifactRunId:o}){let s=e||``,{scheme:c}=Kc(s);return c===`standard`?n(`figure`,{className:`my-4`,children:[t(`img`,{src:e,alt:r,className:a}),t(`figcaption`,{className:`mt-2 text-sm text-muted text-center italic`,children:i})]}):t(Yc,{rawSrc:s,alt:r,caption:i,artifactRunId:o,className:a})}function Yc({rawSrc:e,alt:r,caption:i,artifactRunId:a,className:o}){let{url:s,isLoading:c,error:l,retry:u}=qc({rawUrl:e,artifactRunId:a,disposition:`inline`});return c?t(_c,{type:`image`,message:r?`Loading ${r}...`:void 0}):l?t(_c,{type:`image`,error:l,onRetry:u}):s?n(`figure`,{className:`my-4`,children:[t(`img`,{src:s,alt:r,className:o}),t(`figcaption`,{className:`mt-2 text-sm text-muted text-center italic`,children:i})]}):null}function Xc({node:e,src:n,alt:r,className:i,artifactRunId:a,ExistingImg:o,...s}){let c=n||``,{scheme:l}=Kc(c);return l===`standard`?typeof o==`function`?t(o,{node:e,src:n,alt:r,...s}):t(`img`,{src:n,alt:r,className:i,...s}):t(Zc,{rawSrc:c,alt:r,artifactRunId:a,className:i,rest:s})}function Zc({rawSrc:e,alt:n,artifactRunId:r,className:i,rest:a}){let{url:o,isLoading:s,error:c,retry:l}=qc({rawUrl:e,artifactRunId:r,disposition:`inline`});return s?t(_c,{type:`image`,message:n?`Loading ${n}...`:void 0}):c?t(_c,{type:`image`,error:c,onRetry:l}):o?t(`img`,{src:o,alt:n,className:i,...a}):null}const Qc=nt(()=>({kind:`none`}));Qc.Provider;function $c(){return at(Qc)}const el={store:`document`,document:`document`,collection:`collection`,interaction:`interaction`,prompt:`prompt`,agent:`agent`,workflow:`workflow`,process:`process`,run:`interaction_run`};function tl(e){let t=e.indexOf(`:`);if(t<=0)return;let n=e.slice(0,t);if(!Object.hasOwn(el,n))return;let r=e.slice(t+1).trim().replace(/^\/+/,``);if(r)return{type:el[n],id:r}}function nl({node:e,href:n,children:r,className:i,artifactRunId:a,onArtifactOpen:o,ExistingLink:s,...c}){let l=n||``,u=tl(l);if(u)return t(rl,{resource:u,rawHref:l,artifactRunId:a,className:i,ExistingLink:s,rest:c,children:r});let{scheme:d,path:f}=Kc(l);return d===`standard`?typeof s==`function`?t(s,{node:e,href:n,className:i,...c,children:r}):t(`a`,{href:n,...c,className:i,target:`_blank`,rel:`noopener noreferrer`,children:r}):t(il,{rawHref:l,artifactRunId:a,artifactPath:d===`artifact`?f:void 0,onArtifactOpen:o,className:i,rest:c,children:r})}function rl({resource:e,rawHref:n,artifactRunId:r,className:i,children:a,ExistingLink:s,rest:c}){let l=$c()(e,{workflowRunId:r,source:`markdown`,rawHref:n});return l.kind===`navigate`?typeof s==`function`?t(s,{href:l.href,className:i,...c,children:a}):t(`a`,{href:l.href,...c,className:i,target:`_blank`,rel:`noopener noreferrer`,children:a}):l.kind===`activate`?t(o,{variant:`link`,size:`none`,className:i,onClick:l.onActivate,children:a}):t(`span`,{className:i,children:a})}function il({rawHref:e,artifactRunId:n,artifactPath:r,onArtifactOpen:i,className:a,children:o,rest:s}){let{url:c,isLoading:l,error:u,retry:d}=qc({rawUrl:e,artifactRunId:n,disposition:`attachment`});return l?t(`span`,{className:`inline-flex items-center gap-1 text-muted`,children:t(_c,{type:`link`})}):u?t(`span`,{className:`inline-flex items-center gap-1`,children:t(_c,{type:`link`,error:u,onRetry:d})}):t(`a`,{href:c||`#`,...s,className:a,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>{r&&/\.md$/i.test(r)&&i&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&e.button===0&&(e.preventDefault(),i(r))},children:o})}const al=[`artifact:`,`image:`,`store:`,`document://`,`collection:`,`interaction:`,`prompt:`,`agent:`,`workflow:`,`process:`,`run:`],ol=/(!?\[[^[\]\n]*\]\()((?:artifact:|image:|store:|document:\/\/|collection:|interaction:|prompt:|agent:|workflow:|process:|run:)[^)[\n]+)(\))/g,sl=/`[^`\n]*`/g,cl=/(^|\n)(`{3,}|~{3,})[^\n]*\n[\s\S]*?\n\2(?=\n|$)/g,ll=/\s+("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\([^)]*\))\s*$/;function ul(e){return al.some(t=>e.startsWith(t))}function dl(e){let t=e.trim();if(t.startsWith(`<`)){let n=t.indexOf(`>`);if(n>0&&ul(t.slice(1,n).trim()))return e}let n=t.match(ll)?.index??-1,r=(n>=0?t.slice(0,n):t).trim(),i=n>=0?t.slice(n):``;return ul(r)?`<${r}>${i}`:e}function fl(e){return e.replace(ol,(e,t,n,r)=>`${t}${dl(n)}${r}`)}function pl(e){let t=``,n=0;for(let r of e.matchAll(sl))t+=fl(e.slice(n,r.index)),t+=r[0],n=r.index+r[0].length;return t+=fl(e.slice(n)),t}function ml(e){if(!e||!al.some(t=>e.includes(t)))return e;let t=``,n=0;for(let r of e.matchAll(cl))t+=pl(e.slice(n,r.index)),t+=r[0],n=r.index+r[0].length;return t+=pl(e.slice(n)),t}const hl=/^([ \t]*):::([^\n]*?):::[ \t]*$/gm,gl=/^\w+/;function _l(e){return e?.includes(`:::`)?e.replace(hl,(e,t,n)=>{let r=n.trim(),i=gl.exec(r);if(!i)return e;let a=i[0],o=r.slice(a.length).trim();return o?`${t}:::${a}\n${t}${o}\n${t}:::`:`${t}::${a}`}):e}const vl=/(^|\n)(`{3,}|~{3,})[^\n]*\n[\s\S]*?\n\2(?=\n|$)/g,yl=/`[^`\n]*`/g,bl=/\\\$/g,xl=/\\[^\s]/,Sl=/[{}]/,Cl=/[_^][\w{]/,wl=/^[a-zA-Z]$/,Tl=/^[a-zA-Z]\s*=/,El=/^\s/,Dl=/\s$/,Ol=/[+*/-]$/,kl=/\^[+-]$/;function Al(e){return xl.test(e)||Sl.test(e)||Cl.test(e)||wl.test(e)||Tl.test(e)}function jl(e){return!!(El.test(e)||Dl.test(e)||Ol.test(e)&&!kl.test(e))}function Ml(e){let t=[];for(let n=0;n<e.length;n++)if(e[n]===`$`&&!(n>0&&e[n-1]===`\\`)){if(n+1<e.length&&e[n+1]===`$`){n++;continue}n>0&&e[n-1]===`$`&&(n<2||e[n-2]!==`\\`)||t.push(n)}return t}function Nl(e,t,n){let r=e.slice(t+1,n);return r.length===0||r.includes(`
|
|
4
|
-
`)?null:r}function Pl(e){let t=Ml(e);if(t.length<2)return e;let n=new Set,r=new Set,i=Array(t.length-1);for(let n=0;n<t.length-1;n++)i[n]=Nl(e,t[n],t[n+1]);let a=[];for(let e=0;e<t.length-1;e++){if(n.has(e))continue;let r=i[e];r!==null&&Al(r)&&(n.add(e),n.add(e+1),a.push([t[e],t[e+1]]))}let o=0;for(;o<t.length;){if(n.has(o)){o++;continue}let e=o+1;for(;e<t.length&&n.has(e);)e++;if(e>=t.length)break;if(e>o+1){r.add(t[o]),o++;continue}let a=i[o];if(a===null){o++;continue}jl(a)&&(r.add(t[o]),r.add(t[e])),n.add(o),n.add(e),o=e+1}for(let e=0;e<t.length;e++)n.has(e)||e+1<t.length&&n.has(e+1)&&r.add(t[e]);if(r.size===0&&a.length===0)return e;let s=[],c=0,l=Array.from(r).sort((e,t)=>e-t),u=0,d=0;for(;u<l.length||d<a.length;){let t=u<l.length?l[u]:1/0;if(t<(d<a.length?a[d][0]:1/0))t>c&&s.push(e.slice(c,t)),s.push(`\\$`),c=t+1,u++;else{let[t,n]=a[d];t>c&&s.push(e.slice(c,t));let r=e.slice(t,n+1);for(s.push(r.replace(bl,`\\text{\\textdollar}`)),c=n+1;u<l.length&&l[u]<=n;)u++;d++}}return c<e.length&&s.push(e.slice(c)),s.join(``)}function Fl(e){let t=[],n=0;for(let r of e.matchAll(yl))t.push(Pl(e.slice(n,r.index))),t.push(r[0]),n=r.index+r[0].length;return t.push(Pl(e.slice(n))),t.join(``)}function Il(e){if(!e?.includes(`$`))return e;let t=[],n=0;for(let r of e.matchAll(vl))t.push(Fl(e.slice(n,r.index))),t.push(r[0]),n=r.index+r[0].length;return t.push(Fl(e.slice(n))),t.join(``)}const Ll={note:`md-callout-info`,tip:`md-callout-info`,warning:`md-callout-attention`,important:`md-callout-attention`,caution:`md-callout-destructive`},Rl={note:`Note`,tip:`Tip`,warning:`Warning`,important:`Important`,caution:`Caution`};function zl(){return e=>{da(e,e=>{if(e.type!==`containerDirective`&&e.type!==`leafDirective`&&e.type!==`textDirective`)return;let t=e;t.data||={};let n=t.data,r=t.attributes||{},i=t.name;if(i===`pagebreak`){n.hName=`hr`,n.hProperties={className:`md-pagebreak`};return}if(i===`columns`){n.hName=`div`,n.hProperties={className:`md-columns`};return}if(i===`column`){n.hName=`div`;let e={className:`md-column`};r.width&&(e.style=`flex-basis:${r.width};flex-grow:0;flex-shrink:0`),n.hProperties=e;return}if(i in Ll){n.hName=`div`,n.hProperties={className:`md-callout ${Ll[i]}`,"data-callout-type":i};let e=Rl[i];if(e&&t.children){let n={type:`paragraph`,data:{hName:`p`,hProperties:{className:`md-callout-title`}},children:[{type:`text`,value:e}]};t.children.unshift(n)}return}n.hName=`div`,n.hProperties={className:`md-${i}`,...Object.fromEntries(Object.entries(r).filter(([e])=>e!==`class`))},r.class&&(n.hProperties.className+=` ${r.class}`)})}}const Bl=[`artifact:`,`image:`,`store:`,`document:`,`document://`,`collection:`,`interaction:`,`prompt:`,`agent:`,`workflow:`,`process:`,`run:`];function Vl(e){return Bl.some(t=>e.startsWith(t))?e:ta(e)}function Hl(){return e=>{da(e,`html`,(e,t,n)=>{let r=e,i=n;if(typeof r.value==`string`&&/<!--[\s\S]*?-->/.test(r.value)&&i?.children&&typeof t==`number`)return i.children.splice(t,1),[ua,t]})}}const Ul=Uc();function Wl({children:e,components:n,remarkPlugins:r=[],removeComments:i=!0,artifactRunId:a,onArtifactOpen:o,className:s,codeClassName:c,inlineCodeClassName:l,linkClassName:u,imageClassName:d,onProposalSelect:f,onProposalSubmit:p,preserveSourcePositions:m=!1}){let h=hc(),g=W.useMemo(()=>m?e:_l(ml(Il(e))),[e,m]),_=t(fc,{artifactRunId:a,onProposalSelect:f,onProposalSubmit:p,MarkdownRenderer:Wl,children:t(ea,{remarkPlugins:W.useMemo(()=>{let e=[oa,aa,zl,sa,ia,la,ca,...r];return i&&e.push(Hl),e},[r,i]),rehypePlugins:W.useMemo(()=>[na],[]),remarkRehypeOptions:W.useMemo(()=>({handlers:{...ra}}),[]),components:W.useMemo(()=>{let e=n||{},r=e.code,i=e.a,s=e.img,f=({node:e,className:n,children:i,...a})=>{let o=/language-([\w-]+)/.exec(n||``),s=!o,u=o?o[1]:``;if(!s&&u){if(h){let e=h.getComponent(u);if(e)return t(e,{code:String(i||``).trim(),language:u})}if(Hc(u))return t(Vc,{code:String(i||``).trim(),language:u});let e=Ul[u];if(e)return t(e,{code:String(i||``).trim(),language:u})}return typeof r==`function`?t(r,{node:e,className:n,...a,children:i}):t(`code`,{...a,className:s?`px-1.5 py-0.5 rounded ${l||``}`:` ${c||``}`,children:i})},p=e=>{let{node:n,href:r,children:s,...c}=e;return t(nl,{node:n,href:r,className:u,artifactRunId:a,onArtifactOpen:o,ExistingLink:typeof i==`function`?i:void 0,...c,children:s})},m=e=>{let{node:n,src:r,alt:i,title:o,...c}=e;return o?t(Jc,{src:r,alt:i,caption:o,className:d,artifactRunId:a}):t(Xc,{node:n,src:r,alt:i,className:d,artifactRunId:a,ExistingImg:typeof s==`function`?s:void 0,...c})};return{...e,code:f,a:p,img:m}},[n,a,o,h,c,l,u,d]),urlTransform:Vl,children:g})});return s?t(`div`,{className:`md-content ${s}`,children:_}):t(`div`,{className:`md-content`,children:_})}const Gl={default:{border:`border-s-attention`,bg:`bg-amber-50 dark:bg-amber-900/20`,icon:`text-attention`},warning:{border:`border-s-destructive`,bg:`bg-red-50 dark:bg-red-900/20`,icon:`text-destructive`},info:{border:`border-s-info`,bg:`bg-blue-50 dark:bg-blue-900/20`,icon:`text-info`},success:{border:`border-s-success`,bg:`bg-green-50 dark:bg-green-900/20`,icon:`text-success`}},Kl={default:Yn,warning:zt,info:pr,success:en},ql=`max-h-80 overflow-y-auto overscroll-contain pe-2`;function Jl({question:r,description:i,options:a,onSelect:s,onMultiSelect:c,onSubmit:l,allowFreeResponse:u=!1,multiSelect:d=!1,placeholder:f,submitLabel:p,isLoading:m=!1,icon:h,variant:g=`default`,hideIcon:_=!1,hideBorder:v=!1,compact:y=!1,answered:b=!1,className:x,cardClassName:S,headerClassName:C,iconClassName:w,questionClassName:T,descriptionClassName:E,optionsClassName:D,buttonClassName:O,inputContainerClassName:k,inputClassName:A,submitButtonClassName:j}){let{t:M}=X(),N=f??M(`agent.typeYourResponse`),P=p??M(`agent.send`),[F,I]=W.useState(``),[L,ee]=W.useState(new Set),R=W.useRef(null),te=Gl[g],z=Kl[g],ne=e=>{ee(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},B=()=>{L.size>0&&c&&(c(Array.from(L)),ee(new Set))},re=()=>{F.trim()&&l&&(l(F.trim()),I(``))},ie=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),re())},ae=v?``:`border-s-4 ${te.border}`;if(y){let c=h||t(z,{className:`size-4`}),l=t(`div`,{className:H(`agent-ask-question text-sm leading-6 text-foreground/85`,T),children:t(Wl,{children:r})});return b?t(`div`,{className:H(`my-1.5 font-sans`,x),children:n(`div`,{className:ql,children:[l,i&&t(`p`,{className:H(`mt-1 text-xs leading-5 text-muted`,E),children:i})]})}):t(`div`,{className:H(`my-2 font-sans`,x),children:n(`div`,{className:H(`rounded-lg border border-border bg-background/60 shadow-none`,S),children:[t(`div`,{className:H(`px-3 py-2`,C),children:n(`div`,{className:`flex items-start gap-2.5`,children:[!_&&t(`div`,{className:H(`mt-1 flex-shrink-0 text-attention`,w),children:c}),t(`div`,{className:`min-w-0 flex-1`,children:n(`div`,{className:ql,children:[l,i&&t(`p`,{className:H(`mt-1 text-xs leading-5 text-muted`,E),children:i})]})})]})}),a&&a.length>0&&t(`div`,{className:H(`flex flex-col gap-1.5 px-3 pb-3 pt-0`,D),children:d?n(e,{children:[a.map(e=>{let r=L.has(e.id);return n(`label`,{className:H(`flex cursor-pointer items-start gap-2.5 rounded-md border px-3 py-2 text-start transition-colors`,r?`border-info/60 bg-info/10`:`border-border bg-background/70 hover:bg-mixer-muted/15`,m&&`cursor-not-allowed opacity-50`,O),children:[t(`input`,{type:`checkbox`,checked:r,onChange:()=>ne(e.id),disabled:m,className:`mt-1 size-4 rounded border-border bg-background text-info focus:ring-info`}),n(`span`,{className:`min-w-0 flex-1`,children:[n(`span`,{className:`flex items-center gap-2 text-sm font-medium leading-5 text-foreground`,children:[e.icon,t(`span`,{className:`break-words`,children:e.label})]}),e.description&&t(`span`,{className:`mt-0.5 block break-words text-xs leading-5 text-muted`,children:e.description})]})]},e.id)}),t(`div`,{className:`pt-1`,children:n(o,{size:`sm`,onClick:B,disabled:m||L.size===0,className:`inline-flex items-center gap-2`,children:[t(Vr,{className:`size-4`}),L.size>0?M(`agent.submitSelectionCount`,{count:L.size}):M(`agent.submitSelection`)]})})]}):a.map(e=>n(`button`,{type:`button`,onClick:()=>s?.(e.id),disabled:m,className:H(`flex w-full cursor-pointer items-start gap-2.5 rounded-md border border-border bg-background/70 px-3 py-2 text-start transition-colors`,`hover:bg-mixer-muted/15 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,m&&`cursor-not-allowed opacity-50`,O),children:[t(`span`,{className:`mt-1 size-4 flex-shrink-0 rounded-full border border-border`,"aria-hidden":`true`}),n(`span`,{className:`min-w-0 flex-1`,children:[n(`span`,{className:`flex items-center gap-2 text-sm font-medium leading-5 text-foreground`,children:[e.icon,t(`span`,{className:`break-words`,children:e.label})]}),e.description&&t(`span`,{className:`mt-0.5 block break-words text-xs leading-5 text-muted`,children:e.description})]})]},e.id))}),u&&t(`div`,{className:H(`px-3 pb-3 pt-0`,k),children:n(`div`,{className:`flex gap-2`,children:[t(`input`,{ref:R,type:`text`,value:F,onChange:e=>I(e.target.value),onKeyDown:ie,placeholder:N,disabled:m,className:H(`min-w-0 flex-1 rounded-md border border-border bg-background/70 px-3 py-2 text-sm text-foreground focus:border-transparent focus:ring-2 focus:ring-ring`,A)}),t(o,{size:`sm`,onClick:re,disabled:m||!F.trim(),className:j,children:m?`...`:P})]})})]})})}return t(`div`,{className:`my-4 font-sans ${x||``}`,children:n(`div`,{className:`${ae} ${te.bg} rounded-e-lg shadow-sm ${S||``}`,children:[t(`div`,{className:`px-4 py-3 ${C||``}`,children:n(`div`,{className:`flex items-start gap-3`,children:[!_&&t(`div`,{className:`flex-shrink-0 mt-0.5 ${te.icon} ${w||``}`,children:h||t(z,{className:`size-5`})}),t(`div`,{className:`min-w-0 flex-1`,children:n(`div`,{className:ql,children:[t(`div`,{className:`agent-ask-question prose prose-sm dark:prose-invert max-w-none text-gray-900 dark:text-gray-100 ${T||``}`,children:t(Wl,{children:r})}),i&&t(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400 ${E||``}`,children:i})]})})]})}),a&&a.length>0&&t(`div`,{className:`px-4 pb-3 pt-1 ${D||``}`,children:d?n(`div`,{className:`space-y-2`,children:[a.map(e=>n(`label`,{className:`flex items-start gap-3 px-4 py-3 rounded-lg cursor-pointer transition-colors
|
|
1
|
+
import{Fragment as e,jsx as t,jsxs as n}from"react/jsx-runtime";import{Avatar as r,Badge as i,Breadcrumbs as a,Button as o,Card as s,CardContent as c,CardDescription as l,CardFooter as u,CardHeader as d,CardTitle as f,Center as p,Checkbox as m,Command as h,CommandEmpty as g,CommandGroup as _,CommandInput as v,CommandItem as y,ConfirmModal as b,CopyButton as x,DialogDescription as S,Divider as C,Dropdown as w,DropdownMenu as T,DropdownMenuContent as E,DropdownMenuItem as D,DropdownMenuRadioGroup as O,DropdownMenuRadioItem as k,DropdownMenuTrigger as A,EmptyCollection as j,ErrorBox as M,FilterBar as N,FilterBtn as P,FilterClear as F,FilterProvider as I,FormItem as L,Heading as ee,Input as R,InputList as te,Label as z,MenuGroup as ne,MenuItem as B,MessageBox as re,Modal as ie,ModalBody as ae,ModalFooter as oe,ModalTitle as se,NumberInput as ce,OverflowMoreMenu as V,OverflowTabsBar as le,Panel as ue,Popover as de,PopoverContent as fe,PopoverTrigger as pe,Portal as me,RadioGroup as he,RadioGroupAdapter as ge,ResizableHandle as _e,ResizablePanel as ve,ResizablePanelGroup as ye,SelectBox as be,SelectList as xe,Separator as Se,SharedState as Ce,SidePanel as we,Slider as Te,SortableTableHeaderCell as Ee,Spinner as De,Styles as Oe,Switch as ke,TBody as Ae,THead as je,TR as Me,Table as Ne,TableHeaderCell as Pe,Tabs as Fe,TabsBar as Ie,TabsPanel as Le,TagsInput as Re,Textarea as ze,VTooltip as Be,cn as H,errorMessage as Ve,insertNewlineAtCursor as He,onActivateKey as Ue,useDebounce as We,useFetch as U,useFetchOnce as Ge,useFlag as Ke,useIntersectionObserver as W,useIsInModal as qe,useOverflowTabs as Je,useTheme as Ye,useToast as Xe,useWatchSharedState as Ze}from"@vertesia/ui/core";import Qe,{clsx as $e}from"clsx";import{AnimatePresence as et,motion as tt}from"motion/react";import*as nt from"react";import G,{Component as rt,Fragment as it,Suspense as at,createContext as ot,lazy as st,memo as ct,useCallback as K,useContext as lt,useEffect as q,useId as ut,useLayoutEffect as dt,useMemo as J,useRef as Y,useState as X,useSyncExternalStore as ft}from"react";import{AgentResourceResolverProvider as pt,AgentResourceResolverProvider as mt,ArtifactEditingSurface as ht,CodeBlockErrorBoundary as gt,CodeBlockPlaceholder as _t,CodeBlockRendererProvider as vt,DropZone as yt,GeneratedForm as bt,JSONCode as xt,JSONDisplay as St,ManagedObject as Ct,MarkdownRenderer as wt,MonacoEditor as Tt,Progress as Et,SchemaEditor as Dt,UploadSummary as Ot,XMLViewer as kt,computeTitleFromName as At,createUnifiedLineDiff as jt,diffTextSegments as Mt,diffWordSegments as Nt,isArtifactRefreshEvent as Pt,isIncompleteJson as Ft,useAgentResourceResolver as It,useAgentResourceResolver as Lt,useCodeBlockContext as Rt,useSchema as zt}from"@vertesia/ui/widgets";import{NAMESPACE as Bt,i18nInstance as Vt,useLocaleFormat as Ht,useUITranslation as Z}from"@vertesia/ui/i18n";import{Activity as Ut,AlertCircle as Wt,AlertCircleIcon as Gt,AlertTriangle as Kt,ArrowLeft as qt,ArrowLeftIcon as Jt,ArrowUpIcon as Yt,BarChart3 as Xt,Bot as Zt,Boxes as Qt,Braces as $t,Brain as en,BrainCircuit as tn,Bug as nn,Check as rn,CheckCheck as an,CheckCircle as on,CheckCircle2 as sn,CheckCircleIcon as cn,CheckIcon as ln,ChevronDown as un,ChevronDownIcon as dn,ChevronLeft as fn,ChevronRight as pn,ChevronRightIcon as mn,ChevronUp as hn,ChevronsDown as gn,ChevronsLeft as _n,ChevronsRight as vn,ChevronsUp as yn,ChevronsUpDown as bn,Circle as xn,ClipboardCopyIcon as Sn,ClipboardList as Cn,Clock as wn,Code as Tn,Copy as En,CopyIcon as Dn,Cpu as On,Database as kn,Download as An,DownloadCloudIcon as jn,DownloadIcon as Mn,EllipsisVertical as Nn,ExternalLink as Pn,ExternalLinkIcon as Fn,Eye as In,FileDown as Ln,FileIcon as Rn,FileJson2 as zn,FilePenLine as Bn,FileSearch as Vn,FileText as Hn,FileTextIcon as Un,FileType as Wn,Filter as Gn,FolderClosed as Kn,FolderIcon as qn,FolderOpenIcon as Jn,GitBranch as Yn,GitCompareArrows as Xn,GitFork as Zn,Grid3X3 as Qn,HandIcon as $n,HelpCircle as er,Image as tr,ImageIcon as nr,Info as rr,InfoIcon as ir,Layers as ar,LayoutGrid as or,LayoutListIcon as sr,Link as cr,Link2 as lr,Link2Off as ur,ListChecks as dr,Loader2 as fr,Loader2Icon as pr,LockKeyhole as mr,LockOpen as hr,Maximize as gr,Maximize2 as _r,MessageCirclePlus as vr,MessageSquare as yr,MessageSquareText as br,MessagesSquare as xr,Minimize2 as Sr,Minus as Cr,MonitorIcon as wr,MoreVertical as Tr,PackageIcon as Er,PanelsTopLeft as Dr,PaperclipIcon as Or,Pause as kr,PenLineIcon as Ar,Pencil as jr,PencilLine as Mr,Play as Nr,PlayCircle as Pr,Plus as Fr,PlusIcon as Ir,Radio as Lr,RefreshCcw as Rr,RefreshCw as zr,RefreshCwIcon as Br,RotateCcw as Vr,Rows3 as Hr,Rows3Icon as Ur,Save as Wr,ScanSearch as Gr,Search as Kr,Send as qr,Settings as Jr,ShieldAlertIcon as Yr,ShieldCheckIcon as Xr,SlidersHorizontal as Zr,Sparkles as Qr,SquareIcon as $r,SquarePen as ei,SquareTerminal as ti,Table as ni,TableProperties as ri,Terminal as ii,Trash2 as ai,Unlink2 as oi,UploadIcon as si,User as ci,Users as li,Users2 as ui,WandSparkles as di,Workflow as fi,Wrench as pi,X as mi,XCircle as hi,XCircleIcon as gi,XIcon as _i}from"lucide-react";import*as vi from"@radix-ui/react-dialog";import{UserSessionContext as yi,useUserSession as Q}from"@vertesia/ui/session";import bi from"papaparse";import{twMerge as xi}from"tailwind-merge";import{AUDIO_RENDITION_NAME as Si,AgentMessageType as $,AgentSearchScope as Ci,ContentNature as wi,ContentObjectStatus as Ti,ContentTypeIntakePolicySchema as Ei,FileProcessingStatus as Di,ImageRenditionFormat as Oi,InteractionStatus as ki,MarkdownRenditionFormat as Ai,PDF_RENDITION_NAME as ji,POSTER_RENDITION_NAME as Mi,Permission as Ni,PrincipalType as Pi,SearchTypes as Fi,SecurityLevelLabels as Ii,SupportedEmbeddingTypes as Li,SupportedProviders as Ri,WorkflowExecutionStatus as zi,getContentTypeRefId as Bi,getResourcesFromMessage as Vi,mergeInCodePromptSchemas as Hi,normalizeAgentToolApprovalMode as Ui,normalizeToolCollection as Wi,supportsToolUse as Gi}from"@vertesia/common";import{Slot as Ki}from"@radix-ui/react-slot";import{cva as qi}from"class-variance-authority";import*as Ji from"@radix-ui/react-tooltip";import{Env as Yi}from"@vertesia/ui/env";import*as Xi from"@radix-ui/react-dropdown-menu";import Zi from"dayjs";import Qi from"dayjs/plugin/localizedFormat";import $i from"dayjs/plugin/relativeTime";import{capitalize as ea}from"lodash-es";import*as ta from"@radix-ui/react-switch";import na,{defaultUrlTransform as ra}from"react-markdown";import{defListHastHandlers as ia,remarkDefinitionList as aa}from"remark-definition-list";import oa from"remark-directive";import sa from"remark-gfm";import ca from"remark-github-blockquote-alert";import la from"remark-math";import ua from"remark-supersub";import{SKIP as da,visit as fa}from"unist-util-visit";import{FusionFragmentHandler as pa,FusionFragmentProvider as ma}from"@vertesia/fusion-ux";import ha from"dompurify";import{NavLink as ga,useNavigate as _a,useRouterContext as va}from"@vertesia/ui/router";import ya,{Ajv as ba}from"ajv";import{Md5 as xa}from"ts-md5";import{ErrorBoundary as Sa}from"react-error-boundary";import{FullHeightLayout as Ca,SidebarItem as wa}from"@vertesia/ui/layout";import Ta from"ajv-formats";var Ea=Object.defineProperty,Da=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},Oa=(e,t)=>{let n={};for(var r in e)Ea(n,r,{get:e[r],enumerable:!0});return t||Ea(n,Symbol.toStringTag,{value:`Module`}),n};function ka({children:e,secondary:n=!1}){return t(`span`,{className:n?`bg-secondary text-primary`:`text-foreground bg-muted`,children:e})}function Aa(e){if(e)return e.name===`array`?Aa(e.innerType):e}function ja({property:e}){return n(`div`,{className:`flex items-center gap-x-2`,children:[t(`div`,{className:`font-semibold text-gray-600`,children:e.name}),e.optional&&t(ka,{children:`optional`}),t(ka,{children:e.type.value})]})}function Ma({activities:e}){return t(`div`,{className:`flex flex-col gap-y-4 divide-y divide-gray-200`,children:e.map(e=>t(Pa,{activity:e},e.name))})}function Na({code:e,children:r}){return n(`div`,{className:`flex gap-2 items-center border-b border-b-gray-200 mb-2`,children:[t(`div`,{className:`text-lg font-medium text-gray-900 py-2 `,children:r}),e&&t(`div`,{children:t(ka,{children:e})})]})}function Pa({activity:e,headingClass:r,headingRef:i}){return n(`div`,{className:r,id:e.name,ref:i,children:[t(`div`,{className:`text-xl font-semibold pt-8`,children:e.title}),t(`div`,{className:`pb-4`,children:t(ka,{children:e.name})}),e.doc&&t(`div`,{className:`text-gray-700 pb-2`,children:e.doc}),n(`div`,{className:`pb-4`,children:[t(Na,{code:e.paramsType,children:`Parameters`}),t(`div`,{className:`divide-y divide-gray-100`,children:e.params.map(e=>t(Fa,{property:e},e.name))})]}),n(`div`,{className:`pb-4`,children:[t(Na,{children:`Returns`}),t(`div`,{children:e.returnType?e.returnType.value:`void`})]})]})}function Fa({property:e,className:r}){let i=J(()=>{let n=Aa(e.type.innerType)??e.type;return n.name===`object`&&n.members?t(La,{members:n.members}):n.name===`enum`&&n.enum?t(Ia,{values:n.enum}):null},[e.type]);return n(`div`,{className:Qe(`py-2`,r),children:[t(ja,{property:e}),e.doc&&t(`div`,{className:`text-gray-700 text-sm pt-2`,children:e.doc}),i&&t(`div`,{className:`my-2 overflow-hidden`,children:i})]})}function Ia({values:e}){return t(`div`,{className:`flex flex-wrap items-center gap-2`,children:e.map(e=>t(ka,{secondary:!0,children:e},e))})}function La({members:e}){return t(za,{className:`rounded-md border border-gray-200`,button:e=>n(`div`,{className:`px-4 py-2 flex items-center gap-x-2 text-sm font-medium hover:text-blue-600`,children:[t(Ba,{isOpen:e}),e?t(`div`,{children:`Hide child properties`}):t(`div`,{children:`Show child properties`})]}),body:t(Ra,{properties:e})})}function Ra({properties:e}){return t(`div`,{className:`border-s-2 border-s-blue-200 flex flex-col divide-y divide-gray-100 border-t border-t-gray-200`,children:e.map(e=>t(Fa,{property:e,className:`px-4 py-2`},e.name))})}function za({button:e,body:r,className:i,isInitiallyOpen:a}){let[s,c]=X(a||!1);return n(`div`,{className:Qe(s?`block`:`inline-block`,i),children:[t(o,{variant:`unstyled`,className:`p-0 m-0 bg-transparent`,onClick:()=>c(!s),children:t(et,{children:e(s)})}),t(et,{children:s&&t(tt.div,{className:`overflow-hidden`,initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},transition:{duration:.3,ease:`easeOut`},children:r})})]})}function Ba({isOpen:e}){return t(et,{propagate:!0,mode:`wait`,children:t(tt.div,{className:`font-mono font-semibold text-gray-400 text-lg`,initial:{rotate:0},animate:{rotate:e?45:0},transition:{duration:.2},children:`+`},`closeIcon`)})}function Va(e){return e===`full_control`?`text-attention`:e===`auto_review`?`text-info`:`text-muted`}function Ha(e){return t(e===`full_control`?Yr:e===`ask`?$n:Xr,{className:`size-4`})}function Ua({mode:e,onChange:r,disabled:i=!1,className:a}){let{t:s}=Z(),c=J(()=>[{mode:`ask`,label:s(`agent.approvalMode.ask`),description:s(`agent.approvalMode.askDescription`),icon:t($n,{className:`size-4`})},{mode:`auto_review`,label:s(`agent.approvalMode.autoReview`),description:s(`agent.approvalMode.autoReviewDescription`),icon:t(Xr,{className:`size-4`})},{mode:`full_control`,label:s(`agent.approvalMode.fullControl`),description:s(`agent.approvalMode.fullControlDescription`),icon:t(Yr,{className:`size-4`})}],[s]),l=c.find(t=>t.mode===e)??c[2],u=t=>{t!==e&&r(t)};return n(T,{children:[t(A,{asChild:!0,children:n(o,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,className:H(`h-8 max-w-[13rem] rounded-full px-2.5 font-medium`,`bg-mixer-muted/15 text-muted hover:bg-muted hover:text-foreground disabled:opacity-60`,a),"aria-label":s(`agent.approvalMode.selectorLabel`),children:[t(`span`,{className:H(`shrink-0`,Va(e)),children:Ha(e)}),t(`span`,{className:`min-w-0 truncate`,children:l.label}),t(dn,{className:`size-4 shrink-0 opacity-70`})]})}),n(E,{align:`start`,className:`z-[1000000] w-[min(28rem,calc(100vw-1rem))] p-2`,children:[t(`div`,{className:`px-2 pb-1.5 pt-1 text-sm font-medium text-foreground`,children:s(`agent.approvalMode.dropdownTitle`)}),t(O,{value:e,onValueChange:e=>u(e),children:c.map(e=>n(k,{value:e.mode,className:`min-h-14 items-start gap-3 rounded-md py-2 pe-8 ps-2 text-start`,children:[t(`span`,{className:H(`mt-0.5 shrink-0`,Va(e.mode)),children:e.icon}),n(`span`,{className:`min-w-0 flex-1`,children:[t(`span`,{className:`block text-sm font-medium text-foreground`,children:e.label}),t(`span`,{className:`mt-0.5 block whitespace-normal text-sm leading-5 text-muted`,children:e.description})]})]},e.mode))})]})]})}function Wa(...e){return xi($e(e))}const Ga=ot(null);function Ka({children:e}){let n=Y(new Map),r=Y(new Map),i=K(e=>n.current.get(e),[]),a=K((e,t)=>{n.current.set(e,t)},[]),o=K(async(e,t)=>{let i=n.current.get(e);if(i)return i;let a=r.current.get(e);if(a)return a;let o=t().then(t=>(n.current.set(e,t),r.current.delete(e),t)).catch(t=>{throw r.current.delete(e),t});return r.current.set(e,o),o},[]),s=G.useMemo(()=>({getUrl:i,setUrl:a,getOrFetch:o}),[i,a,o]);return t(Ga.Provider,{value:s,children:e})}function qa(){return lt(Ga)}function Ja(e){return e.startsWith(`agents/`)||e.startsWith(`documents/`)}function Ya(e,t,n=`inline`){return`artifact:${e}:${t}:${n}`}function Xa(e){return`file:${e}`}const Za=st(()=>import(`react-vega`).then(({VegaEmbed:e})=>({default:e})));function Qa({error:e,chartTitle:r}){return t(`div`,{className:`flex items-center justify-center h-full bg-red-50 dark:bg-red-950 rounded-md p-4`,children:n(`div`,{className:`text-center`,children:[n(`p`,{className:`text-sm font-medium text-red-600 dark:text-red-400`,children:[`Cannot render `,r||`Vega-Lite`,` chart`]}),t(`p`,{className:`text-xs text-red-500 dark:text-red-500 mt-1 max-w-xs truncate`,children:e})]})})}function $a(){return t(`output`,{className:`flex items-center justify-center w-full h-full`,children:t(fr,{className:`w-5 h-5 animate-spin text-gray-500 dark:text-gray-400`})})}function eo({isOpen:e,onClose:r,title:i,description:a,children:s}){let{t:c}=Z();return t(vi.Root,{open:e,onOpenChange:e=>!e&&r(),children:n(vi.Portal,{children:[t(vi.Overlay,{className:`fixed inset-0 z-50 bg-black/80 backdrop-blur-sm transition-all duration-300 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`}),n(vi.Content,{className:`fixed inset-2 sm:inset-4 z-50 flex flex-col bg-white dark:bg-gray-900 rounded-xl shadow-2xl transition-all duration-300 ease-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-98 data-[state=open]:zoom-in-98 data-[state=closed]:slide-out-to-bottom-2 data-[state=open]:slide-in-from-bottom-2`,onEscapeKeyDown:r,children:[t(vi.Close,{asChild:!0,children:t(o,{variant:`unstyled`,onClick:r,className:`absolute top-3 end-3 z-10 p-2 rounded-lg bg-white/80 dark:bg-gray-800/80 backdrop-blur-sm hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors duration-150 shadow-sm`,"aria-label":c(`agent.closeFullscreen`),children:t(mi,{className:`w-5 h-5 text-gray-600 dark:text-gray-300`})})}),t(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6 animate-in fade-in-0 duration-500 delay-150`,children:s}),t(`div`,{className:`flex items-center justify-between px-4 sm:px-6 py-3 border-t border-gray-200 dark:border-gray-800 bg-gray-50/50 dark:bg-gray-800/50 rounded-b-xl`,children:n(`div`,{className:`flex flex-col`,children:[t(vi.Title,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:i||c(`agent.dashboard`)}),a&&t(vi.Description,{className:`text-sm text-gray-500 dark:text-gray-400 mt-0.5`,children:a})]})})]})]})})}function to(e,t){if(t===`chart`)return 280;let n=1;if(e.vconcat)n=Array.isArray(e.vconcat)?e.vconcat.length:1;else if(e.concat){let t=e.columns||2,r=Array.isArray(e.concat)?e.concat.length:1;n=Math.ceil(r/t)}else e.facet&&(n=2);return Math.max(500,n*280+40)}const no={categorical:[`#6366f1`,`#8b5cf6`,`#ec4899`,`#f43f5e`,`#f97316`,`#eab308`,`#22c55e`,`#14b8a6`,`#06b6d4`,`#3b82f6`],blues:[`#dbeafe`,`#93c5fd`,`#3b82f6`,`#1d4ed8`,`#1e3a8a`],purples:[`#f3e8ff`,`#c4b5fd`,`#8b5cf6`,`#6d28d9`,`#4c1d95`],greens:[`#dcfce7`,`#86efac`,`#22c55e`,`#15803d`,`#14532d`],diverging:[`#ef4444`,`#fca5a5`,`#fef3c7`,`#86efac`,`#22c55e`]};function ro(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function io(e){return ro(e)}function ao(e){let t=JSON.parse(JSON.stringify(e)),n=[`vconcat`,`hconcat`,`concat`];if(!n.some(e=>Array.isArray(t[e])))return t;let r=[];if(Array.isArray(t.params))for(let e of t.params)e&&typeof e==`object`&&e.name&&e.select&&r.push({name:e.name,param:e});if(r.length===0)return t;for(let{name:e,param:i}of r){let r=i.select?.fields||[],a=i.select?.bind===`legend`,o=null;for(let e of n)if(Array.isArray(t[e])){o=t[e];break}if(!o||o.length===0)continue;let s=0;for(let e=0;e<o.length;e++){let t=o[e];if(so(t,r)||a&&co(t,r)){s=e;break}}let c=o[s];c.params||=[],c.params.push(i),t.params=(t.params??[]).filter(t=>t.name!==e)}return Array.isArray(t.params)&&t.params.length===0&&delete t.params,t}function oo(e,t){if(!t||Object.keys(t).length===0)return e;let n=JSON.parse(JSON.stringify(e)),r=e=>{for(let n of e)n.name&&n.name in t&&(n.value=t[n.name])};Array.isArray(n.params)&&r(n.params);let i=e=>{if(Array.isArray(e)){for(let t of e)if(Array.isArray(t.params)&&r(t.params),t.vconcat&&i(t.vconcat),t.hconcat&&i(t.hconcat),t.concat&&i(t.concat),Array.isArray(t.layer))for(let e of t.layer)Array.isArray(e.params)&&r(e.params)}};if(n.vconcat&&i(n.vconcat),n.hconcat&&i(n.hconcat),n.concat&&i(n.concat),Array.isArray(n.layer))for(let e of n.layer)e&&Array.isArray(e.params)&&r(e.params);return n}function so(e,t){if(!e?.encoding)return!1;for(let n of t)for(let t of Object.values(e.encoding))if(t.field===n)return!0;if(Array.isArray(e.layer)){for(let n of e.layer)if(so(n,t))return!0}return!1}function co(e,t){if(!e)return!1;let n=e=>{if(!e)return!1;let n=e.color?.field;return!!n&&t.includes(n)};if(n(e.encoding))return!0;if(Array.isArray(e.layer)){for(let t of e.layer)if(n(t.encoding))return!0}return!1}function lo(e,t=[]){let n=[];if(!e||typeof e!=`object`)return n;if(e.data&&typeof e.data==`object`){let r=e.data.url;typeof r==`string`&&r.startsWith(`artifact:`)&&n.push({path:[...t,`data`],artifactPath:r.replace(/^artifact:/,``).trim()})}for(let r of[`layer`,`vconcat`,`hconcat`,`concat`,`spec`,`repeat`,`facet`])if(r in e){let i=e[r];Array.isArray(i)?i.forEach((e,i)=>{io(e)&&n.push(...lo(e,[...t,r,String(i)]))}):io(i)&&n.push(...lo(i,[...t,r]))}return n}function uo(e,t){let n=JSON.parse(JSON.stringify(e));for(let[e,r]of t){let t=e.split(`.`),i=n;for(let e=0;e<t.length-1;e++){let n=i[t[e]];if(!ro(n))break;i=n}let a=t[t.length-1],o=i[a];ro(o)&&(delete o.url,o.values=r)}return n}function fo(e){let t={background:`transparent`,view:{stroke:`transparent`},range:{category:no.categorical,diverging:no.diverging,heatmap:no.purples,ramp:no.blues},mark:{tooltip:!0},bar:{tooltip:!0,cornerRadiusTopLeft:4,cornerRadiusTopRight:4},line:{tooltip:!0,strokeWidth:2.5,strokeCap:`round`},point:{tooltip:!0,size:60,filled:!0},area:{tooltip:!0,fillOpacity:.7,line:!0},rect:{tooltip:!0,cornerRadius:2},arc:{tooltip:!0,cornerRadius:4},circle:{tooltip:!0,size:80}};return e?{...t,axis:{labelColor:`#a1a1aa`,titleColor:`#e4e4e7`,gridColor:`#3f3f46`,domainColor:`#52525b`,tickColor:`#52525b`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,titleFontWeight:500},legend:{labelColor:`#a1a1aa`,titleColor:`#e4e4e7`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,symbolSize:100},title:{color:`#fafafa`,font:`Inter, system-ui, sans-serif`,fontSize:14,fontWeight:600}}:{...t,axis:{labelColor:`#71717a`,titleColor:`#3f3f46`,gridColor:`#e4e4e7`,domainColor:`#d4d4d8`,tickColor:`#d4d4d8`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,titleFontWeight:500},legend:{labelColor:`#71717a`,titleColor:`#3f3f46`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,symbolSize:100},title:{color:`#18181b`,font:`Inter, system-ui, sans-serif`,fontSize:14,fontWeight:600}}}const po=ct(function({spec:r,artifactRunId:i}){let{t:a}=Z(),{title:s,description:c,options:l}=r,u=r.spec,[d,f]=X(!1),[p,m]=X(!1),[h,g]=X(null),[_,v]=X(!1),y=Y(null),b=Y(null),x=Y(null),{client:S}=Q(),C=qa(),w=Y(S);w.current=S;let T=Y(C);T.current=C;let[E,D]=X(null),[O,k]=X(!1),[A,j]=X(null),M=l?.mode||`chart`,N=M===`dashboard`,P=l?.enableFullscreen??N,F=l?.height||to(u,M);q(()=>{let e=lo(u);if(e.length===0){D(u),k(!1),j(null);return}i?console.info(`[VegaLiteChart] resolving artifacts with runId:`,i,e.map(e=>e.artifactPath)):console.warn(`[VegaLiteChart] artifact references found but artifactRunId is missing!`,{references:e.map(e=>e.artifactPath),artifactRunId:i});let t=!1;return k(!0),j(null),(async()=>{let n=new Map,r=w.current,a=T.current;for(let o of e)try{let e=o.path.join(`.`),t;if(i&&!Ja(o.artifactPath)){let e=Ya(i,o.artifactPath,`inline`);t=a?await a.getOrFetch(e,async()=>(await r.files.getArtifactDownloadUrl(i,o.artifactPath,`inline`)).url):(await r.files.getArtifactDownloadUrl(i,o.artifactPath,`inline`)).url}else{let e=Xa(o.artifactPath);t=a?await a.getOrFetch(e,async()=>(await r.files.getDownloadUrl(o.artifactPath)).url):(await r.files.getDownloadUrl(o.artifactPath)).url}let s=await fetch(t);if(!s.ok)throw Error(`Failed to fetch artifact data: ${s.statusText}`);let c=o.artifactPath.toLowerCase().endsWith(`.csv`),l;if(c){let e=await s.text();l=bi.parse(e,{header:!0,skipEmptyLines:!0,dynamicTyping:!0}).data}else{let e=await s.json();l=Array.isArray(e)?e:[e]}n.set(e,l)}catch(e){console.error(`Failed to resolve artifact: ${o.artifactPath}`,e),t||j(`Failed to load data from artifact: ${o.artifactPath}`);return}if(!t){let e=uo(u,n);D(e),k(!1)}})(),()=>{t=!0}},[u,i]);let[I,L]=X(!1),ee=Y(!1);q(()=>{let e=()=>{let e=document.documentElement.classList.contains(`dark`);e!==ee.current&&(ee.current=e,L(e))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]);let[R,te]=X(0),z=Y(0);q(()=>{if(!x.current)return;let e,t=new ResizeObserver(t=>{clearTimeout(e),e=setTimeout(()=>{let e=t[0]?.contentRect.width;e&&e!==z.current&&(z.current=e,te(e))},100)});t.observe(x.current);let n=x.current.clientWidth;return z.current=n,te(n),()=>{clearTimeout(e),t.disconnect()}},[]);let ne=J(()=>lo(u).length>0,[u]),B=J(()=>{if(ne&&!E)return null;let e=E||u;return e?(l?.parameterValues&&(e=oo(e,l.parameterValues)),ao(e)):null},[E,u,ne,l?.parameterValues]),re=K((e,t)=>{if(!e||typeof e!=`object`)return e;if(e.hconcat&&Array.isArray(e.hconcat)){let n=e.hconcat.length,r=(e.spacing??10)*(n-1),i=Math.floor((t-r)/n);return{...e,hconcat:e.hconcat.map(e=>re(e,i))}}if(e.vconcat&&Array.isArray(e.vconcat))return{...e,vconcat:e.vconcat.map(e=>re(e,t))};if(e.concat&&Array.isArray(e.concat)){let n=e.columns??e.concat.length,r=(e.spacing??10)*(n-1),i=Math.floor((t-r)/n);return{...e,concat:e.concat.map(e=>re(e,i))}}let n=e.width;return n===`container`||typeof n==`number`&&n>t?{...e,width:t}:e},[]),ie=K((e,t=!1)=>{if(!B)return null;let n=fo(I),r=t?typeof window<`u`?Math.min(window.innerWidth-80,1400):1200:R>0?R-24:500,i=`vconcat`in B||`hconcat`in B||`concat`in B,a=i?{type:`pad`,contains:`padding`}:{type:`fit`,contains:`padding`},o=B;i&&r&&(o=re(B,r));let c=o.width,l=i?void 0:c===`container`?r:c??r,{width:u,...d}=o;return{$schema:`https://vega.github.io/schema/vega-lite/v6.json`,...!i&&l?{width:l}:{},height:t?void 0:e,autosize:a,...i?o:d,...s&&!B.title?{title:s}:{},config:{...n,...B.config}}},[B,s,I,R,re]),ae=K(async()=>{let e=_?b.current:y.current;if(!(!e||p))try{(await e.toCanvas(2)).toBlob(async e=>{e&&(await navigator.clipboard.write([new ClipboardItem({"image/png":e})]),m(!0),setTimeout(()=>m(!1),2e3))},`image/png`)}catch(e){console.error(`Failed to copy chart:`,e)}},[p,_]),oe=K(async()=>{let e=_?b.current:y.current;if(!(!e||d)){f(!0);try{let t=await e.toImageURL(`png`,2),n=document.createElement(`a`);n.download=`${s||`chart`}.png`,n.href=t,n.click()}catch(e){console.error(`Failed to export chart:`,e)}finally{f(!1)}}},[s,d,_]),se=K(e=>{y.current=e,g(null)},[]),ce=K(e=>{b.current=e},[]),V=K(e=>{console.error(`Vega-Lite rendering error:`,e),g(e instanceof Error?e.message:`Unknown error`)},[]),le=K(()=>{v(e=>!e)},[]);q(()=>{g(null)},[u]);let ue=({className:e})=>n(`div`,{className:Wa(`flex items-center gap-2`,e),children:[n(o,{variant:`unstyled`,onClick:ae,disabled:p,className:`text-xs px-2 py-1 rounded border border-gray-300 dark:border-gray-700 bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 cursor-pointer transition-colors disabled:opacity-50 flex items-center gap-1`,title:a(`agent.copyToClipboard`),children:[t(p?rn:En,{className:`w-3 h-3`}),a(p?`agent.copied`:`agent.copy`)]}),n(o,{variant:`unstyled`,onClick:oe,disabled:d,className:`text-xs px-2 py-1 rounded border border-gray-300 dark:border-gray-700 bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 cursor-pointer transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-1`,title:a(`agent.exportAsPng`),children:[t(An,{className:`w-3 h-3`}),a(d?`agent.exporting`:`agent.export`)]}),P&&n(o,{variant:`unstyled`,onClick:le,className:`text-xs px-2 py-1 rounded border border-gray-300 dark:border-gray-700 bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 cursor-pointer transition-colors flex items-center gap-1`,title:a(_?`agent.exitFullscreen`:`agent.fullscreen`),children:[t(_?Sr:_r,{className:`w-3 h-3`}),a(_?`agent.exit`:`agent.fullscreen`)]})]});if(O||ne&&!E)return t(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||`Chart`})}),t(`div`,{className:`flex items-center justify-center bg-gray-50 dark:bg-gray-800 rounded`,style:{width:`100%`,height:F},children:n(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[t(fr,{className:`w-5 h-5 animate-spin`}),t(`span`,{className:`text-sm`,children:`Loading data from artifacts...`})]})})]})});if(A)return t(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||`Chart`})}),t(`div`,{style:{width:`100%`,height:F},children:t(Qa,{error:A,chartTitle:s})})]})});if(h)return t(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||`Chart`})}),t(`div`,{style:{width:`100%`,height:F},children:t(Qa,{error:h,chartTitle:s})})]})});let de=ie(F),fe=ie(0,!0);return de?(typeof window<`u`&&localStorage.getItem(`DEBUG_VEGA_RENDERS`)&&console.log(`VegaLite rendering with spec:`,{title:s,hasData:!!de.data?.values,dataLength:de.data?.values?.length}),n(e,{children:[t(`div`,{className:Wa(`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,N&&`border-2`),children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[n(`div`,{className:`flex items-center justify-between`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||(N?`Dashboard`:`Chart`)}),N&&t(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-indigo-100 dark:bg-indigo-900 text-indigo-700 dark:text-indigo-300`,children:`Interactive`})]}),t(ue,{})]}),c&&t(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:c}),t(`div`,{ref:x,className:`bg-white dark:bg-gray-900 rounded overflow-hidden`,style:{width:`100%`,height:F,minWidth:0},children:t(at,{fallback:t($a,{}),children:t(Za,{spec:de,onEmbed:e=>se(e.view),onError:V,options:{renderer:l?.renderer||`canvas`,actions:!1}})})})]})}),n(eo,{isOpen:_,onClose:()=>v(!1),title:s||(N?`Dashboard`:`Chart`),description:c,children:[t(`div`,{className:`w-full h-full min-h-[calc(100vh-200px)]`,children:fe&&t(at,{fallback:t($a,{}),children:t(Za,{spec:fe,onEmbed:e=>ce(e.view),onError:V,options:{renderer:l?.renderer||`canvas`,actions:!1}})})}),t(`div`,{className:`absolute bottom-6 end-6`,children:t(ue,{className:`bg-white dark:bg-gray-800 rounded-lg shadow-lg p-2 border border-gray-200 dark:border-gray-700`})})]})]})):null},(e,t)=>JSON.stringify(e.spec)===JSON.stringify(t.spec)&&e.artifactRunId===t.artifactRunId);function mo(e){return e.library===`vega-lite`&&typeof e.spec==`object`}function ho(e){return e.library===`recharts`||e.library===void 0}function go(e){return typeof e.$schema==`string`&&e.$schema.includes(`vega`)}const _o=ct(function({spec:e,artifactRunId:r}){return mo(e)?t(po,{spec:e,artifactRunId:r}):go(e)?t(po,{spec:{library:`vega-lite`,spec:e},artifactRunId:r}):n(`div`,{className:`my-5 rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-200`,children:[`Recharts chart rendering has been retired. Use a Vega-Lite chart spec (`,t(`code`,{children:`library: "vega-lite"`}),` with `,t(`code`,{children:`spec`}),`).`]})},(e,t)=>JSON.stringify(e.spec)===JSON.stringify(t.spec)&&e.artifactRunId===t.artifactRunId);function vo(e,t){return e===`live`?e:t===0?`live`:Math.min(Math.max(e,0),t-1)}function yo(e,t){return t===0?-1:e===`live`?t-1:Math.min(Math.max(e,0),t-1)}function bo(e,t){if(e.length===0)return null;let n=t===`live`?e.length:yo(t,e.length);for(let t=Math.min(n-1,e.length-1);t>=0;t--)if(e[t].type===$.QUESTION)return t;return null}function xo(e,t){if(e.length===0||t===`live`)return null;let n=yo(t,e.length);for(let t=n+1;t<e.length;t++)if(e[t].type===$.QUESTION)return t;return`live`}function So(e,t,n){let r=n?vo(t,e.length):`live`,i=yo(r,e.length),a=!n||r===`live`,o=a?e:e.slice(0,i+1);return{cursor:r,cursorIndex:i,isLive:a,renderedMessageCount:o.length,displayedMessages:o}}function Co(e){let t=e.indexOf(`?`);return t===-1?new URLSearchParams:new URLSearchParams(e.slice(t+1))}function wo(){return!(typeof window>`u`)}function To(){if(!wo())return!1;let e=new URLSearchParams(window.location.search),t=Co(window.location.hash),n=e.get(`agentChatPlayback`)??t.get(`agentChatPlayback`);return n===`1`||n===`true`}const Eo=wo,Do=To;function Oo({cursor:e,messages:r,onChangeCursor:i,className:a}){let{t:s}=Z(),c=r.length,l=e===`live`,u=yo(e,c),d=c>0&&(l||u>0),f=!l&&c>0,p=c>0&&(l||u>0),m=!l&&c>0&&u<c-1,h=c===0?0:u+1,[g,_]=X(String(h));q(()=>{_(String(h))},[h]);let v=()=>{if(c!==0){if(e===`live`){i(c-1);return}i(Math.max(0,u-1))}},y=()=>{if(c!==0&&e!==`live`){if(u>=c-1){i(`live`);return}i(u+1)}},b=()=>{c!==0&&i(0)},x=()=>{c!==0&&i(c-1)},S=()=>{_(String(h))},C=(e,t=!1)=>{if(c===0){_(`0`);return}let n=Number.parseInt(e,10);if(!Number.isFinite(n)){t&&S();return}let r=Math.min(Math.max(n,1),c);_(String(r)),i(r-1)},w=e=>{c!==0&&C(e)},T=c>1,E=+!!T,D=Math.max(1,c),O=`size-7 rounded-lg text-muted hover:text-foreground disabled:opacity-35`,k=`${Math.max(3,String(c).length+1)}ch`;return n(`div`,{className:H(`inline-flex max-w-full flex-col gap-1 rounded-xl border border-border/70 bg-background/95 px-2 py-1 text-sm leading-none text-muted shadow-lg shadow-black/10 backdrop-blur`,a),"data-testid":`agent-test-playback-controls`,"data-playback-cursor":e,"data-live-message-count":c,"data-rendered-message-count":l?c:u+1,children:[n(`div`,{className:`flex max-w-full items-center gap-1`,children:[t(`span`,{className:`ms-2 me-1 font-medium leading-none text-foreground/80`,children:s(`agent.rewind.label`)}),t(o,{type:`button`,variant:`ghost`,size:`icon`,title:s(`agent.rewind.jumpToStart`),disabled:!p,onClick:b,className:O,children:t(_n,{className:`size-4`})}),t(o,{type:`button`,variant:`ghost`,size:`icon`,title:s(`agent.rewind.previousMessage`),disabled:!d,onClick:v,className:O,children:t(fn,{className:`size-4`})}),n(`span`,{className:`inline-flex min-w-16 items-center justify-center gap-0.5 px-1 font-medium leading-none tabular-nums text-foreground/80`,"data-testid":`agent-test-playback-position`,children:[t(R,{type:`text`,variant:`unstyled`,size:`sm`,clearable:!1,inputMode:`numeric`,pattern:`[0-9]*`,value:g,"aria-label":s(`agent.rewind.positionInput`),disabled:c===0,onChange:e=>{let t=e.replace(/\D/g,``);_(t)},onBlur:e=>C(e.currentTarget.value,!0),onKeyDown:e=>{e.key===`Enter`&&(C(e.currentTarget.value,!0),e.currentTarget.blur())},style:{width:k},className:`h-7 w-auto rounded-md border border-transparent bg-transparent px-1 text-center text-sm font-medium leading-none tabular-nums text-foreground outline-none transition-colors hover:border-border focus:border-ring focus:bg-muted/30 disabled:opacity-50`}),t(`span`,{"aria-hidden":`true`,className:`text-muted`,children:`/`}),t(`span`,{className:`text-muted`,children:c})]}),t(o,{type:`button`,variant:`ghost`,size:`icon`,title:s(`agent.rewind.nextMessage`),disabled:!f,onClick:y,className:O,children:t(pn,{className:`size-4`})}),t(o,{type:`button`,variant:`ghost`,size:`icon`,title:s(`agent.rewind.jumpToLatest`),disabled:!m,onClick:x,className:O,children:t(vn,{className:`size-4`})}),t(o,{type:`button`,variant:l?`secondary`:`ghost`,size:`icon`,title:s(`agent.rewind.jumpToLive`),disabled:l,onClick:()=>i(`live`),className:H(O,l&&`bg-muted text-foreground`),children:t(Lr,{className:`size-4`})})]}),t(`div`,{className:`px-2 pb-1`,children:t(Te,{min:E,max:D,step:1,value:[h],"aria-label":s(`agent.rewind.positionInput`),disabled:!T,onValueChange:([e])=>w(String(e)),className:`h-2`})})]})}const ko=G.createContext(void 0);function Ao(){return G.useContext(ko)}const jo=Ji.Provider,Mo=Ji.Root,No=Ji.Trigger,Po=nt.forwardRef(({className:e,sideOffset:n=4,side:r=`top`,...i},a)=>{let o=Ao();return t(Ji.Portal,{container:o,children:t(Ji.Content,{ref:a,sideOffset:n,side:r,style:{zIndex:100},className:Wa(`max-w-[90vw]`,`z-50 overflow-hidden rounded-md bg-tooltips border border-border px-3 py-1.5 text-xs animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...i})})});Po.displayName=Ji.Content.displayName;function Fo({description:e,children:r,size:i=`sm`,placement:a=`top`,className:o,asChild:s}){let[c,l]=nt.useState(!1),u=nt.useRef(!1);return nt.useEffect(()=>{let e=()=>{l(!1),u.current=!0,requestAnimationFrame(()=>{u.current=!1})};return window.addEventListener(`blur`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`blur`,e),document.removeEventListener(`visibilitychange`,e)}},[]),t(jo,{delayDuration:0,children:n(Mo,{open:c,onOpenChange:e=>{u.current||l(e)},children:[t(No,{className:`cursor-pointer`,asChild:s,children:r}),t(Po,{side:a,className:`px-3 py-1.5 max-w-${i} text-${i} px-3 ${o}`,children:e})]})})}const Io=new Set;function Lo(e,t,n){q(()=>{t&&!Io.has(e)&&(Io.add(e),console.warn(`[@vertesia/ui] ${e} is deprecated: ${n}`))},[t,n,e])}function Ro(e){return nt.Children.toArray(e).some(e=>{if(typeof e==`string`)return e.trim().length>0;if(typeof e==`number`)return!0;if(nt.isValidElement(e)){let t=e.props;return t[`aria-hidden`]===!0||t[`aria-hidden`]===`true`?!1:Ro(t.children)}return!1})}const zo=qi(`hover:cursor-pointer inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`,{variants:{variant:{destructive:`bg-destructive dark:bg-destructive/10 text-destructive ring-1 ring-inset ring-destructive-muted/50 dark:ring-destructive-muted/50 shadow-xs hover:bg-destructive/50`,outline:`border border-input bg-background shadow-xs hover:bg-muted ring-inset`,secondary:`bg-primary/5 dark:bg-primary/10 text-primary shadow-xs hover:bg-primary/10 dark:hover:bg-primary/20 ring-inset`,ghost:`hover:bg-muted/50 dark:hover:bg-muted/20 ring-inset`,link:`text-foreground underline-offset-4 hover:underline ring-inset`,primary:`bg-primary text-white shadow-xs hover:bg-primary/90 ring-inset`,unstyled:``},size:{xs:`h-7 rounded px-2 py-1 text-xs gap-x-1`,sm:`h-8 rounded px-3 text-xs`,md:`h-9 rounded-md px-4 py-2`,lg:`h-10 rounded-md px-3`,xl:`rounded-md px-3.5 py-2.5 text-sm gap-x-2`,icon:`p-0 m-0 rounded-full`,none:``}},defaultVariants:{variant:`primary`,size:`md`}}),Bo=nt.forwardRef(({className:r,variant:i,size:a,asChild:o=!1,alt:s,isDisabled:c,isLoading:l,title:u,tooltipPlacement:d=`top`,onClick:f,type:p,...m},h)=>{Lo(`Button.alt`,s!==void 0,"use `title` instead — it drives the same tooltip and the accessible name. `alt` remains an alias for one release.");let g=o?Ki:`button`,_=o?p:p??`button`,v=u??s,y=m[`aria-label`]??s??(Ro(m.children)?void 0:u),b=o?m.children:n(e,{children:[l&&t(fr,{className:`animate-spin`}),m.children]}),x=t(g,{className:Qe(Wa(zo({variant:i,size:a})),r),disabled:c||l||m.disabled,ref:h,onClick:f,type:_,autoFocus:!1,...m,"aria-label":y,children:b});return v?t(Fo,{description:v,asChild:!0,className:`cursor-pointer`,size:`xs`,placement:d,children:x}):x});Bo.displayName=`Button`;const Vo=nt.forwardRef(({size:e,content:n,toast:r,className:i,alt:a,"aria-label":o,...s},c)=>{let[l,u]=X(!1),{t:d}=Z();Lo(`CopyButton.alt`,a!==void 0,"use aria-label for the accessible name. `alt` is forwarded for one release.");let f=e=>{e.stopPropagation(),navigator.clipboard.writeText(n).then(()=>{u(!0),setTimeout(()=>u(!1),2e3),r?.toast&&r.toast({status:`success`,title:r.message||d(`misc.copiedToClipboard`),duration:2e3})}).catch(e=>{console.error(`Failed to copy text: `,e),r?.toast&&r.toast({status:`error`,title:d(`misc.failedToCopy`),duration:2e3})})},p=o??a??d(`misc.copy`);return t(Bo,{ref:c,className:Wa(i),variant:`unstyled`,size:e||`sm`,onClick:f,...s,title:p,children:l?t(rn,{className:`text-success`}):t(Dn,{className:`size-4`})})});Vo.displayName=`CopyButton`;function Ho(e){return t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e(t))}}const Uo=qi(`inline-flex items-center rounded-md px-2 py-1 text-xs font-medium`,{variants:{variant:{default:`text-foreground bg-muted`,secondary:`bg-secondary text-primary`,destructive:`bg-destructive text-destructive`,attention:`bg-attention text-attention`,success:`bg-success text-success`,info:`bg-info text-info`,done:`bg-done text-done`,outline:`bg-transparent border border-border text-foreground`}},defaultVariants:{variant:`default`}});function Wo({className:e,variant:n,children:r,onClick:i,...a}){let o=i?{role:`button`,tabIndex:0,onClick:i,onKeyDown:Ho(i)}:{};return t(`span`,{className:Wa(Uo({variant:n}),e),...o,...a,children:r})}qi(`inline-flex items-center gap-x-1.5 rounded-md px-2 py-1 text-xs font-medium ring-1 ring-inset ring-border`,{variants:{variant:{default:``,success:``,destructive:``,attention:``,done:``,info:``,outline:``}},defaultVariants:{variant:`default`}}),qi(`h-1.5 w-1.5`,{variants:{variant:{default:`fill-foreground`,success:`fill-success`,destructive:`fill-destructive`,attention:`fill-attention`,done:`fill-done`,info:`fill-info`,outline:`fill-foreground`}},defaultVariants:{variant:`default`}});function Go({children:e}){return t(`span`,{style:{border:0,clip:`rect(0 0 0 0)`,height:`1px`,margin:`-1px`,overflow:`hidden`,padding:0,position:`absolute`,width:`1px`,whiteSpace:`nowrap`,wordWrap:`normal`},children:e})}const Ko=ot(!1);function qo({children:e}){return t(Ko.Provider,{value:!0,children:e})}function Jo({className:e,children:r,isOpen:i,onClose:a,description:o=`Modal Description`,noCloseButton:s=!1,allowOverflow:c=!1,disableCloseOnClickOutside:l=!1,size:u=`md`,action:d}){let f=e=>{e||a()};function p(){switch(u){case`sm`:return`max-w-[20vw]`;case`md`:return`max-w-[60vw] lg:max-w-[40vw]`;case`lg`:return`max-w-[80vw] md:max-w-[60vw]`;case`xl`:return`max-w-[95vw] lg:max-w-[80vw]`;case`full`:return`h-[calc(100vh-2rem)] max-w-[calc(100vw-2rem)]`;default:return`max-w-[60vw] lg:max-w-[40vw]`}}return n(Zo,{open:i,onOpenChange:e=>{(!l||e)&&f(e)},children:[c&&t(es,{className:`z-50 fixed inset-0 bg-black/80`}),t(Go,{children:t(ns,{children:o})}),n(ts,{className:Wa(`min-h-20 p-4`,`fixed left-[50%] top-[50%] z-50 grid w-full translate-x-[-50%] translate-y-[-50%] border bg-background shadow-lg duration-200 sm:rounded-lg`,p(),e),children:[t(`div`,{className:`top-4 end-4 absolute`,children:n(`div`,{className:`flex gap-2`,children:[d&&d,!s&&t($o,{onClick:()=>f(!1),asChild:!0,autoFocus:!1,children:t(Bo,{variant:`outline`,title:`Close`,className:`data-[state=open]:bg-accent opacity-70 hover:opacity-100 rounded-sm focus:outline-none focus:ring-2 focus:ring-ring ring-offset-background focus:ring-offset-2 data-[state=open]:text-muted-foreground transition-opacity disabled:pointer-events-none`,children:t(mi,{className:`size-4`})})})]})}),t(qo,{children:r})]})]})}const Yo=({children:e,show:r=!0,className:i,description:a,showDivider:o=!1,...s})=>r?n(rs,{className:Wa(o?`border-b-solid border-b border-b-1 pb-2 mb-4`:``,`text-lg font-semibold leading-6 tracking-tight`,{"py-2":!a},i),...s,children:[e,a&&t(ns,{className:`text-sm !font-normal text-muted-foreground pb-2`,children:a})]}):n(Go,{children:[t(rs,{children:e}),a&&t(ns,{children:a})]}),Xo=({children:e,className:n,...r})=>t(`div`,{className:Wa(`text-sm max-h-[80vh] overflow-y-auto`,n),...r,children:e}),Zo=vi.Root,Qo=vi.Portal,$o=vi.Close,es=nt.forwardRef(({className:e,...n},r)=>t(vi.Overlay,{ref:r,className:Wa(`fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...n}));es.displayName=vi.Overlay.displayName;const ts=nt.forwardRef(({className:e,children:r,...i},a)=>{let o=Ao();return n(Qo,{container:o,children:[t(es,{}),t(vi.Content,{ref:a,className:Wa(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] border bg-background shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg`,e),...i,children:r})]})});ts.displayName=vi.Content.displayName;const ns=nt.forwardRef(({className:e,...n},r)=>t(vi.Description,{ref:r,className:Wa(`text-sm text-muted`,e),...n}));ns.displayName=vi.Description.displayName;const rs=nt.forwardRef(({className:e,...n},r)=>t(vi.Title,{ref:r,className:Wa(`text-lg font-semibold leading-none tracking-tight`,e),...n}));rs.displayName=vi.Title.displayName;const is=nt.createContext(!1);function as({...e}){return t(Xi.Root,{"data-slot":`dropdown-menu`,...e})}function os({...e}){return t(Xi.Trigger,{"data-slot":`dropdown-menu-trigger`,...e})}function ss({className:e,align:n=`start`,sideOffset:r=4,...i}){return t(Xi.Portal,{children:t(Xi.Content,{"data-slot":`dropdown-menu-content`,sideOffset:r,align:n,className:Wa(`data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 bg-popover text-popover-foreground min-w-32 rounded-lg p-1 shadow-md ring-1 duration-100 z-50 max-h-(--radix-dropdown-menu-content-available-height) w-(--radix-dropdown-menu-trigger-width) origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto data-[state=closed]:overflow-hidden`,e),...i})})}function cs({className:e,inset:n,variant:r=`default`,...i}){return t(Xi.Item,{"data-slot":`dropdown-menu-item`,"data-inset":n,"data-variant":r,className:Wa(`hover:bg-muted focus:bg-muted data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:text-destructive gap-2 rounded-md px-1.5 py-1 text-sm data-inset:ps-7 [&_svg:not([class*='size-'])]:size-4 group/dropdown-menu-item relative flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0`,e),...i})}const ls={left:`start`,center:`center`,right:`end`};function us({trigger:e,children:r,align:i=`right`,hover:a}){let[o,s]=nt.useState(!1),c=nt.useRef(null);return a?n(`div`,{className:`relative inline-flex`,onMouseEnter:()=>{c.current&&clearTimeout(c.current),s(!0)},onMouseLeave:()=>{c.current=setTimeout(()=>s(!1),80)},children:[e,o&&t(`div`,{className:Wa(`absolute top-full pt-1 z-50`,i===`right`?`end-0`:i===`center`?`left-1/2 -translate-x-1/2`:`start-0`),children:t(`div`,{className:`min-w-32 rounded-lg p-1 shadow-md ring-1 ring-foreground/10 bg-popover text-popover-foreground`,children:t(is.Provider,{value:!0,children:r})})})]}):n(as,{children:[t(os,{asChild:!0,children:t(`span`,{className:`-m-1.5 flex items-center p-1.5`,children:e})}),t(ss,{align:ls[i],className:`w-max`,children:r})]})}function ds({children:e,href:n,onClick:r,isDisabled:i=!1,variant:a=`default`,className:o}){let s=nt.useContext(is),c=Wa(`w-full gap-2 rounded-md px-1.5 py-1 text-sm text-nowrap [&_svg:not([class*='size-'])]:size-4 flex cursor-default items-center select-none [&_svg]:pointer-events-none [&_svg]:shrink-0`,a===`destructive`?`text-destructive`:``,i?`pointer-events-none opacity-50`:`hover:bg-muted focus:bg-muted`,o);return s?n?t(`a`,{href:n,className:c,children:e}):t(`button`,{type:`button`,className:c,disabled:i,onClick:e=>{e.stopPropagation(),r?.(e)},children:e}):t(cs,{className:Wa(`data-[disabled]:pointer-events-none data-[disabled]:opacity-50 text-nowrap`,o),disabled:i,variant:a,onClick:e=>{e.stopPropagation(),r?.(e)},asChild:!!n,children:n?t(`a`,{href:n,children:e}):e})}Zi.extend($i),Zi.extend(Qi);var fs=Zi;const ps={sm:[`h-5 w-8`,`size-3`,`translate-x-4 rtl:-translate-x-4`],md:[`h-6 w-11`,`size-4`,`translate-x-6 rtl:-translate-x-6`],lg:[`h-8 w-16`,`size-6`,`translate-x-9 rtl:-translate-x-9`]};function ms({className:e,size:r=`md`,value:i,onChange:a,children:o,disabled:s,...c}){let[l,u,d]=ps[r],f=t(ta.Root,{"data-slot":`switch`,checked:i,onCheckedChange:a,disabled:s,...c,className:Wa(`data-[state=checked]:bg-primary data-[state=unchecked]:bg-muted focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 shrink-0 rounded-full border focus-visible:ring-3 aria-invalid:ring-3 peer group/switch relative inline-flex items-center transition-all outline-none after:absolute after:-inset-x-3 after:-inset-y-2 data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50`,l,!o&&e),children:t(ta.Thumb,{"data-slot":`switch-thumb`,className:Wa(`bg-white rounded-full pointer-events-none block ring-0 transition-transform`,u,i?d:`translate-x-1 rtl:-translate-x-1`)})});return o?n(`div`,{className:Wa(`flex items-center`,e),children:[f,t(`span`,{className:`px-2`,children:o})]}):f}function hs(e){switch(e){case`xs`:return`size-2`;case`sm`:return`size-3`;case`md`:return`size-4`;case`lg`:return`size-5`;case`xl`:return`size-7`;case`2xl`:return`size-10`;default:throw Error(`Unexpected size: ${e}`)}}function gs({size:e,className:r}){let i=hs(e||`md`);return n(`svg`,{className:Qe(`animate-[spin_0.8s_linear_infinite] text-indigo-500`,i,r),xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,role:`img`,"aria-label":`Loading`,children:[t(`title`,{children:`Loading`}),t(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),t(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z`})]})}function _s(e){return typeof e==`object`&&!!e&&`type`in e&&e.type===`oauth-complete`&&`success`in e&&typeof e.success==`boolean`}function vs({onComplete:e,onError:t}){let n=Y(null),r=Y(e),i=Y(t);return q(()=>{r.current=e,i.current=t},[e,t]),q(()=>()=>{n.current&&=(n.current(),null)},[]),{openOAuthPopup:e=>{n.current&&=(n.current(),null);let t=window.screenX+(window.outerWidth-600)/2,a=window.screenY+(window.outerHeight-700)/2,o=window.open(e,`oauth_popup`,`width=600,height=700,left=${t},top=${a},popup=yes`),s=!1,c=null,l=new BroadcastChannel(`oauth-callback`);l.addEventListener(`message`,e=>{_s(e.data)&&(s=!0,l.close(),c&&clearInterval(c),r.current(),!e.data.success&&e.data.error&&i.current?.(e.data.error),n.current=null)}),o&&(c=setInterval(()=>{o.closed&&(c&&clearInterval(c),l.close(),s||r.current(),n.current=null)},1e3)),n.current=()=>{l.close(),c&&clearInterval(c)}}}}function ys({appId:r,collectionId:i,collectionName:a,authenticated:o,onAuthChange:s,onError:c,variant:l=`default`,showLabel:u=!1,showDisconnect:d=!1,readOnly:f=!1}){let{client:p}=Q(),{t:m}=Z(),[h,g]=X(null),[_,v]=X(o===void 0&&!f),[y,b]=X(!1),[x,S]=X(!1),C=o??h?.authenticated??!1,w=a??i,T=`h-6 w-32 justify-center px-2 text-xs`,E=K(async()=>{if(o!==void 0){v(!1);return}if(f){v(!1);return}try{v(!0);let e=await p.remoteMcpConnections.getCollectionStatus(r,i);g(e)}catch(e){console.error(`[RemoteMcpConnectionButton] Failed to load OAuth status:`,e)}finally{v(!1)}},[p,r,i,o,f]);q(()=>{E()},[E]);let{openOAuthPopup:D}=vs({onComplete:()=>{b(!1),E(),s?.()},onError:e=>{console.error(`OAuth failed:`,e),b(!1)}}),O=async()=>{try{b(!0),c?.(null);let e=await p.remoteMcpConnections.authorize(r,i);e.connected?(b(!1),await E(),s?.()):e.authorization_url?D(e.authorization_url):(c?.(`${w}: Authorization URL not provided by server`),b(!1))}catch(e){console.error(`Failed to authorize:`,e);let t=(e instanceof Error?e.original_message??e.message:`Failed to connect`).replace(/^[A-Za-z\s]+:\s/,``);c?.(`${w}: ${t}`),b(!1)}},k=async()=>{try{S(!0),await p.remoteMcpConnections.disconnect(r,i),await E(),s?.()}catch(e){console.error(`Failed to disconnect:`,e)}finally{S(!1)}};return _?l===`compact`?t(Bo,{variant:`outline`,size:`sm`,disabled:!0,className:T,title:m(`mcpConnections.checkingStatus`),children:t(gs,{className:`size-3`})}):t(`div`,{className:`flex items-center gap-2 text-sm`,children:t(gs,{className:`size-4`})}):l===`full`?C?n(`div`,{className:`flex items-center gap-2`,children:[u&&n(`span`,{className:`font-medium text-sm text-foreground`,children:[w,`:`]}),n(`div`,{className:`flex items-center gap-1 text-success text-sm`,children:[t(sn,{className:`size-4`}),t(`span`,{children:m(`mcpOAuth.connected`)})]}),d&&t(Bo,{variant:`ghost`,size:`sm`,onClick:k,disabled:x,children:x?t(gs,{className:`size-4`}):m(`mcpOAuth.disconnect`)})]}):n(`div`,{className:`flex items-center gap-2 text-sm`,children:[u&&n(`span`,{className:`font-medium text-foreground`,children:[w,`:`]}),t(Bo,{variant:`ghost`,size:`sm`,onClick:O,disabled:y,children:y?n(e,{children:[t(gs,{className:`size-4`}),t(`span`,{children:m(`mcpOAuth.authenticating`)})]}):n(e,{children:[t(Yr,{className:`size-4`}),t(`span`,{children:m(`mcpOAuth.authenticate`)})]})})]}):C?l===`compact`?n(`div`,{className:`flex items-center gap-2`,children:[u&&n(`span`,{className:`font-medium text-xs text-foreground`,children:[w,`:`]}),!f&&d&&t(Bo,{variant:`outline`,size:`sm`,onClick:k,disabled:x,className:T,children:x?t(gs,{className:`size-3`}):n(e,{children:[t(oi,{className:`size-3`}),t(`span`,{children:m(`mcpOAuth.disconnect`)})]})})]}):n(`div`,{className:`flex items-center gap-1 text-success`,children:[t(sn,{className:`size-4`}),t(`span`,{className:`text-sm`,children:m(`mcpOAuth.connected`)})]}):l===`compact`?f?n(`div`,{className:`flex items-center gap-2`,children:[u&&n(`span`,{className:`font-medium text-xs text-foreground`,children:[a,`:`]}),t(`div`,{className:`flex items-center gap-1 text-muted`,children:t(`span`,{className:`text-xs`,children:m(`mcpOAuth.notConnected`)})})]}):n(`div`,{className:`flex items-center gap-2`,children:[u&&n(`span`,{className:`font-medium text-xs text-foreground`,children:[w,`:`]}),t(Bo,{variant:`outline`,size:`sm`,onClick:O,disabled:y,className:T,children:y?n(e,{children:[t(gs,{className:`size-3`}),t(`span`,{children:m(`mcpOAuth.connecting`)})]}):n(e,{children:[t(lr,{className:`size-3`}),t(`span`,{children:m(`mcpOAuth.connect`)})]})})]}):t(Bo,{variant:`outline`,size:`sm`,onClick:O,disabled:f||y,children:y?n(e,{children:[t(gs,{className:`size-4`}),t(`span`,{children:m(`mcpOAuth.connecting`)})]}):n(e,{children:[t(lr,{className:`size-4 me-1`}),t(`span`,{children:m(`mcpOAuth.connect`)})]})})}const bs=G.createContext({});function xs({children:e,artifactRunId:n,onProposalSelect:r,onProposalSubmit:i,MarkdownRenderer:a}){let o=J(()=>({artifactRunId:n,onProposalSelect:r,onProposalSubmit:i,MarkdownRenderer:a}),[n,r,i,a]);return t(bs.Provider,{value:o,children:e})}function Ss(){return G.useContext(bs)}const Cs=ot(null);function ws(){return lt(Cs)}const Ts={chart:{icon:Xt,label:`chart`,defaultHeight:200},mermaid:{icon:Yn,label:`diagram`,defaultHeight:150},proposal:{icon:yr,label:`options`,defaultHeight:100},code:{icon:Tn,label:`code`,defaultHeight:80},image:{icon:tr,label:`image`,defaultHeight:150},link:{icon:cr,label:`link`,defaultHeight:24},expand:{icon:An,label:`content`,defaultHeight:100},table:{icon:ni,label:`table`,defaultHeight:150},markdown:{icon:Hn,label:`content`,defaultHeight:100},"fusion-fragment":{icon:Tn,label:`fragment`,defaultHeight:150}};function Es({type:e,error:r,onRetry:i,message:a,height:s}){let c=Ts[e],l=s??c.defaultHeight,u=e===`link`;if(r)return n(`div`,{className:`flex items-center gap-2 rounded border border-destructive/30 bg-destructive/5 text-destructive ${u?`inline-flex px-2 py-1 text-sm`:`p-4`}`,style:u?void 0:{minHeight:l},children:[n(`span`,{className:`text-destructive`,children:[`Failed to load `,c.label]}),i&&t(o,{variant:`unstyled`,onClick:i,className:`ms-2 rounded bg-destructive/10 px-2 py-1 text-xs hover:bg-destructive/20 transition-colors text-destructive`,children:`Retry`})]});let d=c.icon;return u?n(`span`,{className:`inline-flex items-center gap-1 text-muted animate-pulse`,children:[t(d,{className:`h-3 w-3`}),t(`span`,{children:a||`Loading ${c.label}...`})]}):n(`div`,{className:`flex flex-col items-center justify-center gap-3 rounded border border-border bg-muted/30 animate-pulse`,style:{minHeight:l},children:[t(d,{className:`h-8 w-8 text-muted`}),t(`span`,{className:`text-sm text-muted`,children:a||`Loading ${c.label}...`}),t(`div`,{className:`flex gap-1`,children:[...[,,,]].map((e,n)=>t(`div`,{className:`h-2 w-2 rounded-full bg-muted animate-bounce`,style:{animationDelay:`${n*150}ms`}},`dot-${n}`))})]})}var Ds=class extends G.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`CodeBlock rendering error (${this.props.type}):`,e,t),this.props.onError?.(e)}handleRetry=()=>{this.setState({hasError:!1,error:void 0})};render(){if(this.state.hasError){let{type:e,fallbackCode:r}=this.props;return n(`div`,{className:`space-y-2`,children:[t(Es,{type:e,error:this.state.error?.message||`Rendering failed`,onRetry:this.handleRetry}),r&&n(`details`,{className:`text-sm`,children:[t(`summary`,{className:`cursor-pointer text-muted hover:text-foreground`,children:`Show raw content`}),t(`pre`,{className:`mt-2 overflow-x-auto rounded bg-muted/50 p-2 text-xs`,children:t(`code`,{children:r})})]})]})}return this.props.children}};function Os(e,t,n){let r=t.split(`.`).pop()?.toLowerCase();if(r===`svg`)return`mockup`;if([`png`,`jpg`,`jpeg`,`gif`,`webp`].includes(r||``))return`image`;if(r===`md`)return`markdown`;if(r===`csv`)return`table`;if(n===`json`&&typeof e==`object`&&e){let t=e;if(typeof t.$schema==`string`&&t.$schema.includes(`vega`)||t.library===`vega-lite`&&`spec`in t)return`vega-lite`;if(`template`in t&&`data`in t)return`fusion-fragment`;if(Array.isArray(e)&&e.length>0&&typeof e[0]==`object`)return`table`}return`code`}function ks(e){if(typeof e!=`object`||!e)return null;let t=e;return t.library===`vega-lite`&&`spec`in t&&typeof t.spec==`object`&&t.spec!==null?t:typeof t.$schema==`string`&&t.$schema.includes(`vega`)?{library:`vega-lite`,spec:t}:null}function As({content:e}){let{headers:r,rows:i}=J(()=>{if(!Array.isArray(e)||e.length===0)return{headers:[],rows:[]};let t=e[0];if(typeof t!=`object`||!t)return{headers:[],rows:[]};let n=Object.keys(t);return{headers:n,rows:e.map(e=>n.map(t=>{let n=e[t];return n==null?``:typeof n==`object`?JSON.stringify(n):String(n)}))}},[e]);return r.length===0?t(Es,{type:`table`,error:`No table data found`}):n(`div`,{className:`overflow-x-auto`,children:[n(`table`,{className:`min-w-full text-sm border-collapse`,children:[t(`thead`,{children:t(`tr`,{className:`border-b`,children:r.map(e=>t(`th`,{className:`px-3 py-2 text-start font-medium text-muted`,children:e},e))})}),t(`tbody`,{children:i.slice(0,100).map((e,n)=>t(`tr`,{className:`border-b border-muted/20`,children:e.map((e,n)=>t(`td`,{className:`px-3 py-2`,children:e},`cell-${n}`))},`row-${n}`))})]}),i.length>100&&n(`div`,{className:`text-sm text-muted py-2`,children:[`Showing 100 of `,i.length,` rows`]})]})}function js({content:e,path:n}){let r=n.split(`.`).pop()?.toLowerCase()||``,i=typeof e==`string`?e:JSON.stringify(e,null,2);return t(`pre`,{className:`overflow-x-auto p-3 bg-muted/10 rounded text-sm`,children:t(`code`,{className:`language-${r}`,children:i})})}function Ms(e){return ha.sanitize(e,{USE_PROFILES:{svg:!0,svgFilters:!0},ADD_TAGS:[`use`],FORBID_TAGS:[`foreignObject`]})}function Ns(e){return e.replace(/<svg([^>]*)>/i,(e,t)=>{let n=t;if(!/viewBox/i.test(n)){let e=/\swidth\s*=\s*["']?(\d+(?:\.\d+)?)/i.exec(n),t=/\sheight\s*=\s*["']?(\d+(?:\.\d+)?)/i.exec(n);e&&t&&(n+=` viewBox="0 0 ${e[1]} ${t[1]}"`)}return n=n.replace(/\swidth\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/i,``).replace(/\sheight\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/i,``),/style="/i.test(n)?n=n.replace(/style="([^"]*)"/i,(e,t)=>`style="${t};width:100%;height:auto;display:block;max-width:100%;"`):n+=` style="width:100%;height:auto;display:block;max-width:100%;"`,/preserveAspectRatio=/i.test(n)||(n+=` preserveAspectRatio="xMidYMid meet"`),`<svg${n}>`})}function Ps({content:e}){let n=J(()=>{let t=typeof e==`string`?e.trim():``;return t?Ns(Ms(t)):null},[e]);return n?t(`div`,{style:{margin:`16px 0`,width:`100%`,overflowX:`auto`},dangerouslySetInnerHTML:{__html:n}}):t(Es,{type:`expand`,error:`Empty mockup`})}function Fs({content:e,path:n}){let r=typeof e==`string`?e:``,i=n.split(`/`).pop()||`Artifact image`;return t(`img`,{src:r,alt:i,className:`max-w-full h-auto rounded`,loading:`lazy`})}function Is({content:e,renderType:n,path:r,runId:i,contentType:a}){let{MarkdownRenderer:o}=Ss();switch(J(()=>n===`auto`?Os(e,r,a):n,[e,r,a,n])){case`chart`:{let n=ks(e);return n?t(Ds,{type:`chart`,fallbackCode:JSON.stringify(e,null,2),children:t(po,{spec:n,artifactRunId:i})}):t(Es,{type:`chart`,error:`Only Vega-Lite charts are supported. Recharts rendering has been retired.`})}case`vega-lite`:{let n=ks(e);return n?t(Ds,{type:`chart`,fallbackCode:JSON.stringify(e,null,2),children:t(po,{spec:n,artifactRunId:i})}):t(Es,{type:`chart`,error:`Invalid Vega-Lite specification`})}case`fusion-fragment`:{let n=e;return console.log(`[ArtifactContentRenderer] fusion-fragment:`,{hasTemplate:!!n.template,hasData:!!n.data,runId:i,hasVegaLiteChart:!!po}),n.template&&n.data?t(Ds,{type:`fusion-fragment`,fallbackCode:JSON.stringify(e,null,2),children:t(ma,{data:n.data,ChartComponent:po,artifactRunId:i,children:t(pa,{code:JSON.stringify(n.template),data:n.data})})}):t(Ds,{type:`fusion-fragment`,fallbackCode:JSON.stringify(e,null,2),children:t(pa,{code:JSON.stringify(e)})})}case`table`:return t(Ds,{type:`table`,fallbackCode:JSON.stringify(e,null,2),children:t(As,{content:e})});case`markdown`:{let n=typeof e==`string`?e:String(e);return t(Ds,{type:`markdown`,fallbackCode:n,children:o?t(o,{artifactRunId:i,children:n}):t(`pre`,{className:`overflow-x-auto p-3 bg-muted/10 rounded text-sm`,children:t(`code`,{children:n})})})}case`mockup`:return t(Ds,{type:`expand`,fallbackCode:typeof e==`string`?e:r,children:t(Ps,{content:e})});case`image`:return t(Ds,{type:`image`,fallbackCode:r,children:t(Fs,{content:e,path:r})});default:return t(js,{content:e,path:r})}}const Ls=`Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif`;function Rs(e){let t=e.trim(),n=``,r=!1,i=!1;for(let e=0;e<t.length;e++){let a=t[e],o=e>0?t[e-1]:``;if(a===`"`&&!i&&o!==`\\`){r=!r,n+=a;continue}if(a===`'`&&!r&&o!==`\\`){i=!i,n+=a;continue}if((r||i)&&a===`\\`){let r=e;for(;t[r]===`\\`;)r++;if(t[r]===`n`){n+=`<br/>`,e=r;continue}}n+=a}return n}function zs(e){return e.replace(/<svg([^<>]*)>/i,(e,t)=>{let n=t.replace(/\swidth="[^"]*"/i,``).replace(/\sheight="[^"]*"/i,``);return/style="/i.test(n)?n=n.replace(/style="([^"]*)"/i,(e,t)=>`style="${t};width:100%;height:auto;display:block;max-width:100%;"`):n+=` style="width:100%;height:auto;display:block;max-width:100%;"`,/preserveAspectRatio=/i.test(n)||(n+=` preserveAspectRatio="xMidYMid meet"`),`<svg${n}>`})}let Bs;function Vs(){return Bs||=import(`mermaid`).then(({default:e})=>(e.initialize({startOnLoad:!1,theme:`default`,securityLevel:`loose`,fontFamily:Ls,suppressErrorRendering:!0,flowchart:{htmlLabels:!0,useMaxWidth:!0,nodeSpacing:40,rankSpacing:50,padding:12},sequence:{useMaxWidth:!0},themeVariables:{fontFamily:Ls}}),e)),Bs}function Hs({code:e,className:n}){let r=Y(null),[i,a]=X(null),[o,s]=X(null),c=ut().replace(/:/g,`_`);return q(()=>{let t=!1;return(async()=>{if(!e.trim()){a(null),s(null);return}try{s(null);let n=`mermaid-${c}-${Date.now()}`,r=Rs(e),{svg:i}=await(await Vs()).render(n,r),o=zs(i);t||a(o)}catch(e){if(!t){let t=e instanceof Error?e.message:`Failed to render mermaid diagram`;s(t),a(null)}}})(),()=>{t=!0}},[e,c]),o?null:i?t(`div`,{ref:r,className:`my-4 w-full overflow-x-auto [&_svg]:mx-auto [&_svg]:w-full [&_svg]:h-auto [&_svg]:max-w-full ${n||``}`,dangerouslySetInnerHTML:{__html:i}}):t(`div`,{className:`my-4 p-4 bg-gray-50 dark:bg-gray-800 rounded-lg animate-pulse ${n||``}`,children:t(`div`,{className:`h-32 bg-gray-200 dark:bg-gray-700 rounded`})})}function Us(e){switch(e.split(`.`).pop()?.toLowerCase()){case`json`:return`json`;case`md`:case`txt`:case`csv`:case`yaml`:case`yml`:return`text`;case`png`:case`jpg`:case`jpeg`:case`gif`:case`webp`:case`pdf`:return`binary`;default:return`text`}}function Ws({runId:e,path:t,parseJson:n=!0}){let{client:r}=Q(),i=qa(),a=Y(r);a.current=r;let o=Y(i);o.current=i;let[s,c]=X({data:void 0,rawContent:void 0,isLoading:!0,error:void 0,contentType:void 0}),l=K(async()=>{if(!e){c({data:void 0,rawContent:void 0,isLoading:!1,error:`No run ID provided`,contentType:void 0});return}if(!t){c({data:void 0,rawContent:void 0,isLoading:!1,error:`No artifact path provided`,contentType:void 0});return}c(e=>({...e,isLoading:!0,error:void 0}));let r=a.current,i=o.current,s=Us(t);try{let a=Ya(e,t,`inline`),o;o=i?await i.getOrFetch(a,async()=>(await r.files.getArtifactDownloadUrl(e,t,`inline`)).url):(await r.files.getArtifactDownloadUrl(e,t,`inline`)).url;let l=await fetch(o);if(!l.ok)throw Error(`Failed to fetch artifact: ${l.status} ${l.statusText}`);if(s===`binary`){c({data:o,rawContent:void 0,isLoading:!1,error:void 0,contentType:s,etag:l.headers.get(`etag`)?.replace(/^"(.*)"$/,`$1`)});return}let u=await l.text(),d;if(n&&s===`json`)try{d=JSON.parse(u)}catch{d=u}else d=u;c({data:d,rawContent:u,isLoading:!1,error:void 0,contentType:s,etag:l.headers.get(`etag`)?.replace(/^"(.*)"$/,`$1`)})}catch(e){let n=e instanceof Error?e.message:`Failed to fetch artifact`;console.error(`Failed to fetch artifact content:`,t,e),c({data:void 0,rawContent:void 0,isLoading:!1,error:n,contentType:s})}},[e,t,n]);q(()=>{l()},[l]);let u=K(()=>{c({data:void 0,rawContent:void 0,isLoading:!0,error:void 0,contentType:void 0}),l()},[l]);return{data:s.data,rawContent:s.rawContent,isLoading:s.isLoading,error:s.error,contentType:s.contentType,etag:s.etag,retry:u}}function Gs(e){let t=e.trim();if(t.length<2)return!0;if(!t.startsWith(`{`))return!1;try{return JSON.parse(t),!1}catch(e){let n=e instanceof Error?e.message:``,r=[`unexpected end`,`unterminated string`,`expected`,`unexpected token`],i=n.toLowerCase();if(r.some(e=>i.includes(e))){let e=0,n=0,r=!1,i=!1;for(let a of t){if(i){i=!1;continue}if(a===`\\`){i=!0;continue}if(a===`"`){r=!r;continue}r||(a===`{`?e++:a===`}`?e--:a===`[`?n++:a===`]`&&n--)}return e>0||n>0||r}return!1}}function Ks(e){try{let t=e.trim(),n=t.indexOf(`{`),r=t.lastIndexOf(`}`);return n!==-1&&r>n&&(t=t.slice(n,r+1)),JSON.parse(t)}catch{return null}}function qs(e){let t=typeof e.$schema==`string`&&e.$schema.includes(`vega`),n=e.library===`vega-lite`&&`spec`in e;return t||n?`vega-lite`:null}function Js({code:e}){let{artifactRunId:n}=Ss();n||console.warn(`[VegaLiteCodeBlockHandler] artifactRunId is missing from CodeBlockContext`);let r=J(()=>Gs(e),[e]),i=J(()=>{if(r)return null;let t=Ks(e);return t?{library:`vega-lite`,spec:t}:null},[e,r]);return r?t(Es,{type:`chart`,message:`Loading chart...`}):i?t(Ds,{type:`chart`,fallbackCode:e,children:t(po,{spec:i,artifactRunId:n})}):t(Es,{type:`chart`,error:`Invalid Vega-Lite specification`})}function Ys({code:e}){let{artifactRunId:n}=Ss();n||console.warn(`[ChartCodeBlockHandler] artifactRunId is missing from CodeBlockContext`);let r=J(()=>Gs(e),[e]),i=J(()=>{if(r)return null;let t=Ks(e);return!t||!qs(t)?null:t.library===`vega-lite`&&`spec`in t&&typeof t.spec==`object`?t:{library:`vega-lite`,spec:t}},[e,r]);return r?t(Es,{type:`chart`,message:`Loading chart...`}):i?t(Ds,{type:`chart`,fallbackCode:e,children:t(po,{spec:i,artifactRunId:n})}):t(Es,{type:`chart`,error:`Invalid Vega-Lite chart specification`})}function Xs({code:e}){let n=e.trim();return n?t(Ds,{type:`mermaid`,fallbackCode:e,children:t(Hs,{code:n})}):t(Es,{type:`mermaid`,error:`Empty diagram`})}function Zs({code:e}){let n=J(()=>{let t=e.trim();return t?Ns(Ms(t)):null},[e]);return n?t(Ds,{type:`code`,fallbackCode:e,children:t(`div`,{style:{margin:`16px 0`,width:`100%`,overflowX:`auto`},dangerouslySetInnerHTML:{__html:n}})}):t(Es,{type:`code`,error:`Empty mockup`})}function Qs({code:e,language:n}){let{artifactRunId:r}=Ss(),i=e.trim(),a=J(()=>{if(!n?.includes(`:`))return`auto`;let e=n.split(`:`)[1];return[`chart`,`vega-lite`,`table`,`markdown`,`fusion-fragment`,`mockup`,`code`,`image`,`auto`].includes(e)?e:`auto`},[n]),{data:o,isLoading:s,error:c,contentType:l}=Ws({runId:r,path:i});return r?s?t(Es,{type:`expand`,message:`Loading ${i}...`}):c?t(Es,{type:`expand`,error:`Failed to load artifact: ${c}`}):o===void 0?t(Es,{type:`expand`,error:`No content found in artifact`}):t(Is,{content:o,renderType:a,path:i,runId:r,contentType:l}):t(Es,{type:`expand`,error:`No artifact run ID available`})}function $s(e){return e?.startsWith(`expand`)??!1}function ec(){return{chart:Ys,"vega-lite":Js,vegalite:Js,mermaid:Xs,mockup:Zs,svg:Zs}}const tc=new Set([`store`,`document`,`collection`,`interaction`,`prompt`,`agent`,`workflow`,`process`,`run`]);function nc(e){return e.trim().replace(/^\/+/,``)}function rc(e){if(e.startsWith(`artifact:`))return{scheme:`artifact`,path:e.slice(9).trim()};if(e.startsWith(`image:`))return{scheme:`image`,path:e.slice(6).trim()};let t=e.indexOf(`:`);if(t>0){let n=e.slice(0,t);if(tc.has(n))return{scheme:n,path:nc(e.slice(t+1))}}return{scheme:`standard`,path:e}}function ic({rawUrl:e,artifactRunId:t,disposition:n=`inline`}){let{client:r}=Q(),i=qa(),a=Y(r);a.current=r;let o=Y(i);o.current=i;let{scheme:s,path:c}=rc(e),[l,u]=X(()=>{if(s===`standard`)return{url:e,isLoading:!1,error:void 0};if(i&&(s===`artifact`||s===`image`)){let e;e=s===`artifact`&&t&&!Ja(c)?Ya(t,c,n):Xa(c);let r=i.getUrl(e);if(r)return{url:r,isLoading:!1,error:void 0}}return{url:void 0,isLoading:!0,error:void 0}}),d=K(async()=>{if(s===`standard`)return;if(s!==`artifact`&&s!==`image`){u({url:void 0,isLoading:!1,error:`Unknown scheme: ${s}`});return}u(e=>({...e,isLoading:!0,error:void 0}));let e=a.current,r=o.current;try{let i;if(s===`artifact`){if(t&&!Ja(c)){let a=Ya(t,c,n);i=r?await r.getOrFetch(a,async()=>(await e.files.getArtifactDownloadUrl(t,c,n)).url):(await e.files.getArtifactDownloadUrl(t,c,n)).url}else{let t=Xa(c);i=r?await r.getOrFetch(t,async()=>(await e.files.getDownloadUrl(c)).url):(await e.files.getDownloadUrl(c)).url}}else{let t=Xa(c);i=r?await r.getOrFetch(t,async()=>(await e.files.getDownloadUrl(c)).url):(await e.files.getDownloadUrl(c)).url}u({url:i,isLoading:!1,error:void 0})}catch(e){let t=e instanceof Error?e.message:`Failed to resolve URL`;console.error(`Failed to resolve URL:`,c,e),u({url:void 0,isLoading:!1,error:t})}},[s,c,t,n]);q(()=>{if(l.url&&!l.error)return;let e=!1;return e||(async()=>{await d()})(),()=>{e=!0}},[d,l.url,l.error]);let f=K(()=>{u({url:void 0,isLoading:!0,error:void 0}),d()},[d]);return{url:l.url,isLoading:l.isLoading,error:l.error,scheme:s,retry:f}}function ac({src:e,alt:r,caption:i,className:a,artifactRunId:o}){let s=e||``,{scheme:c}=rc(s);return c===`standard`?n(`figure`,{className:`my-4`,children:[t(`img`,{src:e,alt:r,className:a}),t(`figcaption`,{className:`mt-2 text-sm text-muted text-center italic`,children:i})]}):t(oc,{rawSrc:s,alt:r,caption:i,artifactRunId:o,className:a})}function oc({rawSrc:e,alt:r,caption:i,artifactRunId:a,className:o}){let{url:s,isLoading:c,error:l,retry:u}=ic({rawUrl:e,artifactRunId:a,disposition:`inline`});return c?t(Es,{type:`image`,message:r?`Loading ${r}...`:void 0}):l?t(Es,{type:`image`,error:l,onRetry:u}):s?n(`figure`,{className:`my-4`,children:[t(`img`,{src:s,alt:r,className:o}),t(`figcaption`,{className:`mt-2 text-sm text-muted text-center italic`,children:i})]}):null}function sc({node:e,src:n,alt:r,className:i,artifactRunId:a,ExistingImg:o,...s}){let c=n||``,{scheme:l}=rc(c);return l===`standard`?typeof o==`function`?t(o,{node:e,src:n,alt:r,...s}):t(`img`,{src:n,alt:r,className:i,...s}):t(cc,{rawSrc:c,alt:r,artifactRunId:a,className:i,rest:s})}function cc({rawSrc:e,alt:n,artifactRunId:r,className:i,rest:a}){let{url:o,isLoading:s,error:c,retry:l}=ic({rawUrl:e,artifactRunId:r,disposition:`inline`});return s?t(Es,{type:`image`,message:n?`Loading ${n}...`:void 0}):c?t(Es,{type:`image`,error:c,onRetry:l}):o?t(`img`,{src:o,alt:n,className:i,...a}):null}const lc=ot(()=>({kind:`none`}));lc.Provider;function uc(){return lt(lc)}const dc={store:`document`,document:`document`,collection:`collection`,interaction:`interaction`,prompt:`prompt`,agent:`agent`,workflow:`workflow`,process:`process`,run:`interaction_run`};function fc(e){let t=e.indexOf(`:`);if(t<=0)return;let n=e.slice(0,t);if(!Object.hasOwn(dc,n))return;let r=e.slice(t+1).trim().replace(/^\/+/,``);if(r)return{type:dc[n],id:r}}function pc({node:e,href:n,children:r,className:i,artifactRunId:a,onArtifactOpen:o,ExistingLink:s,...c}){let l=n||``,u=fc(l);if(u)return t(mc,{resource:u,rawHref:l,artifactRunId:a,className:i,ExistingLink:s,rest:c,children:r});let{scheme:d,path:f}=rc(l);return d===`standard`?typeof s==`function`?t(s,{node:e,href:n,className:i,...c,children:r}):t(`a`,{href:n,...c,className:i,target:`_blank`,rel:`noopener noreferrer`,children:r}):t(hc,{rawHref:l,artifactRunId:a,artifactPath:d===`artifact`?f:void 0,onArtifactOpen:o,className:i,rest:c,children:r})}function mc({resource:e,rawHref:n,artifactRunId:r,className:i,children:a,ExistingLink:s,rest:c}){let l=uc()(e,{workflowRunId:r,source:`markdown`,rawHref:n});return l.kind===`navigate`?typeof s==`function`?t(s,{href:l.href,className:i,...c,children:a}):t(`a`,{href:l.href,...c,className:i,target:`_blank`,rel:`noopener noreferrer`,children:a}):l.kind===`activate`?t(o,{variant:`link`,size:`none`,className:i,onClick:l.onActivate,children:a}):t(`span`,{className:i,children:a})}function hc({rawHref:e,artifactRunId:n,artifactPath:r,onArtifactOpen:i,className:a,children:o,rest:s}){let{url:c,isLoading:l,error:u,retry:d}=ic({rawUrl:e,artifactRunId:n,disposition:`attachment`});return l?t(`span`,{className:`inline-flex items-center gap-1 text-muted`,children:t(Es,{type:`link`})}):u?t(`span`,{className:`inline-flex items-center gap-1`,children:t(Es,{type:`link`,error:u,onRetry:d})}):t(`a`,{href:c||`#`,...s,className:a,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>{r&&/\.md$/i.test(r)&&i&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&e.button===0&&(e.preventDefault(),i(r))},children:o})}const gc=[`artifact:`,`image:`,`store:`,`document://`,`collection:`,`interaction:`,`prompt:`,`agent:`,`workflow:`,`process:`,`run:`],_c=/(!?\[[^[\]\n]*\]\()((?:artifact:|image:|store:|document:\/\/|collection:|interaction:|prompt:|agent:|workflow:|process:|run:)[^)[\n]+)(\))/g,vc=/`[^`\n]*`/g,yc=/(^|\n)(`{3,}|~{3,})[^\n]*\n[\s\S]*?\n\2(?=\n|$)/g,bc=/\s+("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\([^)]*\))\s*$/;function xc(e){return gc.some(t=>e.startsWith(t))}function Sc(e){let t=e.trim();if(t.startsWith(`<`)){let n=t.indexOf(`>`);if(n>0&&xc(t.slice(1,n).trim()))return e}let n=t.match(bc)?.index??-1,r=(n>=0?t.slice(0,n):t).trim(),i=n>=0?t.slice(n):``;return xc(r)?`<${r}>${i}`:e}function Cc(e){return e.replace(_c,(e,t,n,r)=>`${t}${Sc(n)}${r}`)}function wc(e){let t=``,n=0;for(let r of e.matchAll(vc))t+=Cc(e.slice(n,r.index)),t+=r[0],n=r.index+r[0].length;return t+=Cc(e.slice(n)),t}function Tc(e){if(!e||!gc.some(t=>e.includes(t)))return e;let t=``,n=0;for(let r of e.matchAll(yc))t+=wc(e.slice(n,r.index)),t+=r[0],n=r.index+r[0].length;return t+=wc(e.slice(n)),t}const Ec=/^([ \t]*):::([^\n]*?):::[ \t]*$/gm,Dc=/^\w+/;function Oc(e){return e?.includes(`:::`)?e.replace(Ec,(e,t,n)=>{let r=n.trim(),i=Dc.exec(r);if(!i)return e;let a=i[0],o=r.slice(a.length).trim();return o?`${t}:::${a}\n${t}${o}\n${t}:::`:`${t}::${a}`}):e}const kc=/(^|\n)(`{3,}|~{3,})[^\n]*\n[\s\S]*?\n\2(?=\n|$)/g,Ac=/`[^`\n]*`/g,jc=/\\\$/g,Mc=/\\[^\s]/,Nc=/[{}]/,Pc=/[_^][\w{]/,Fc=/^[a-zA-Z]$/,Ic=/^[a-zA-Z]\s*=/,Lc=/^\s/,Rc=/\s$/,zc=/[+*/-]$/,Bc=/\^[+-]$/;function Vc(e){return Mc.test(e)||Nc.test(e)||Pc.test(e)||Fc.test(e)||Ic.test(e)}function Hc(e){return!!(Lc.test(e)||Rc.test(e)||zc.test(e)&&!Bc.test(e))}function Uc(e){let t=[];for(let n=0;n<e.length;n++)if(e[n]===`$`&&!(n>0&&e[n-1]===`\\`)){if(n+1<e.length&&e[n+1]===`$`){n++;continue}n>0&&e[n-1]===`$`&&(n<2||e[n-2]!==`\\`)||t.push(n)}return t}function Wc(e,t,n){let r=e.slice(t+1,n);return r.length===0||r.includes(`
|
|
2
|
+
`)?null:r}function Gc(e){let t=Uc(e);if(t.length<2)return e;let n=new Set,r=new Set,i=Array(t.length-1);for(let n=0;n<t.length-1;n++)i[n]=Wc(e,t[n],t[n+1]);let a=[];for(let e=0;e<t.length-1;e++){if(n.has(e))continue;let r=i[e];r!==null&&Vc(r)&&(n.add(e),n.add(e+1),a.push([t[e],t[e+1]]))}let o=0;for(;o<t.length;){if(n.has(o)){o++;continue}let e=o+1;for(;e<t.length&&n.has(e);)e++;if(e>=t.length)break;if(e>o+1){r.add(t[o]),o++;continue}let a=i[o];if(a===null){o++;continue}Hc(a)&&(r.add(t[o]),r.add(t[e])),n.add(o),n.add(e),o=e+1}for(let e=0;e<t.length;e++)n.has(e)||e+1<t.length&&n.has(e+1)&&r.add(t[e]);if(r.size===0&&a.length===0)return e;let s=[],c=0,l=Array.from(r).sort((e,t)=>e-t),u=0,d=0;for(;u<l.length||d<a.length;){let t=u<l.length?l[u]:1/0;if(t<(d<a.length?a[d][0]:1/0))t>c&&s.push(e.slice(c,t)),s.push(`\\$`),c=t+1,u++;else{let[t,n]=a[d];t>c&&s.push(e.slice(c,t));let r=e.slice(t,n+1);for(s.push(r.replace(jc,`\\text{\\textdollar}`)),c=n+1;u<l.length&&l[u]<=n;)u++;d++}}return c<e.length&&s.push(e.slice(c)),s.join(``)}function Kc(e){let t=[],n=0;for(let r of e.matchAll(Ac))t.push(Gc(e.slice(n,r.index))),t.push(r[0]),n=r.index+r[0].length;return t.push(Gc(e.slice(n))),t.join(``)}function qc(e){if(!e?.includes(`$`))return e;let t=[],n=0;for(let r of e.matchAll(kc))t.push(Kc(e.slice(n,r.index))),t.push(r[0]),n=r.index+r[0].length;return t.push(Kc(e.slice(n))),t.join(``)}const Jc={note:`md-callout-info`,tip:`md-callout-info`,warning:`md-callout-attention`,important:`md-callout-attention`,caution:`md-callout-destructive`},Yc={note:`Note`,tip:`Tip`,warning:`Warning`,important:`Important`,caution:`Caution`};function Xc(){return e=>{fa(e,e=>{if(e.type!==`containerDirective`&&e.type!==`leafDirective`&&e.type!==`textDirective`)return;let t=e;t.data||={};let n=t.data,r=t.attributes||{},i=t.name;if(i===`pagebreak`){n.hName=`hr`,n.hProperties={className:`md-pagebreak`};return}if(i===`columns`){n.hName=`div`,n.hProperties={className:`md-columns`};return}if(i===`column`){n.hName=`div`;let e={className:`md-column`};r.width&&(e.style=`flex-basis:${r.width};flex-grow:0;flex-shrink:0`),n.hProperties=e;return}if(i in Jc){n.hName=`div`,n.hProperties={className:`md-callout ${Jc[i]}`,"data-callout-type":i};let e=Yc[i];if(e&&t.children){let n={type:`paragraph`,data:{hName:`p`,hProperties:{className:`md-callout-title`}},children:[{type:`text`,value:e}]};t.children.unshift(n)}return}n.hName=`div`,n.hProperties={className:`md-${i}`,...Object.fromEntries(Object.entries(r).filter(([e])=>e!==`class`))},r.class&&(n.hProperties.className+=` ${r.class}`)})}}const Zc=/(?:^|[^\\])\$/,Qc=[];let $c,el;function tl(){return el||=import(`rehype-katex`).then(({default:e})=>($c=e,e)),el}function nl(e){let t=G.useMemo(()=>Zc.test(e),[e]),[n,r]=G.useState(()=>$c);return G.useEffect(()=>{if(!t||n)return;let e=!1;return tl().then(t=>{e||r(()=>t)}).catch(e=>{console.error(`Failed to load KaTeX; math will render unstyled`,e)}),()=>{e=!0}},[t,n]),G.useMemo(()=>n?[n]:Qc,[n])}const rl=[`artifact:`,`image:`,`store:`,`document:`,`document://`,`collection:`,`interaction:`,`prompt:`,`agent:`,`workflow:`,`process:`,`run:`];function il(e){return rl.some(t=>e.startsWith(t))?e:ra(e)}function al(){return e=>{fa(e,`html`,(e,t,n)=>{let r=e,i=n;if(typeof r.value==`string`&&/<!--[\s\S]*?-->/.test(r.value)&&i?.children&&typeof t==`number`)return i.children.splice(t,1),[da,t]})}}const ol=ec();function sl({children:e,components:n,remarkPlugins:r=[],removeComments:i=!0,artifactRunId:a,onArtifactOpen:o,className:s,codeClassName:c,inlineCodeClassName:l,linkClassName:u,imageClassName:d,onProposalSelect:f,onProposalSubmit:p,preserveSourcePositions:m=!1}){let h=ws(),g=G.useMemo(()=>m?e:Oc(Tc(qc(e))),[e,m]),_=G.useMemo(()=>{let e=[sa,oa,Xc,ca,aa,ua,la,...r];return i&&e.push(al),e},[r,i]),v=nl(g),y=G.useMemo(()=>({handlers:{...ia}}),[]),b=G.useMemo(()=>{let e=n||{},r=e.code,i=e.a,s=e.img,f=({node:e,className:n,children:i,...a})=>{let o=/language-([\w-]+)/.exec(n||``),s=!o,u=o?o[1]:``;if(!s&&u){if(h){let e=h.getComponent(u);if(e){let n=String(i||``).trim();return t(e,{code:n,language:u})}}if($s(u)){let e=String(i||``).trim();return t(Qs,{code:e,language:u})}let e=ol[u];if(e){let n=String(i||``).trim();return t(e,{code:n,language:u})}}return typeof r==`function`?t(r,{node:e,className:n,...a,children:i}):t(`code`,{...a,className:s?`px-1.5 py-0.5 rounded ${l||``}`:` ${c||``}`,children:i})},p=e=>{let{node:n,href:r,children:s,...c}=e;return t(pc,{node:n,href:r,className:u,artifactRunId:a,onArtifactOpen:o,ExistingLink:typeof i==`function`?i:void 0,...c,children:s})},m=e=>{let{node:n,src:r,alt:i,title:o,...c}=e;return o?t(ac,{src:r,alt:i,caption:o,className:d,artifactRunId:a}):t(sc,{node:n,src:r,alt:i,className:d,artifactRunId:a,ExistingImg:typeof s==`function`?s:void 0,...c})};return{...e,code:f,a:p,img:m}},[n,a,o,h,c,l,u,d]),x=t(xs,{artifactRunId:a,onProposalSelect:f,onProposalSubmit:p,MarkdownRenderer:sl,children:t(na,{remarkPlugins:_,rehypePlugins:v,remarkRehypeOptions:y,components:b,urlTransform:il,children:g})});return s?t(`div`,{className:`md-content ${s}`,children:x}):t(`div`,{className:`md-content`,children:x})}const cl={default:{border:`border-s-attention`,bg:`bg-amber-50 dark:bg-amber-900/20`,icon:`text-attention`},warning:{border:`border-s-destructive`,bg:`bg-red-50 dark:bg-red-900/20`,icon:`text-destructive`},info:{border:`border-s-info`,bg:`bg-blue-50 dark:bg-blue-900/20`,icon:`text-info`},success:{border:`border-s-success`,bg:`bg-green-50 dark:bg-green-900/20`,icon:`text-success`}},ll={default:er,warning:Wt,info:yr,success:on},ul=`max-h-80 overflow-y-auto overscroll-contain pe-2`;function dl({question:r,description:i,options:a,onSelect:s,onMultiSelect:c,onSubmit:l,allowFreeResponse:u=!1,multiSelect:d=!1,placeholder:f,submitLabel:p,isLoading:m=!1,icon:h,variant:g=`default`,hideIcon:_=!1,hideBorder:v=!1,compact:y=!1,answered:b=!1,className:x,cardClassName:S,headerClassName:C,iconClassName:w,questionClassName:T,descriptionClassName:E,optionsClassName:D,buttonClassName:O,inputContainerClassName:k,inputClassName:A,submitButtonClassName:j}){let{t:M}=Z(),N=f??M(`agent.typeYourResponse`),P=p??M(`agent.send`),[F,I]=G.useState(``),[L,ee]=G.useState(new Set),R=G.useRef(null),te=cl[g],z=ll[g],ne=Array.isArray(a)?a:[],B=G.useRef(!1);G.useEffect(()=>{a===void 0||Array.isArray(a)||B.current||(B.current=!0,Yi.logger.warn(`AskUserWidget received invalid options; rendering without options`,{vertesia:{component:`AskUserWidget`,received_type:typeof a}}),console.warn(`[AskUserWidget] Invalid options received; rendering without options.`))},[a]);let re=e=>{ee(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ie=()=>{L.size>0&&c&&(c(Array.from(L)),ee(new Set))},ae=()=>{F.trim()&&l&&(l(F.trim()),I(``))},oe=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),ae())},se=v?``:`border-s-4 ${te.border}`;if(y){let a=h||t(z,{className:`size-4`}),c=t(`div`,{className:H(`agent-ask-question text-sm leading-6 text-foreground/85`,T),children:t(sl,{children:r})});return b?t(`div`,{className:H(`my-1.5 font-sans`,x),children:n(`div`,{className:ul,children:[c,i&&t(`p`,{className:H(`mt-1 text-xs leading-5 text-muted`,E),children:i})]})}):t(`div`,{className:H(`my-2 font-sans`,x),children:n(`div`,{className:H(`rounded-lg border border-border bg-background/60 shadow-none`,S),children:[t(`div`,{className:H(`px-3 py-2`,C),children:n(`div`,{className:`flex items-start gap-2.5`,children:[!_&&t(`div`,{className:H(`mt-1 flex-shrink-0 text-attention`,w),children:a}),t(`div`,{className:`min-w-0 flex-1`,children:n(`div`,{className:ul,children:[c,i&&t(`p`,{className:H(`mt-1 text-xs leading-5 text-muted`,E),children:i})]})})]})}),ne.length>0&&t(`div`,{className:H(`flex flex-col gap-1.5 px-3 pb-3 pt-0`,D),children:d?n(e,{children:[ne.map(e=>{let r=L.has(e.id);return n(`label`,{className:H(`flex cursor-pointer items-start gap-2.5 rounded-md border px-3 py-2 text-start transition-colors`,r?`border-info/60 bg-info/10`:`border-border bg-background/70 hover:bg-mixer-muted/15`,m&&`cursor-not-allowed opacity-50`,O),children:[t(`input`,{type:`checkbox`,checked:r,onChange:()=>re(e.id),disabled:m,className:`mt-1 size-4 rounded border-border bg-background text-info focus:ring-info`}),n(`span`,{className:`min-w-0 flex-1`,children:[n(`span`,{className:`flex items-center gap-2 text-sm font-medium leading-5 text-foreground`,children:[e.icon,t(`span`,{className:`break-words`,children:e.label})]}),e.description&&t(`span`,{className:`mt-0.5 block break-words text-xs leading-5 text-muted`,children:e.description})]})]},e.id)}),t(`div`,{className:`pt-1`,children:n(o,{size:`sm`,onClick:ie,disabled:m||L.size===0,className:`inline-flex items-center gap-2`,children:[t(qr,{className:`size-4`}),L.size>0?M(`agent.submitSelectionCount`,{count:L.size}):M(`agent.submitSelection`)]})})]}):ne.map(e=>n(`button`,{type:`button`,onClick:()=>s?.(e.id),disabled:m,className:H(`flex w-full cursor-pointer items-start gap-2.5 rounded-md border border-border bg-background/70 px-3 py-2 text-start transition-colors`,`hover:bg-mixer-muted/15 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,m&&`cursor-not-allowed opacity-50`,O),children:[t(`span`,{className:`mt-1 size-4 flex-shrink-0 rounded-full border border-border`,"aria-hidden":`true`}),n(`span`,{className:`min-w-0 flex-1`,children:[n(`span`,{className:`flex items-center gap-2 text-sm font-medium leading-5 text-foreground`,children:[e.icon,t(`span`,{className:`break-words`,children:e.label})]}),e.description&&t(`span`,{className:`mt-0.5 block break-words text-xs leading-5 text-muted`,children:e.description})]})]},e.id))}),u&&t(`div`,{className:H(`px-3 pb-3 pt-0`,k),children:n(`div`,{className:`flex gap-2`,children:[t(`input`,{ref:R,type:`text`,value:F,onChange:e=>I(e.target.value),onKeyDown:oe,placeholder:N,disabled:m,className:H(`min-w-0 flex-1 rounded-md border border-border bg-background/70 px-3 py-2 text-sm text-foreground focus:border-transparent focus:ring-2 focus:ring-ring`,A)}),t(o,{size:`sm`,onClick:ae,disabled:m||!F.trim(),className:j,children:m?`...`:P})]})})]})})}return t(`div`,{className:`my-4 font-sans ${x||``}`,children:n(`div`,{className:`${se} ${te.bg} rounded-e-lg shadow-sm ${S||``}`,children:[t(`div`,{className:`px-4 py-3 ${C||``}`,children:n(`div`,{className:`flex items-start gap-3`,children:[!_&&t(`div`,{className:`flex-shrink-0 mt-0.5 ${te.icon} ${w||``}`,children:h||t(z,{className:`size-5`})}),t(`div`,{className:`min-w-0 flex-1`,children:n(`div`,{className:ul,children:[t(`div`,{className:`agent-ask-question prose prose-sm dark:prose-invert max-w-none text-gray-900 dark:text-gray-100 ${T||``}`,children:t(sl,{children:r})}),i&&t(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400 ${E||``}`,children:i})]})})]})}),ne.length>0&&t(`div`,{className:`px-4 pb-3 pt-1 ${D||``}`,children:d?n(`div`,{className:`space-y-2`,children:[ne.map(e=>n(`label`,{className:`flex items-start gap-3 px-4 py-3 rounded-lg cursor-pointer transition-colors
|
|
5
3
|
${L.has(e.id)?`bg-blue-50 dark:bg-blue-900/30 border border-blue-300 dark:border-blue-700`:`bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-700`}
|
|
6
|
-
${m?`opacity-50 cursor-not-allowed`:``}`,children:[t(`input`,{type:`checkbox`,checked:L.has(e.id),onChange:()=>
|
|
4
|
+
${m?`opacity-50 cursor-not-allowed`:``}`,children:[t(`input`,{type:`checkbox`,checked:L.has(e.id),onChange:()=>re(e.id),disabled:m,className:`mt-0.5 w-4 h-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700`}),n(`div`,{className:`flex-1 overflow-hidden`,children:[n(`div`,{className:`flex items-center gap-2 text-sm font-medium text-gray-900 dark:text-gray-100 break-words`,children:[e.icon,t(`span`,{className:`break-words`,children:e.label})]}),e.description&&t(`div`,{className:`mt-1 text-sm text-gray-500 dark:text-gray-400 break-words whitespace-pre-wrap`,children:e.description})]})]},e.id)),t(`div`,{className:`pt-2`,children:n(o,{size:`sm`,onClick:ie,disabled:m||L.size===0,className:`flex items-center gap-2`,children:[t(qr,{className:`size-4`}),L.size>0?M(`agent.submitSelectionCount`,{count:L.size}):M(`agent.submitSelection`)]})})]}):t(`div`,{className:`flex flex-col gap-2 w-full`,children:ne.map(e=>t(o,{variant:`unstyled`,onClick:()=>s?.(e.id),disabled:m,className:`w-full h-auto whitespace-normal text-start px-4 py-3 rounded-lg border border-gray-200 dark:border-gray-700
|
|
7
5
|
bg-white dark:bg-gray-800
|
|
8
6
|
hover:bg-gray-50 dark:hover:bg-gray-700 hover:border-gray-300 dark:hover:border-gray-600
|
|
9
7
|
focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-1
|
|
10
8
|
transition-colors
|
|
11
9
|
${m?`opacity-50 cursor-not-allowed`:`cursor-pointer`}
|
|
12
|
-
${O||``}`,children:n(`div`,{className:`flex items-start gap-3`,children:[e.icon&&t(`span`,{className:`flex-shrink-0 mt-0.5 text-gray-500 dark:text-gray-400`,children:e.icon}),n(`div`,{className:`flex-1 overflow-hidden`,children:[t(`div`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100 break-words text-center`,children:e.label}),e.description&&t(`div`,{className:`mt-1 text-sm text-gray-500 dark:text-gray-400 break-words whitespace-pre-wrap`,children:e.description})]})]})},e.id))})}),u&&t(`div`,{className:`px-4 pb-3 pt-1 ${k||``}`,children:n(`div`,{className:`flex gap-2`,children:[t(`input`,{ref:R,type:`text`,value:F,onChange:e=>I(e.target.value),onKeyDown:
|
|
13
|
-
`).trim()||void 0}function Cu(e){return Su(e.message)}function wu(e,t){let n=Su(e.text);if(!n)return!1;let r=e.workstreamId||`main`;return t.some(t=>{if(gu(t.timestamp)<e.startTimestamp||_u(t)!==r)return!1;let i=typeof t.details?.streaming_id==`string`?t.details.streaming_id:void 0;return e.streamingId&&i?!(i!==e.streamingId||t.details?.display_role===`thinking`||Eu(t)||t.details?.tool_status):e.activityId&&t.details?.activity_id===e.activityId?!(t.details?.display_role===`thinking`||Eu(t)||t.details?.tool_status):t.type!==Q.THOUGHT&&t.type!==Q.ANSWER&&t.type!==Q.COMPLETE&&t.type!==Q.IDLE||!t.details?.streamed?!1:Cu(t)===n})}function Tu(e,t){if(_u(e)!==_u(t))return!1;let n=Cu(e),r=Cu(t);if(!n||n!==r)return!1;let i=gu(e.timestamp);return gu(t.timestamp)-i>1e4?!1:!!(e.type===Q.ANSWER&&(t.type===Q.COMPLETE||t.type===Q.IDLE)||e.type===Q.THOUGHT&&(t.type===Q.ANSWER||t.type===Q.COMPLETE||t.type===Q.IDLE)&&(e.details?.streamed||t.details?.streamed)||e.type===t.type&&(e.details?.streamed||t.details?.streamed)&&(t.type===Q.THOUGHT||t.type===Q.ANSWER||t.type===Q.COMPLETE||t.type===Q.IDLE))}function Eu(e){return e.type===Q.THOUGHT&&!!e.details?.tool}function Du(e){let t=e.details;return e.type===Q.THOUGHT&&(t?.display_role===`tool_preamble`||t?.tool===`think`)}function Ou(e){if(Du(e))return!1;if(Eu(e))return!0;if(e.type!==Q.THOUGHT)return!1;let t=e.details;return!!(Array.isArray(t?.tools)&&t.tools.length>0)}function ku(e){return e.details?.tool_run_id}function Au(e){return e.details?.tool_iteration}function ju(e){return e.details?.tool_status}function Mu(e){let t=e.details?.activity_group_id;if(typeof t==`string`&&t.trim()!==``)return t}function Nu(e,t,n){let r=new Map,i=new Map,a=new Map,o=[];for(let t of e){let e=Mu(t);if(t.type===Q.REQUEST_INPUT||t.type===Q.BATCH_PROGRESS)o.push(t);else if(Du(t))o.push(t);else if(e)r.has(e)||r.set(e,{messages:[],firstTimestamp:gu(t.timestamp)}),r.get(e)?.messages.push(t);else if(Ou(t)){let e=Au(t),n=ku(t);e===void 0?n?(a.has(n)||a.set(n,{messages:[],firstTimestamp:gu(t.timestamp)}),a.get(n)?.messages.push(t)):o.push(t):(i.has(e)||i.set(e,{messages:[],firstTimestamp:gu(t.timestamp)}),i.get(e)?.messages.push(t))}else o.push(t)}let s=[];r.forEach((e,t)=>{s.push({kind:`activity_group`,activityGroupId:t,messages:e.messages,timestamp:e.firstTimestamp})}),i.forEach((e,t)=>{s.push({kind:`iteration_group`,iteration:t,messages:e.messages,timestamp:e.firstTimestamp})}),a.forEach((e,t)=>{s.push({kind:`tool_run`,toolRunId:t,messages:e.messages,timestamp:e.firstTimestamp})});for(let e of o)s.push({kind:`message`,message:e,timestamp:gu(e.timestamp)});t.forEach((t,r)=>{t.text&&(wu(t,e)||n&&n!==`all`&&n!==(t.workstreamId||`main`)||s.push({kind:`streaming`,streamingId:r,data:t,timestamp:t.startTimestamp}))}),s.sort((e,t)=>{let n=e.kind===`streaming`&&!e.data.isComplete,r=t.kind===`streaming`&&!t.data.isComplete;return n&&!r?1:r&&!n?-1:e.timestamp-t.timestamp});let c=[],l=[],u=()=>{l.length>0&&(l.length===1&&!Du(l[0])?c.push({type:`single`,message:l[0]}):c.push({type:`tool_group`,messages:l,firstTimestamp:gu(l[0].timestamp)}),l=[])};for(let e of s)if(e.kind===`streaming`)u(),c.push({type:`streaming`,streamingId:e.streamingId,text:e.data.text,workstreamId:e.data.workstreamId,startTimestamp:e.data.startTimestamp,isComplete:e.data.isComplete});else if(e.kind===`activity_group`){u();let t=[...e.messages].sort((e,t)=>gu(e.timestamp)-gu(t.timestamp)),n=t.reduce((e,t)=>ju(t)||e,void 0);c.push({type:`tool_group`,messages:t,firstTimestamp:e.timestamp,toolRunId:e.activityGroupId,toolStatus:n})}else if(e.kind===`iteration_group`){u();let t=[...e.messages].sort((e,t)=>gu(e.timestamp)-gu(t.timestamp)),n=t.reduce((e,t)=>ju(t)||e,void 0);c.push({type:`tool_group`,messages:t,firstTimestamp:e.timestamp,toolStatus:n})}else if(e.kind===`tool_run`){u();let t=[...e.messages].sort((e,t)=>gu(e.timestamp)-gu(t.timestamp)),n=t.reduce((e,t)=>ju(t)||e,void 0);c.push({type:`tool_group`,messages:t,firstTimestamp:e.timestamp,toolRunId:e.toolRunId,toolStatus:n})}else Ou(e.message)?l.push(e.message):(u(),c.push({type:`single`,message:e.message}));return u(),c}function Pu(e,t){return t??e}function Fu(e){let t=[],n=null,r=()=>{n&&=(t.push({type:`tool_group`,messages:n.messages,firstTimestamp:n.firstTimestamp,toolRunId:n.toolRunId,toolStatus:n.toolStatus,preambleText:n.preambleText,preambleMessage:n.preambleMessage}),null)};for(let i of e)i.type===`tool_group`?n?(n.messages=[...n.messages,...i.messages],n.toolStatus=Pu(n.toolStatus,i.toolStatus),!n.toolRunId&&i.toolRunId&&(n.toolRunId=i.toolRunId),!n.preambleMessage&&i.preambleMessage&&(n.preambleMessage=i.preambleMessage,n.preambleText=i.preambleText)):n={messages:[...i.messages],firstTimestamp:i.firstTimestamp,toolRunId:i.toolRunId,toolStatus:i.toolStatus,preambleText:i.preambleText,preambleMessage:i.preambleMessage}:(r(),t.push(i));return r(),t}function Iu(e){return e.message?typeof e.message==`object`?JSON.stringify(e.message,null,2):String(e.message).trim():``}function Lu(e){let t=Ru(e.details?.tool_approval);if(!t)return Iu(e);let n=zu(t.tool_title)??zu(t.tool_name),r=Vu(zu(t.target));if(n&&r)return`Approve ${n}: ${r}?`;let i=zu(t.action_summary);return i?`Approve ${Bu(i)}?`:Iu(e)}function Ru(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:void 0}function zu(e){return typeof e==`string`&&e.trim()?e.trim():void 0}function Bu(e){return e.replace(/:\s*name(?::|\s+)/i,`: `)}function Vu(e){if(!e)return;let t=e.indexOf(`:`);if(t<0)return e;let n=e.slice(0,t),r=e.slice(t+1).trim();if(!r)return e;switch(n){case`document_id`:return`document ${r}`;case`object_id`:return`object ${r}`;case`collection_id`:return`collection ${r}`;case`process_id`:return`process ${r}`;case`process_definition_id`:return`process definition ${r}`;case`interaction_id`:return`interaction ${r}`;case`prompt_id`:return`prompt ${r}`;case`dashboard_id`:return`dashboard ${r}`;case`database_id`:return`database ${r}`;case`table_id`:return`table ${r}`;default:return r}}function Hu(e){let t=e.details;return e.type===Q.REQUEST_INPUT&&!!t?.ux}function Uu(e){let t=e.details;return[t?.request_id,t?.requestId,t?.activity_id,t?.activityId,t?.tool_run_id,t?.toolRunId,e.timestamp,Iu(e)].filter(e=>typeof e==`string`||typeof e==`number`).map(String).join(`|`)}function Wu(e){let t=e.details,n=t?.request_id??t?.tool_use_id;return typeof n==`string`&&n?n:void 0}function Gu(e){return Wu(e)??Uu(e)}function Ku(e,t){return`vertesia:answered-request-input:${e}:${t}`}function qu(e,t){if(!(typeof window>`u`))try{window.sessionStorage.setItem(Ku(e,t),`1`)}catch{}}function Ju(e,t){if(!(typeof window>`u`))try{window.sessionStorage.removeItem(Ku(e,t))}catch{}}function Yu(e,t){if(t.type!==Q.REQUEST_INPUT)return!1;let n=Wu(t);if(!n||typeof window>`u`)return!1;try{return window.sessionStorage.getItem(Ku(e,n))===`1`}catch{return!1}}function Xu(e){if(e.type!==Q.QUESTION)return;let t=Ru(e.details),n=Ru(t?.metadata),r=(Ru(t?.request_input_response)??Ru(n?.request_input_response))?.request_id;return typeof r==`string`&&r?r:void 0}function Zu(e){let t=e.details;return[t?.ack,t?._messageId,t?._deliveryStatus,e.timestamp,_u(e),Iu(e)].filter(e=>typeof e==`string`||typeof e==`number`).map(String).join(`|`)}function Qu(e){let t=new Set,n=new Map;return e.forEach((e,t)=>{let r=Xu(e);r&&n.set(r,t)}),e.forEach((r,i)=>{if(r.type!==Q.REQUEST_INPUT)return;let a=Wu(r),o=a?n.get(a):void 0;if(o!==void 0&&o>i){t.add(Uu(r));return}let s=_u(r);for(let n=i+1;n<e.length;n+=1){let i=e[n];if(_u(i)===s){if(i.type===Q.REQUEST_INPUT)break;if(i.type===Q.QUESTION){Xu(i)||t.add(Uu(r));break}}}}),t}function $u(e,t){let n=Wu(e);return n?{...t,request_input_response:{request_id:n}}:t}function ed(e,t,n,r){if(!e)return;let i=$u(t,r);i?e(n,i):e(n)}function td(e){let t=Ru(e?.request_input_response)?.request_id;return typeof t==`string`&&t?t:void 0}function nd(e){let t=new Set;for(let n of e){let e=Ru(n.details),r=Ru(e?.approval_request)?.approval_key,i=e?.approval_decision;typeof r==`string`&&(i===`denied`||i===`denied_with_feedback`||i===`timeout`||i===`reviewer_denied`||i===`cancelled_after_denial`)&&t.add(r)}return t}function rd(e){let t=Ru(Ru(e.details)?.tool_approval)?.approval_key;return typeof t==`string`?t:void 0}function id(e){return e.type===Q.REQUEST_INPUT&&rd(e)!==void 0}const ad=new Set([`allow_once`,`allow_for_run`,`deny`]);function od(e,t){let n=rd(e);if(!(!n||!ad.has(t)))return{tool_approval_response:{decision:t,approval_key:n}}}function sd(e){if(e.type!==Q.QUESTION)return!1;let t=Iu(e).trim().toLowerCase();return t===`allow_once`||t===`allow_for_run`||t===`deny`}function cd(e){if(e.type!==Q.QUESTION)return!1;let t=Ru(e.details),n=Ru(t?.metadata),r=(Ru(t?.tool_approval_response)??Ru(n?.tool_approval_response))?.decision;return r===`deny_with_feedback`||typeof r==`string`&&ad.has(r)}function ld(e){return sd(e)||cd(e)}function ud(e,t){if(e.type!==Q.REQUEST_INPUT)return!1;let n=rd(e);return n?t.has(n):!1}function dd(e){let t=new Set;return e.forEach((n,r)=>{if(!id(n))return;let i=_u(n);for(let a=r+1;a<e.length;a+=1){let r=e[a];if(_u(r)===i){if(r.type===Q.REQUEST_INPUT)break;if(r.type===Q.QUESTION){ld(r)&&t.add(Uu(n));break}}}}),t}function fd(e,t,n){return id(e)&&(t.has(Uu(e))||ud(e,n))}function pd(e,t){let n=new Set;return e.forEach((r,i)=>{if(!id(r)||t&&!ud(r,t))return;let a=_u(r);for(let t=i+1;t<e.length;t+=1){let r=e[t];if(_u(r)===a){if(r.type===Q.REQUEST_INPUT)break;if(r.type===Q.QUESTION){sd(r)&&n.add(Zu(r));break}}}}),n}function md(e,t){return e.type===Q.QUESTION&&t.has(Zu(e))}function hd(e,t){return e.type===Q.REQUEST_INPUT&&t.has(Uu(e))}function gd(e,t=`main`,n){let r=Qu(e),i=nd(e);for(let a=e.length-1;a>=0;--a){let o=e[a];if(Hu(o)&&_u(o)===t&&!n?.has(Gu(o))&&!hd(o,r)&&!ud(o,i))return o}}function _d({mcpConnect:e,onMcpConnected:r,onDecline:i,disabled:a}){let{client:s}=Z(),{t:c}=X();return n(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[t(uc,{appId:e.app_install_id,collectionId:e.collection_id,collectionName:e.name,variant:`default`,onAuthChange:()=>{s.remoteMcpConnections.getCollectionStatus(e.app_install_id,e.collection_id).then(t=>{t.authenticated&&r?.(e)}).catch(()=>{})},readOnly:a}),n(o,{variant:`ghost`,size:`sm`,onClick:i,disabled:a,children:[t(di,{className:`size-4`}),t(`span`,{children:c(`mcpOAuth.decline`)})]})]})}function vd({message:e,onSendMessage:r,onMcpConnected:i,isLoading:a=!1,disabled:o=!1,className:s}){let{t:c}=X();if(!e)return null;let l=e.details.ux,u=l.options??[],d=l.mcp_connect,f=l.free_response,p=o||a||!r,m=Lu(e),h=(t,n)=>{p||ed(r,e,t,n)},g=H(`flex-shrink-0 border-t border-border/70 bg-background/95 backdrop-blur`,`fixed bottom-0 end-0 start-0 z-20 lg:sticky lg:start-auto lg:end-auto`,`pb-safe-area`,s);return d?t(`div`,{className:g,"data-agent-request-input-overlay":!0,children:n(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-3 px-3 py-3 sm:flex-row sm:items-center sm:justify-between`,children:[t(`div`,{className:`min-w-0 text-sm leading-6 text-foreground/85`,children:m}),t(_d,{mcpConnect:d,onMcpConnected:t=>i?.(t,$u(e)),onDecline:()=>h(c(`agent.mcpDeclinedMessage`,{name:d.name})),disabled:p})]})}):t(`div`,{className:g,"data-agent-request-input-overlay":!0,children:t(`div`,{className:`mx-auto w-full max-w-3xl px-3 py-3`,children:t(Jl,{question:m,options:u,variant:l.variant,multiSelect:l.multiSelect,allowFreeResponse:u.length===0||!!f,placeholder:f?.placeholder,submitLabel:f?.submit_label,onSelect:t=>h(t,od(e,t)),onMultiSelect:e=>h(e.join(`, `)),onSubmit:e=>h(e,f?.metadata),hideBorder:!0,compact:!0,isLoading:p,className:`my-0`,cardClassName:`bg-background/80 shadow-lg shadow-black/5 dark:shadow-none`})})})}function yd({className:e,inline:r=!1,color:i=`blue`}){let a={blue:`from-blue-400 to-indigo-500 dark:from-blue-500 dark:to-indigo-400`,purple:`from-purple-400 to-violet-500 dark:from-purple-500 dark:to-violet-400`,teal:`from-teal-400 to-emerald-500 dark:from-teal-500 dark:to-emerald-400`,green:`from-green-400 to-emerald-500 dark:from-green-500 dark:to-emerald-400`,amber:`from-amber-400 to-orange-500 dark:from-amber-500 dark:to-orange-400`}[i];return n(`div`,{className:H(`flex items-center gap-1.5`,r?`inline-flex`:``,e),children:[t(`div`,{className:`w-2 h-2 bg-gradient-to-r ${a} rounded-full animate-[bounce_1.2s_ease-in-out_infinite]`}),t(`div`,{className:`w-2 h-2 bg-gradient-to-r ${a} rounded-full animate-[bounce_1.2s_ease-in-out_0.2s_infinite]`}),t(`div`,{className:`w-2 h-2 bg-gradient-to-r ${a} rounded-full animate-[bounce_1.2s_ease-in-out_0.4s_infinite]`})]})}function bd({className:e,size:r=`md`,color:i=`blue`}){let a={sm:`w-3 h-3`,md:`w-5 h-5`,lg:`w-7 h-7`},o={blue:`bg-blue-500 dark:bg-blue-400`,purple:`bg-purple-500 dark:bg-purple-400`,teal:`bg-teal-500 dark:bg-teal-400`,green:`bg-green-500 dark:bg-green-400`,amber:`bg-amber-500 dark:bg-amber-400`};return n(`span`,{className:H(`relative flex`,e),children:[t(`span`,{className:H(`animate-ping absolute inline-flex h-full w-full rounded-full opacity-60`,o[i])}),t(`span`,{className:H(`animate-pulse absolute inline-flex h-[80%] w-[80%] rounded-full opacity-80`,o[i]),style:{left:`10%`,top:`10%`,animationDuration:`2s`}}),t(`span`,{className:H(`relative inline-flex rounded-full`,o[i],a[r])})]})}function xd({className:e,color:n=`blue`}){let[r,i]=Y(`.`);return K(()=>{let e=setInterval(()=>{i(e=>e===`.`?`..`:e===`..`?`...`:`.`)},500);return()=>clearInterval(e)},[]),t(`span`,{className:H({blue:`text-blue-600 dark:text-blue-400`,purple:`text-purple-600 dark:text-purple-400`,teal:`text-teal-600 dark:text-teal-400`,green:`text-green-600 dark:text-green-400`,amber:`text-amber-600 dark:text-amber-400`}[n],`font-bold`,e),children:r})}function Sd({message:e,className:r,color:i=`blue`}){let a={blue:{dot:`bg-blue-500 dark:bg-blue-400`,text:`text-blue-700 dark:text-blue-300`},purple:{dot:`bg-purple-500 dark:bg-purple-400`,text:`text-purple-700 dark:text-purple-300`},teal:{dot:`bg-teal-500 dark:bg-teal-400`,text:`text-teal-700 dark:text-teal-300`},green:{dot:`bg-green-500 dark:bg-green-400`,text:`text-green-700 dark:text-green-300`},amber:{dot:`bg-amber-500 dark:bg-amber-400`,text:`text-amber-700 dark:text-amber-300`}};return n(`div`,{className:H(`flex items-center gap-2 py-1`,r),children:[n(`div`,{className:`flex gap-1`,children:[t(`div`,{className:`w-1.5 h-1.5 ${a[i].dot} rounded-full animate-bounce`}),t(`div`,{className:`w-1.5 h-1.5 ${a[i].dot} rounded-full animate-bounce`,style:{animationDelay:`0.2s`}}),t(`div`,{className:`w-1.5 h-1.5 ${a[i].dot} rounded-full animate-bounce`,style:{animationDelay:`0.4s`}})]}),t(`div`,{className:`${a[i].text} font-medium text-xs`,children:e})]})}function Cd({className:e,color:r=`blue`,width:i=`md`,message:a}){let[o,s]=Y(15),[c,l]=Y(`increasing`),[u,d]=Y(.4),f=J(null),p=J(!0);return K(()=>{let e=f.current;if(!e)return;let t=new IntersectionObserver(([e])=>{p.current=e.isIntersecting},{threshold:0});return t.observe(e),()=>t.disconnect()},[]),K(()=>{let e,t=Date.now(),n=()=>{if(!p.current){e=requestAnimationFrame(n);return}let r=Date.now(),i=r-t;t=r,s(e=>{let t=i/16*u,n=c===`increasing`?e+t:e-t;return n>=85?(l(`decreasing`),d(.3+Math.random()*.2),85):n<=15?(l(`increasing`),d(.3+Math.random()*.2),15):(Math.random()>.99&&d(e=>Math.max(.2,Math.min(.5,e+(Math.random()*.1-.05)))),n)}),e=requestAnimationFrame(n)};return e=requestAnimationFrame(n),()=>{cancelAnimationFrame(e)}},[c,u]),n(`div`,{ref:f,className:H(`flex flex-col gap-1`,e),children:[a&&t(`div`,{className:`text-xs font-medium ${{blue:`text-blue-700 dark:text-blue-300`,purple:`text-purple-700 dark:text-purple-300`,teal:`text-teal-700 dark:text-teal-300`,green:`text-green-700 dark:text-green-300`,amber:`text-amber-700 dark:text-amber-300`}[r]} mb-1`,children:a}),t(`div`,{className:H(`h-1.5 rounded-full overflow-hidden shadow-inner`,{blue:`bg-blue-200 dark:bg-blue-900/30`,purple:`bg-purple-200 dark:bg-purple-900/30`,teal:`bg-teal-200 dark:bg-teal-900/30`,green:`bg-green-200 dark:bg-green-900/30`,amber:`bg-amber-200 dark:bg-amber-900/30`}[r],{sm:`w-24`,md:`w-32`,lg:`w-48`,xl:`w-64`,full:`w-full`}[i]),children:t(`div`,{className:H(`h-full rounded-full`,{blue:`bg-gradient-to-r from-blue-400 to-blue-500 dark:from-blue-500 dark:to-blue-400`,purple:`bg-gradient-to-r from-purple-400 to-purple-500 dark:from-purple-500 dark:to-purple-400`,teal:`bg-gradient-to-r from-teal-400 to-teal-500 dark:from-teal-500 dark:to-teal-400`,green:`bg-gradient-to-r from-green-400 to-green-500 dark:from-green-500 dark:to-green-400`,amber:`bg-gradient-to-r from-amber-400 to-amber-500 dark:from-amber-500 dark:to-amber-400`}[r]),style:{width:`${o}%`,transition:`width 150ms cubic-bezier(0.4, 0.0, 0.2, 1)`}})})]})}function wd({className:e,color:n=`blue`,size:r=`md`}){let[i,a]=Y(Array(7).fill(50)),o=J(null),s=J(!0);K(()=>{let e=o.current;if(!e)return;let t=new IntersectionObserver(([e])=>{s.current=e.isIntersecting},{threshold:0});return t.observe(e),()=>t.disconnect()},[]);let c={sm:{width:`w-16`,height:`h-4`,barWidth:`w-0.5`,gap:`gap-[2px]`},md:{width:`w-20`,height:`h-5`,barWidth:`w-1`,gap:`gap-[3px]`},lg:{width:`w-24`,height:`h-6`,barWidth:`w-1.5`,gap:`gap-1`}},l={blue:`bg-gradient-to-b from-blue-400 to-blue-500 dark:from-blue-400 dark:to-blue-500`,purple:`bg-gradient-to-b from-purple-400 to-purple-500 dark:from-purple-400 dark:to-purple-500`,teal:`bg-gradient-to-b from-teal-400 to-teal-500 dark:from-teal-400 dark:to-teal-500`,green:`bg-gradient-to-b from-green-400 to-green-500 dark:from-green-400 dark:to-green-500`,amber:`bg-gradient-to-b from-amber-400 to-amber-500 dark:from-amber-400 dark:to-amber-500`};return K(()=>{let e,t=[1.2,1,1.5,.8,1.3,.9,1.1],n=[0,.5,1,1.5,2,2.5,3],r=0,i=()=>{if(!s.current){e=requestAnimationFrame(i);return}r+=.02;let o=Array(7).fill(0).map((e,i)=>10+(Math.sin(r*t[i]+n[i])+1)*40);a(o),e=requestAnimationFrame(i)};return e=requestAnimationFrame(i),()=>{cancelAnimationFrame(e)}},[]),t(`div`,{ref:o,className:H(`flex items-end justify-center`,c[r].width,c[r].height,c[r].gap,e),children:i.map((e,i)=>t(`div`,{className:H(c[r].barWidth,`rounded-full transform-gpu`,l[n]),style:{height:`${e}%`,transition:`height 100ms cubic-bezier(0.4, 0.0, 0.2, 1)`,opacity:.9}},`bar-${i}`))})}const Td=[`agent-markdown vprose prose max-w-none break-words text-sm leading-6 text-foreground/80`,`prose-p:my-2 prose-p:leading-6 prose-li:my-0.5 prose-pre:my-3 prose-headings:tracking-normal`,`prose-headings:text-foreground prose-strong:text-foreground prose-code:text-foreground`,`prose-a:text-foreground prose-a:underline prose-a:decoration-muted prose-a:underline-offset-4`,`[&_p]:text-foreground/80 [&_li]:text-foreground/80 [&_li::marker]:text-muted`].join(` `);function Ed({children:e,artifactRunId:r,components:i,disableCollapse:a,className:o,"data-testid":s}){let{t:c}=X(),l=e.trim(),[u,d]=Y(!1),f=l?l.split(/\r?\n/).length:0,p=l.length>520||f>6,m=p&&!a&&!u;return n(`div`,{className:H(`min-w-0`,o),children:[t(`div`,{"data-testid":s,className:H(Td,m&&`[display:-webkit-box] overflow-hidden [-webkit-box-orient:vertical] [-webkit-line-clamp:6]`),style:{overflowWrap:`anywhere`},children:t(bt,{artifactRunId:r,components:i,children:e})}),p&&!a?t(`div`,{className:`mt-1.5 flex justify-end`,children:n(`button`,{type:`button`,"aria-expanded":u,className:H(`inline-flex items-center gap-1 text-sm font-medium text-muted transition-colors`,`[text-decoration:none] hover:text-foreground hover:[text-decoration:none]`,`focus-visible:text-foreground focus-visible:[text-decoration:none]`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`),onClick:()=>d(e=>!e),children:[c(u?`agent.showLess`:`agent.showMore`),t(an,{className:H(`size-4 transition-transform`,u&&`rotate-180`),"aria-hidden":`true`})]})}):null]})}const Dd=new Set([`heading`,`paragraph`,`list`,`list_item`,`blockquote`,`code_block`,`table`,`separator`]);function Od(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:void 0}function kd(e,t){let n=e?.[t];return typeof n==`string`&&n.length>0?n:void 0}function Ad(e){let t=Od(e),n=kd(t,`kind`);if(n===`store_document`){let e=kd(t,`document_id`);if(!e)return;let r=kd(t,`name`);return{kind:n,document_id:e,...r?{name:r}:{}}}if(n===`agent_artifact`){let e=kd(t,`run_id`),r=kd(t,`path`);return e&&r?{kind:n,run_id:e,path:r}:void 0}}function jd(e){let t=Od(e),n=Od(t?.anchor),r=kd(t,`operation_id`),i=kd(t,`action`),a=kd(n,`block_id`),o=kd(n,`block_type`),s=kd(n,`exact_text`),c=Ad(t?.resource);if(!r||i!==`comment`&&i!==`edit`||!a||!o||!Dd.has(o)||!s||!c)return;let l=kd(t,`base_version`),u=kd(t,`comment`),d=Od(t?.user_change),f=kd(d,`before`),p=kd(d,`after`);if(i===`comment`&&!u||i===`edit`&&(!f||!p))return;let m=kd(t,`updated_document_id`);return{operation_id:r,resource:c,...l?{base_version:l}:{},action:i,anchor:{block_id:a,block_type:o,exact_text:s},...u?{comment:u}:{},...f&&p?{user_change:{before:f,after:p}}:{},...t?.applied===!0?{applied:!0}:{},...m?{updated_document_id:m}:{}}}function Md(e){return e.length>12?`${e.slice(0,4)}…${e.slice(-4)}`:e}function Nd(e){return e.kind===`store_document`?e.name||Md(e.document_id):e.path}const Pd=[`[&_h1]:text-base [&_h2]:text-base [&_h3]:text-base [&_h4]:text-base [&_h5]:text-base [&_h6]:text-base`,`[&_h1]:leading-snug [&_h2]:leading-snug [&_h3]:leading-snug`,`[&_:first-child]:mt-0 [&_:last-child]:mb-0`].join(` `);function Fd({children:e,className:n}){return t(`pre`,{className:H(`m-0 max-h-48 overflow-auto whitespace-pre-wrap font-mono text-xs leading-5 text-foreground/80`,n),children:e})}function Id({before:e,after:n}){return t(Fd,{children:q(()=>Ot(e,n),[e,n]).map((e,n)=>e.type===`removed`?t(`del`,{className:`rounded-xs bg-mixer-destructive/15 text-destructive line-through decoration-destructive/50`,children:e.text},n):e.type===`added`?t(`ins`,{className:`rounded-xs bg-mixer-success/15 text-success no-underline`,children:e.text},n):t(`span`,{children:e.text},n))})}function Ld({action:r}){let{t:i}=X(),a=r.action===`comment`,o=r.applied===!0,s=r.anchor.block_type.replaceAll(`_`,` `),c=a?mr:Er,l=r.resource.kind===`agent_artifact`?r.resource.run_id:void 0;return n(`div`,{className:`min-w-0 space-y-2 text-start`,"data-document-edit-action":r.action,children:[n(`div`,{className:`flex min-w-0 items-center gap-1.5 text-sm text-muted`,children:[t(c,{className:`size-4 shrink-0`,"aria-hidden":`true`}),t(`span`,{className:`shrink-0 font-medium text-foreground`,children:i(a?`agent.documentEditCardComment`:o?`agent.documentEditCardApplied`:`agent.documentEditCardDirectEdit`)}),t(`span`,{"aria-hidden":`true`,children:`·`}),t(`span`,{className:`shrink-0 capitalize`,children:s}),t(`span`,{"aria-hidden":`true`,children:`·`}),t(`span`,{className:`truncate`,children:Nd(r.resource)})]}),a?n(e,{children:[r.comment?t(Ed,{artifactRunId:l,disableCollapse:!0,className:Pd,children:r.comment}):null,t(Ed,{artifactRunId:l,disableCollapse:!0,className:H(`border-s-2 border-mixer-muted/30 ps-3 text-foreground/70`,Pd),children:r.anchor.exact_text})]}):t(Id,{before:r.user_change?.before??r.anchor.exact_text,after:r.user_change?.after??``})]})}const Rd=`Brewing some code magic...(Doing the robot dance...(Cooking up something good...(Working my gears...(Parsing the possibilities...(Crunching the numbers...(Connecting the digital dots...(Processing at maximum capacity...(Searching through my circuits...(Running advanced algorithms...(Computing optimal solutions...(Loading brilliance.exe...(Scanning the knowledge base...(Optimizing response protocols...(Having a quick brainstorm...(Thinking cap firmly on...(Pondering the digital universe...(Consulting my silicon wisdom...(Untangling the logic knots...(Assembling clever responses...(Mixing thoughtful ingredients...(Polishing the perfect answer...(Taking a momentary mind sprint...(Connecting virtual synapses...(Baking fresh ideas...(Stirring the thought pot...(Simmering solutions slowly...(Whipping up a smart response...(Adding a dash of intelligence...(Preparing a gourmet answer...(Growing brilliant ideas...(Cultivating the perfect response...(Gathering digital nectar...(Planting seeds of solutions...(Exploring the data landscape...(Mapping the solution path...(Navigating through possibilities...(Charting the course to answers...(Embarking on a thought expedition...(Sketching out concepts...(Painting with digital brushstrokes...(Composing my response symphony...(Crafting precision answers...(Weaving threads of information...(Just a moment of processing...(Taking a quick thinking break...(Almost there, final touches...(Putting the pieces together...(Making progress, hold tight...`.split(`(`);function zd(e,t){if(e.startsWith(t))return e.slice(t.length).split(/[/?#]/,1)[0]||void 0}function Bd(e={}){let{StoreLinkComponent:n,CollectionLinkComponent:r,addStickyParams:i}=e;return function({node:e,ref:a,...o}){let s=o.href||``,c=s.startsWith(`/`)&&!s.startsWith(`//`),l=c&&i?i(s):s,u=c?zd(s,`/store/objects/`):void 0;if(u&&n)return t(n,{href:l,documentId:u,className:o.className,children:o.children});let d=c?zd(s,`/store/collections/`):void 0;return d&&r?t(r,{href:l,collectionId:d,className:o.className,children:o.children}):c?t(ga,{href:l,className:o.className,topLevelNav:!0,children:o.children}):t(`a`,{...o,target:`_blank`,rel:`noopener noreferrer`})}}const Vd=nt(null);function Hd(){return at(Vd)||{openImage:e=>window.open(e,`_blank`),closeImage:()=>{}}}function Ud({children:e}){let[r,i]=Y(null),a=G((e,t)=>{i({src:e,alt:t})},[]),s=G(()=>{i(null)},[]),{t:c}=X();return n(Vd.Provider,{value:{openImage:a,closeImage:s},children:[e,r&&t(`div`,{role:`button`,tabIndex:-1,"aria-label":c(`agent.close`),className:`fixed inset-0 z-[100] flex items-center justify-center bg-black/80 backdrop-blur-sm`,onClick:s,onKeyDown:Ve(s),children:n(`div`,{className:`relative max-w-[90vw] max-h-[90vh]`,children:[t(`img`,{src:r.src,alt:r.alt||c(`agent.enlargedView`),className:`max-w-full max-h-[90vh] object-contain rounded-lg shadow-2xl`}),t(o,{variant:`unstyled`,className:`absolute top-2 end-2 text-white bg-black/50 rounded-full p-2 hover:bg-black/70 transition-colors`,onClick:s,title:c(`agent.close`),children:t(ci,{className:`size-6`})}),t(`a`,{href:r.src,target:`_blank`,rel:`noopener noreferrer`,className:`absolute bottom-2 end-2 text-white bg-black/50 rounded-full p-2 hover:bg-black/70 transition-colors`,onClick:e=>e.stopPropagation(),title:c(`agent.openInNewTab`),children:t(kn,{className:`size-5`})})]})})]})}const Wd=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`svg`]),Gd=new Set([`css`,`csv`,`html`,`js`,`json`,`jsx`,`log`,`md`,`mjs`,`sql`,`ts`,`tsx`,`txt`,`xml`,`yaml`,`yml`]);function Kd(e){let t=e?.split(/[?#]/)[0]??``;return t.includes(`.`)?(t.split(`.`).pop()??``).toLowerCase():``}function qd(e){return e.contentType?.toLowerCase().startsWith(`image/`)?!0:Wd.has(Kd(e.artifactPath||e.href||e.name))}function Jd(e){let t=e.contentType?.toLowerCase()??``;return t.startsWith(`text/`)||t===`application/json`||t.includes(`xml`)?!0:Gd.has(Kd(e.artifactPath||e.href||e.name))}function Yd(e){if(e.artifactPath)return e.artifactPath;if(e.href?.startsWith(`artifact:`))return e.href.slice(9)}function Xd(e){let t=e.split(`/store/objects/`)[1];return t?t.split(/[?#]/)[0]:e.replace(/^store:/,``).replace(/^document:(?:\/\/)?/,``).split(/[?#]/)[0]}function Zd(e){return e.split(`/store/collections/`)[1]||e.replace(/^collection:/,``)}function Qd(e){return!!(e?.includes(`/store/objects/`)||e?.startsWith(`store:`)||e?.startsWith(`document:`))}function $d(e){return!!(e?.includes(`/store/collections/`)||e?.startsWith(`collection:`))}function ef({item:n,children:r,onOpenArtifact:i,StoreLinkComponent:a,CollectionLinkComponent:o}){let s=n.href;if(!s)return t(e,{children:r});let c=Yd(n);if(c&&/\.md$/i.test(c)&&i)return t(`button`,{type:`button`,className:`max-w-full text-start`,onClick:()=>i(c),children:r});if(Qd(s)){let e=Xd(s);return a?t(a,{href:s,documentId:e,children:r}):t(`a`,{href:s.startsWith(`store:`)||s.startsWith(`document:`)?`/store/objects/${e}`:s,children:r})}if($d(s)){let e=Zd(s);return o?t(o,{href:s,collectionId:e,children:r}):t(`a`,{href:s.startsWith(`collection:`)?`/store/collections/${e}`:s,children:r})}return/^https?:\/\//.test(s)||s.startsWith(`/`)?t(`a`,{href:s,target:s.startsWith(`/`)?void 0:`_blank`,rel:`noopener noreferrer`,children:r}):t(e,{children:r})}function tf({item:e,artifactRunId:r,variant:i,onRemove:a,onOpenArtifact:s,StoreLinkComponent:c,CollectionLinkComponent:l}){let{t:u}=X(),d=at(pi),f=Za(),{openImage:p}=Hd(),m=Yd(e),h=qd(e),g=h&&!Jd(e),[_,v]=Y(e.previewUrl);K(()=>{v(e.previewUrl)},[e.previewUrl]),K(()=>{if(!g||e.previewUrl||!r||!m||!d?.client)return;let t=!1,n=$a(r,m,`inline`);return(async()=>{let e=f?await f.getOrFetch(n,async()=>(await d.client.files.getArtifactDownloadUrl(r,m,`inline`)).url):(await d.client.files.getArtifactDownloadUrl(r,m,`inline`)).url;t||v(e)})().catch(()=>{t||v(void 0)}),()=>{t=!0}},[m,r,e.previewUrl,d?.client,g,f]);let y={attention:`bg-attention/15 text-attention`,destructive:`bg-destructive/15 text-destructive`,info:`bg-info/15 text-info`,muted:`bg-muted text-muted`,success:`bg-success/15 text-success`}[e.statusTone??`muted`],b=!!(a&&e.removable!==!1),x=t=>{t.stopPropagation(),t.preventDefault(),a?.(e.id)},S=b?t(o,{variant:`unstyled`,size:`none`,"aria-label":u(`agent.removeFile`,{name:e.name}),onClick:x,className:H(`absolute -end-1.5 -top-1.5 inline-flex size-5 items-center justify-center rounded-full`,`border border-border bg-background text-muted shadow-sm transition-colors hover:text-foreground`),children:t(di,{className:`size-3`,"aria-hidden":`true`})}):null,C=b?t(o,{variant:`unstyled`,size:`none`,"aria-label":u(`agent.removeFile`,{name:e.name}),onClick:x,className:H(`-me-1 inline-flex size-6 shrink-0 items-center justify-center rounded-md text-muted`,`transition-colors hover:bg-mixer-muted/30 hover:text-foreground`),children:t(di,{className:`size-3.5`,"aria-hidden":`true`})}):null,w=n(`span`,{className:`inline-flex min-w-0 max-w-full items-center gap-1.5`,children:[g&&_?t(o,{type:`button`,variant:`unstyled`,size:`none`,onClick:t=>{t.stopPropagation(),t.preventDefault(),p(_,e.name)},"aria-label":e.name,title:u(`agent.enlargedView`),className:H(`group shrink-0 overflow-hidden rounded border border-border/60 p-0`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,i===`composer`?`size-6`:`size-24`),children:t(`img`,{src:_,alt:e.name,className:`h-full w-full object-cover transition-transform group-hover:scale-[1.05]`})}):t(h?Zn:Rn,{className:`size-3.5 shrink-0 text-muted`,"aria-hidden":`true`}),t(`span`,{className:H(`truncate`,i===`composer`?`max-w-[14rem]`:`max-w-[16rem]`),children:e.name}),e.statusLabel?t(`span`,{className:H(`shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium`,y),children:e.statusLabel}):null]});return i===`composer`?n(`span`,{title:e.name,className:H(`inline-flex min-h-8 max-w-full items-center gap-1 rounded-xl border border-border/60`,`bg-mixer-muted/15 px-2.5 py-1 text-sm text-foreground/80 transition-colors`,e.href&&`hover:bg-mixer-muted/25`),children:[t(ef,{item:e,StoreLinkComponent:c,CollectionLinkComponent:l,children:w}),C]}):n(`span`,{className:`relative inline-flex max-w-full`,children:[t(ef,{item:e,onOpenArtifact:s,StoreLinkComponent:c,CollectionLinkComponent:l,children:t(`span`,{title:e.name,className:H(`inline-flex max-w-full items-center gap-1.5 rounded-md border border-border/60 bg-mixer-muted/15`,`px-2.5 py-1.5 text-xs text-foreground/80 transition-colors`,e.href&&`hover:bg-mixer-muted/25`),children:w})}),S]})}function nf({items:e,artifactRunId:r,className:i,align:a=`start`,variant:s=`message`,onRemove:c,onOpenArtifact:l,StoreLinkComponent:u,CollectionLinkComponent:d}){let{t:f}=X(),[p,m]=Y(!1),h=ot(),g=s===`composer`&&e.length>3,_=g&&!p?e.slice(0,3):e,v=e.length-3;return K(()=>{e.length<=3&&m(!1)},[e.length]),e.length===0?null:n(`div`,{id:h,className:H(`flex flex-wrap gap-2`,a===`end`&&`justify-end`,i),children:[_.map(e=>t(tf,{item:e,artifactRunId:r,variant:s,onRemove:c,onOpenArtifact:l,StoreLinkComponent:u,CollectionLinkComponent:d},e.id)),g&&n(o,{type:`button`,variant:`ghost`,size:`sm`,"aria-controls":h,"aria-expanded":p,onClick:()=>m(e=>!e),className:`h-8 shrink-0 gap-1 rounded-xl px-2.5 text-xs text-muted`,children:[!p&&n(`span`,{children:[`+`,v]}),f(p?`agent.showLess`:`agent.showMore`),t(an,{className:H(`size-3.5 transition-transform`,p&&`rotate-180`),"aria-hidden":`true`})]})]})}const rf=/^\s*(?:\*\*)?(attachments|uploaded artifacts):(?:\*\*)?\s*$/i,af=/^\s*(?:[-*]\s*)?\[([^\]]+)]\(([^)]+)\)(?:\s+\((.*)\))?\s*$/;function of(e){let t=e.split(/\r?\n/),n=[],r=[],i=!1;for(let e of t){let t=e.trim();if(rf.test(t)){i=!0;continue}if(!i){n.push(e);continue}if(!t)continue;let a=af.exec(t);if(!a){i=!1,n.push(e);continue}let[,o,s,c]=a,l=s.startsWith(`artifact:`)?s.slice(9):void 0;r.push({id:`${s}-${r.length}`,name:o,href:s,artifactPath:l,contentType:c?.toLowerCase().includes(`image`)?`image/*`:void 0})}return{body:n.join(`
|
|
14
|
-
`).trim(),attachments:r}}function
|
|
15
|
-
`&&e!==`\r`}function
|
|
10
|
+
${O||``}`,children:n(`div`,{className:`flex items-start gap-3`,children:[e.icon&&t(`span`,{className:`flex-shrink-0 mt-0.5 text-gray-500 dark:text-gray-400`,children:e.icon}),n(`div`,{className:`flex-1 overflow-hidden`,children:[t(`div`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100 break-words text-center`,children:e.label}),e.description&&t(`div`,{className:`mt-1 text-sm text-gray-500 dark:text-gray-400 break-words whitespace-pre-wrap`,children:e.description})]})]})},e.id))})}),u&&t(`div`,{className:`px-4 pb-3 pt-1 ${k||``}`,children:n(`div`,{className:`flex gap-2`,children:[t(`input`,{ref:R,type:`text`,value:F,onChange:e=>I(e.target.value),onKeyDown:oe,placeholder:N,disabled:m,className:`flex-1 px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 focus:ring-2 focus:ring-blue-500 focus:border-transparent ${A||``}`}),t(o,{size:`sm`,onClick:ae,disabled:m||!F.trim(),className:j,children:m?`...`:P})]})})]})})}function fl({question:e,description:n,onConfirm:r,onCancel:i,confirmLabel:a,cancelLabel:o,isLoading:s=!1,variant:c=`default`,className:l}){let{t:u}=Z(),d=a??u(`agent.yes`),f=o??u(`agent.no`);return t(dl,{question:e,description:n,variant:c,isLoading:s,className:l,options:[{id:`confirm`,label:d,icon:t(on,{className:`size-4`})},{id:`cancel`,label:f,icon:t(hi,{className:`size-4`})}],onSelect:e=>{e===`confirm`?r():i()}})}function pl(e){let t=e.replace(/^workstream[:_-]?/i,``).replace(/^sys:/i,``).replace(/[-_:]?[0-9a-f]{8}-[0-9a-f-]{12,}$/i,``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1 $2`).replace(/[:_-]+/g,` `).trim();return t?t.split(/\s+/).map(e=>{let t=e.toLowerCase();return t===`qa`?`QA`:t===`ui`?`UI`:t===`api`?`API`:t===`url`?`URL`:t.charAt(0).toUpperCase()+t.slice(1)}).join(` `):e}function ml(e){return/[0-9a-f]{8}-[0-9a-f-]{12,}/i.test(e)}function hl(e,t){let n=t?pl(t):``,r=pl(e);if(!n)return r;if(ml(e))return n;let i=n.toLowerCase().replace(/\s+/g,``);return r.toLowerCase().replace(/\s+/g,``).startsWith(i)?n:r}function gl(e){return e.message?typeof e.message==`object`?JSON.stringify(e.message,null,2):String(e.message).trim():``}function _l(e){if(typeof e!=`string`)return!1;let t=e.trim().toLowerCase();return!!(t&&t!==`main`&&t!==`all`)}function vl(e){let t=e.trim();if(!t||!/^[{[]/.test(t))return!1;try{return JSON.parse(t),!0}catch{return!1}}function yl(e,t){return _l(t)&&vl(e)}function bl(e){return!yl(gl(e),e.workstream_id)||e.type!==$.ANSWER&&e.type!==$.COMPLETE?!1:e.details?.event_class===`user_content`||e.details?.streamed===!0}function xl(e){switch(e){case`running`:return`bg-info`;case`canceling`:return`bg-attention`;case`completed`:return`bg-success`;case`canceled`:case`failed`:case`timeout`:return`bg-destructive`}}function Sl(e){let t=e.details,n=t?.status;if(n===`running`||n===`canceling`||n===`completed`||n===`canceled`||n===`failed`||n===`timeout`)return n;if(t?.workstream_event===`completed`)return`completed`}function Cl(e){let t=e.details;if(t?.workstream_event!==`launched`)return null;let n=typeof t.workstream_id==`string`?t.workstream_id:typeof e.workstream_id==`string`?e.workstream_id:``;return!n||n===`main`||n===`all`?null:{workstreamId:n,launchId:typeof t.launch_id==`string`?t.launch_id:void 0,kind:typeof t.kind==`string`?t.kind:void 0,interaction:typeof t.interaction==`string`?t.interaction:void 0,childWorkflowId:typeof t.child_workflow_id==`string`?t.child_workflow_id:void 0,childWorkflowRunId:typeof t.child_workflow_run_id==`string`?t.child_workflow_run_id:void 0}}function wl(e){let t=e.details;if(t?.event_class!==`activity`||t.workstream_event!==void 0||e.type===$.ERROR)return null;let n=typeof t.child_workflow_id==`string`?t.child_workflow_id:void 0,r=typeof t.child_workflow_run_id==`string`?t.child_workflow_run_id:void 0;if(!n&&!r)return null;let i=typeof t.workstream_id==`string`&&t.workstream_id.trim()?t.workstream_id:typeof e.workstream_id==`string`?e.workstream_id:``;return _l(i)?{workstreamId:i,launchId:typeof t.launch_id==`string`?t.launch_id:void 0,kind:typeof t.kind==`string`?t.kind:void 0,interaction:typeof t.interaction==`string`?t.interaction:void 0,childWorkflowId:n,childWorkflowRunId:r}:null}function Tl(e){let t=e.indexOf(`?`);return t===-1?null:new URLSearchParams(e.slice(t+1)).get(`agentChatDebug`)}function El(){if(typeof window>`u`)return!1;let e=new URLSearchParams(window.location.search).get(`agentChatDebug`),t=Tl(window.location.hash),n=e??t;if(n!==null)return n===`1`||n===`true`;try{let e=window.localStorage.getItem(`agentChatDebug`);return e===`1`||e===`true`}catch{return!1}}function Dl(e,t){El()&&console.debug(`[agent-chat] ${e}`,t??{})}function Ol(e,t){let n=typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime(),r=e.findIndex(e=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())>n);r===-1?e.push(t):e.splice(r,0,t)}const kl=[$.COMPLETE,$.IDLE,$.REQUEST_INPUT,$.TERMINATED];function Al(e){return e.type===$.UPDATE&&e.details?.event_class===`artifact_updated`}function jl(e){if(!e.length)return!0;let t=e=>e.details?._optimistic&&e.details?._deliveryStatus===`failed`&&kl.includes(e.type),n=e.filter(e=>!t(e)&&!Al(e)),r=n.filter(e=>Pl(e)===`main`);if(r.length===0){let e=n[n.length-1];return!e||!kl.includes(e.type)}let i=r[r.length-1];return!kl.includes(i.type)}function Ml(e){if(e.type!==$.IDLE)return!1;let t=e.details?.status_reason,n=e.details?.display_role;return t===`user_stopped`||n===`user_stopped`||String(e.message??``).trim().toLowerCase().startsWith(`stopped.`)}function Nl(e){return typeof e==`number`?e:new Date(e).getTime()}function Pl(e){return e.workstream_id?e.workstream_id:`main`}function Fl(e){let t=e.details;return!t||typeof t!=`object`||Array.isArray(t)?{}:t}function Il(e){if(Pl(e)===`main`||Cl(e)||wl(e))return!0;let t=Fl(e),n=typeof t.child_workflow_id==`string`||typeof t.child_workflow_run_id==`string`,r=typeof t.tool==`string`||typeof t.tool_run_id==`string`;return t.event_class===`activity`&&(e.type===$.ERROR||e.type===$.WARNING)&&!n&&!r}function Ll(e,t){return t===`all`?e.filter(Il):e.filter(e=>(Cl(e)??wl(e))?.workstreamId!==t&&Pl(e)===t)}async function Rl(e,t){return e.agents.getArtifactUrl(t,`conversation.json`).then(e=>e.url)}function zl(e,t){if(!t)return!0;let n=e.workstreamId||`main`;return t===`all`?n===`main`:t===n}function Bl(e){if(typeof e==`string`)return e.replace(/\r\n/g,`
|
|
11
|
+
`).trim()||void 0}function Vl(e){return Bl(e.message)}function Hl(e,t){let n=Bl(e.text);if(!n)return!1;let r=e.workstreamId||`main`;return t.some(t=>{if(Nl(t.timestamp)<e.startTimestamp||Pl(t)!==r)return!1;let i=typeof t.details?.streaming_id==`string`?t.details.streaming_id:void 0;return e.streamingId&&i?i===e.streamingId?t.details?.display_role===`thinking`?Vl(t)===n:!(Wl(t)||t.details?.tool_status):!1:e.activityId&&t.details?.activity_id===e.activityId?t.details?.display_role===`thinking`?Vl(t)===n:!(Wl(t)||t.details?.tool_status):t.type!==$.THOUGHT&&t.type!==$.ANSWER&&t.type!==$.COMPLETE&&t.type!==$.IDLE?!1:Vl(t)===n})}function Ul(e,t){if(Pl(e)!==Pl(t))return!1;let n=Vl(e),r=Vl(t);if(!n||n!==r)return!1;let i=Nl(e.timestamp);return Nl(t.timestamp)-i>1e4?!1:!!(e.type===$.ANSWER&&(t.type===$.COMPLETE||t.type===$.IDLE)||e.type===$.THOUGHT&&(t.type===$.ANSWER||t.type===$.COMPLETE||t.type===$.IDLE)&&(e.details?.streamed||t.details?.streamed)||e.type===t.type&&(e.details?.streamed||t.details?.streamed)&&(t.type===$.THOUGHT||t.type===$.ANSWER||t.type===$.COMPLETE||t.type===$.IDLE))}function Wl(e){return e.type===$.THOUGHT&&!!e.details?.tool}function Gl(e){let t=e.details;return e.type===$.THOUGHT&&(t?.display_role===`tool_preamble`||t?.tool===`think`)}function Kl(e){if(Gl(e))return!1;if(Wl(e))return!0;if(e.type!==$.THOUGHT)return!1;let t=e.details;return!!(Array.isArray(t?.tools)&&t.tools.length>0)}function ql(e){return e.details?.tool_run_id}function Jl(e){return e.details?.tool_iteration}function Yl(e){return e.details?.tool_status}function Xl(e){let t=e.details?.activity_group_id;if(typeof t==`string`&&t.trim()!==``)return t}function Zl(e,t,n){let r=new Map,i=new Map,a=new Map,o=[];for(let t of e){let e=Xl(t);if(t.type===$.REQUEST_INPUT||t.type===$.BATCH_PROGRESS)o.push(t);else if(Gl(t))o.push(t);else if(e)r.has(e)||r.set(e,{messages:[],firstTimestamp:Nl(t.timestamp)}),r.get(e)?.messages.push(t);else if(Kl(t)){let e=Jl(t),n=ql(t);e===void 0?n?(a.has(n)||a.set(n,{messages:[],firstTimestamp:Nl(t.timestamp)}),a.get(n)?.messages.push(t)):o.push(t):(i.has(e)||i.set(e,{messages:[],firstTimestamp:Nl(t.timestamp)}),i.get(e)?.messages.push(t))}else o.push(t)}let s=[];r.forEach((e,t)=>{s.push({kind:`activity_group`,activityGroupId:t,messages:e.messages,timestamp:e.firstTimestamp})}),i.forEach((e,t)=>{s.push({kind:`iteration_group`,iteration:t,messages:e.messages,timestamp:e.firstTimestamp})}),a.forEach((e,t)=>{s.push({kind:`tool_run`,toolRunId:t,messages:e.messages,timestamp:e.firstTimestamp})});for(let e of o)s.push({kind:`message`,message:e,timestamp:Nl(e.timestamp)});t.forEach((t,r)=>{t.text&&(Hl(t,e)||zl(t,n)&&s.push({kind:`streaming`,streamingId:r,data:t,timestamp:t.startTimestamp}))}),s.sort((e,t)=>{let n=e.kind===`streaming`&&!e.data.isComplete,r=t.kind===`streaming`&&!t.data.isComplete;return n&&!r?1:r&&!n?-1:e.timestamp-t.timestamp});let c=[],l=[],u=()=>{l.length>0&&(l.length===1&&!Gl(l[0])?c.push({type:`single`,message:l[0]}):c.push({type:`tool_group`,messages:l,firstTimestamp:Nl(l[0].timestamp)}),l=[])};for(let e of s)if(e.kind===`streaming`)u(),c.push({type:`streaming`,streamingId:e.streamingId,text:e.data.text,workstreamId:e.data.workstreamId,startTimestamp:e.data.startTimestamp,isComplete:e.data.isComplete});else if(e.kind===`activity_group`){u();let t=[...e.messages].sort((e,t)=>Nl(e.timestamp)-Nl(t.timestamp)),n=t.reduce((e,t)=>Yl(t)||e,void 0);c.push({type:`tool_group`,messages:t,firstTimestamp:e.timestamp,toolRunId:e.activityGroupId,toolStatus:n})}else if(e.kind===`iteration_group`){u();let t=[...e.messages].sort((e,t)=>Nl(e.timestamp)-Nl(t.timestamp)),n=t.reduce((e,t)=>Yl(t)||e,void 0);c.push({type:`tool_group`,messages:t,firstTimestamp:e.timestamp,toolStatus:n})}else if(e.kind===`tool_run`){u();let t=[...e.messages].sort((e,t)=>Nl(e.timestamp)-Nl(t.timestamp)),n=t.reduce((e,t)=>Yl(t)||e,void 0);c.push({type:`tool_group`,messages:t,firstTimestamp:e.timestamp,toolRunId:e.toolRunId,toolStatus:n})}else Kl(e.message)?l.push(e.message):(u(),c.push({type:`single`,message:e.message}));return u(),c}function Ql(e,t){return t??e}function $l(e){let t=[],n=null,r=()=>{n&&=(t.push({type:`tool_group`,messages:n.messages,firstTimestamp:n.firstTimestamp,toolRunId:n.toolRunId,toolStatus:n.toolStatus,preambleText:n.preambleText,preambleMessage:n.preambleMessage}),null)};for(let i of e)i.type===`tool_group`?n?(n.messages=[...n.messages,...i.messages],n.toolStatus=Ql(n.toolStatus,i.toolStatus),!n.toolRunId&&i.toolRunId&&(n.toolRunId=i.toolRunId),!n.preambleMessage&&i.preambleMessage&&(n.preambleMessage=i.preambleMessage,n.preambleText=i.preambleText)):n={messages:[...i.messages],firstTimestamp:i.firstTimestamp,toolRunId:i.toolRunId,toolStatus:i.toolStatus,preambleText:i.preambleText,preambleMessage:i.preambleMessage}:(r(),t.push(i));return r(),t}function eu(e){return e.message?typeof e.message==`object`?JSON.stringify(e.message,null,2):String(e.message).trim():``}function tu(e){let t=nu(e.details?.tool_approval);if(!t)return eu(e);let n=ru(t.tool_title)??ru(t.tool_name),r=au(ru(t.target));if(n&&r)return`Approve ${n}: ${r}?`;let i=ru(t.action_summary);return i?`Approve ${iu(i)}?`:eu(e)}function nu(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:void 0}function ru(e){return typeof e==`string`&&e.trim()?e.trim():void 0}function iu(e){return e.replace(/:\s*name(?::|\s+)/i,`: `)}function au(e){if(!e)return;let t=e.indexOf(`:`);if(t<0)return e;let n=e.slice(0,t),r=e.slice(t+1).trim();if(!r)return e;switch(n){case`document_id`:return`document ${r}`;case`object_id`:return`object ${r}`;case`collection_id`:return`collection ${r}`;case`process_id`:return`process ${r}`;case`process_definition_id`:return`process definition ${r}`;case`interaction_id`:return`interaction ${r}`;case`prompt_id`:return`prompt ${r}`;case`dashboard_id`:return`dashboard ${r}`;case`database_id`:return`database ${r}`;case`table_id`:return`table ${r}`;default:return r}}function ou(e){let t=e.details;return e.type===$.REQUEST_INPUT&&!!t?.ux}function su(e){let t=e.details;return[t?.request_id,t?.requestId,t?.activity_id,t?.activityId,t?.tool_run_id,t?.toolRunId,e.timestamp,eu(e)].filter(e=>typeof e==`string`||typeof e==`number`).map(String).join(`|`)}function cu(e){let t=e.details,n=t?.request_id??t?.tool_use_id;return typeof n==`string`&&n?n:void 0}function lu(e){return cu(e)??su(e)}function uu(e,t){return`vertesia:answered-request-input:${e}:${t}`}function du(e,t){if(!(typeof window>`u`))try{window.sessionStorage.setItem(uu(e,t),`1`)}catch{}}function fu(e,t){if(!(typeof window>`u`))try{window.sessionStorage.removeItem(uu(e,t))}catch{}}function pu(e,t){if(t.type!==$.REQUEST_INPUT)return!1;let n=cu(t);if(!n||typeof window>`u`)return!1;try{return window.sessionStorage.getItem(uu(e,n))===`1`}catch{return!1}}function mu(e){if(e.type!==$.QUESTION)return;let t=nu(e.details),n=nu(t?.metadata),r=(nu(t?.request_input_response)??nu(n?.request_input_response))?.request_id;return typeof r==`string`&&r?r:void 0}function hu(e){let t=e.details;return[t?.ack,t?._messageId,t?._deliveryStatus,e.timestamp,Pl(e),eu(e)].filter(e=>typeof e==`string`||typeof e==`number`).map(String).join(`|`)}function gu(e){let t=new Set,n=new Map;return e.forEach((e,t)=>{let r=mu(e);r&&n.set(r,t)}),e.forEach((r,i)=>{if(r.type!==$.REQUEST_INPUT)return;let a=cu(r),o=a?n.get(a):void 0;if(o!==void 0&&o>i){t.add(su(r));return}let s=Pl(r);for(let n=i+1;n<e.length;n+=1){let i=e[n];if(Pl(i)===s){if(i.type===$.REQUEST_INPUT)break;if(i.type===$.QUESTION){mu(i)||t.add(su(r));break}}}}),t}function _u(e,t){let n=cu(e);return n?{...t,request_input_response:{request_id:n}}:t}function vu(e,t,n,r){if(!e)return;let i=_u(t,r);i?e(n,i):e(n)}function yu(e){let t=nu(e?.request_input_response)?.request_id;return typeof t==`string`&&t?t:void 0}function bu(e){let t=new Set;for(let n of e){let e=nu(n.details),r=nu(e?.approval_request)?.approval_key,i=e?.approval_decision;typeof r==`string`&&(i===`denied`||i===`denied_with_feedback`||i===`timeout`||i===`reviewer_denied`||i===`cancelled_after_denial`)&&t.add(r)}return t}function xu(e){let t=nu(nu(e.details)?.tool_approval)?.approval_key;return typeof t==`string`?t:void 0}function Su(e){return e.type===$.REQUEST_INPUT&&xu(e)!==void 0}const Cu=new Set([`allow_once`,`allow_for_run`,`deny`]);function wu(e,t){let n=xu(e);if(!(!n||!Cu.has(t)))return{tool_approval_response:{decision:t,approval_key:n}}}function Tu(e){if(e.type!==$.QUESTION)return!1;let t=eu(e).trim().toLowerCase();return t===`allow_once`||t===`allow_for_run`||t===`deny`}function Eu(e){if(e.type!==$.QUESTION)return!1;let t=nu(e.details),n=nu(t?.metadata),r=(nu(t?.tool_approval_response)??nu(n?.tool_approval_response))?.decision;return r===`deny_with_feedback`||typeof r==`string`&&Cu.has(r)}function Du(e){return Tu(e)||Eu(e)}function Ou(e,t){if(e.type!==$.REQUEST_INPUT)return!1;let n=xu(e);return n?t.has(n):!1}function ku(e){let t=new Set;return e.forEach((n,r)=>{if(!Su(n))return;let i=Pl(n);for(let a=r+1;a<e.length;a+=1){let r=e[a];if(Pl(r)===i){if(r.type===$.REQUEST_INPUT)break;if(r.type===$.QUESTION){Du(r)&&t.add(su(n));break}}}}),t}function Au(e,t,n){return Su(e)&&(t.has(su(e))||Ou(e,n))}function ju(e,t){let n=new Set;return e.forEach((r,i)=>{if(!Su(r)||t&&!Ou(r,t))return;let a=Pl(r);for(let t=i+1;t<e.length;t+=1){let r=e[t];if(Pl(r)===a){if(r.type===$.REQUEST_INPUT)break;if(r.type===$.QUESTION){Tu(r)&&n.add(hu(r));break}}}}),n}function Mu(e,t){return e.type===$.QUESTION&&t.has(hu(e))}function Nu(e,t){return e.type===$.REQUEST_INPUT&&t.has(su(e))}function Pu(e,t=`main`,n){let r=gu(e),i=bu(e);for(let a=e.length-1;a>=0;--a){let o=e[a];if(ou(o)&&Pl(o)===t&&!n?.has(lu(o))&&!Nu(o,r)&&!Ou(o,i))return o}}function Fu({mcpConnect:e,onMcpConnected:r,onDecline:i,disabled:a}){let{client:s}=Q(),{t:c}=Z();return n(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[t(ys,{appId:e.app_install_id,collectionId:e.collection_id,collectionName:e.name,variant:`default`,onAuthChange:()=>{s.remoteMcpConnections.getCollectionStatus(e.app_install_id,e.collection_id).then(t=>{t.authenticated&&r?.(e)}).catch(()=>{})},readOnly:a}),n(o,{variant:`ghost`,size:`sm`,onClick:i,disabled:a,children:[t(_i,{className:`size-4`}),t(`span`,{children:c(`mcpOAuth.decline`)})]})]})}function Iu({message:e,onSendMessage:r,onMcpConnected:i,isLoading:a=!1,disabled:o=!1,className:s}){let{t:c}=Z();if(!e)return null;let l=e.details.ux,u=l.options??[],d=l.mcp_connect,f=l.free_response,p=o||a||!r,m=tu(e),h=(t,n)=>{p||vu(r,e,t,n)},g=H(`flex-shrink-0 border-t border-border/70 bg-background/95 backdrop-blur`,`fixed bottom-0 end-0 start-0 z-20 lg:sticky lg:start-auto lg:end-auto`,`pb-safe-area`,s);return d?t(`div`,{className:g,"data-agent-request-input-overlay":!0,children:n(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-3 px-3 py-3 sm:flex-row sm:items-center sm:justify-between`,children:[t(`div`,{className:`min-w-0 text-sm leading-6 text-foreground/85`,children:m}),t(Fu,{mcpConnect:d,onMcpConnected:t=>i?.(t,_u(e)),onDecline:()=>h(c(`agent.mcpDeclinedMessage`,{name:d.name})),disabled:p})]})}):t(`div`,{className:g,"data-agent-request-input-overlay":!0,children:t(`div`,{className:`mx-auto w-full max-w-3xl px-3 py-3`,children:t(dl,{question:m,options:u,variant:l.variant,multiSelect:l.multiSelect,allowFreeResponse:u.length===0||!!f,placeholder:f?.placeholder,submitLabel:f?.submit_label,onSelect:t=>h(t,wu(e,t)),onMultiSelect:e=>h(e.join(`, `)),onSubmit:e=>h(e,f?.metadata),hideBorder:!0,compact:!0,isLoading:p,className:`my-0`,cardClassName:`bg-background/80 shadow-lg shadow-black/5 dark:shadow-none`})})})}function Lu({className:e,inline:r=!1,color:i=`blue`}){let a={blue:`from-blue-400 to-indigo-500 dark:from-blue-500 dark:to-indigo-400`,purple:`from-purple-400 to-violet-500 dark:from-purple-500 dark:to-violet-400`,teal:`from-teal-400 to-emerald-500 dark:from-teal-500 dark:to-emerald-400`,green:`from-green-400 to-emerald-500 dark:from-green-500 dark:to-emerald-400`,amber:`from-amber-400 to-orange-500 dark:from-amber-500 dark:to-orange-400`}[i];return n(`div`,{className:H(`flex items-center gap-1.5`,r?`inline-flex`:``,e),children:[t(`div`,{className:`w-2 h-2 bg-gradient-to-r ${a} rounded-full animate-[bounce_1.2s_ease-in-out_infinite]`}),t(`div`,{className:`w-2 h-2 bg-gradient-to-r ${a} rounded-full animate-[bounce_1.2s_ease-in-out_0.2s_infinite]`}),t(`div`,{className:`w-2 h-2 bg-gradient-to-r ${a} rounded-full animate-[bounce_1.2s_ease-in-out_0.4s_infinite]`})]})}function Ru({className:e,size:r=`md`,color:i=`blue`}){let a={sm:`w-3 h-3`,md:`w-5 h-5`,lg:`w-7 h-7`},o={blue:`bg-blue-500 dark:bg-blue-400`,purple:`bg-purple-500 dark:bg-purple-400`,teal:`bg-teal-500 dark:bg-teal-400`,green:`bg-green-500 dark:bg-green-400`,amber:`bg-amber-500 dark:bg-amber-400`};return n(`span`,{className:H(`relative flex`,e),children:[t(`span`,{className:H(`animate-ping absolute inline-flex h-full w-full rounded-full opacity-60`,o[i])}),t(`span`,{className:H(`animate-pulse absolute inline-flex h-[80%] w-[80%] rounded-full opacity-80`,o[i]),style:{left:`10%`,top:`10%`,animationDuration:`2s`}}),t(`span`,{className:H(`relative inline-flex rounded-full`,o[i],a[r])})]})}function zu({className:e,color:n=`blue`}){let[r,i]=X(`.`);return q(()=>{let e=setInterval(()=>{i(e=>e===`.`?`..`:e===`..`?`...`:`.`)},500);return()=>clearInterval(e)},[]),t(`span`,{className:H({blue:`text-blue-600 dark:text-blue-400`,purple:`text-purple-600 dark:text-purple-400`,teal:`text-teal-600 dark:text-teal-400`,green:`text-green-600 dark:text-green-400`,amber:`text-amber-600 dark:text-amber-400`}[n],`font-bold`,e),children:r})}function Bu({message:e,className:r,color:i=`blue`}){let a={blue:{dot:`bg-blue-500 dark:bg-blue-400`,text:`text-blue-700 dark:text-blue-300`},purple:{dot:`bg-purple-500 dark:bg-purple-400`,text:`text-purple-700 dark:text-purple-300`},teal:{dot:`bg-teal-500 dark:bg-teal-400`,text:`text-teal-700 dark:text-teal-300`},green:{dot:`bg-green-500 dark:bg-green-400`,text:`text-green-700 dark:text-green-300`},amber:{dot:`bg-amber-500 dark:bg-amber-400`,text:`text-amber-700 dark:text-amber-300`}};return n(`div`,{className:H(`flex items-center gap-2 py-1`,r),children:[n(`div`,{className:`flex gap-1`,children:[t(`div`,{className:`w-1.5 h-1.5 ${a[i].dot} rounded-full animate-bounce`}),t(`div`,{className:`w-1.5 h-1.5 ${a[i].dot} rounded-full animate-bounce`,style:{animationDelay:`0.2s`}}),t(`div`,{className:`w-1.5 h-1.5 ${a[i].dot} rounded-full animate-bounce`,style:{animationDelay:`0.4s`}})]}),t(`div`,{className:`${a[i].text} font-medium text-xs`,children:e})]})}function Vu({className:e,color:r=`blue`,width:i=`md`,message:a}){let[o,s]=X(15),[c,l]=X(`increasing`),[u,d]=X(.4),f=Y(null),p=Y(!0);return q(()=>{let e=f.current;if(!e)return;let t=new IntersectionObserver(([e])=>{p.current=e.isIntersecting},{threshold:0});return t.observe(e),()=>t.disconnect()},[]),q(()=>{let e,t=Date.now(),n=()=>{if(!p.current){e=requestAnimationFrame(n);return}let r=Date.now(),i=r-t;t=r,s(e=>{let t=i/16*u,n=c===`increasing`?e+t:e-t;return n>=85?(l(`decreasing`),d(.3+Math.random()*.2),85):n<=15?(l(`increasing`),d(.3+Math.random()*.2),15):(Math.random()>.99&&d(e=>Math.max(.2,Math.min(.5,e+(Math.random()*.1-.05)))),n)}),e=requestAnimationFrame(n)};return e=requestAnimationFrame(n),()=>{cancelAnimationFrame(e)}},[c,u]),n(`div`,{ref:f,className:H(`flex flex-col gap-1`,e),children:[a&&t(`div`,{className:`text-xs font-medium ${{blue:`text-blue-700 dark:text-blue-300`,purple:`text-purple-700 dark:text-purple-300`,teal:`text-teal-700 dark:text-teal-300`,green:`text-green-700 dark:text-green-300`,amber:`text-amber-700 dark:text-amber-300`}[r]} mb-1`,children:a}),t(`div`,{className:H(`h-1.5 rounded-full overflow-hidden shadow-inner`,{blue:`bg-blue-200 dark:bg-blue-900/30`,purple:`bg-purple-200 dark:bg-purple-900/30`,teal:`bg-teal-200 dark:bg-teal-900/30`,green:`bg-green-200 dark:bg-green-900/30`,amber:`bg-amber-200 dark:bg-amber-900/30`}[r],{sm:`w-24`,md:`w-32`,lg:`w-48`,xl:`w-64`,full:`w-full`}[i]),children:t(`div`,{className:H(`h-full rounded-full`,{blue:`bg-gradient-to-r from-blue-400 to-blue-500 dark:from-blue-500 dark:to-blue-400`,purple:`bg-gradient-to-r from-purple-400 to-purple-500 dark:from-purple-500 dark:to-purple-400`,teal:`bg-gradient-to-r from-teal-400 to-teal-500 dark:from-teal-500 dark:to-teal-400`,green:`bg-gradient-to-r from-green-400 to-green-500 dark:from-green-500 dark:to-green-400`,amber:`bg-gradient-to-r from-amber-400 to-amber-500 dark:from-amber-500 dark:to-amber-400`}[r]),style:{width:`${o}%`,transition:`width 150ms cubic-bezier(0.4, 0.0, 0.2, 1)`}})})]})}function Hu({className:e,color:n=`blue`,size:r=`md`}){let[i,a]=X(Array(7).fill(50)),o=Y(null),s=Y(!0);q(()=>{let e=o.current;if(!e)return;let t=new IntersectionObserver(([e])=>{s.current=e.isIntersecting},{threshold:0});return t.observe(e),()=>t.disconnect()},[]);let c={sm:{width:`w-16`,height:`h-4`,barWidth:`w-0.5`,gap:`gap-[2px]`},md:{width:`w-20`,height:`h-5`,barWidth:`w-1`,gap:`gap-[3px]`},lg:{width:`w-24`,height:`h-6`,barWidth:`w-1.5`,gap:`gap-1`}},l={blue:`bg-gradient-to-b from-blue-400 to-blue-500 dark:from-blue-400 dark:to-blue-500`,purple:`bg-gradient-to-b from-purple-400 to-purple-500 dark:from-purple-400 dark:to-purple-500`,teal:`bg-gradient-to-b from-teal-400 to-teal-500 dark:from-teal-400 dark:to-teal-500`,green:`bg-gradient-to-b from-green-400 to-green-500 dark:from-green-400 dark:to-green-500`,amber:`bg-gradient-to-b from-amber-400 to-amber-500 dark:from-amber-400 dark:to-amber-500`};return q(()=>{let e,t=[1.2,1,1.5,.8,1.3,.9,1.1],n=[0,.5,1,1.5,2,2.5,3],r=0,i=()=>{if(!s.current){e=requestAnimationFrame(i);return}r+=.02;let o=Array(7).fill(0).map((e,i)=>10+(Math.sin(r*t[i]+n[i])+1)*40);a(o),e=requestAnimationFrame(i)};return e=requestAnimationFrame(i),()=>{cancelAnimationFrame(e)}},[]),t(`div`,{ref:o,className:H(`flex items-end justify-center`,c[r].width,c[r].height,c[r].gap,e),children:i.map((e,i)=>t(`div`,{className:H(c[r].barWidth,`rounded-full transform-gpu`,l[n]),style:{height:`${e}%`,transition:`height 100ms cubic-bezier(0.4, 0.0, 0.2, 1)`,opacity:.9}},`bar-${i}`))})}const Uu=[`agent-markdown vprose prose max-w-none break-words text-sm leading-6 text-foreground/80`,`prose-p:my-2 prose-p:leading-6 prose-li:my-0.5 prose-pre:my-3 prose-headings:tracking-normal`,`prose-headings:text-foreground prose-strong:text-foreground prose-code:text-foreground`,`prose-a:text-foreground prose-a:underline prose-a:decoration-muted prose-a:underline-offset-4`,`[&_p]:text-foreground/80 [&_li]:text-foreground/80 [&_li::marker]:text-muted`].join(` `);function Wu({children:e,artifactRunId:r,components:i,disableCollapse:a,className:o,"data-testid":s}){let{t:c}=Z(),l=e.trim(),[u,d]=X(!1),f=l?l.split(/\r?\n/).length:0,p=l.length>520||f>6,m=p&&!a&&!u;return n(`div`,{className:H(`min-w-0`,o),children:[t(`div`,{"data-testid":s,className:H(Uu,m&&`[display:-webkit-box] overflow-hidden [-webkit-box-orient:vertical] [-webkit-line-clamp:6]`),style:{overflowWrap:`anywhere`},children:t(wt,{artifactRunId:r,components:i,children:e})}),p&&!a?t(`div`,{className:`mt-1.5 flex justify-end`,children:n(`button`,{type:`button`,"aria-expanded":u,className:H(`inline-flex items-center gap-1 text-sm font-medium text-muted transition-colors`,`[text-decoration:none] hover:text-foreground hover:[text-decoration:none]`,`focus-visible:text-foreground focus-visible:[text-decoration:none]`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`),onClick:()=>d(e=>!e),children:[c(u?`agent.showLess`:`agent.showMore`),t(un,{className:H(`size-4 transition-transform`,u&&`rotate-180`),"aria-hidden":`true`})]})}):null]})}const Gu=new Set([`heading`,`paragraph`,`list`,`list_item`,`blockquote`,`code_block`,`table`,`separator`]);function Ku(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:void 0}function qu(e,t){let n=e?.[t];return typeof n==`string`&&n.length>0?n:void 0}function Ju(e){let t=Ku(e),n=qu(t,`kind`);if(n===`store_document`){let e=qu(t,`document_id`);if(!e)return;let r=qu(t,`name`);return{kind:n,document_id:e,...r?{name:r}:{}}}if(n===`agent_artifact`){let e=qu(t,`run_id`),r=qu(t,`path`);return e&&r?{kind:n,run_id:e,path:r}:void 0}}function Yu(e){let t=Ku(e),n=Ku(t?.anchor),r=qu(t,`operation_id`),i=qu(t,`action`),a=qu(n,`block_id`),o=qu(n,`block_type`),s=qu(n,`exact_text`),c=Ju(t?.resource);if(!r||i!==`comment`&&i!==`edit`||!a||!o||!Gu.has(o)||!s||!c)return;let l=qu(t,`base_version`),u=qu(t,`comment`),d=Ku(t?.user_change),f=qu(d,`before`),p=qu(d,`after`);if(i===`comment`&&!u||i===`edit`&&(!f||!p))return;let m=qu(t,`updated_document_id`);return{operation_id:r,resource:c,...l?{base_version:l}:{},action:i,anchor:{block_id:a,block_type:o,exact_text:s},...u?{comment:u}:{},...f&&p?{user_change:{before:f,after:p}}:{},...t?.applied===!0?{applied:!0}:{},...m?{updated_document_id:m}:{}}}function Xu(e){return e.length>12?`${e.slice(0,4)}…${e.slice(-4)}`:e}function Zu(e){return e.kind===`store_document`?e.name||Xu(e.document_id):e.path}const Qu=[`[&_h1]:text-base [&_h2]:text-base [&_h3]:text-base [&_h4]:text-base [&_h5]:text-base [&_h6]:text-base`,`[&_h1]:leading-snug [&_h2]:leading-snug [&_h3]:leading-snug`,`[&_:first-child]:mt-0 [&_:last-child]:mb-0`].join(` `);function $u({children:e,className:n}){return t(`pre`,{className:H(`m-0 max-h-48 overflow-auto whitespace-pre-wrap font-mono text-xs leading-5 text-foreground/80`,n),children:e})}function ed({before:e,after:n}){let r=J(()=>Nt(e,n),[e,n]);return t($u,{children:r.map((e,n)=>e.type===`removed`?t(`del`,{className:`rounded-xs bg-mixer-destructive/15 text-destructive line-through decoration-destructive/50`,children:e.text},n):e.type===`added`?t(`ins`,{className:`rounded-xs bg-mixer-success/15 text-success no-underline`,children:e.text},n):t(`span`,{children:e.text},n))})}function td({action:r}){let{t:i}=Z(),a=r.action===`comment`,o=r.applied===!0,s=r.anchor.block_type.replaceAll(`_`,` `),c=a?br:Mr,l=r.resource.kind===`agent_artifact`?r.resource.run_id:void 0;return n(`div`,{className:`min-w-0 space-y-2 text-start`,"data-document-edit-action":r.action,children:[n(`div`,{className:`flex min-w-0 items-center gap-1.5 text-sm text-muted`,children:[t(c,{className:`size-4 shrink-0`,"aria-hidden":`true`}),t(`span`,{className:`shrink-0 font-medium text-foreground`,children:i(a?`agent.documentEditCardComment`:o?`agent.documentEditCardApplied`:`agent.documentEditCardDirectEdit`)}),t(`span`,{"aria-hidden":`true`,children:`·`}),t(`span`,{className:`shrink-0 capitalize`,children:s}),t(`span`,{"aria-hidden":`true`,children:`·`}),t(`span`,{className:`truncate`,children:Zu(r.resource)})]}),a?n(e,{children:[r.comment?t(Wu,{artifactRunId:l,disableCollapse:!0,className:Qu,children:r.comment}):null,t(Wu,{artifactRunId:l,disableCollapse:!0,className:H(`border-s-2 border-mixer-muted/30 ps-3 text-foreground/70`,Qu),children:r.anchor.exact_text})]}):t(ed,{before:r.user_change?.before??r.anchor.exact_text,after:r.user_change?.after??``})]})}const nd=`Brewing some code magic...(Doing the robot dance...(Cooking up something good...(Working my gears...(Parsing the possibilities...(Crunching the numbers...(Connecting the digital dots...(Processing at maximum capacity...(Searching through my circuits...(Running advanced algorithms...(Computing optimal solutions...(Loading brilliance.exe...(Scanning the knowledge base...(Optimizing response protocols...(Having a quick brainstorm...(Thinking cap firmly on...(Pondering the digital universe...(Consulting my silicon wisdom...(Untangling the logic knots...(Assembling clever responses...(Mixing thoughtful ingredients...(Polishing the perfect answer...(Taking a momentary mind sprint...(Connecting virtual synapses...(Baking fresh ideas...(Stirring the thought pot...(Simmering solutions slowly...(Whipping up a smart response...(Adding a dash of intelligence...(Preparing a gourmet answer...(Growing brilliant ideas...(Cultivating the perfect response...(Gathering digital nectar...(Planting seeds of solutions...(Exploring the data landscape...(Mapping the solution path...(Navigating through possibilities...(Charting the course to answers...(Embarking on a thought expedition...(Sketching out concepts...(Painting with digital brushstrokes...(Composing my response symphony...(Crafting precision answers...(Weaving threads of information...(Just a moment of processing...(Taking a quick thinking break...(Almost there, final touches...(Putting the pieces together...(Making progress, hold tight...`.split(`(`);function rd(e,t){if(e.startsWith(t))return e.slice(t.length).split(/[/?#]/,1)[0]||void 0}function id(e={}){let{StoreLinkComponent:n,CollectionLinkComponent:r,addStickyParams:i}=e;return function({node:e,ref:a,...o}){let s=o.href||``,c=s.startsWith(`/`)&&!s.startsWith(`//`),l=c&&i?i(s):s,u=c?rd(s,`/store/objects/`):void 0;if(u&&n)return t(n,{href:l,documentId:u,className:o.className,children:o.children});let d=c?rd(s,`/store/collections/`):void 0;return d&&r?t(r,{href:l,collectionId:d,className:o.className,children:o.children}):c?t(ga,{href:l,className:o.className,topLevelNav:!0,children:o.children}):t(`a`,{...o,target:`_blank`,rel:`noopener noreferrer`})}}const ad=ot(null);function od(){return lt(ad)||{openImage:e=>window.open(e,`_blank`),closeImage:()=>{}}}function sd({children:e}){let[r,i]=X(null),a=K((e,t)=>{i({src:e,alt:t})},[]),s=K(()=>{i(null)},[]),{t:c}=Z();return n(ad.Provider,{value:{openImage:a,closeImage:s},children:[e,r&&t(`div`,{role:`button`,tabIndex:-1,"aria-label":c(`agent.close`),className:`fixed inset-0 z-[100] flex items-center justify-center bg-black/80 backdrop-blur-sm`,onClick:s,onKeyDown:Ue(s),children:n(`div`,{className:`relative max-w-[90vw] max-h-[90vh]`,children:[t(`img`,{src:r.src,alt:r.alt||c(`agent.enlargedView`),className:`max-w-full max-h-[90vh] object-contain rounded-lg shadow-2xl`}),t(o,{variant:`unstyled`,className:`absolute top-2 end-2 text-white bg-black/50 rounded-full p-2 hover:bg-black/70 transition-colors`,onClick:s,title:c(`agent.close`),children:t(mi,{className:`size-6`})}),t(`a`,{href:r.src,target:`_blank`,rel:`noopener noreferrer`,className:`absolute bottom-2 end-2 text-white bg-black/50 rounded-full p-2 hover:bg-black/70 transition-colors`,onClick:e=>e.stopPropagation(),title:c(`agent.openInNewTab`),children:t(Pn,{className:`size-5`})})]})})]})}const cd=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`svg`]),ld=new Set([`css`,`csv`,`html`,`js`,`json`,`jsx`,`log`,`md`,`mjs`,`sql`,`ts`,`tsx`,`txt`,`xml`,`yaml`,`yml`]);function ud(e){let t=e?.split(/[?#]/)[0]??``;return t.includes(`.`)?(t.split(`.`).pop()??``).toLowerCase():``}function dd(e){return e.contentType?.toLowerCase().startsWith(`image/`)?!0:cd.has(ud(e.artifactPath||e.href||e.name))}function fd(e){let t=e.contentType?.toLowerCase()??``;return t.startsWith(`text/`)||t===`application/json`||t.includes(`xml`)?!0:ld.has(ud(e.artifactPath||e.href||e.name))}function pd(e){if(e.artifactPath)return e.artifactPath;if(e.href?.startsWith(`artifact:`))return e.href.slice(9)}function md(e){let t=e.split(`/store/objects/`)[1];return t?t.split(/[?#]/)[0]:e.replace(/^store:/,``).replace(/^document:(?:\/\/)?/,``).split(/[?#]/)[0]}function hd(e){return e.split(`/store/collections/`)[1]||e.replace(/^collection:/,``)}function gd(e){return!!(e?.includes(`/store/objects/`)||e?.startsWith(`store:`)||e?.startsWith(`document:`))}function _d(e){return!!(e?.includes(`/store/collections/`)||e?.startsWith(`collection:`))}function vd({item:n,children:r,onOpenArtifact:i,StoreLinkComponent:a,CollectionLinkComponent:o}){let s=n.href;if(!s)return t(e,{children:r});let c=pd(n);if(c&&/\.md$/i.test(c)&&i)return t(`button`,{type:`button`,className:`max-w-full text-start`,onClick:()=>i(c),children:r});if(gd(s)){let e=md(s);return a?t(a,{href:s,documentId:e,children:r}):t(`a`,{href:s.startsWith(`store:`)||s.startsWith(`document:`)?`/store/objects/${e}`:s,children:r})}if(_d(s)){let e=hd(s);return o?t(o,{href:s,collectionId:e,children:r}):t(`a`,{href:s.startsWith(`collection:`)?`/store/collections/${e}`:s,children:r})}return/^https?:\/\//.test(s)||s.startsWith(`/`)?t(`a`,{href:s,target:s.startsWith(`/`)?void 0:`_blank`,rel:`noopener noreferrer`,children:r}):t(e,{children:r})}function yd({item:e,artifactRunId:r,variant:i,onRemove:a,onOpenArtifact:s,StoreLinkComponent:c,CollectionLinkComponent:l}){let{t:u}=Z(),d=lt(yi),f=qa(),{openImage:p}=od(),m=pd(e),h=dd(e),g=h&&!fd(e),[_,v]=X(e.previewUrl);q(()=>{v(e.previewUrl)},[e.previewUrl]),q(()=>{if(!g||e.previewUrl||!r||!m||!d?.client)return;let t=!1,n=Ya(r,m,`inline`);return(async()=>{let e=f?await f.getOrFetch(n,async()=>(await d.client.files.getArtifactDownloadUrl(r,m,`inline`)).url):(await d.client.files.getArtifactDownloadUrl(r,m,`inline`)).url;t||v(e)})().catch(()=>{t||v(void 0)}),()=>{t=!0}},[m,r,e.previewUrl,d?.client,g,f]);let y={attention:`bg-attention/15 text-attention`,destructive:`bg-destructive/15 text-destructive`,info:`bg-info/15 text-info`,muted:`bg-muted text-muted`,success:`bg-success/15 text-success`}[e.statusTone??`muted`],b=!!(a&&e.removable!==!1),x=t=>{t.stopPropagation(),t.preventDefault(),a?.(e.id)},S=b?t(o,{variant:`unstyled`,size:`none`,"aria-label":u(`agent.removeFile`,{name:e.name}),onClick:x,className:H(`absolute -end-1.5 -top-1.5 inline-flex size-5 items-center justify-center rounded-full`,`border border-border bg-background text-muted shadow-sm transition-colors hover:text-foreground`),children:t(_i,{className:`size-3`,"aria-hidden":`true`})}):null,C=b?t(o,{variant:`unstyled`,size:`none`,"aria-label":u(`agent.removeFile`,{name:e.name}),onClick:x,className:H(`-me-1 inline-flex size-6 shrink-0 items-center justify-center rounded-md text-muted`,`transition-colors hover:bg-mixer-muted/30 hover:text-foreground`),children:t(_i,{className:`size-3.5`,"aria-hidden":`true`})}):null,w=g&&_?t(o,{type:`button`,variant:`unstyled`,size:`none`,onClick:t=>{t.stopPropagation(),t.preventDefault(),p(_,e.name)},"aria-label":e.name,title:u(`agent.enlargedView`),className:H(`group shrink-0 overflow-hidden rounded border border-border/60 p-0`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,i===`composer`?`size-6`:`size-24`),children:t(`img`,{src:_,alt:e.name,className:`h-full w-full object-cover transition-transform group-hover:scale-[1.05]`})}):t(h?nr:Un,{className:`size-3.5 shrink-0 text-muted`,"aria-hidden":`true`}),T=n(`span`,{className:`inline-flex min-w-0 max-w-full items-center gap-1.5`,children:[w,t(`span`,{className:H(`truncate`,i===`composer`?`max-w-[14rem]`:`max-w-[16rem]`),children:e.name}),e.statusLabel?t(`span`,{className:H(`shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium`,y),children:e.statusLabel}):null]});if(i===`composer`)return n(`span`,{title:e.name,className:H(`inline-flex min-h-8 max-w-full items-center gap-1 rounded-xl border border-border/60`,`bg-mixer-muted/15 px-2.5 py-1 text-sm text-foreground/80 transition-colors`,e.href&&`hover:bg-mixer-muted/25`),children:[t(vd,{item:e,StoreLinkComponent:c,CollectionLinkComponent:l,children:T}),C]});let E=t(`span`,{title:e.name,className:H(`inline-flex max-w-full items-center gap-1.5 rounded-md border border-border/60 bg-mixer-muted/15`,`px-2.5 py-1.5 text-xs text-foreground/80 transition-colors`,e.href&&`hover:bg-mixer-muted/25`),children:T});return n(`span`,{className:`relative inline-flex max-w-full`,children:[t(vd,{item:e,onOpenArtifact:s,StoreLinkComponent:c,CollectionLinkComponent:l,children:E}),S]})}function bd({items:e,artifactRunId:r,className:i,align:a=`start`,variant:s=`message`,onRemove:c,onOpenArtifact:l,StoreLinkComponent:u,CollectionLinkComponent:d}){let{t:f}=Z(),[p,m]=X(!1),h=ut(),g=s===`composer`&&e.length>3,_=g&&!p?e.slice(0,3):e,v=e.length-3;return q(()=>{e.length<=3&&m(!1)},[e.length]),e.length===0?null:n(`div`,{id:h,className:H(`flex flex-wrap gap-2`,a===`end`&&`justify-end`,i),children:[_.map(e=>t(yd,{item:e,artifactRunId:r,variant:s,onRemove:c,onOpenArtifact:l,StoreLinkComponent:u,CollectionLinkComponent:d},e.id)),g&&n(o,{type:`button`,variant:`ghost`,size:`sm`,"aria-controls":h,"aria-expanded":p,onClick:()=>m(e=>!e),className:`h-8 shrink-0 gap-1 rounded-xl px-2.5 text-xs text-muted`,children:[!p&&n(`span`,{children:[`+`,v]}),f(p?`agent.showLess`:`agent.showMore`),t(un,{className:H(`size-3.5 transition-transform`,p&&`rotate-180`),"aria-hidden":`true`})]})]})}const xd=/^\s*(?:\*\*)?(attachments|uploaded artifacts):(?:\*\*)?\s*$/i,Sd=/\s/,Cd=[`image -`,`text extracted to `];function wd(e){let t=e;if((t.startsWith(`-`)||t.startsWith(`*`))&&(t=t.slice(1).trimStart()),!t.startsWith(`[`)||!t.endsWith(`)`))return null;let n=t.indexOf(`]`);if(n<2||t[n+1]!==`(`)return null;let r=t.slice(1,n),i=t.slice(n+2,-1);for(let e=i.lastIndexOf(`(`);e>0;e=i.lastIndexOf(`(`,e-1)){let t=e;for(;t>0&&Sd.test(i[t-1]);)t--;if(t===e||t<2||i[t-1]!==`)`)continue;let n=i.slice(e+1);if(Cd.some(e=>n.startsWith(e)))return{name:r,href:i.slice(0,t-1),note:n}}return i?{name:r,href:i}:null}function Td(e){let t=e.split(/\r?\n/),n=[],r=[],i=!1;for(let e of t){let t=e.trim();if(xd.test(t)){i=!0;continue}if(!i){n.push(e);continue}if(!t)continue;let a=wd(t);if(!a){i=!1,n.push(e);continue}let{name:o,href:s,note:c}=a,l=s.startsWith(`artifact:`)?s.slice(9):void 0;r.push({id:`${s}-${r.length}`,name:o,href:s,artifactPath:l,contentType:c?.toLowerCase().includes(`image`)?`image/*`:void 0})}return{body:n.join(`
|
|
12
|
+
`).trim(),attachments:r}}function Ed(e){let t=new Set;for(let n of e)if(!(n.type!==$.QUESTION||n.details?._optimistic||typeof n.message!=`string`))for(let e of Td(n.message).attachments)e.href&&t.add(e.href),e.artifactPath&&t.add(e.artifactPath);return t}function Dd({message:e,batchData:r,isRunning:i=!1,className:a,headerClassName:s,senderClassName:c,progressBarClassName:l,itemListClassName:u,itemClassName:d,summaryClassName:f}){let[p,m]=X(!1),h=Xe(),{t:g}=Z(),{tool_name:_,total:v,completed:y,succeeded:b,failed:x,items:S,started_at:C,completed_at:w}=r,T=v>0?y/v*100:0,E=x>0,D=y===v&&!i,O=i||!D?`running`:x===v?`error`:x>0?`warning`:`completed`,k=()=>i||!D?t(Ru,{size:`sm`,color:`blue`}):O===`completed`?t(on,{className:`size-4 text-success`}):O===`error`||O===`warning`?t(Wt,{className:`size-4 text-destructive`}):t(ar,{className:`size-4 text-purple-600`}),A=()=>O===`completed`?`border-s-success`:O===`error`?`border-s-destructive`:O===`warning`?`border-s-attention`:`border-s-blue-500`,j=()=>E?`bg-attention`:D?`bg-success`:`bg-blue-500`,M=()=>{let e=JSON.stringify(r,null,2);navigator.clipboard.writeText(e).then(()=>{h({status:`success`,title:g(`agent.copiedBatchDetails`),duration:2e3})})},N=((w?w-C:Date.now()-C)/1e3).toFixed(1);return n(`div`,{className:H(`border-s-4 shadow-md overflow-hidden bg-white dark:bg-gray-900 mb-5`,A(),a),children:[n(`div`,{role:`button`,tabIndex:0,"aria-expanded":p,className:H(`flex items-center justify-between px-4 py-2 border-b border-gray-100/80 dark:border-gray-800/80 bg-blue-50/50 dark:bg-blue-900/10 cursor-pointer`,s),onClick:()=>m(!p),onKeyDown:Ue(()=>m(!p)),children:[n(`div`,{className:`flex items-center gap-2`,children:[k(),t(`span`,{className:H(`text-xs font-medium text-muted`,c),children:g(`agent.batch`)}),t(`span`,{className:`text-xs text-blue-600 dark:text-blue-400 font-medium`,children:_}),n(`span`,{className:`text-xs text-muted`,children:[y,`/`,v]}),p?t(un,{className:`size-3 text-muted`}):t(pn,{className:`size-3 text-muted cn-rtl-flip`})]}),n(`div`,{className:`flex items-center gap-2`,children:[n(`span`,{className:`text-xs text-muted`,children:[N,`s`]}),t(`span`,{className:`text-xs text-muted`,children:fs(C).format(`HH:mm:ss`)}),t(o,{variant:`ghost`,size:`xs`,onClick:e=>{e.stopPropagation(),M()},className:`text-muted`,title:g(`agent.copyBatchDetails`),children:t(Dn,{className:`size-3`})})]})]}),t(`div`,{className:H(`px-4 py-2 bg-gray-50/50 dark:bg-gray-800/30`,l),children:n(`div`,{className:`flex items-center gap-3`,children:[t(`div`,{className:`flex-1 h-2 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden`,children:t(`div`,{className:`h-full ${j()} transition-all duration-300 ease-out`,style:{width:`${T}%`}})}),n(`div`,{className:`flex items-center gap-2 text-xs`,children:[b>0&&n(`span`,{className:`text-success flex items-center gap-1`,children:[t(on,{className:`size-3`}),b]}),x>0&&n(`span`,{className:`text-destructive flex items-center gap-1`,children:[t(Wt,{className:`size-3`}),x]}),i&&y<v&&n(`span`,{className:`text-blue-500 flex items-center gap-1`,children:[t(fr,{className:`size-3 animate-spin`}),v-y]})]})]})}),p&&S.length>0&&t(`div`,{className:H(`max-h-64 overflow-y-auto`,u),children:S.map(e=>n(`div`,{className:H(`flex items-center gap-2 px-4 py-1.5 text-xs border-b border-gray-100 dark:border-gray-800 last:border-b-0 hover:bg-gray-50 dark:hover:bg-gray-800/50`,d),children:[n(`div`,{className:`w-4 flex-shrink-0`,children:[e.status===`success`&&t(on,{className:`size-3 text-success`}),e.status===`error`&&t(Wt,{className:`size-3 text-destructive`}),e.status===`running`&&t(fr,{className:`size-3 text-blue-500 animate-spin`}),e.status===`pending`&&t(`div`,{className:`size-3 rounded-full border border-gray-300 dark:border-gray-600`})]}),t(`span`,{className:`font-mono text-muted w-24 truncate flex-shrink-0`,title:e.id,children:e.id}),t(`span`,{className:`text-muted truncate flex-1`,title:e.message,children:e.message||(e.status===`pending`?g(`agent.waiting`):``)}),e.duration_ms!==void 0&&n(`span`,{className:`text-muted flex-shrink-0`,children:[(e.duration_ms/1e3).toFixed(1),`s`]})]},e.id))}),!p&&e.message&&t(`div`,{className:H(`px-4 py-2 text-xs text-muted`,f),children:e.message})]})}const Od=ct(Dd,(e,t)=>e.isRunning===t.isRunning&&e.batchData.completed===t.batchData.completed&&e.batchData.succeeded===t.batchData.succeeded&&e.batchData.failed===t.batchData.failed),kd={sending:{icon:wn,className:`text-muted/70`},received:{icon:rn,className:`text-info`},consumed:{icon:an,className:`text-success`},failed:{icon:Wt,className:`text-destructive`}};function Ad(e){return e===`sending`||e===`received`||e===`consumed`||e===`failed`}function jd(e){if(e.type!==$.QUESTION&&!Ml(e))return;let t=e.details?._deliveryStatus;if(Ad(t))return t;if(e.details?.ack)return`consumed`}function Md(e,t){switch(t){case`sending`:return e(`agent.messageSending`);case`received`:return e(`agent.messageReceived`);case`consumed`:return e(`agent.messageConsumed`);case`failed`:return e(`agent.messageFailed`)}return t}function Nd({message:e,className:n}){let{t:r}=Z(),i=jd(e);if(!i)return null;let a=kd[i],o=a.icon,s=Md(r,i);return t(Be,{description:s,asChild:!0,children:t(`span`,{"aria-label":s,className:H(`inline-flex h-5 w-5 items-center justify-center`,a.className,n),role:`img`,children:t(o,{className:`size-3.5`,"aria-hidden":`true`})})})}function Pd(e){return e.content?.name||e.name}function Fd({client:e,toast:t}){let n=Vt.getFixedT(null,Bt),[r,i]=X(!1),a=K(async(r,a)=>{if(r){i(!0);try{Id((await e.files.getDownloadUrlWithOptions({file:r,name:a})).url,a)}catch(e){t({status:`error`,title:n(`store.downloadFailed`),description:e instanceof Error?e.message:n(`store.failedToGetDownloadUrl`),duration:5e3})}finally{i(!1)}}},[e,t,n]),o=K((e,t)=>{e&&Id(e,t)},[]),s=K(async(t,n)=>{let r=await(`store`in e?e.store:e).rendering.render(t);if(r.download_url)Id(r.download_url,n);else if(r.file_uri)Id((await e.files.getDownloadUrlWithOptions({file:r.file_uri,name:n})).url,n);else throw Error(`No download URL or file URI in response`)},[e]);return{downloadFromContentSource:a,downloadFromUrl:o,renderDocument:K(async(e,r)=>{i(!0);try{let i=`${r.title||`document`}.${r.format}`;await s({object_id:e,format:r.format,title:r.title,pandoc_options:r.pandocOptions,use_default_template:r.useDefaultTemplate,template_path:r.templateObjectId?`store:${r.templateObjectId}`:void 0},i),t({status:`success`,title:n(`store.documentExported`),description:n(`store.successfullyExportedTo`,{format:r.format.toUpperCase()}),duration:2e3})}catch(e){t({status:`error`,title:n(`store.exportFailed`),description:e instanceof Error?e.message:n(`store.failedToExportDocument`),duration:5e3})}finally{i(!1)}},[s,t,n]),renderContent:K(async(e,r)=>{i(!0);try{let i=`${r.title||`export`}.${r.format}`;await s({content:e,format:r.format,title:r.title,artifact_run_id:r.artifactRunId,pandoc_options:r.pandocOptions},i),t({status:`success`,title:n(`store.contentExported`),description:n(`store.successfullyExportedTo`,{format:r.format.toUpperCase()}),duration:2e3})}catch(e){t({status:`error`,title:n(`store.exportFailed`),description:e instanceof Error?e.message:n(`store.failedToExportContent`),duration:5e3})}finally{i(!1)}},[s,t,n]),isDownloading:r}}function Id(e,t){fetch(e).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.blob()}).then(n=>{let r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t||Ld(e),i.style.display=`none`,document.body.appendChild(i),i.click(),setTimeout(()=>{document.body.removeChild(i),URL.revokeObjectURL(r)},100)}).catch(()=>{let n=document.createElement(`a`);n.href=e,n.download=t||Ld(e),n.target=`_blank`,n.rel=`noopener noreferrer`,n.style.display=`none`,document.body.appendChild(n),n.click(),setTimeout(()=>{document.body.removeChild(n)},100)})}function Ld(e){try{let t=new URL(e).pathname.split(`/`);return t[t.length-1]||`download`}catch{return`download`}}function Rd(e){return e!==void 0&&e>=`0`&&e<=`9`}function zd(e){return e===` `||e===` `}function Bd(e){return e!==void 0&&e!==` `&&e!==` `&&e!==`
|
|
13
|
+
`&&e!==`\r`}function Vd(e,t){if(t>0&&Rd(e[t-1]))return;let n=t;for(;Rd(e[n]);)n++;if(n===t||e[n]!==`.`)return;n++;let r=n;for(;zd(e[n]);)n++;return n>r&&Bd(e[n])?n:void 0}function Hd(e,t){for(let n=t;n<e.length;n++)if(Vd(e,n)!==void 0)return n;return-1}function Ud(e){let t=Hd(e,0);if(t===-1)return e;let n=e.slice(0,t),r=t;for(;r!==-1;){let t=Hd(e,Vd(e,r)??r+1);if(t===-1){n+=e.slice(r),n+=`
|
|
16
14
|
|
|
17
|
-
`;break}let i=t;for(;i>r&&
|
|
15
|
+
`;break}let i=t;for(;i>r&&zd(e[i-1]);)i--;n+=e.slice(r,i),n+=`
|
|
18
16
|
|
|
19
|
-
`,r=t}return n}function
|
|
17
|
+
`,r=t}return n}function Wd(e){let t=0;for(;zd(e[t]);)t++;return Vd(e,t)!==void 0}function Gd(e){if(!e.includes(`
|
|
20
18
|
`))return e;let t=e.split(`
|
|
21
|
-
`),n=!1;return t.map(e=>{let t=n&&e.length>=2&&!
|
|
22
|
-
`)}function
|
|
19
|
+
`),n=!1;return t.map(e=>{let t=n&&e.length>=2&&!Rd(e[0])&&e[1]!==`:`?` ${e}`:e;return n=Wd(e),t}).join(`
|
|
20
|
+
`)}function Kd(e,t,n){if(typeof e!=`string`)return e;if(t===$.THOUGHT||typeof n==`string`&&(n.toLowerCase().includes(`thinking about`)||n.toLowerCase().includes(`i'm thinking`)||n.toLowerCase().includes(`💭`))){let t=e;return t=Gd(Ud(t)),t.includes(`:`)&&!t.includes(`
|
|
23
21
|
|
|
24
22
|
`)&&(t=t.replace(/\b(First|Next|Then|Finally|Lastly|Additionally|Step \d+):\s+/gi,`
|
|
25
23
|
|
|
26
24
|
$&`)),t.includes(` - `)&&(t=t.replace(/(^|\S)\s+-\s+/g,`$1
|
|
27
25
|
- `)),t}return e.includes(`
|
|
28
26
|
|
|
29
|
-
`)?e:wf(e)}const Of=[`className`,`cardClassName`,`headerClassName`,`contentClassName`,`timestampClassName`,`senderClassName`,`iconClassName`,`detailsClassName`,`artifactsClassName`,`proseClassName`];function kf(e,t,...n){let r={};for(let i of Of)r[i]=H(e[i],t[i],...n.map(e=>e?.[i]));return r}const Af={Ready:`agent.ready`,Error:`agent.error`},jf={[Q.ANSWER]:{borderColor:`border-s-info`,iconColor:`text-info`,sender:`Agent`,Icon:Kt},[Q.COMPLETE]:{borderColor:`border-s-success`,iconColor:`text-success`,sender:`Completed`,Icon:en},[Q.IDLE]:{borderColor:`border-s-info`,iconColor:`text-info`,sender:`Ready`,Icon:yn},[Q.REQUEST_INPUT]:{borderColor:`border-s-attention`,iconColor:`text-attention`,sender:`Input`,Icon:ni},[Q.QUESTION]:{borderColor:`border-s-muted`,iconColor:`text-muted`,sender:`User`,Icon:ni},[Q.THOUGHT]:{borderColor:`border-s-purple-500`,iconColor:`text-purple-600 dark:text-purple-400`,sender:`Agent`,Icon:Kt},[Q.ERROR]:{borderColor:`border-s-destructive`,iconColor:`text-destructive`,sender:`Error`,Icon:zt},[Q.UPDATE]:{borderColor:`border-s-success`,iconColor:`text-success`,sender:`Update`,Icon:Qn},[Q.PLAN]:{borderColor:`border-s-attention`,iconColor:`text-attention`,sender:`Plan`,Icon:pr},[Q.TERMINATED]:{borderColor:`border-s-muted`,iconColor:`text-muted`,sender:`Terminated`,Icon:en},[Q.WARNING]:{borderColor:`border-s-attention`,iconColor:`text-attention`,sender:`Warning`,Icon:zt},[Q.SYSTEM]:{borderColor:`border-s-muted`,iconColor:`text-muted`,sender:`System`,Icon:Qn},[Q.STREAMING_CHUNK]:{borderColor:`border-s-info`,iconColor:`text-info`,sender:`Agent`,Icon:Kt},[Q.BATCH_PROGRESS]:{borderColor:`border-s-blue-500`,iconColor:`text-blue-600 dark:text-blue-400`,sender:`Batch`,Icon:er},[Q.RESTARTING]:{borderColor:`border-s-attention`,iconColor:`text-attention`,sender:`Restarting`,Icon:Mr},default:{borderColor:`border-s-muted`,iconColor:`text-muted`,sender:`Agent`,Icon:Kt}};function Mf({message:e,showPulsatingCircle:r=!1,onSendMessage:a,onOpenArtifact:s,requestInputAnswered:c=!1,className:l,cardClassName:u,headerClassName:d,contentClassName:f,timestampClassName:p,senderClassName:m,iconClassName:h,detailsClassName:g,artifactsClassName:_,proseClassName:v,messageStyleOverrides:y,StoreLinkComponent:b,CollectionLinkComponent:x}){let[S,C]=Y(!1),{t:T}=X(),{client:E}=Z(),D=Ye(),O=Za(),{openImage:k}=Hd(),{router:A}=va(),j=J(E);j.current=E;let M=J(O);M.current=O;let{renderContent:N,isDownloading:P}=gf({client:E,toast:D}),F=q(()=>{let t=jf[e.type]||jf.default,n=y?.default,r=y?.[e.type];return{...t,...n,...r,...kf(t,{className:l,cardClassName:u,headerClassName:d,contentClassName:f,timestampClassName:p,senderClassName:m,iconClassName:h,detailsClassName:g,artifactsClassName:_,proseClassName:v},n,r)}},[e.type,y,l,u,d,f,p,m,h,g,_,v]),I=q(()=>{let t=``;if(e.message&&(t=typeof e.message==`object`?JSON.stringify(e.message,null,2):e.message.trim?e.message.trim():String(e.message)),typeof t==`string`&&t.includes(`%thinking_message%`)){let e=Math.floor(Math.random()*Rd.length);t=t.replace(/%thinking_message%/g,Rd[e])}return t},[e.message]),L=q(()=>e.type===Q.QUESTION?of(I):null,[I,e.type]),ee=L?.body??I,R=L?.attachments??[],te=q(()=>e.type===Q.QUESTION?jd(e.details?.editing_action):void 0,[e.details,e.type]),z=q(()=>ee?Df(ee,e.type,typeof e.message==`string`?e.message:void 0):``,[ee,e.type,e.message]),ne=()=>{let t=I||``,n=typeof e.details==`string`?e.details:e.details?JSON.stringify(e.details,null,2):``,r=[t,n?`\n\nDetails:\n${n}`:``].join(``).trim();navigator.clipboard.writeText(r).then(()=>{D({status:`success`,title:T(`agent.copiedToClipboard`),duration:2e3})})},re=async t=>{let n=typeof I==`string`?I:``;if(!n.trim()){D({status:`error`,title:T(`agent.noContentToExport`),duration:2e3});return}let r=`Message ${Ki(e.timestamp).format(`YYYY-MM-DD HH-mm-ss`)}`;await N(n,{format:t,title:r,artifactRunId:le})},ie=typeof I==`string`&&I.trim().length>0,ae=e.type===Q.REQUEST_INPUT?e.details?.ux:void 0,oe=q(()=>({a:Bd({StoreLinkComponent:b,CollectionLinkComponent:x,addStickyParams:e=>A.getTopRouter().navigator.addStickyParams(e)}),img:({node:e,ref:n,...r})=>t(o,{variant:`unstyled`,className:`block p-0`,onClick:()=>r.src&&k(r.src,r.alt),"aria-label":r.alt||r.src||`image`,children:t(`img`,{...r,alt:r.alt??``,className:`max-w-full h-auto rounded-lg shadow-md my-3 cursor-pointer hover:shadow-lg transition-shadow`,loading:`lazy`})})}),[k,b,x,A]),se=n=>{if(typeof n==`object`)return t(`pre`,{className:`text-xs font-mono whitespace-pre-wrap overflow-x-auto bg-gray-100 dark:bg-gray-800 p-2 rounded text-gray-700`,children:JSON.stringify(n,null,2)});let r=e.workflow_run_id;return!r&&typeof n==`string`&&n.includes(`artifact:`)&&console.warn(`[MessageItem] message contains artifact references but workflow_run_id is missing!`,{type:e.type,workflow_run_id:e.workflow_run_id,hasArtifact:n.includes(`artifact:`)}),t(`div`,{className:H(`vprose prose prose-slate dark:prose-invert prose-p:leading-relaxed prose-p:my-3 prose-headings:font-semibold prose-headings:tracking-normal prose-headings:mt-6 prose-headings:mb-3 prose-h1:text-xl prose-h2:text-lg prose-h3:text-base prose-li:my-1 prose-ul:my-3 prose-ol:my-3 prose-table:my-5 prose-pre:my-4 prose-hr:my-6 max-w-none text-[15px] break-words`,F.proseClassName),style:{overflowWrap:`anywhere`},children:t(bt,{artifactRunId:r,onArtifactOpen:s,onProposalSelect:e=>a?.(e),onProposalSubmit:e=>a?.(e),components:oe,children:n})})},[ce,V]=Y([]),le=e.workflow_run_id,ue=e.details,de=ue?.outputFiles??ue?.files;K(()=>{(async()=>{if(!le||!Array.isArray(de)||de.length===0){V([]);return}let e=j.current,t=M.current;try{let n=await Promise.all(de.map(async n=>{if(typeof n!=`string`||!n.trim())return null;let r=n.trim(),i=r.startsWith(`artifact:`)?r.slice(9):r,a=i.split(`.`).pop()?.toLowerCase()||``,o=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`svg`]).has(a),s=o?`inline`:`attachment`;try{let n=$a(le,i,s),a;return a=t?await t.getOrFetch(n,async()=>(await e.files.getArtifactDownloadUrl(le,i,s)).url):(await e.files.getArtifactDownloadUrl(le,i,s)).url,{displayName:r,artifactPath:i,url:a,isImage:o}}catch(e){return console.error(`Failed to resolve artifact URL for ${i}`,e),null}}));V(n.filter(e=>!!e))}catch(e){console.error(`Error loading artifact URLs from message details`,e),V([])}})()},[le,de]);let fe=_u(e),{Icon:pe}=F;return t(`div`,{className:H(`w-full max-w-full`,F.className),children:n(`div`,{className:H(`border-s-4 bg-white dark:bg-gray-900 mb-4 w-full max-w-full overflow-hidden`,F.borderColor,F.cardClassName),"data-workstream-id":fe,children:[n(`div`,{className:H(`flex items-center justify-between px-4 py-1.5`,F.headerClassName),children:[n(`div`,{className:`flex items-center gap-1.5`,children:[t(`div`,{className:H(r?`animate-fadeIn`:``,F.iconClassName),children:r?t(bd,{size:`sm`,color:`blue`}):t(pe,{className:`size-4 ${F.iconColor}`})}),t(`span`,{className:H(`text-xs font-medium text-muted`,F.senderClassName),children:Af[F.sender]?T(Af[F.sender]):F.sender}),fe!==`main`&&fe!==`all`&&t(i,{variant:`default`,className:`text-xs text-muted ms-1`,children:fe})]}),n(`div`,{className:`flex items-center gap-1.5 print:hidden`,children:[t(mf,{message:e}),t(`span`,{className:H(`text-[11px] text-muted/70`,F.timestampClassName),children:Ki(e.timestamp).format(`HH:mm:ss`)}),t(o,{variant:`ghost`,size:`xs`,onClick:ne,className:`text-muted/50 hover:text-muted h-5 w-5 p-0`,title:T(`agent.copyMessage`),children:t(Sn,{className:`size-3`})}),ie&&n(w,{trigger:t(o,{variant:`ghost`,size:`xs`,className:`text-muted/50 hover:text-muted h-5 w-5 p-0`,title:T(`agent.exportMessage`),disabled:P,children:t(Tn,{className:`size-3 ${P?`animate-pulse`:``}`})}),children:[t(B,{onClick:()=>re(Ti.pdf),children:T(`agent.exportAsPdf`)}),t(B,{onClick:()=>re(Ti.docx),children:T(`agent.exportAsWord`)})]})]})]}),n(`div`,{className:H(`px-4 pb-3 bg-white dark:bg-gray-900 overflow-hidden`,F.contentClassName),children:[ae?t(Jl,{question:typeof I==`string`?I:``,options:ae.options,variant:ae.variant,multiSelect:ae.multiSelect,onSelect:t=>ed(a,e,t,od(e,t)),onMultiSelect:t=>ed(a,e,t.join(`, `)),allowFreeResponse:!ae.options?.length||!!ae.free_response,placeholder:ae.free_response?.placeholder,submitLabel:ae.free_response?.submit_label,onSubmit:t=>ed(a,e,t,ae.free_response?.metadata),hideBorder:!0,compact:!0,answered:c}):te?t(Ld,{action:te}):ee&&t(`div`,{className:`message-content break-words w-full`,style:{overflowWrap:`anywhere`,wordBreak:`break-word`},children:se(z||ee)}),R.length>0&&t(nf,{items:R,artifactRunId:le,onOpenArtifact:s,variant:`message`,className:H(ee&&`mt-3`),StoreLinkComponent:b,CollectionLinkComponent:x}),ce.length>0&&n(`div`,{className:H(`mt-3 text-xs`,F.artifactsClassName),children:[t(`div`,{className:`font-medium text-muted mb-1`,children:`Artifacts`}),ce.some(e=>e.isImage)&&t(`div`,{className:`mb-2 flex flex-wrap gap-3`,children:ce.filter(e=>e.isImage).map(({displayName:e,artifactPath:r,url:i})=>n(o,{variant:`unstyled`,className:`max-w-xs cursor-pointer text-start p-0`,onClick:()=>k(i,e),"aria-label":e,children:[t(`img`,{src:i,alt:e,className:`max-w-full h-auto rounded-lg shadow-sm hover:shadow-md transition-shadow`}),t(`div`,{className:`mt-1 text-[11px] text-muted truncate`,children:e})]},`${r}-preview`))}),t(`div`,{className:`flex flex-wrap gap-2 print:hidden`,children:ce.map(({displayName:e,artifactPath:n,url:r})=>t(o,{variant:`outline`,size:`xs`,className:`px-2 py-1 text-xs`,onClick:()=>{if(/\.md$/i.test(n)&&s){s(n);return}window.open(r,`_blank`)},title:n,children:e},n+r))})]}),e.details&&n(`div`,{className:H(`mt-2 print:hidden`,F.detailsClassName),children:[n(o,{variant:`unstyled`,onClick:()=>C(!S),className:`text-[11px] text-muted flex items-center`,children:[T(S?`agent.hideDetails`:`agent.showDetails`),t(`svg`,{xmlns:`http://www.w3.org/2000/svg`,className:`h-3 w-3 ms-1 transition-transform ${S?`rotate-180`:``}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,"aria-hidden":`true`,children:t(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 9l-7 7-7-7`})})]}),S&&t(`div`,{className:`mt-1 p-1.5 bg-muted border border-mixer-muted/40 rounded text-sm`,children:typeof e.details==`string`?se(e.details):t(`pre`,{className:`text-xs font-mono whitespace-pre-wrap overflow-x-auto bg-muted p-2 rounded text-muted`,children:JSON.stringify(e.details,null,2)})})]})]})]})})}const Nf=it(Mf,(e,t)=>e.message.timestamp===t.message.timestamp&&e.message.type===t.message.type&&e.message.message===t.message.message&&e.message.details===t.message.details&&e.message.workstream_id===t.message.workstream_id&&e.message.workflow_run_id===t.message.workflow_run_id&&e.showPulsatingCircle===t.showPulsatingCircle&&e.onSendMessage===t.onSendMessage&&e.onOpenArtifact===t.onOpenArtifact&&e.requestInputAnswered===t.requestInputAnswered&&e.messageStyleOverrides===t.messageStyleOverrides&&Of.every(n=>e[n]===t[n])),Pf={document:wn,collection:qt,content_type:zn,interaction:hr,prompt:Yr,agent:Xt,workflow:oi,process:oi,process_run:Or,interaction_run:Or,view:xr};function Ff(e){return Pf[e]}function If(e){switch(e){case`created`:return`success`;case`deleted`:return`outline`;default:return`info`}}function Lf({resource:r,workflowRunId:a,showAction:s=!0,className:c}){let{t:l}=X(),u=Mt()(r,{workflowRunId:a,source:`structured`}),d=Ff(r.type),f=r.action===`created`?l(`agent.resourceActionCreated`):r.action===`deleted`?l(`agent.resourceActionDeleted`):l(`agent.resourceActionUpdated`),p=n(e,{children:[t(d,{className:`size-3.5 shrink-0 text-foreground`,"aria-hidden":`true`}),t(`span`,{className:`truncate`,children:r.label}),s&&t(i,{variant:If(r.action),className:`shrink-0 px-1.5 py-0 text-[10px]`,children:f})]}),m=H(`inline-flex max-w-full items-center gap-1.5 rounded-md border border-border bg-background px-2 py-1 text-xs`,c);return u.kind===`navigate`?t(ga,{href:u.href,topLevelNav:!0,className:H(m,`font-medium transition-colors hover:bg-muted/60`),children:p}):u.kind===`activate`?t(o,{variant:`unstyled`,onClick:u.onActivate,className:H(m,`font-medium transition-colors hover:bg-muted/60`),children:p}):t(`span`,{className:H(m,`text-muted`),children:p})}function Rf({resources:e,workflowRunId:r,className:i}){let{t:a}=X();return e.length===0?null:t(`div`,{className:H(`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1`,i),"data-agent-resource-activity":!0,children:e.map(e=>n(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[t(`span`,{className:`shrink-0 text-sm text-muted`,children:e.action===`created`?a(`agent.resourceActionCreated`):e.action===`deleted`?a(`agent.resourceActionDeleted`):a(`agent.resourceActionUpdated`)}),t(Lf,{resource:e,workflowRunId:r,showAction:!1,className:`py-0.5`})]},`${e.type}:${e.id}:${e.action}`))})}function zf({resources:e,workflowRunId:n,className:r}){return e.length===0?null:t(`div`,{className:H(`flex flex-wrap gap-1.5`,r),children:e.map(e=>t(Lf,{resource:e,workflowRunId:n},`${e.type}:${e.id}:${e.action}`))})}function Bf({resources:e,workflowRunId:r,className:i}){let{t:a}=X(),[s,c]=Y(!1);if(e.length===0)return null;let l=e.length>5,u=l&&!s?e.slice(0,5):e;return n(`div`,{className:H(`mx-auto w-full max-w-3xl py-2`,i),"data-agent-resource-summary":!0,children:[t(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:a(`agent.resourcesChanged`)}),t(zf,{resources:u,workflowRunId:r}),l&&t(o,{variant:`outline`,size:`xs`,className:`mt-2`,onClick:()=>c(e=>!e),children:s?a(`agent.resourceShowLess`):a(`agent.resourceViewAll`,{total:e.length})})]})}function Vf(e){let t=[],n=new Map;for(let r of e)for(let e of Fi(r)){let r=`${e.type}:${e.id}`,i=n.get(r);i||(i={ref:e,firstAction:e.action,lastAction:e.action,createdInTurn:!1},n.set(r,i),t.push(r)),i.ref=e,i.lastAction=e.action,e.action===`created`&&(i.createdInTurn=!0)}let r=[];for(let e of t){let t=n.get(e);if(!t||t.firstAction===`created`&&t.lastAction===`deleted`)continue;let i=t.lastAction===`deleted`?`deleted`:t.lastAction===`created`||t.createdInTurn?`created`:`updated`;r.push({...t.ref,action:i})}return r}function Hf(e){if(e.length===0)return[];let t=[],n=[],r=!1;for(let i of e)i.type===Q.QUESTION&&r&&(t.push(n),n=[],r=!1),i.type===Q.QUESTION&&(r=!0),n.push(i);return n.length>0&&t.push(n),t.map(Vf)}function Uf(e){if(!mu(e))return!0;let t=e.filter(e=>_u(e)===`main`);return t[t.length-1]?.type===Q.ANSWER}function Wf(e,t,n,r){if(n.length===0)return e;let i=[],a=e=>{let t=n[e];!t||t.length===0||e>=n.length-1&&!r||i.push({type:`resource_summary`,key:`resource-summary-${e}`,resources:t})},o=0;for(let n of e){let e=t(n);e&&o>0&&a(o-1),e&&(o+=1),i.push(n)}return a(o>0?o-1:n.length-1),i}function Gf({text:e,workstreamId:r,artifactRunId:i,revealSpeed:a=300,isComplete:s=!1,timestamp:c,className:l,cardClassName:u,headerClassName:d,contentClassName:f,proseClassName:p,senderClassName:m,iconClassName:h}){let{t:g}=X(),[_,v]=Y(0),[y,b]=Y(``),x=J(null),S=J(e.length),C=J(0),w=J(c||Date.now()),T=J(e),E=J(0),D=J(performance.now()),O=J(a),k=J(0);K(()=>{let t=performance.now(),n=e.length-E.current,r=t-D.current;if(n>0&&r>30){let e=n/r*1e3,t=.2;O.current=O.current*(1-t)+e*t,O.current=Math.max(50,Math.min(2e3,O.current))}E.current=e.length,D.current=t},[e.length]),S.current=e.length,T.current=e;let A=G(()=>{let e=performance.now(),t=n=>{let r=n-e;e=n;let i=S.current-C.current;if(i<=0){k.current=0,x.current=null;return}let a;if(s)a=Math.max(500,O.current*2);else if(i<20)a=O.current*.85;else if(i<100)a=O.current;else if(i<500){let e=(i-100)/400;a=O.current*(1+e*.5)}else a=O.current*2;let o=a*r/1e3+k.current,c=Math.floor(o);k.current=o-c,c>0&&(C.current=Math.min(C.current+c,S.current),v(C.current)),x.current=requestAnimationFrame(t)};x.current=requestAnimationFrame(t)},[s]);K(()=>(e.length>C.current&&!x.current&&A(),()=>{x.current&&=(cancelAnimationFrame(x.current),null)}),[e.length,A]),K(()=>{s&&C.current<e.length&&(x.current&&=(cancelAnimationFrame(x.current),null),A())},[s,e.length,A]);let j=J(null),M=J(0);K(()=>{(_>=S.current||s)&&(b(T.current.slice(0,_)),M.current=_)},[_,s]);let N=_<e.length&&!s;K(()=>{if(!N){j.current&&=(clearInterval(j.current),null);return}return j.current||=window.setInterval(()=>{let e=C.current;e>M.current&&(b(T.current.slice(0,e)),M.current=e)},33),()=>{j.current&&=(clearInterval(j.current),null)}},[N]);let P=Ye(),F=q(()=>Ki(w.current).format(`HH:mm:ss`),[]),I=_<e.length,L=q(()=>{let t=y||e.slice(0,_);return I?t+`│`:t},[y,e,_,I]);return e?t(`div`,{className:H(`w-full max-w-full`,l),children:n(`div`,{className:H(`border-s-4 bg-white dark:bg-gray-900 mb-4 border-s-purple-500 w-full max-w-full overflow-hidden`,u),"data-workstream-id":r,children:[n(`div`,{className:H(`flex items-center justify-between px-4 py-1.5`,d),children:[n(`div`,{className:`flex items-center gap-1.5`,children:[t(`div`,{className:H(`animate-fadeIn`,h),children:I?t(`span`,{className:`size-2 rounded-full bg-blue-500 animate-pulse inline-block`}):t(Kt,{className:`size-4 text-purple-600 dark:text-purple-400`})}),t(`span`,{className:H(`text-xs font-medium text-muted`,m),children:`Agent`}),r&&r!==`main`&&n(`span`,{className:`text-xs text-muted`,children:[`• Task `,r]})]}),n(`div`,{className:`flex items-center gap-2 text-muted`,children:[t(`span`,{className:`text-[11px]`,children:F}),t(o,{variant:`ghost`,size:`xs`,onClick:()=>{navigator.clipboard.writeText(e).then(()=>{P({status:`success`,title:g(`agent.copiedToClipboard`),duration:2e3})})},className:`size-6 p-0 hover:bg-gray-100 dark:hover:bg-gray-800`,title:g(`agent.copyMessage`),children:t(Sn,{className:`size-3`})})]})]}),n(`div`,{className:H(`px-3 pb-2 streaming-content`,I&&`streaming-active`,f),children:[t(`div`,{className:H(`vprose prose prose-slate dark:prose-invert prose-p:leading-relaxed prose-p:my-3 prose-headings:font-semibold prose-headings:tracking-normal prose-headings:mt-6 prose-headings:mb-3 prose-h1:text-xl prose-h2:text-lg prose-h3:text-base prose-li:my-1 prose-ul:my-3 prose-ol:my-3 prose-table:my-5 prose-pre:my-4 prose-hr:my-6 max-w-none text-[15px] break-words`,p),style:{overflowWrap:`anywhere`},children:t(bt,{artifactRunId:i,children:L})}),t(`style`,{children:`
|
|
27
|
+
`)?e:Ud(e)}const qd=[`className`,`cardClassName`,`headerClassName`,`contentClassName`,`timestampClassName`,`senderClassName`,`iconClassName`,`detailsClassName`,`artifactsClassName`,`proseClassName`];function Jd(e,t,...n){let r={};for(let i of qd)r[i]=H(e[i],t[i],...n.map(e=>e?.[i]));return r}const Yd={Ready:`agent.ready`,Error:`agent.error`},Xd={[$.ANSWER]:{borderColor:`border-s-info`,iconColor:`text-info`,sender:`Agent`,Icon:Zt},[$.COMPLETE]:{borderColor:`border-s-success`,iconColor:`text-success`,sender:`Completed`,Icon:on},[$.IDLE]:{borderColor:`border-s-info`,iconColor:`text-info`,sender:`Ready`,Icon:wn},[$.REQUEST_INPUT]:{borderColor:`border-s-attention`,iconColor:`text-attention`,sender:`Input`,Icon:ci},[$.QUESTION]:{borderColor:`border-s-muted`,iconColor:`text-muted`,sender:`User`,Icon:ci},[$.THOUGHT]:{borderColor:`border-s-purple-500`,iconColor:`text-purple-600 dark:text-purple-400`,sender:`Agent`,Icon:Zt},[$.ERROR]:{borderColor:`border-s-destructive`,iconColor:`text-destructive`,sender:`Error`,Icon:Wt},[$.UPDATE]:{borderColor:`border-s-success`,iconColor:`text-success`,sender:`Update`,Icon:rr},[$.PLAN]:{borderColor:`border-s-attention`,iconColor:`text-attention`,sender:`Plan`,Icon:yr},[$.TERMINATED]:{borderColor:`border-s-muted`,iconColor:`text-muted`,sender:`Terminated`,Icon:on},[$.WARNING]:{borderColor:`border-s-attention`,iconColor:`text-attention`,sender:`Warning`,Icon:Wt},[$.SYSTEM]:{borderColor:`border-s-muted`,iconColor:`text-muted`,sender:`System`,Icon:rr},[$.STREAMING_CHUNK]:{borderColor:`border-s-info`,iconColor:`text-info`,sender:`Agent`,Icon:Zt},[$.BATCH_PROGRESS]:{borderColor:`border-s-blue-500`,iconColor:`text-blue-600 dark:text-blue-400`,sender:`Batch`,Icon:ar},[$.RESTARTING]:{borderColor:`border-s-attention`,iconColor:`text-attention`,sender:`Restarting`,Icon:Rr},default:{borderColor:`border-s-muted`,iconColor:`text-muted`,sender:`Agent`,Icon:Zt}};function Zd({message:e,showPulsatingCircle:r=!1,onSendMessage:a,onOpenArtifact:s,requestInputAnswered:c=!1,className:l,cardClassName:u,headerClassName:d,contentClassName:f,timestampClassName:p,senderClassName:m,iconClassName:h,detailsClassName:g,artifactsClassName:_,proseClassName:v,messageStyleOverrides:y,StoreLinkComponent:b,CollectionLinkComponent:x}){let[S,C]=X(!1),{t:T}=Z(),{client:E}=Q(),D=Xe(),O=qa(),{openImage:k}=od(),{router:A}=va(),j=Y(E);j.current=E;let M=Y(O);M.current=O;let{renderContent:N,isDownloading:P}=Fd({client:E,toast:D}),F=J(()=>{let t=Xd[e.type]||Xd.default,n=y?.default,r=y?.[e.type];return{...t,...n,...r,...Jd(t,{className:l,cardClassName:u,headerClassName:d,contentClassName:f,timestampClassName:p,senderClassName:m,iconClassName:h,detailsClassName:g,artifactsClassName:_,proseClassName:v},n,r)}},[e.type,y,l,u,d,f,p,m,h,g,_,v]),I=J(()=>{let t=``;if(e.message&&(t=typeof e.message==`object`?JSON.stringify(e.message,null,2):e.message.trim?e.message.trim():String(e.message)),typeof t==`string`&&t.includes(`%thinking_message%`)){let e=Math.floor(Math.random()*nd.length);t=t.replace(/%thinking_message%/g,nd[e])}return t},[e.message]),L=J(()=>e.type===$.QUESTION?Td(I):null,[I,e.type]),ee=L?.body??I,R=L?.attachments??[],te=J(()=>e.type===$.QUESTION?Yu(e.details?.editing_action):void 0,[e.details,e.type]),z=J(()=>ee?Kd(ee,e.type,typeof e.message==`string`?e.message:void 0):``,[ee,e.type,e.message]),ne=()=>{let t=I||``,n=typeof e.details==`string`?e.details:e.details?JSON.stringify(e.details,null,2):``,r=[t,n?`\n\nDetails:\n${n}`:``].join(``).trim();navigator.clipboard.writeText(r).then(()=>{D({status:`success`,title:T(`agent.copiedToClipboard`),duration:2e3})})},re=async t=>{let n=typeof I==`string`?I:``;if(!n.trim()){D({status:`error`,title:T(`agent.noContentToExport`),duration:2e3});return}let r=`Message ${fs(e.timestamp).format(`YYYY-MM-DD HH-mm-ss`)}`;await N(n,{format:t,title:r,artifactRunId:le})},ie=typeof I==`string`&&I.trim().length>0,ae=e.type===$.REQUEST_INPUT?e.details?.ux:void 0,oe=J(()=>({a:id({StoreLinkComponent:b,CollectionLinkComponent:x,addStickyParams:e=>A.getTopRouter().navigator.addStickyParams(e)}),img:({node:e,ref:n,...r})=>t(o,{variant:`unstyled`,className:`block p-0`,onClick:()=>r.src&&k(r.src,r.alt),"aria-label":r.alt||r.src||`image`,children:t(`img`,{...r,alt:r.alt??``,className:`max-w-full h-auto rounded-lg shadow-md my-3 cursor-pointer hover:shadow-lg transition-shadow`,loading:`lazy`})})}),[k,b,x,A]),se=n=>{if(typeof n==`object`)return t(`pre`,{className:`text-xs font-mono whitespace-pre-wrap overflow-x-auto bg-gray-100 dark:bg-gray-800 p-2 rounded text-gray-700`,children:JSON.stringify(n,null,2)});let r=e.workflow_run_id;return!r&&typeof n==`string`&&n.includes(`artifact:`)&&console.warn(`[MessageItem] message contains artifact references but workflow_run_id is missing!`,{type:e.type,workflow_run_id:e.workflow_run_id,hasArtifact:n.includes(`artifact:`)}),t(`div`,{className:H(`vprose prose prose-slate dark:prose-invert prose-p:leading-relaxed prose-p:my-3 prose-headings:font-semibold prose-headings:tracking-normal prose-headings:mt-6 prose-headings:mb-3 prose-h1:text-xl prose-h2:text-lg prose-h3:text-base prose-li:my-1 prose-ul:my-3 prose-ol:my-3 prose-table:my-5 prose-pre:my-4 prose-hr:my-6 max-w-none text-[15px] break-words`,F.proseClassName),style:{overflowWrap:`anywhere`},children:t(wt,{artifactRunId:r,onArtifactOpen:s,onProposalSelect:e=>a?.(e),onProposalSubmit:e=>a?.(e),components:oe,children:n})})},[ce,V]=X([]),le=e.workflow_run_id,ue=e.details,de=ue?.outputFiles??ue?.files;q(()=>{(async()=>{if(!le||!Array.isArray(de)||de.length===0){V([]);return}let e=j.current,t=M.current;try{let n=await Promise.all(de.map(async n=>{if(typeof n!=`string`||!n.trim())return null;let r=n.trim(),i=r.startsWith(`artifact:`)?r.slice(9):r,a=i.split(`.`).pop()?.toLowerCase()||``,o=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`svg`]).has(a),s=o?`inline`:`attachment`;try{let n=Ya(le,i,s),a;return a=t?await t.getOrFetch(n,async()=>(await e.files.getArtifactDownloadUrl(le,i,s)).url):(await e.files.getArtifactDownloadUrl(le,i,s)).url,{displayName:r,artifactPath:i,url:a,isImage:o}}catch(e){return console.error(`Failed to resolve artifact URL for ${i}`,e),null}}));V(n.filter(e=>!!e))}catch(e){console.error(`Error loading artifact URLs from message details`,e),V([])}})()},[le,de]);let fe=Pl(e),{Icon:pe}=F;return t(`div`,{className:H(`w-full max-w-full`,F.className),children:n(`div`,{className:H(`border-s-4 bg-white dark:bg-gray-900 mb-4 w-full max-w-full overflow-hidden`,F.borderColor,F.cardClassName),"data-workstream-id":fe,children:[n(`div`,{className:H(`flex items-center justify-between px-4 py-1.5`,F.headerClassName),children:[n(`div`,{className:`flex items-center gap-1.5`,children:[t(`div`,{className:H(r?`animate-fadeIn`:``,F.iconClassName),children:r?t(Ru,{size:`sm`,color:`blue`}):t(pe,{className:`size-4 ${F.iconColor}`})}),t(`span`,{className:H(`text-xs font-medium text-muted`,F.senderClassName),children:Yd[F.sender]?T(Yd[F.sender]):F.sender}),fe!==`main`&&fe!==`all`&&t(i,{variant:`default`,className:`text-xs text-muted ms-1`,children:fe})]}),n(`div`,{className:`flex items-center gap-1.5 print:hidden`,children:[t(Nd,{message:e}),t(`span`,{className:H(`text-[11px] text-muted/70`,F.timestampClassName),children:fs(e.timestamp).format(`HH:mm:ss`)}),t(o,{variant:`ghost`,size:`xs`,onClick:ne,className:`text-muted/50 hover:text-muted h-5 w-5 p-0`,title:T(`agent.copyMessage`),children:t(Dn,{className:`size-3`})}),ie&&n(w,{trigger:t(o,{variant:`ghost`,size:`xs`,className:`text-muted/50 hover:text-muted h-5 w-5 p-0`,title:T(`agent.exportMessage`),disabled:P,children:t(An,{className:`size-3 ${P?`animate-pulse`:``}`})}),children:[t(B,{onClick:()=>re(Ai.pdf),children:T(`agent.exportAsPdf`)}),t(B,{onClick:()=>re(Ai.docx),children:T(`agent.exportAsWord`)})]})]})]}),n(`div`,{className:H(`px-4 pb-3 bg-white dark:bg-gray-900 overflow-hidden`,F.contentClassName),children:[ae?t(dl,{question:typeof I==`string`?I:``,options:ae.options,variant:ae.variant,multiSelect:ae.multiSelect,onSelect:t=>vu(a,e,t,wu(e,t)),onMultiSelect:t=>vu(a,e,t.join(`, `)),allowFreeResponse:!ae.options?.length||!!ae.free_response,placeholder:ae.free_response?.placeholder,submitLabel:ae.free_response?.submit_label,onSubmit:t=>vu(a,e,t,ae.free_response?.metadata),hideBorder:!0,compact:!0,answered:c}):te?t(td,{action:te}):ee&&t(`div`,{className:`message-content break-words w-full`,style:{overflowWrap:`anywhere`,wordBreak:`break-word`},children:se(z||ee)}),R.length>0&&t(bd,{items:R,artifactRunId:le,onOpenArtifact:s,variant:`message`,className:H(ee&&`mt-3`),StoreLinkComponent:b,CollectionLinkComponent:x}),ce.length>0&&n(`div`,{className:H(`mt-3 text-xs`,F.artifactsClassName),children:[t(`div`,{className:`font-medium text-muted mb-1`,children:`Artifacts`}),ce.some(e=>e.isImage)&&t(`div`,{className:`mb-2 flex flex-wrap gap-3`,children:ce.filter(e=>e.isImage).map(({displayName:e,artifactPath:r,url:i})=>n(o,{variant:`unstyled`,className:`max-w-xs cursor-pointer text-start p-0`,onClick:()=>k(i,e),"aria-label":e,children:[t(`img`,{src:i,alt:e,className:`max-w-full h-auto rounded-lg shadow-sm hover:shadow-md transition-shadow`}),t(`div`,{className:`mt-1 text-[11px] text-muted truncate`,children:e})]},`${r}-preview`))}),t(`div`,{className:`flex flex-wrap gap-2 print:hidden`,children:ce.map(({displayName:e,artifactPath:n,url:r})=>t(o,{variant:`outline`,size:`xs`,className:`px-2 py-1 text-xs`,onClick:()=>{if(/\.md$/i.test(n)&&s){s(n);return}window.open(r,`_blank`)},title:n,children:e},n+r))})]}),e.details&&n(`div`,{className:H(`mt-2 print:hidden`,F.detailsClassName),children:[n(o,{variant:`unstyled`,onClick:()=>C(!S),className:`text-[11px] text-muted flex items-center`,children:[T(S?`agent.hideDetails`:`agent.showDetails`),t(`svg`,{xmlns:`http://www.w3.org/2000/svg`,className:`h-3 w-3 ms-1 transition-transform ${S?`rotate-180`:``}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,"aria-hidden":`true`,children:t(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 9l-7 7-7-7`})})]}),S&&t(`div`,{className:`mt-1 p-1.5 bg-muted border border-mixer-muted/40 rounded text-sm`,children:typeof e.details==`string`?se(e.details):t(`pre`,{className:`text-xs font-mono whitespace-pre-wrap overflow-x-auto bg-muted p-2 rounded text-muted`,children:JSON.stringify(e.details,null,2)})})]})]})]})})}const Qd=ct(Zd,(e,t)=>e.message.timestamp===t.message.timestamp&&e.message.type===t.message.type&&e.message.message===t.message.message&&e.message.details===t.message.details&&e.message.workstream_id===t.message.workstream_id&&e.message.workflow_run_id===t.message.workflow_run_id&&e.showPulsatingCircle===t.showPulsatingCircle&&e.onSendMessage===t.onSendMessage&&e.onOpenArtifact===t.onOpenArtifact&&e.requestInputAnswered===t.requestInputAnswered&&e.messageStyleOverrides===t.messageStyleOverrides&&qd.every(n=>e[n]===t[n])),$d={document:kn,collection:Qt,content_type:Wn,interaction:xr,prompt:ti,agent:tn,workflow:fi,process:fi,process_run:Pr,interaction_run:Pr,view:Dr};function ef(e){return $d[e]}function tf(e){switch(e){case`created`:return`success`;case`deleted`:return`outline`;default:return`info`}}function nf({resource:r,workflowRunId:a,showAction:s=!0,className:c}){let{t:l}=Z(),u=Lt()(r,{workflowRunId:a,source:`structured`}),d=ef(r.type),f=r.action===`created`?l(`agent.resourceActionCreated`):r.action===`deleted`?l(`agent.resourceActionDeleted`):l(`agent.resourceActionUpdated`),p=n(e,{children:[t(d,{className:`size-3.5 shrink-0 text-foreground`,"aria-hidden":`true`}),t(`span`,{className:`truncate`,children:r.label}),s&&t(i,{variant:tf(r.action),className:`shrink-0 px-1.5 py-0 text-[10px]`,children:f})]}),m=H(`inline-flex max-w-full items-center gap-1.5 rounded-md border border-border bg-background px-2 py-1 text-xs`,c);return u.kind===`navigate`?t(ga,{href:u.href,topLevelNav:!0,className:H(m,`font-medium transition-colors hover:bg-muted/60`),children:p}):u.kind===`activate`?t(o,{variant:`unstyled`,onClick:u.onActivate,className:H(m,`font-medium transition-colors hover:bg-muted/60`),children:p}):t(`span`,{className:H(m,`text-muted`),children:p})}function rf({resources:e,workflowRunId:r,className:i}){let{t:a}=Z();return e.length===0?null:t(`div`,{className:H(`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1`,i),"data-agent-resource-activity":!0,children:e.map(e=>{let i=e.action===`created`?a(`agent.resourceActionCreated`):e.action===`deleted`?a(`agent.resourceActionDeleted`):a(`agent.resourceActionUpdated`);return n(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[t(`span`,{className:`shrink-0 text-sm text-muted`,children:i}),t(nf,{resource:e,workflowRunId:r,showAction:!1,className:`py-0.5`})]},`${e.type}:${e.id}:${e.action}`)})})}function af({resources:e,workflowRunId:n,className:r}){return e.length===0?null:t(`div`,{className:H(`flex flex-wrap gap-1.5`,r),children:e.map(e=>t(nf,{resource:e,workflowRunId:n},`${e.type}:${e.id}:${e.action}`))})}function of({resources:e,workflowRunId:r,className:i}){let{t:a}=Z(),[s,c]=X(!1);if(e.length===0)return null;let l=e.length>5,u=l&&!s?e.slice(0,5):e;return n(`div`,{className:H(`mx-auto w-full max-w-3xl py-2`,i),"data-agent-resource-summary":!0,children:[t(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:a(`agent.resourcesChanged`)}),t(af,{resources:u,workflowRunId:r}),l&&t(o,{variant:`outline`,size:`xs`,className:`mt-2`,onClick:()=>c(e=>!e),children:s?a(`agent.resourceShowLess`):a(`agent.resourceViewAll`,{total:e.length})})]})}function sf(e){let t=[],n=new Map;for(let r of e)for(let e of Vi(r)){let r=`${e.type}:${e.id}`,i=n.get(r);i||(i={ref:e,firstAction:e.action,lastAction:e.action,createdInTurn:!1},n.set(r,i),t.push(r)),i.ref=e,i.lastAction=e.action,e.action===`created`&&(i.createdInTurn=!0)}let r=[];for(let e of t){let t=n.get(e);if(!t||t.firstAction===`created`&&t.lastAction===`deleted`)continue;let i=t.lastAction===`deleted`?`deleted`:t.lastAction===`created`||t.createdInTurn?`created`:`updated`;r.push({...t.ref,action:i})}return r}function cf(e){if(e.length===0)return[];let t=[],n=[],r=!1;for(let i of e)i.type===$.QUESTION&&r&&(t.push(n),n=[],r=!1),i.type===$.QUESTION&&(r=!0),n.push(i);return n.length>0&&t.push(n),t.map(sf)}function lf(e){if(!jl(e))return!0;let t=e.filter(e=>Pl(e)===`main`);return t[t.length-1]?.type===$.ANSWER}function uf(e,t,n,r){if(n.length===0)return e;let i=[],a=e=>{let t=n[e];!t||t.length===0||e>=n.length-1&&!r||i.push({type:`resource_summary`,key:`resource-summary-${e}`,resources:t})},o=0;for(let n of e){let e=t(n);e&&o>0&&a(o-1),e&&(o+=1),i.push(n)}return a(o>0?o-1:n.length-1),i}function df({text:e,workstreamId:r,artifactRunId:i,revealSpeed:a=300,isComplete:s=!1,timestamp:c,className:l,cardClassName:u,headerClassName:d,contentClassName:f,proseClassName:p,senderClassName:m,iconClassName:h}){let{t:g}=Z(),[_,v]=X(0),[y,b]=X(``),x=Y(null),S=Y(e.length),C=Y(0),w=Y(c||Date.now()),T=Y(e),E=Y(0),D=Y(performance.now()),O=Y(a),k=Y(0);q(()=>{let t=performance.now(),n=e.length-E.current,r=t-D.current;if(n>0&&r>30){let e=n/r*1e3;O.current=O.current*.8+e*.2,O.current=Math.max(50,Math.min(2e3,O.current))}E.current=e.length,D.current=t},[e.length]),S.current=e.length,T.current=e;let A=K(()=>{let e=performance.now(),t=n=>{let r=n-e;e=n;let i=S.current-C.current;if(i<=0){k.current=0,x.current=null;return}let a;if(s)a=Math.max(500,O.current*2);else if(i<20)a=O.current*.85;else if(i<100)a=O.current;else if(i<500){let e=(i-100)/400;a=O.current*(1+e*.5)}else a=O.current*2;let o=a*r/1e3+k.current,c=Math.floor(o);k.current=o-c,c>0&&(C.current=Math.min(C.current+c,S.current),v(C.current)),x.current=requestAnimationFrame(t)};x.current=requestAnimationFrame(t)},[s]);q(()=>(e.length>C.current&&!x.current&&A(),()=>{x.current&&=(cancelAnimationFrame(x.current),null)}),[e.length,A]),q(()=>{s&&C.current<e.length&&(x.current&&=(cancelAnimationFrame(x.current),null),A())},[s,e.length,A]);let j=Y(null),M=Y(0);q(()=>{(_>=S.current||s)&&(b(T.current.slice(0,_)),M.current=_)},[_,s]);let N=_<e.length&&!s;q(()=>{if(!N){j.current&&=(clearInterval(j.current),null);return}return j.current||=window.setInterval(()=>{let e=C.current;e>M.current&&(b(T.current.slice(0,e)),M.current=e)},33),()=>{j.current&&=(clearInterval(j.current),null)}},[N]);let P=Xe(),F=J(()=>fs(w.current).format(`HH:mm:ss`),[]),I=_<e.length,L=J(()=>{let t=y||e.slice(0,_);return I?t+`│`:t},[y,e,_,I]);return e?t(`div`,{className:H(`w-full max-w-full`,l),children:n(`div`,{className:H(`border-s-4 bg-white dark:bg-gray-900 mb-4 border-s-purple-500 w-full max-w-full overflow-hidden`,u),"data-workstream-id":r,children:[n(`div`,{className:H(`flex items-center justify-between px-4 py-1.5`,d),children:[n(`div`,{className:`flex items-center gap-1.5`,children:[t(`div`,{className:H(`animate-fadeIn`,h),children:I?t(`span`,{className:`size-2 rounded-full bg-blue-500 animate-pulse inline-block`}):t(Zt,{className:`size-4 text-purple-600 dark:text-purple-400`})}),t(`span`,{className:H(`text-xs font-medium text-muted`,m),children:`Agent`}),r&&r!==`main`&&n(`span`,{className:`text-xs text-muted`,children:[`• Task `,r]})]}),n(`div`,{className:`flex items-center gap-2 text-muted`,children:[t(`span`,{className:`text-[11px]`,children:F}),t(o,{variant:`ghost`,size:`xs`,onClick:()=>{navigator.clipboard.writeText(e).then(()=>{P({status:`success`,title:g(`agent.copiedToClipboard`),duration:2e3})})},className:`size-6 p-0 hover:bg-gray-100 dark:hover:bg-gray-800`,title:g(`agent.copyMessage`),children:t(Dn,{className:`size-3`})})]})]}),n(`div`,{className:H(`px-3 pb-2 streaming-content`,I&&`streaming-active`,f),children:[t(`div`,{className:H(`vprose prose prose-slate dark:prose-invert prose-p:leading-relaxed prose-p:my-3 prose-headings:font-semibold prose-headings:tracking-normal prose-headings:mt-6 prose-headings:mb-3 prose-h1:text-xl prose-h2:text-lg prose-h3:text-base prose-li:my-1 prose-ul:my-3 prose-ol:my-3 prose-table:my-5 prose-pre:my-4 prose-hr:my-6 max-w-none text-[15px] break-words`,p),style:{overflowWrap:`anywhere`},children:t(wt,{artifactRunId:i,children:L})}),t(`style`,{children:`
|
|
30
28
|
/* Ensure inline elements flow properly */
|
|
31
29
|
.streaming-content p:last-child,
|
|
32
30
|
.streaming-content li:last-child {
|
|
@@ -37,11 +35,11 @@ $&`)),t.includes(` - `)&&(t=t.replace(/(^|\S)\s+-\s+/g,`$1
|
|
|
37
35
|
mask-image: linear-gradient(to right, black 97%, transparent 100%);
|
|
38
36
|
-webkit-mask-image: linear-gradient(to right, black 97%, transparent 100%);
|
|
39
37
|
}
|
|
40
|
-
`})]})]})}):null}const Kf=W.memo(Gf);function qf(e){return e.message?typeof e.message==`object`?JSON.stringify(e.message,null,2):String(e.message).trim():``}function Jf(e){let t=e.replace(/\s+/g,` `).trim().toLowerCase();return t===`thinking`||t===`thinking...`||t===`working`||t===`working...`||t===`waiting`||t===`waiting...`}function Yf(e){return e.type===Q.THOUGHT&&e.details?.display_role===`thinking`}function Xf(e){if(Yf(e))return!0;if(e.type!==Q.WARNING)return!1;let t=e.details,n=qf(e).replace(/^[^A-Za-z0-9]+/,``).toLowerCase();return typeof t?.attempt==`number`&&typeof t?.maxAttempts==`number`&&typeof t?.estimatedBackoffSeconds==`number`&&typeof t?.activityId==`string`&&(n.startsWith(`retrying operation`)||n.startsWith(`retrying checkpoint operation`))}function Zf(e){if(typeof e==`number`)return e;if(!e)return-1/0;let t=new Date(e).getTime();return Number.isFinite(t)?t:-1/0}function Qf(e){return e.reduce((e,t)=>Math.max(e,Zf(t.timestamp)),-1/0)}function $f(e,t){let n=e.details?.[t];return typeof n==`string`&&n.trim()||void 0}function ep(e,t,n){if(!e.some(Xf))return e;if(!t)return e.filter(e=>!Xf(e));let r=-1,i=-1;return e.forEach((e,t)=>{Xf(e)?i=t:r=t}),e.filter((e,t)=>!Xf(e)||t===i&&t>r&&Zf(e.timestamp)>=n)}function tp(e){if(ru(e))return!1;let t=qf(e);return!t||Jf(t)?!1:e.type===Q.ANSWER||!Du(e)&&e.type===Q.THOUGHT&&!!e.details?.streamed}function np(e){if(e.type!==Q.ERROR&&e.type!==Q.WARNING)return!1;let t=e.details;return!!(t?.tool||t?.tool_status||t?.tool_run_id||t?.activity_group_id||t?.tool_event)}function rp(e){if(e.type!==Q.ERROR||np(e))return!1;let t=e.details;return qf(e).startsWith(`Error analyzing conversation:`)&&typeof t?.error==`string`}function ip(e){if(e.type!==Q.ERROR)return!1;let t=e.details;if(t?.event_class!==`activity`||t.workstream_event)return!1;let n=typeof e.workstream_id==`string`&&e.workstream_id.trim()?e.workstream_id.trim():typeof t.workstream_id==`string`?t.workstream_id.trim():``,r=n.toLowerCase();return!n||r===`main`||r===`all`?!1:!(t.tool||t.tool_status||t.tool_run_id||t.activity_group_id||t.tool_event)}function ap(e){return ru(e)||ip(e)?!1:e.type===Q.QUESTION||!!ou(e)||tp(e)||e.type===Q.REQUEST_INPUT&&!id(e)||e.type===Q.TERMINATED||(e.type===Q.ERROR||e.type===Q.WARNING)&&!np(e)&&!Xf(e)}function op(e){let t=e.details?.tool_status;if(t===`running`||t===`completed`||t===`error`||t===`warning`)return t;if(e.type===Q.ERROR)return`error`;if(e.type===Q.WARNING)return`warning`}function sp(e,t){for(let n=e.length-1;n>=0;n--){let r=op(e[n]);if(r===`error`||r===`warning`)return r;if(r)return t?`running`:`completed`}return t?`running`:`completed`}function cp(e,t){return Ou(e)&&!Yf(e)&&t.length>0&&t.every(Yf)}function lp(e){return ru(e)||tp(e)||ou(e)?!1:ip(e)||Xf(e)||id(e)||np(e)||Du(e)||Ou(e)||e.type===Q.UPDATE||e.type===Q.PLAN?!0:e.type===Q.THOUGHT&&!e.details?.streamed}function up(e,t,n=Qf(e)){let r=[],i=[],a=new Set,o=(e,t)=>{if(i.length===0)return;let a=ep(i,e,n);if(a.length===0){i=[];return}let o=a[0],s=a[a.length-1],c=sp(a,e);r.push({type:`work`,id:e?`${o.timestamp}-active`:`${o.timestamp}-${s.timestamp}-${a.length}`,messages:a,isActive:e,status:c,startTimestamp:o.timestamp,endTimestamp:t?.timestamp??s.timestamp}),i=[]};for(let t of e){let e=ou(t),n=e?null:su(t),s=e??n;if(s){let n=a.has(s.workstreamId);if(a.add(s.workstreamId),e||!n){o(!1,t),r.push({type:`message`,message:t});continue}}if(t.type===Q.COMPLETE||t.type===Q.IDLE){if(hu(t)){let e=i[0]?.timestamp;o(!1,t);let n=r[r.length-1];r.push({type:`stopped`,message:t,startTimestamp:e!==void 0&&n?.type===`work`?n.startTimestamp:e??t.timestamp,endTimestamp:t.timestamp});continue}o(!1,t);continue}if(lp(t)||i.length>0&&rp(t)){if(cp(t,i)){let e=r[r.length-1];if(e?.type===`work`&&!e.isActive){r.pop(),i=[...e.messages,t];continue}}i.push(t);continue}ap(t)&&(o(!1,t),r.push({type:`message`,message:t}))}return o(!t),r}function dp(e,t){if(e.activityId){let n=t.find(t=>Ou(t)&&($f(t,`activity_id`)===e.activityId||$f(t,`activity_group_id`)===e.activityId));if(n)return n;let r=t.find(t=>$f(t,`activity_id`)===e.activityId&&$f(t,`activity_group_id`))?.details?.activity_group_id;if(typeof r==`string`){let e=t.find(e=>Ou(e)&&$f(e,`activity_group_id`)===r);if(e)return e}}if(e.isComplete)return;let n=Zf(e.startTimestamp);if(!Number.isFinite(n))return;let r=[...t].filter(e=>Zf(e.timestamp)>=n).sort((e,t)=>Zf(e.timestamp)-Zf(t.timestamp));for(let e of r){if(Zf(e.timestamp)-n>6e4)return;if(Ou(e))return e;if(ap(e))return}}function fp(e,t){if(t.size===0)return e;let n=e.find(e=>e.workflow_run_id)?.workflow_run_id??``,r=[];return t.forEach((t,i)=>{let a=t.text.trim();if(!a||wu(t,e)||nu(a,t.workstreamId))return;let o=dp(t,e),s=o?$f(o,`activity_group_id`):void 0;r.push({timestamp:t.startTimestamp,workflow_run_id:n,type:o?Q.THOUGHT:Q.ANSWER,message:a,workstream_id:t.workstreamId,details:{activity_id:t.activityId,activity_group_id:s,display_role:o?`tool_preamble`:void 0,source:`streaming_summary`,streamed:!0,streaming_id:i,tools:o?.details?.tool?[o.details.tool]:void 0}})}),r.length===0?e:[...e,...r].sort((e,t)=>Zf(e.timestamp)-Zf(t.timestamp))}function pp(e,t,n){let r=e[e.length-1];return r?r.type===`work`?r.endTimestamp??r.startTimestamp:r.message.timestamp??n:t.reduce((e,t)=>{let n=Zf(t.timestamp);return!Number.isFinite(n)||n>=e.ms?e:{timestamp:t.timestamp,ms:n}},{ms:1/0}).timestamp??n}function mp(e,t,n){if(!t||n||e.some(e=>e.type===`work`&&e.isActive))return!1;let r=e[e.length-1];return r?r.type===`work`||r.message.type===Q.QUESTION:!1}function hp(e){let t=e[e.length-1];return t?t.type===`message`&&t.message.type===Q.QUESTION&&e.length===1:!1}const gp=new Set([`tool`,`tool_event`,`tool_run_id`,`tool_use_id`,`activity_group_id`,`event_class`,`tool_iteration`,`tool_status`,`message_to_human`,`tools`,`streamed`,`files`,`outputFiles`,`display_role`,`duration_ms`,`observation`,`progress_messages`,`resources`,`browseruse`,`browser_use`]);function _p(e){return e?Object.entries(e).filter(([e,t])=>!gp.has(e)&&t!=null&&t!==``):[]}function vp(e){return e.replace(/_/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function yp(e){let t=e?.progress_messages;return Array.isArray(t)?t.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e,n=typeof t.message==`string`?t.message.trim():``;return n?[{message:n,status:typeof t.status==`string`?t.status:void 0,timestamp:typeof t.timestamp==`number`||typeof t.timestamp==`string`?t.timestamp:void 0}]:[]}):[]}function bp(e){return[`progress`,e.timestamp??`no-time`,e.status??`status`,e.message].join(`:`)}function xp(e){let t=e.details,n=typeof t?.tool_run_id==`string`?t.tool_run_id:void 0;if(n)return`tool-run:${n}`;let r=typeof t?.activity_group_id==`string`?t.activity_group_id:void 0,i=typeof t?.tool_use_id==`string`?t.tool_use_id:void 0;return r||i?`tool:${r??`no-activity`}:${i??`no-use`}`:[`message`,e.workstream_id??`main`,e.type,e.timestamp,kp(e)].join(`:`)}function Sp(e,t){return e.timestamp===t.timestamp&&e.type===t.type&&e.message===t.message&&e.details===t.details&&e.workstream_id===t.workstream_id&&e.workflow_run_id===t.workflow_run_id}function Cp(e){switch(e){case`completed`:return`bg-green-50 dark:bg-green-900/30 text-green-700 dark:text-green-300 border-green-200 dark:border-green-800`;case`running`:return`bg-blue-50 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 border-blue-200 dark:border-blue-800`;case`error`:return`bg-red-50 dark:bg-red-900/30 text-red-700 dark:text-red-300 border-red-200 dark:border-red-800`;case`warning`:return`bg-yellow-50 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-300 border-yellow-200 dark:border-yellow-800`;default:return``}}function wp(e){let t=new Map,n=[];for(let r of e){let e=r.details?.tool_run_id;e?(t.has(e)||t.set(e,[]),t.get(e)?.push(r)):n.push(r)}for(let[e,r]of t){if(r.length<=1){n.push(...r);continue}r.sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime()));let e=r[r.length-1],t=r.find(e=>e.details?.tool_event===`started`),i=r.find(e=>e.details?.tool_status===`running`),a=t??i??r.find(e=>e.message?.trim()),o=(typeof a?.details?.message_to_human==`string`?a.details.message_to_human:void 0)||a?.message||e.message,s=r.filter(e=>e.details?.tool_event===`progress`&&e.message?.trim()).map(e=>({message:e.message.trim(),status:e.details?.tool_status,timestamp:e.timestamp})),c={};for(let e of r)Object.assign(c,e.details);s.length>0&&(c.progress_messages=s),n.push({...e,message:o,details:c})}return n.sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),n}const Tp=e=>/\.(png|jpg|jpeg|gif|webp|svg)(\?|$)/i.test(e);function Ep({files:e,className:r}){let{t:i}=X(),{openImage:a}=Hd();return!e||e.length===0?null:t(`div`,{className:H(`mt-2 flex flex-wrap gap-2`,r),children:e.map(e=>{let r=e.split(`/`).pop()?.split(`?`)[0]||`file`;return Tp(e)?t(o,{variant:`unstyled`,className:`cursor-pointer p-0`,onClick:()=>a(e,r),title:i(`agent.clickToEnlarge`),"aria-label":r,children:t(`img`,{src:e,alt:r,className:`max-w-[300px] max-h-[200px] rounded border hover:opacity-80 transition-opacity hover:shadow-lg`})},e):n(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 px-2 py-1 bg-muted rounded text-xs hover:bg-muted/80`,children:[`📎 `,r]},e)})})}const Dp=e=>{if(!e)return;let t=e.files??e.outputFiles;return Array.isArray(t)?t:void 0},Op=e=>{let t=e.details;return e.type===Q.THOUGHT&&t?.display_role===`tool_preamble`},kp=e=>{let t=e.details;if(Op(e))return`assistant`;if(t?.tool)return t.tool;switch(e.type){case Q.UPDATE:return`update`;case Q.WARNING:return`warning`;case Q.ERROR:return`error`;case Q.SYSTEM:return`system`;default:return`activity`}},Ap=e=>Op(e)?`text-[10px] px-1.5 py-0.5 rounded-md bg-gray-50 dark:bg-gray-800 text-gray-700 dark:text-gray-300 border border-gray-200 dark:border-gray-700 font-medium`:`text-[10px] px-1.5 py-0.5 rounded-md bg-purple-50 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300 border border-purple-200 dark:border-purple-800 font-medium`;function jp({message:e,isExpanded:r,onToggle:i,artifactRunId:a,classNames:s={}}){let{t:c}=X(),[l,u]=Y([]),d=Ye(),{client:f}=Z(),p=Za(),m=J(f);m.current=f;let h=J(p);h.current=p;let g=e.details,_=kp(e),v=Ap(e),y=Dp(g),b=typeof e.message==`string`?e.message:``;K(()=>{if(!y||y.length===0||!a){u([]);return}let e=!1;return(async()=>{let t=m.current,n=h.current,r=await Promise.all(y.map(async e=>{if(!e||typeof e!=`string`)return null;if(e.startsWith(`http://`)||e.startsWith(`https://`))return e;let r=e.startsWith(`artifact:`)?e.slice(9):e,i=r.split(`.`).pop()?.toLowerCase()||``,o=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`svg`]).has(i)?`inline`:`attachment`;try{let e=$a(a,r,o);return n?await n.getOrFetch(e,async()=>(await t.files.getArtifactDownloadUrl(a,r,o)).url):(await t.files.getArtifactDownloadUrl(a,r,o)).url}catch(e){return console.error(`Failed to resolve artifact URL for ${r}`,e),null}}));e||u(r.filter(e=>!!e))})(),()=>{e=!0}},[y,a]);let x=l.filter(e=>Tp(e)),S=l.filter(e=>!Tp(e)),C=()=>{let e=[b,g?`\n\nDetails:\n${JSON.stringify(g,null,2)}`:``].join(``).trim();navigator.clipboard.writeText(e).then(()=>{d({status:`success`,title:c(`agent.copiedToClipboard`),duration:2e3})})};return n(`div`,{className:H(`border-b border-gray-100 dark:border-gray-800 last:border-b-0`,s.itemClassName),children:[n(`div`,{role:`button`,tabIndex:0,className:H(`flex items-start justify-between px-3 py-2 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800/50 transition-colors`,s.itemHeaderClassName),onClick:i,onKeyDown:Ve(i),children:[n(`div`,{className:`flex items-start gap-2 flex-1 min-w-0`,children:[t(`div`,{className:`flex-shrink-0 pt-0.5`,children:r?t(an,{className:`size-3 text-muted`}):t(cn,{className:`size-3 text-muted cn-rtl-flip`})}),t(`div`,{className:`flex-1 min-w-0`,children:b?t(`span`,{className:`text-xs text-foreground line-clamp-2`,children:b}):n(`span`,{className:`text-xs text-muted italic`,children:[`Activity: `,_]})})]}),n(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[!r&&t(`span`,{className:H(v,s.toolBadgeClassName),children:_}),t(o,{variant:`ghost`,size:`xs`,onClick:e=>{e.stopPropagation(),C()},className:`text-muted opacity-0 group-hover:opacity-100 transition-opacity`,title:c(`agent.copyMessage`),children:t(Sn,{className:`size-3`})})]})]}),x.length>0&&t(`div`,{className:`px-3 pb-1.5`,children:t(Ep,{files:x})}),r&&(()=>{let r=g?.tool_status,i=_p(g),o=yp(g);return n(`div`,{className:H(`px-4 py-2 bg-gray-50/50 dark:bg-gray-800/30`,s.itemContentClassName),children:[n(`div`,{className:`flex items-center gap-2 mb-2 flex-wrap`,children:[t(`span`,{className:H(v,s.toolBadgeClassName),children:_}),r&&t(`span`,{className:H(`text-[10px] px-1.5 py-0.5 rounded-md border font-medium`,Cp(r)),children:r}),t(`span`,{className:`text-[10px] text-muted/70`,children:Ki(e.timestamp).format(`HH:mm:ss`)})]}),i.length>0&&t(`div`,{className:`mb-2 space-y-0.5`,children:i.map(([e,r])=>n(`div`,{className:`flex gap-1.5 text-xs`,children:[n(`span`,{className:`text-muted font-medium flex-shrink-0`,children:[vp(e),`:`]}),t(`span`,{className:`text-foreground break-all`,children:typeof r==`object`?JSON.stringify(r):String(r)})]},e))}),o.length>0&&n(`div`,{className:`mb-2 space-y-1`,children:[t(`div`,{className:`text-[10px] uppercase tracking-wide text-muted/70 font-medium`,children:c(`agent.progress`)}),o.map(e=>n(`div`,{className:`text-xs text-muted`,children:[e.timestamp&&t(`span`,{className:`me-1 text-muted/60`,children:Ki(e.timestamp).format(`HH:mm:ss`)}),t(`span`,{children:e.message})]},bp(e)))]}),(()=>{let e=typeof g?.observation==`string`?g.observation:void 0;return e&&e!==b?t(`div`,{className:`vprose prose prose-slate dark:prose-invert prose-p:leading-relaxed prose-p:my-1.5 max-w-none text-sm`,children:t(bt,{artifactRunId:a,children:e})}):null})(),S.length>0&&t(Ep,{files:S})]})})()]})}function Mp({files:e,artifactRunId:n}){let[r,i]=Y([]),{client:a}=Z(),o=Za(),s=J(a);s.current=a;let c=J(o);return c.current=o,K(()=>{if(!e||e.length===0||!n){i([]);return}let t=!1;return(async()=>{let r=s.current,a=c.current,o=await Promise.all(e.map(async e=>{if(!e||typeof e!=`string`)return null;let t=e.startsWith(`artifact:`)?e.slice(9):e,i=t.split(`.`).pop()?.toLowerCase()||``;if(new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`svg`]).has(i))return null;if(t.startsWith(`http://`)||t.startsWith(`https://`))return t;try{let e=$a(n,t,`attachment`);return a?await a.getOrFetch(e,async()=>(await r.files.getArtifactDownloadUrl(n,t,`attachment`)).url):(await r.files.getArtifactDownloadUrl(n,t,`attachment`)).url}catch(e){return console.error(`Failed to resolve artifact URL for ${t}`,e),null}}));t||i(o.filter(e=>!!e))})(),()=>{t=!0}},[e,n]),r.length===0?null:t(`div`,{className:`ps-4 pe-2 pb-1.5`,children:t(Ep,{files:r})})}function Np({messages:e,artifactRunId:n}){let[r,i]=Y([]),{client:a}=Z(),o=Za(),s=J(a);s.current=a;let c=J(o);return c.current=o,K(()=>{if(!n||e.length===0){i([]);return}let t=e[e.length-1].details,r=Dp(t);if(!r||r.length===0){i([]);return}let a=!1;return(async()=>{let e=s.current,t=c.current,o=await Promise.all(r.map(async r=>{if(!r||typeof r!=`string`)return null;let i=r.startsWith(`artifact:`)?r.slice(9):r,a=i.split(`.`).pop()?.toLowerCase()||``;if(!new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`svg`]).has(a))return null;if(i.startsWith(`http://`)||i.startsWith(`https://`))return i;try{let r=$a(n,i,`inline`);return t?await t.getOrFetch(r,async()=>(await e.files.getArtifactDownloadUrl(n,i,`inline`)).url):(await e.files.getArtifactDownloadUrl(n,i,`inline`)).url}catch(e){return console.error(`Failed to resolve artifact URL for ${i}`,e),null}}));a||i(o.filter(e=>!!e))})(),()=>{a=!0}},[e,n]),r.length===0?null:t(`div`,{className:`px-3 py-1.5 border-b border-gray-100 dark:border-gray-800`,children:t(Ep,{files:r})})}function Pp({messages:r,showPulsatingCircle:i=!1,toolRunId:a,toolStatus:s,preambleText:c,preambleMessage:l,rootClassName:u,headerClassName:d,senderClassName:f,toolSummaryClassName:p,toolBadgeClassName:m,itemClassName:h,itemHeaderClassName:g,itemContentClassName:_}){let v=q(()=>wp(r),[r]),y=q(()=>v.map(xp),[v]),[b,x]=Y(!0),[S,C]=Y(new Set),[w,T]=Y(new Set),E=J(y),{t:D}=X(),O=Ye(),k=v.find(e=>e.workflow_run_id)?.workflow_run_id??v[0]?.workflow_run_id,A=q(()=>{let e=new Set,t=[];for(let n of v)for(let r of Fi(n)){let n=`${r.type}:${r.id}:${r.action}`;e.has(n)||(e.add(n),t.push(r))}return t},[v]),j=()=>i?t(bd,{size:`sm`,color:`blue`}):s===`running`?t(`span`,{className:`size-2 rounded-full bg-blue-500 inline-block`}):s===`completed`?t(en,{className:`size-4 text-success`}):s===`error`?t(zt,{className:`size-4 text-destructive`}):s===`warning`?t(Vt,{className:`size-4 text-attention`}):t(Kt,{className:`size-4 text-purple-600 dark:text-purple-400`}),M=()=>s===`completed`?`border-s-success`:s===`error`?`border-s-destructive`:s===`warning`?`border-s-attention`:`border-s-purple-500`;K(()=>{let e=E.current,t=new Set(e),n=y.filter(e=>!t.has(e));if(n.length>0){T(new Set(n));let e=setTimeout(()=>{T(new Set)},500);return E.current=y,()=>clearTimeout(e)}E.current=y},[y]);let N=v[0],P=v[v.length-1],F=N.timestamp,I=P.timestamp,L=v.map(e=>kp(e)),ee=new Set(L).size===1?`${v.length}× ${L[0]}`:`${v.length} activity updates`,R=e=>{C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},te=()=>{let e=v.map(e=>{let t=e.details;return`[${kp(e)}] ${e.message||``}\n${t?JSON.stringify(t,null,2):``}`}).join(`
|
|
38
|
+
`})]})]})}):null}const ff=G.memo(df);function pf(e){return e.message?typeof e.message==`object`?JSON.stringify(e.message,null,2):String(e.message).trim():``}function mf(e){let t=e.replace(/\s+/g,` `).trim().toLowerCase();return t===`thinking`||t===`thinking...`||t===`working`||t===`working...`||t===`waiting`||t===`waiting...`}function hf(e){return e.type===$.THOUGHT&&e.details?.display_role===`thinking`}function gf(e){if(hf(e))return!0;if(e.type!==$.WARNING)return!1;let t=e.details,n=pf(e).replace(/^[^A-Za-z0-9]+/,``).toLowerCase();return typeof t?.attempt==`number`&&typeof t?.maxAttempts==`number`&&typeof t?.estimatedBackoffSeconds==`number`&&typeof t?.activityId==`string`&&(n.startsWith(`retrying operation`)||n.startsWith(`retrying checkpoint operation`))}function _f(e){if(typeof e==`number`)return e;if(!e)return-1/0;let t=new Date(e).getTime();return Number.isFinite(t)?t:-1/0}function vf(e){return e.reduce((e,t)=>Math.max(e,_f(t.timestamp)),-1/0)}function yf(e,t){let n=e.details?.[t];return typeof n==`string`&&n.trim()||void 0}function bf(e,t,n){if(!e.some(gf))return e;if(!t)return e.filter(e=>!gf(e));let r=-1,i=-1;return e.forEach((e,t)=>{gf(e)?i=t:r=t}),e.filter((e,t)=>!gf(e)||t===i&&t>r&&_f(e.timestamp)>=n)}function xf(e){if(bl(e))return!1;let t=pf(e);return!t||mf(t)?!1:e.type===$.ANSWER||!Gl(e)&&e.type===$.THOUGHT&&!!e.details?.streamed}function Sf(e){if(e.type!==$.ERROR&&e.type!==$.WARNING)return!1;let t=e.details;return!!(t?.tool||t?.tool_status||t?.tool_run_id||t?.activity_group_id||t?.tool_event)}function Cf(e){if(e.type!==$.ERROR||Sf(e))return!1;let t=e.details;return pf(e).startsWith(`Error analyzing conversation:`)&&typeof t?.error==`string`}function wf(e){if(e.type!==$.ERROR)return!1;let t=e.details;if(t?.event_class!==`activity`||t.workstream_event)return!1;let n=typeof e.workstream_id==`string`&&e.workstream_id.trim()?e.workstream_id.trim():typeof t.workstream_id==`string`?t.workstream_id.trim():``,r=n.toLowerCase();return!n||r===`main`||r===`all`?!1:!(t.tool||t.tool_status||t.tool_run_id||t.activity_group_id||t.tool_event)}function Tf(e){return bl(e)||wf(e)?!1:e.type===$.QUESTION||!!Cl(e)||xf(e)||e.type===$.REQUEST_INPUT&&!Su(e)||e.type===$.TERMINATED||(e.type===$.ERROR||e.type===$.WARNING)&&!Sf(e)&&!gf(e)}function Ef(e){let t=e.details?.tool_status;if(t===`running`||t===`completed`||t===`error`||t===`warning`)return t;if(e.type===$.ERROR)return`error`;if(e.type===$.WARNING)return`warning`}function Df(e,t){for(let n=e.length-1;n>=0;n--){let r=Ef(e[n]);if(r===`error`||r===`warning`)return r;if(r)return t?`running`:`completed`}return t?`running`:`completed`}function Of(e,t){return Kl(e)&&!hf(e)&&t.length>0&&t.every(hf)}function kf(e){return bl(e)||xf(e)||Cl(e)?!1:wf(e)||gf(e)||Su(e)||Sf(e)||Gl(e)||Kl(e)||e.type===$.UPDATE||e.type===$.PLAN?!0:e.type===$.THOUGHT&&!e.details?.streamed}function Af(e,t,n=vf(e)){let r=[],i=[],a=new Set,o=(e,t)=>{if(i.length===0)return;let a=bf(i,e,n);if(a.length===0){i=[];return}let o=a[0],s=a[a.length-1],c=Df(a,e);r.push({type:`work`,id:e?`${o.timestamp}-active`:`${o.timestamp}-${s.timestamp}-${a.length}`,messages:a,isActive:e,status:c,startTimestamp:o.timestamp,endTimestamp:t?.timestamp??s.timestamp}),i=[]};for(let t of e){let e=Cl(t),n=e?null:wl(t),s=e??n;if(s){let n=a.has(s.workstreamId);if(a.add(s.workstreamId),e||!n){o(!1,t),r.push({type:`message`,message:t});continue}}if(t.type===$.COMPLETE||t.type===$.IDLE){if(Ml(t)){let e=i[0]?.timestamp;o(!1,t);let n=r[r.length-1];r.push({type:`stopped`,message:t,startTimestamp:e!==void 0&&n?.type===`work`?n.startTimestamp:e??t.timestamp,endTimestamp:t.timestamp});continue}o(!1,t);continue}if(kf(t)||i.length>0&&Cf(t)){if(Of(t,i)){let e=r[r.length-1];if(e?.type===`work`&&!e.isActive){r.pop(),i=[...e.messages,t];continue}}i.push(t);continue}Tf(t)&&(o(!1,t),r.push({type:`message`,message:t}))}return o(!t),r}function jf(e,t){if(e.activityId){let n=t.find(t=>Kl(t)&&(yf(t,`activity_id`)===e.activityId||yf(t,`activity_group_id`)===e.activityId));if(n)return n;let r=t.find(t=>yf(t,`activity_id`)===e.activityId&&yf(t,`activity_group_id`))?.details?.activity_group_id;if(typeof r==`string`){let e=t.find(e=>Kl(e)&&yf(e,`activity_group_id`)===r);if(e)return e}}if(e.isComplete)return;let n=_f(e.startTimestamp);if(!Number.isFinite(n))return;let r=[...t].filter(e=>_f(e.timestamp)>=n).sort((e,t)=>_f(e.timestamp)-_f(t.timestamp));for(let e of r){if(_f(e.timestamp)-n>6e4)return;if(Kl(e))return e;if(Tf(e))return}}function Mf(e,t){if(t.size===0)return e;let n=e.find(e=>e.workflow_run_id)?.workflow_run_id??``,r=[];return t.forEach((t,i)=>{let a=t.text.trim();if(!a||Hl(t,e)||yl(a,t.workstreamId))return;let o=jf(t,e),s=o?yf(o,`activity_group_id`):void 0;r.push({timestamp:t.startTimestamp,workflow_run_id:n,type:o?$.THOUGHT:$.ANSWER,message:a,workstream_id:t.workstreamId,details:{activity_id:t.activityId,activity_group_id:s,display_role:o?`tool_preamble`:void 0,source:`streaming_summary`,streamed:!0,streaming_id:i,tools:o?.details?.tool?[o.details.tool]:void 0}})}),r.length===0?e:[...e,...r].sort((e,t)=>_f(e.timestamp)-_f(t.timestamp))}function Nf(e,t,n){let r=e[e.length-1];return r?r.type===`work`?r.endTimestamp??r.startTimestamp:r.message.timestamp??n:t.reduce((e,t)=>{let n=_f(t.timestamp);return!Number.isFinite(n)||n>=e.ms?e:{timestamp:t.timestamp,ms:n}},{ms:1/0}).timestamp??n}function Pf(e,t,n){if(!t||n||e.some(e=>e.type===`work`&&e.isActive))return!1;let r=e[e.length-1];return r?r.type===`work`||r.message.type===$.QUESTION:!1}function Ff(e){let t=e[e.length-1];return t?t.type===`message`&&t.message.type===$.QUESTION&&e.length===1:!1}const If=new Set([`tool`,`tool_event`,`tool_run_id`,`tool_use_id`,`activity_group_id`,`event_class`,`tool_iteration`,`tool_status`,`message_to_human`,`tools`,`streamed`,`files`,`outputFiles`,`display_role`,`duration_ms`,`observation`,`progress_messages`,`resources`,`browseruse`,`browser_use`]);function Lf(e){return e?Object.entries(e).filter(([e,t])=>!If.has(e)&&t!=null&&t!==``):[]}function Rf(e){return e.replace(/_/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function zf(e){let t=e?.progress_messages;return Array.isArray(t)?t.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e,n=typeof t.message==`string`?t.message.trim():``;return n?[{message:n,status:typeof t.status==`string`?t.status:void 0,timestamp:typeof t.timestamp==`number`||typeof t.timestamp==`string`?t.timestamp:void 0}]:[]}):[]}function Bf(e){return[`progress`,e.timestamp??`no-time`,e.status??`status`,e.message].join(`:`)}function Vf(e){let t=e.details,n=typeof t?.tool_run_id==`string`?t.tool_run_id:void 0;if(n)return`tool-run:${n}`;let r=typeof t?.activity_group_id==`string`?t.activity_group_id:void 0,i=typeof t?.tool_use_id==`string`?t.tool_use_id:void 0;return r||i?`tool:${r??`no-activity`}:${i??`no-use`}`:[`message`,e.workstream_id??`main`,e.type,e.timestamp,Yf(e)].join(`:`)}function Hf(e,t){return e.timestamp===t.timestamp&&e.type===t.type&&e.message===t.message&&e.details===t.details&&e.workstream_id===t.workstream_id&&e.workflow_run_id===t.workflow_run_id}function Uf(e){switch(e){case`completed`:return`bg-green-50 dark:bg-green-900/30 text-green-700 dark:text-green-300 border-green-200 dark:border-green-800`;case`running`:return`bg-blue-50 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 border-blue-200 dark:border-blue-800`;case`error`:return`bg-red-50 dark:bg-red-900/30 text-red-700 dark:text-red-300 border-red-200 dark:border-red-800`;case`warning`:return`bg-yellow-50 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-300 border-yellow-200 dark:border-yellow-800`;default:return``}}function Wf(e){let t=new Map,n=[];for(let r of e){let e=r.details?.tool_run_id;e?(t.has(e)||t.set(e,[]),t.get(e)?.push(r)):n.push(r)}for(let[e,r]of t){if(r.length<=1){n.push(...r);continue}r.sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime()));let e=r[r.length-1],t=r.find(e=>e.details?.tool_event===`started`),i=r.find(e=>e.details?.tool_status===`running`),a=t??i??r.find(e=>e.message?.trim()),o=(typeof a?.details?.message_to_human==`string`?a.details.message_to_human:void 0)||a?.message||e.message,s=r.filter(e=>e.details?.tool_event===`progress`&&e.message?.trim()).map(e=>({message:e.message.trim(),status:e.details?.tool_status,timestamp:e.timestamp})),c={};for(let e of r)Object.assign(c,e.details);s.length>0&&(c.progress_messages=s),n.push({...e,message:o,details:c})}return n.sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),n}const Gf=e=>/\.(png|jpg|jpeg|gif|webp|svg)(\?|$)/i.test(e);function Kf({files:e,className:r}){let{t:i}=Z(),{openImage:a}=od();return!e||e.length===0?null:t(`div`,{className:H(`mt-2 flex flex-wrap gap-2`,r),children:e.map(e=>{let r=e.split(`/`).pop()?.split(`?`)[0]||`file`;return Gf(e)?t(o,{variant:`unstyled`,className:`cursor-pointer p-0`,onClick:()=>a(e,r),title:i(`agent.clickToEnlarge`),"aria-label":r,children:t(`img`,{src:e,alt:r,className:`max-w-[300px] max-h-[200px] rounded border hover:opacity-80 transition-opacity hover:shadow-lg`})},e):n(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 px-2 py-1 bg-muted rounded text-xs hover:bg-muted/80`,children:[`📎 `,r]},e)})})}const qf=e=>{if(!e)return;let t=e.files??e.outputFiles;return Array.isArray(t)?t:void 0},Jf=e=>{let t=e.details;return e.type===$.THOUGHT&&t?.display_role===`tool_preamble`},Yf=e=>{let t=e.details;if(Jf(e))return`assistant`;if(t?.tool)return t.tool;switch(e.type){case $.UPDATE:return`update`;case $.WARNING:return`warning`;case $.ERROR:return`error`;case $.SYSTEM:return`system`;default:return`activity`}},Xf=e=>Jf(e)?`text-[10px] px-1.5 py-0.5 rounded-md bg-gray-50 dark:bg-gray-800 text-gray-700 dark:text-gray-300 border border-gray-200 dark:border-gray-700 font-medium`:`text-[10px] px-1.5 py-0.5 rounded-md bg-purple-50 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300 border border-purple-200 dark:border-purple-800 font-medium`;function Zf({message:e,isExpanded:r,onToggle:i,artifactRunId:a,classNames:s={}}){let{t:c}=Z(),[l,u]=X([]),d=Xe(),{client:f}=Q(),p=qa(),m=Y(f);m.current=f;let h=Y(p);h.current=p;let g=e.details,_=Yf(e),v=Xf(e),y=qf(g),b=typeof e.message==`string`?e.message:``;q(()=>{if(!y||y.length===0||!a){u([]);return}let e=!1;return(async()=>{let t=m.current,n=h.current,r=await Promise.all(y.map(async e=>{if(!e||typeof e!=`string`)return null;if(e.startsWith(`http://`)||e.startsWith(`https://`))return e;let r=e.startsWith(`artifact:`)?e.slice(9):e,i=r.split(`.`).pop()?.toLowerCase()||``,o=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`svg`]).has(i)?`inline`:`attachment`;try{let e=Ya(a,r,o);return n?await n.getOrFetch(e,async()=>(await t.files.getArtifactDownloadUrl(a,r,o)).url):(await t.files.getArtifactDownloadUrl(a,r,o)).url}catch(e){return console.error(`Failed to resolve artifact URL for ${r}`,e),null}}));e||u(r.filter(e=>!!e))})(),()=>{e=!0}},[y,a]);let x=l.filter(e=>Gf(e)),S=l.filter(e=>!Gf(e)),C=()=>{let e=[b,g?`\n\nDetails:\n${JSON.stringify(g,null,2)}`:``].join(``).trim();navigator.clipboard.writeText(e).then(()=>{d({status:`success`,title:c(`agent.copiedToClipboard`),duration:2e3})})};return n(`div`,{className:H(`border-b border-gray-100 dark:border-gray-800 last:border-b-0`,s.itemClassName),children:[n(`div`,{role:`button`,tabIndex:0,className:H(`flex items-start justify-between px-3 py-2 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800/50 transition-colors`,s.itemHeaderClassName),onClick:i,onKeyDown:Ue(i),children:[n(`div`,{className:`flex items-start gap-2 flex-1 min-w-0`,children:[t(`div`,{className:`flex-shrink-0 pt-0.5`,children:r?t(un,{className:`size-3 text-muted`}):t(pn,{className:`size-3 text-muted cn-rtl-flip`})}),t(`div`,{className:`flex-1 min-w-0`,children:b?t(`span`,{className:`text-xs text-foreground line-clamp-2`,children:b}):n(`span`,{className:`text-xs text-muted italic`,children:[`Activity: `,_]})})]}),n(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[!r&&t(`span`,{className:H(v,s.toolBadgeClassName),children:_}),t(o,{variant:`ghost`,size:`xs`,onClick:e=>{e.stopPropagation(),C()},className:`text-muted opacity-0 group-hover:opacity-100 transition-opacity`,title:c(`agent.copyMessage`),children:t(Dn,{className:`size-3`})})]})]}),x.length>0&&t(`div`,{className:`px-3 pb-1.5`,children:t(Kf,{files:x})}),r&&(()=>{let r=g?.tool_status,i=Lf(g),o=zf(g);return n(`div`,{className:H(`px-4 py-2 bg-gray-50/50 dark:bg-gray-800/30`,s.itemContentClassName),children:[n(`div`,{className:`flex items-center gap-2 mb-2 flex-wrap`,children:[t(`span`,{className:H(v,s.toolBadgeClassName),children:_}),r&&t(`span`,{className:H(`text-[10px] px-1.5 py-0.5 rounded-md border font-medium`,Uf(r)),children:r}),t(`span`,{className:`text-[10px] text-muted/70`,children:fs(e.timestamp).format(`HH:mm:ss`)})]}),i.length>0&&t(`div`,{className:`mb-2 space-y-0.5`,children:i.map(([e,r])=>n(`div`,{className:`flex gap-1.5 text-xs`,children:[n(`span`,{className:`text-muted font-medium flex-shrink-0`,children:[Rf(e),`:`]}),t(`span`,{className:`text-foreground break-all`,children:typeof r==`object`?JSON.stringify(r):String(r)})]},e))}),o.length>0&&n(`div`,{className:`mb-2 space-y-1`,children:[t(`div`,{className:`text-[10px] uppercase tracking-wide text-muted/70 font-medium`,children:c(`agent.progress`)}),o.map(e=>n(`div`,{className:`text-xs text-muted`,children:[e.timestamp&&t(`span`,{className:`me-1 text-muted/60`,children:fs(e.timestamp).format(`HH:mm:ss`)}),t(`span`,{children:e.message})]},Bf(e)))]}),(()=>{let e=typeof g?.observation==`string`?g.observation:void 0;return e&&e!==b?t(`div`,{className:`vprose prose prose-slate dark:prose-invert prose-p:leading-relaxed prose-p:my-1.5 max-w-none text-sm`,children:t(wt,{artifactRunId:a,children:e})}):null})(),S.length>0&&t(Kf,{files:S})]})})()]})}function Qf({files:e,artifactRunId:n}){let[r,i]=X([]),{client:a}=Q(),o=qa(),s=Y(a);s.current=a;let c=Y(o);return c.current=o,q(()=>{if(!e||e.length===0||!n){i([]);return}let t=!1;return(async()=>{let r=s.current,a=c.current,o=await Promise.all(e.map(async e=>{if(!e||typeof e!=`string`)return null;let t=e.startsWith(`artifact:`)?e.slice(9):e,i=t.split(`.`).pop()?.toLowerCase()||``;if(new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`svg`]).has(i))return null;if(t.startsWith(`http://`)||t.startsWith(`https://`))return t;try{let e=Ya(n,t,`attachment`);return a?await a.getOrFetch(e,async()=>(await r.files.getArtifactDownloadUrl(n,t,`attachment`)).url):(await r.files.getArtifactDownloadUrl(n,t,`attachment`)).url}catch(e){return console.error(`Failed to resolve artifact URL for ${t}`,e),null}}));t||i(o.filter(e=>!!e))})(),()=>{t=!0}},[e,n]),r.length===0?null:t(`div`,{className:`ps-4 pe-2 pb-1.5`,children:t(Kf,{files:r})})}function $f({messages:e,artifactRunId:n}){let[r,i]=X([]),{client:a}=Q(),o=qa(),s=Y(a);s.current=a;let c=Y(o);return c.current=o,q(()=>{if(!n||e.length===0){i([]);return}let t=e[e.length-1].details,r=qf(t);if(!r||r.length===0){i([]);return}let a=!1;return(async()=>{let e=s.current,t=c.current,o=await Promise.all(r.map(async r=>{if(!r||typeof r!=`string`)return null;let i=r.startsWith(`artifact:`)?r.slice(9):r,a=i.split(`.`).pop()?.toLowerCase()||``;if(!new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`svg`]).has(a))return null;if(i.startsWith(`http://`)||i.startsWith(`https://`))return i;try{let r=Ya(n,i,`inline`);return t?await t.getOrFetch(r,async()=>(await e.files.getArtifactDownloadUrl(n,i,`inline`)).url):(await e.files.getArtifactDownloadUrl(n,i,`inline`)).url}catch(e){return console.error(`Failed to resolve artifact URL for ${i}`,e),null}}));a||i(o.filter(e=>!!e))})(),()=>{a=!0}},[e,n]),r.length===0?null:t(`div`,{className:`px-3 py-1.5 border-b border-gray-100 dark:border-gray-800`,children:t(Kf,{files:r})})}function ep({messages:r,showPulsatingCircle:i=!1,toolRunId:a,toolStatus:s,preambleText:c,preambleMessage:l,rootClassName:u,headerClassName:d,senderClassName:f,toolSummaryClassName:p,toolBadgeClassName:m,itemClassName:h,itemHeaderClassName:g,itemContentClassName:_}){let v=J(()=>Wf(r),[r]),y=J(()=>v.map(Vf),[v]),[b,x]=X(!0),[S,C]=X(new Set),[w,T]=X(new Set),E=Y(y),{t:D}=Z(),O=Xe(),k=v.find(e=>e.workflow_run_id)?.workflow_run_id??v[0]?.workflow_run_id,A=J(()=>{let e=new Set,t=[];for(let n of v)for(let r of Vi(n)){let n=`${r.type}:${r.id}:${r.action}`;e.has(n)||(e.add(n),t.push(r))}return t},[v]),j=()=>i?t(Ru,{size:`sm`,color:`blue`}):s===`running`?t(`span`,{className:`size-2 rounded-full bg-blue-500 inline-block`}):s===`completed`?t(on,{className:`size-4 text-success`}):s===`error`?t(Wt,{className:`size-4 text-destructive`}):s===`warning`?t(Kt,{className:`size-4 text-attention`}):t(Zt,{className:`size-4 text-purple-600 dark:text-purple-400`}),M=()=>s===`completed`?`border-s-success`:s===`error`?`border-s-destructive`:s===`warning`?`border-s-attention`:`border-s-purple-500`;q(()=>{let e=E.current,t=new Set(e),n=y.filter(e=>!t.has(e));if(n.length>0){T(new Set(n));let e=setTimeout(()=>{T(new Set)},500);return E.current=y,()=>clearTimeout(e)}E.current=y},[y]);let N=v[0],P=v[v.length-1],F=N.timestamp,I=P.timestamp,L=v.map(e=>Yf(e)),ee=new Set(L).size===1?`${v.length}× ${L[0]}`:`${v.length} activity updates`,R=e=>{C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},te=()=>{let e=v.map(e=>{let t=e.details;return`[${Yf(e)}] ${e.message||``}\n${t?JSON.stringify(t,null,2):``}`}).join(`
|
|
41
39
|
|
|
42
40
|
---
|
|
43
41
|
|
|
44
|
-
`);navigator.clipboard.writeText(e).then(()=>{O({status:`success`,title:D(`agent.copiedAllToolCalls`),duration:2e3})})};return n(`div`,{className:H(`border-s-4 overflow-hidden bg-white dark:bg-gray-900 mb-4`,M(),u),children:[n(`div`,{role:`button`,tabIndex:0,"aria-expanded":!b,className:H(`flex items-center justify-between px-4 py-1.5 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800/50 transition-colors`,d),onClick:()=>x(!b),onKeyDown:
|
|
42
|
+
`);navigator.clipboard.writeText(e).then(()=>{O({status:`success`,title:D(`agent.copiedAllToolCalls`),duration:2e3})})};return n(`div`,{className:H(`border-s-4 overflow-hidden bg-white dark:bg-gray-900 mb-4`,M(),u),children:[n(`div`,{role:`button`,tabIndex:0,"aria-expanded":!b,className:H(`flex items-center justify-between px-4 py-1.5 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800/50 transition-colors`,d),onClick:()=>x(!b),onKeyDown:Ue(()=>x(!b)),children:[n(`div`,{className:`flex items-center gap-1 flex-1 min-w-0`,children:[j(),c?t(`span`,{className:H(`text-xs text-foreground line-clamp-2 flex-1 min-w-0`,p),children:c}):n(e,{children:[t(`span`,{className:H(`text-xs font-medium text-muted`,f),children:`Agent`}),t(`span`,{className:H(`text-xs text-purple-600 dark:text-purple-400 font-medium`,p),children:ee})]}),b?t(pn,{className:`size-3 text-muted flex-shrink-0 cn-rtl-flip`}):t(un,{className:`size-3 text-muted flex-shrink-0`})]}),n(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[c&&t(`span`,{className:H(`text-[10px] text-purple-600 dark:text-purple-400 font-medium`,p),children:ee}),n(`span`,{className:`text-[11px] text-muted/70`,children:[fs(F).format(`HH:mm:ss`),v.length>1&&` - ${fs(I).format(`HH:mm:ss`)}`]}),t(o,{variant:`ghost`,size:`xs`,onClick:e=>{e.stopPropagation(),te()},className:`text-muted/50 hover:text-muted h-5 w-5 p-0`,title:D(`agent.copyAllToolCalls`),children:t(Dn,{className:`size-3`})})]})]}),t($f,{messages:v,artifactRunId:k}),A.length>0&&t(`div`,{className:`px-4 pt-1 pb-2`,children:t(af,{resources:A,workflowRunId:k})}),b&&t(`div`,{className:`px-3 py-0.5 space-y-0`,children:v.map((e,r)=>{let i=y[r]??Vf(e),a=e.details,o=Yf(e),s=Xf(e),c=typeof e.message==`string`?e.message:``,l=w.has(i),u=S.has(i),d=qf(a);return n(`div`,{className:H(`border-b border-gray-100 dark:border-gray-800 last:border-b-0`,h),style:{opacity:+!l,transform:l?`translateX(-10px)`:`translateX(0)`,transition:`opacity 0.3s ease-out, transform 0.3s ease-out`,transitionDelay:`${(r-(v.length-w.size))*100}ms`,animation:l?`slideInFade 0.4s ease-out forwards`:`none`,animationDelay:`${(r-(v.length-w.size))*100}ms`},children:[n(`div`,{role:`button`,tabIndex:0,"aria-expanded":u,className:H(`flex items-start gap-2 py-1.5 text-xs cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800/50`,g),onClick:()=>R(i),onKeyDown:Ue(()=>R(i)),title:c,children:[t(`div`,{className:`flex-shrink-0 pt-0.5`,children:u?t(un,{className:`size-3 text-muted`}):t(pn,{className:`size-3 text-muted cn-rtl-flip`})}),t(`div`,{className:`flex-1 min-w-0`,children:c?t(`span`,{className:`text-foreground line-clamp-2`,children:c}):n(`span`,{className:`text-muted italic`,children:[`Activity: `,o]})}),!u&&t(`span`,{className:H(s,`flex-shrink-0`,m),children:o})]}),t(Qf,{files:d,artifactRunId:k}),u&&(()=>{let r=a?.tool_status,i=Lf(a),l=zf(a);return n(`div`,{className:H(`ps-5 pe-3 pb-2 text-sm`,_),children:[n(`div`,{className:`flex items-center gap-2 mb-1.5 flex-wrap`,children:[t(`span`,{className:H(s,m),children:o}),r&&t(`span`,{className:H(`text-[10px] px-1.5 py-0.5 rounded-md border font-medium`,Uf(r)),children:r}),t(`span`,{className:`text-[10px] text-muted/70`,children:fs(e.timestamp).format(`HH:mm:ss`)})]}),i.length>0&&t(`div`,{className:`mb-1.5 space-y-0.5`,children:i.map(([e,r])=>n(`div`,{className:`flex gap-1.5 text-xs`,children:[n(`span`,{className:`text-muted font-medium flex-shrink-0`,children:[Rf(e),`:`]}),t(`span`,{className:`text-foreground break-all`,children:typeof r==`object`?JSON.stringify(r):String(r)})]},e))}),l.length>0&&n(`div`,{className:`mb-1.5 space-y-1`,children:[t(`div`,{className:`text-[10px] uppercase tracking-wide text-muted/70 font-medium`,children:D(`agent.progress`)}),l.map(e=>n(`div`,{className:`text-xs text-muted`,children:[e.timestamp&&t(`span`,{className:`me-1 text-muted/60`,children:fs(e.timestamp).format(`HH:mm:ss`)}),t(`span`,{children:e.message})]},Bf(e)))]}),(()=>{let e=typeof a?.observation==`string`?a.observation:void 0;return e&&e!==c?t(`div`,{className:`vprose prose prose-slate dark:prose-invert prose-p:leading-relaxed prose-p:my-1.5 max-w-none text-sm`,children:t(wt,{artifactRunId:k,children:e})}):null})()]})})()]},i)})}),t(`style`,{children:`
|
|
45
43
|
@keyframes slideInFade {
|
|
46
44
|
from {
|
|
47
45
|
opacity: 0;
|
|
@@ -52,12 +50,12 @@ $&`)),t.includes(` - `)&&(t=t.replace(/(^|\S)\s+-\s+/g,`$1
|
|
|
52
50
|
transform: translateX(0);
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
`}),!b&&t(`div`,{className:`group`,children:v.map((e,n)=>{let r=y[n]??xp(e);return t(jp,{message:e,isExpanded:S.has(r),onToggle:()=>R(r),artifactRunId:k,classNames:{toolBadgeClassName:m,itemClassName:h,itemHeaderClassName:g,itemContentClassName:_}},r)})})]})}const Fp=it(Pp,(e,t)=>e.messages.length!==t.messages.length||e.showPulsatingCircle!==t.showPulsatingCircle||e.toolRunId!==t.toolRunId||e.toolStatus!==t.toolStatus||e.preambleText!==t.preambleText||e.rootClassName!==t.rootClassName||e.headerClassName!==t.headerClassName||e.senderClassName!==t.senderClassName||e.toolSummaryClassName!==t.toolSummaryClassName||e.toolBadgeClassName!==t.toolBadgeClassName||e.itemClassName!==t.itemClassName||e.itemHeaderClassName!==t.itemHeaderClassName||e.itemContentClassName!==t.itemContentClassName?!1:e.messages.every((e,n)=>Sp(e,t.messages[n]))),Ip=`flex items-center gap-1.5 px-2 py-1 text-xs font-medium whitespace-nowrap transition-colors border-b-2 shrink-0 cursor-pointer`,Lp=`border-transparent text-muted hover:bg-muted`,Rp=`border-info bg-info text-info`;function zp(e){return e.length>20?`${e.substring(0,18)}...`:e}function Bp({items:e,current:r,onSelect:i,label:a,active:o,count:s,completionStatus:c}){let[l,u]=Y(!1),d=J(null),f=J(!1),p=()=>{d.current&&=(clearTimeout(d.current),null)},m=()=>{p(),f.current=!0,u(!0)},h=()=>{p(),d.current=setTimeout(()=>u(!1),150)};return K(()=>()=>clearTimeout(d.current??void 0),[]),n(T,{modal:!1,open:l,onOpenChange:e=>{p(),e&&(f.current=!1),u(e)},children:[t(A,{asChild:!0,children:n(`button`,{type:`button`,onMouseEnter:m,onMouseLeave:h,className:H(Ip,o?Rp:Lp),children:[a,t(an,{className:`ms-0.5 size-3.5`})]})}),t(E,{align:`end`,className:`w-max`,onMouseEnter:p,onMouseLeave:h,onCloseAutoFocus:e=>{f.current&&e.preventDefault()},children:e.map(([e,a])=>{let o=(s?.get(e)??0)>0;return n(D,{onClick:()=>i(e),className:H(`flex items-center gap-2`,e===r&&`text-info`),children:[t(`span`,{className:`truncate`,children:a}),o&&n(`span`,{className:`ms-auto inline-flex items-center gap-1`,children:[t(`span`,{className:`inline-flex items-center justify-center rounded-full bg-muted px-1.5 text-[10px] text-muted`,children:s?.get(e)}),c&&e!==`all`&&(c.get(e)?t(en,{className:`size-3 text-success`}):t(yn,{className:`size-3 text-attention`}))]})]},e)})})]})}function Vp({entries:r,activeWorkstream:i,onSelectWorkstream:a,count:o,completionStatus:s}){let{t:c}=X(),l=J(null),u=J([]),d=J(null),[f,p]=Y({count:r.length,promote:!1}),m=()=>{let e=l.current;if(!e)return;let t=e.clientWidth,n=r.map((e,t)=>u.current[t]?.offsetWidth??0),a=n.reduce((e,t)=>e+t,0)+4*Math.max(0,r.length-1),o=(e,t)=>{let i=0,a=0;for(let o=0;o<r.length;o++){if(o===t)continue;let r=i+(a>0?4:0)+n[o];if(r>e)break;i=r,a+=1}return a},s;if(a<=t)s={count:r.length,promote:!1};else{let e=d.current?.offsetWidth??0,a=Math.max(1,o(t-e-4,-1)),c=r.findIndex(([e])=>e===i);s=c<0||c<a?{count:a,promote:!1}:{count:o(t-e-n[c]-8,c),promote:!0}}p(e=>e.count===s.count&&e.promote===s.promote?e:s)},h=J(m);h.current=m,st(()=>{h.current()}),K(()=>{let e=l.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>h.current());return t.observe(e),()=>t.disconnect()},[]);let g=r.findIndex(([e])=>e===i),_,v;if(f.promote&&g>=0){let e=r.filter((e,t)=>t!==g);_=[...e.slice(0,f.count),r[g]],v=e.slice(f.count)}else _=r.slice(0,f.count),v=r.slice(f.count);let y=v.some(([e])=>e===i),b=c(`agent.moreTabs`),x=(r,i,a)=>{let c=(o?.get(r)??0)>0;return n(e,{children:[zp(i),c&&n(`span`,{className:`flex items-center gap-1`,children:[t(`span`,{className:H(`inline-flex items-center justify-center p-1 text-xs rounded-full`,a?`bg-info text-info`:`bg-muted text-muted`),children:o?.get(r)}),s&&r!==`all`&&(s.get(r)?t(en,{className:`size-3 text-success`}):t(yn,{className:`size-3 text-attention`}))]})]})};return n(`div`,{ref:l,className:`relative mb-1 bg-muted border-b border-muted/20`,children:[n(`div`,{"aria-hidden":!0,className:`pointer-events-none invisible absolute start-0 top-0 flex w-max gap-1`,children:[r.map(([e,n],r)=>t(`button`,{type:`button`,tabIndex:-1,ref:e=>{u.current[r]=e},className:H(Ip,Lp),children:x(e,n,!1)},e)),n(`button`,{type:`button`,tabIndex:-1,ref:d,className:H(Ip,Lp),children:[b,t(an,{className:`ms-0.5 size-3.5`})]})]}),n(`div`,{className:`flex gap-1 overflow-hidden`,children:[_.map(([e,n])=>{let r=i===e;return t(`button`,{type:`button`,"aria-current":r?`page`:void 0,onClick:()=>a(e),title:n.length>20?n:void 0,className:H(Ip,r?Rp:Lp),children:x(e,n,r)},e)}),v.length>0&&t(Bp,{items:v,current:i,onSelect:a,label:b,active:y,count:o,completionStatus:s})]})]})}function Hp({workstreams:e,activeWorkstream:n,onSelectWorkstream:r,count:i,completionStatus:a}){let{t:o}=X(),s=new Map;s.set(`all`,o(`agent.allMessages`)),s.set(`main`,o(`agent.main`)),e.forEach((e,t)=>{t!==`all`&&t!==`main`&&t!==`research_france`&&t!==`statistics`&&s.set(t,e)}),e=s;let c=Array.from(e.entries()).sort(([e],[t])=>e===`all`?-1:t===`all`?1:e===`main`?-1:t===`main`?1:e.localeCompare(t));return c.length>2?t(Vp,{entries:c,activeWorkstream:n,onSelectWorkstream:r,count:i,completionStatus:a}):t(`div`,{className:`py-0.5`})}function Up(e){let t=new Map,n=It.getFixedT(null,Ft);return t.set(`all`,n(`agent.allMessages`)),t.set(`main`,n(`agent.main`)),e.forEach(e=>{e.workstream_id&&e.workstream_id!==`main`&&e.workstream_id!==`all`&&!t.has(e.workstream_id)&&t.set(e.workstream_id,e.workstream_id)}),t}function Wp(e,t){return t===`all`?[...e]:t===`main`?e.filter(e=>_u(e)===`main`):e.filter(e=>_u(e)===t)}const Gp=e=>e.type===Q.BATCH_PROGRESS&&!!e.details?.batch_id;function Kp(e){if(e==null||e===``)return Date.now();let t=typeof e==`number`?e:new Date(e).getTime();return Number.isFinite(t)?t:Date.now()}function qp(e){let t=Date.now()-Kp(e);return Math.max(0,Math.round(t/1e3))}function Jp(e,t){let n=Kp(t)-Kp(e);return Math.max(0,Math.round(n/1e3))}function Yp(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function Xp(e){if(e==null||e===``)return;let t=typeof e==`number`?e:new Date(e).getTime();return Number.isFinite(t)?t:void 0}function Zp(e){let t=Xp(e);if(t!==void 0)return new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}).format(new Date(t))}function Qp(e){let t=e.details,n=t?.tool||``,r=Array.isArray(t?.tools)?t.tools.map(e=>typeof e==`string`?e:e.name||e.tool||``).filter(Boolean):[],i=[n,...r].join(` `).toLowerCase(),a=n.toLowerCase(),o=typeof e.message==`string`?e.message.trim():``;return t?.display_role===`tool_preamble`?i.includes(`search`)||i.includes(`web`)||i.includes(`fetch`)?`Preparing search`:r.length>0?`Preparing tools`:`Thinking`:a.includes(`search`)?`Searching`:a.includes(`fetch`)||a.includes(`web`)?`Searching the web`:a.includes(`read`)||a.includes(`document`)?`Reading`:a.includes(`edit`)||a.includes(`write`)||a.includes(`create`)?`Editing`:a.includes(`bash`)||a.includes(`shell`)||a.includes(`command`)?`Running command`:o||`Using tool`}function $p(e){return e?`Working`:`Worked`}function em(e){return e.length>0&&e.every(Xf)}function tm(e){return $p(e)}function nm(e){let t=e.filter(e=>_u(e)===`main`);return(t[t.length-1]??e[e.length-1])?.type===Q.QUESTION}function rm(e,t){let n=e.filter(e=>_u(e)===`main`),r=n[n.length-1]??e[e.length-1];if(!r||!md(r,t))return!1;let i=$m(r);return i===`allow_once`||i===`allow_for_run`}function im(e){if(e.type!==Q.UPDATE)return;let t=Rm(e);if(t.tool!==void 0||t.activity_group_id!==void 0)return;let n=typeof t.path==`string`&&t.path.trim()?t.path.trim():void 0;if(n)return sm(e)===`Prepared and saved artifact to ${n}`?n:void 0}function am(e,t){let n=_u(e[t]);for(let r=t-1;r>=0;--r){let t=e[r];if(_u(t)!==n)continue;let i=Rm(t);if(i.tool===`write_artifact`&&typeof i.activity_group_id==`string`)return t;if(t.type!==Q.REQUEST_INPUT&&!$m(t)&&i.display_role!==`thinking`&&(typeof i.tool==`string`&&i.tool!==`write_artifact`||t.type===Q.ANSWER||t.type===Q.COMPLETE||t.type===Q.IDLE||t.type===Q.TERMINATED))return}}function om(e){return e.map((t,n)=>{let r=im(t);if(!r)return t;let i=am(e,n),a=i?Rm(i):void 0;if(!a)return t;let o=typeof a.activity_group_id==`string`?a.activity_group_id:void 0,s=typeof a.tool_run_id==`string`?a.tool_run_id:void 0,c=typeof a.tool_use_id==`string`?a.tool_use_id:void 0,l=typeof a.tool_iteration==`number`?a.tool_iteration:void 0;return o?{...t,details:{...t.details,event_class:`activity`,tool:`write_artifact`,tool_run_id:s??`write_artifact`,tool_use_id:c??s??`write_artifact`,tool_iteration:l,tool_status:`completed`,tool_event:`progress`,activity_group_id:o,output:sm(t),path:r}}:t})}function sm(e){return e.message?typeof e.message==`object`?JSON.stringify(e.message,null,2):String(e.message).trim():``}function cm({message:e,details:r,onSelectWorkstream:i}){let{t:a}=X(),o=Ql(r.workstreamId,r.interaction),s=r.interaction?Xl(r.interaction):``,c=s&&s!==o?s:void 0;return t(`div`,{className:`mx-auto w-full max-w-3xl px-1`,"data-workstream-id":r.workstreamId,children:n(`button`,{type:`button`,className:H(`group flex w-full items-start gap-3 border-b border-border/70 py-2 text-start text-sm text-muted`,`transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2`,`focus-visible:ring-focus focus-visible:ring-offset-2 focus-visible:ring-offset-background`),onClick:()=>i?.(r.workstreamId),children:[t(Kt,{className:`mt-0.5 size-4 shrink-0 text-muted`,"aria-hidden":`true`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1`,children:[t(`span`,{className:`font-medium text-muted`,children:a(`agent.workstreams`)}),t(`span`,{className:`min-w-0 truncate text-foreground/85`,children:o})]}),c&&t(`div`,{className:`mt-0.5 truncate text-xs text-muted/75`,children:c}),t(`span`,{className:`sr-only`,children:sm(e)})]}),t(cn,{className:`mt-0.5 size-4 shrink-0 text-muted transition-transform group-hover:translate-x-0.5 rtl:rotate-180 rtl:group-hover:-translate-x-0.5`})]})})}const lm=/\[[^\]]+\]\((?:\/store\/(?:objects|collections)\/|store:|document:|document:\/\/|collection:)[^)]+\)/,um={table:ym};function dm(e){if(!e||typeof e!=`object`)return``;let t=e;return typeof t.value==`string`?t.value:Array.isArray(t.children)?t.children.map(dm).join(``):``}function fm(e,t){if(!e||typeof e!=`object`)return[];let n=e.children;return Array.isArray(n)?n.filter(e=>{if(!e||typeof e!=`object`)return!1;let n=e;return t?n.tagName===t:typeof n.tagName==`string`}):[]}function pm(e){return fm(e).filter(e=>e.tagName===`thead`||e.tagName===`tbody`).flatMap(e=>fm(e,`tr`).map(e=>fm(e).filter(e=>e.tagName===`th`||e.tagName===`td`).map(e=>dm(e).replace(/\s+/g,` `).trim())))}function mm(e){return fm(e,`tbody`).flatMap(e=>fm(e,`tr`).map(e=>fm(e,`td`).map(e=>dm(e).replace(/\s+/g,` `).trim())))}function hm(e){let t=pm(e),n=mm(e),r=Math.max(0,...t.map(e=>e.length));if(r<=1)return new Set;let i=new Set;for(let e=0;e<r;e+=1){let t=n.map(t=>t[e]||``).map(e=>e.trim()).filter(Boolean);if(t.length===0)continue;let r=t.map(e=>e.length),a=Math.max(...r),o=r.reduce((e,t)=>e+t,0)/r.length,s=t.some(e=>/\S{12,}/.test(e));a<=16&&o<=10&&!s&&i.add(e)}return i.size>=r?new Set:i}function gm(e,t,n){return Math.min(n,Math.max(t,e))}function _m(e){return e.reduce((e,t)=>{let n=t.match(/\S+/g)||[];return Math.max(e,...n.map(e=>e.length))},0)}function vm(e){let t=pm(e),n=Math.max(0,...t.map(e=>e.length));if(n<=1)return[];let r=hm(e),i=Array.from({length:n},(e,n)=>{if(r.has(n))return 8;let i=t.map(e=>e[n]||``).map(e=>e.trim()).filter(Boolean);if(i.length===0)return 18;let a=i.map(e=>e.length),o=Math.max(...a),s=a.reduce((e,t)=>e+t,0)/a.length,c=_m(i);return gm(s*.7+o*.25+c*.45,18,90)}),a=i.reduce((e,t)=>e+t,0);return a<=0?[]:i.map((e,t)=>{let n=`${(e/a*100).toFixed(3)}%`;return{key:`agent-markdown-table-column-${t}`,compact:r.has(t),width:n}})}function ym({node:e,className:r,children:i,...a}){let o=vm(e);return n(`table`,{...a,className:r,children:[o.length>0?t(`colgroup`,{children:o.map(e=>t(`col`,{className:e.compact?`agent-markdown-table-compact-col`:void 0,style:{"--agent-markdown-table-column-width":e.width}},e.key))}):null,i]})}function bm(e){if(e==null||typeof e==`boolean`)return 0;if(typeof e==`string`||typeof e==`number`)return String(e).length;if(Array.isArray(e))return e.reduce((e,t)=>e+bm(t),0);if(W.isValidElement(e)){let t=e.props;return bm(t.children)}return 0}function xm(e,t){let[n,r]=Y(()=>qp(e));return K(()=>{if(!t){r(qp(e));return}let n=()=>r(qp(e));n();let i=window.setInterval(n,1e3);return()=>window.clearInterval(i)},[t,e]),n}function Sm(e=!0){let[t,n]=Y(0);return K(()=>{if(!e)return;let t=window.setInterval(()=>{n(()=>Math.floor(Math.random()*Rd.length))},4e3);return()=>window.clearInterval(t)},[e]),t}function Cm({children:e,message:r,workstreamId:i,className:a,artifactRunId:o,onOpenArtifact:s,markdownComponents:c}){let{t:l}=X(),[u,d]=Y(!1),f=q(()=>bm(e),[e])>520,p=typeof e==`string`||typeof e==`number`,m=p?String(e):``,h=typeof e==`string`&&lm.test(e),g=r?ff(r):void 0;return K(()=>{!f&&u&&d(!1)},[u,f]),t(`div`,{className:`mx-auto flex w-full max-w-3xl justify-end px-1`,children:n(`div`,{className:H(`max-w-[min(44rem,82%)] rounded-[1.35rem] bg-mixer-muted/35 px-4 py-2.5`,`text-sm font-normal leading-6 text-foreground/90 shadow-sm shadow-black/5 dark:bg-mixer-muted/15 dark:text-foreground/88 dark:shadow-none`,`break-words [overflow-wrap:anywhere]`,a),"data-workstream-id":i,children:[t(`div`,{className:H(p&&!h&&`whitespace-pre-wrap`,f&&!u&&`max-h-72 overflow-hidden [mask-image:linear-gradient(to_bottom,black_76%,transparent_100%)]`),children:h?t(bt,{artifactRunId:o,onArtifactOpen:s,components:c,className:H(`agent-markdown vprose prose max-w-none break-words text-sm leading-6 text-foreground/90`,`prose-p:my-0 prose-p:leading-6 prose-a:text-foreground prose-a:underline prose-a:decoration-muted prose-a:underline-offset-4`,`[&_p+_p]:mt-2`),children:m}):e}),f&&n(`button`,{type:`button`,"aria-expanded":u,className:`mt-2 inline-flex items-center gap-1 text-sm font-medium text-muted transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,onClick:()=>d(e=>!e),children:[l(u?`agent.showLess`:`agent.showMore`),t(an,{className:H(`size-4 transition-transform`,u&&`rotate-180`),"aria-hidden":`true`})]}),r&&g?t(`div`,{className:`mt-1.5 flex justify-end`,children:t(mf,{message:r,className:`h-4 w-4`})}):null]})})}function wm({message:r,onSendMessage:i,onOpenArtifact:a,onSelectWorkstream:o,requestInputAnswered:s=!1,StoreLinkComponent:c,CollectionLinkComponent:l}){let{router:u}=va(),d=r.type===Q.REQUEST_INPUT?Lu(r):sm(r),f=ou(r)??su(r),p=_u(r),m=r.workflow_run_id,h=q(()=>r.type===Q.QUESTION?of(d):null,[d,r.type]),g=q(()=>r.type===Q.QUESTION?jd(r.details?.editing_action):void 0,[r.details,r.type]),_=q(()=>({...um,a:Bd({StoreLinkComponent:c,CollectionLinkComponent:l,addStickyParams:e=>u.getTopRouter().navigator.addStickyParams(e)})}),[c,l,u]);if(f)return t(cm,{message:r,details:f,onSelectWorkstream:o});if(r.type===Q.QUESTION){let i=h?.body??d,o=h?.attachments??[];return n(e,{children:[o.length>0&&t(`div`,{className:`mx-auto flex w-full max-w-3xl justify-end px-1`,children:t(nf,{items:o,artifactRunId:m,onOpenArtifact:a,align:`end`,variant:`message`,StoreLinkComponent:c,CollectionLinkComponent:l})}),i&&t(Cm,{message:r,workstreamId:p,artifactRunId:m,onOpenArtifact:a,markdownComponents:_,className:g?`max-w-[min(44rem,90%)]`:void 0,children:g?t(Ld,{action:g}):i})]})}let v=r.details;if(r.type===Q.REQUEST_INPUT&&v?.ux){let e=v.ux;return t(`div`,{className:`mx-auto w-full max-w-3xl px-1`,children:t(Jl,{question:d,options:e.options,variant:e.variant,multiSelect:e.multiSelect,onSelect:e=>ed(i,r,e,od(r,e)),onMultiSelect:e=>ed(i,r,e.join(`, `)),allowFreeResponse:!e.options?.length||!!e.free_response,placeholder:e.free_response?.placeholder,submitLabel:e.free_response?.submit_label,onSubmit:t=>ed(i,r,t,e.free_response?.metadata),hideBorder:!0,compact:!0,answered:s})})}let y=r.type===Q.ERROR||r.type===Q.WARNING;return n(`div`,{className:`mx-auto w-full max-w-3xl px-1`,"data-workstream-id":p,children:[y&&t(`div`,{className:`mb-2 text-xs font-medium text-destructive`,children:r.type===Q.WARNING?`Warning`:`Error`}),d&&t(`div`,{className:H(Td,y&&`rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2`),style:{overflowWrap:`anywhere`},children:t(bt,{artifactRunId:m,onArtifactOpen:a,onProposalSelect:e=>i?.(e),onProposalSubmit:e=>i?.(e),components:_,children:d})})]})}function Tm(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Em(e){return e==null?!1:typeof e==`string`?e.trim().length>0:Array.isArray(e)?e.length>0:typeof e!=`object`||Object.keys(e).length>0}function Dm(e){return e==null||e===!1?!1:typeof e!=`string`||e.trim().length>0}function Om(e){if(!e||!Tm(e))return{};let t=e.properties;return Tm(t)?t:{}}function km(e,t){let n=e&&Tm(e)?e.title:void 0;return typeof n==`string`&&n.trim()?n:t.replace(/[_-]+/g,` `).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/\b\w/g,e=>e.toUpperCase())}function Am(e){if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}}function jm(e){return e==null||e===``?t(`span`,{className:`text-muted`,children:`Not provided`}):typeof e==`boolean`?e?`Yes`:`No`:typeof e==`number`?String(e):typeof e==`string`?t(`span`,{className:`whitespace-pre-wrap`,children:e}):Array.isArray(e)&&e.every(e=>typeof e!=`object`||!e)?e.map(e=>Am(e)).join(`, `):t(`pre`,{className:`max-h-40 overflow-auto whitespace-pre-wrap rounded-md bg-background/55 px-2 py-1.5 font-mono text-[12px] leading-relaxed text-foreground/80`,children:Am(e)})}function Mm(e,r,i){if(!Em(e))return null;if(!Tm(e))return jm(e);let a=Om(r),o=[...Object.keys(a),...Object.keys(e).filter(e=>!(e in a))].map(t=>({key:t,label:km(a[t],t),value:e[t]})).filter(e=>Em(e.value));return o.length===0?null:n(`div`,{className:`space-y-2 text-start`,children:[i?t(`div`,{className:`text-xs font-medium uppercase tracking-normal text-muted`,children:i}):null,t(`dl`,{className:`space-y-2`,children:o.map(e=>n(`div`,{className:`grid gap-1 sm:grid-cols-[minmax(7rem,32%)_1fr] sm:gap-3`,children:[t(`dt`,{className:`text-xs font-medium text-muted`,children:e.label}),t(`dd`,{className:`min-w-0 break-words text-sm text-foreground`,children:jm(e.value)})]},e.key))})]})}function Nm({data:e,schema:n,title:r,template:i,prependFriendlyMessage:a,timestamp:o,isSummaryView:s,messageItemClassNames:c,messageStyleOverrides:l,StoreLinkComponent:u,CollectionLinkComponent:d}){let f=a?.trim()||(typeof e==`string`?e.trim():``),p=i?.({data:e??a,schema:n,title:r});if(!Dm(p)&&f){let e={type:Q.QUESTION,message:f,timestamp:Kp(o),workflow_run_id:``,workstream_id:`main`};return s?t(wm,{message:e,StoreLinkComponent:u,CollectionLinkComponent:d}):t(Nf,{...c,messageStyleOverrides:l,message:e})}let m=Dm(p)?p:Mm(e,n,r);return Dm(m)?t(Cm,{className:`py-3`,children:m}):null}function Pm({label:e,timestamp:r,className:i}){let a=Sm(),o=xm(r,!0);return t(`div`,{className:H(`mx-auto w-full max-w-3xl px-1`,i),children:n(`div`,{className:`border-b border-border/70 pb-4 text-sm text-muted`,children:[n(`div`,{className:`flex items-center gap-3`,children:[t(bd,{size:`sm`,color:`blue`}),n(`div`,{className:`min-w-0`,children:[n(`div`,{children:[t(`span`,{className:`font-medium`,children:e}),n(`span`,{className:`ms-2 text-muted/75`,children:[`for `,Yp(o)]})]}),t(`div`,{className:`mt-1 truncate text-muted/80`,children:Rd[a]})]})]}),t(`div`,{className:`mt-3 ps-6`,children:t(yd,{color:`blue`})})]})})}const Fm=`_summary_started_at`,Im=`_summary_finished_at`,Lm=new Set([`account_id`,`activity_group_id`,`activity_id`,`channel_id`,`collection_id`,`document_id`,`display_role`,`duration_ms`,`event_class`,`id`,`object_id`,`project_id`,`run_id`,`streamed`,`tenant_id`,`thread_id`,`tool`,`tool_event`,`tool_iteration`,`tool_run_id`,`tool_use_id`,`tool_status`,`tools`,`message_to_human`,`progress_messages`,`resources`,`source`,`token_usage`,`checkpoint_at`,`checkpoint_threshold`,`approval_decision`,`approval_request`,`cancellation_reason`,Fm,Im,`workflow_run_id`]);function Rm(e){return Tm(e.details)?e.details:{}}function zm(e){if(e.type!==Q.UPDATE)return!1;let t=Rm(e).event_class;return t===`document_created`||t===`document_updated`}function Bm(e){return e.replace(/[_-]+/g,` `).replace(/\s+/g,` `).trim().replace(/\b\w/g,e=>e.toUpperCase())}function Vm(e){let t=[];if(typeof e.tool==`string`&&e.tool.trim()&&t.push(e.tool.trim()),Array.isArray(e.tools)){for(let n of e.tools)if(typeof n==`string`&&n.trim())t.push(n.trim());else if(Tm(n)){let e=typeof n.name==`string`?n.name:n.tool;typeof e==`string`&&e.trim()&&t.push(e.trim())}}return t}function Hm(e){let t=Array.from(new Set(Vm(e)));return t.length>0?t.join(`, `):void 0}function Um(e){return typeof e==`number`||typeof e==`string`?e:void 0}const Wm=[`query`,`path`,`file`,`file_name`,`fileName`,`filename`,`name`,`title`,`artifact`,`artifact_path`,`url`,`command`];function Gm(e){for(let t of Wm){let n=e[t];if(typeof n==`string`&&n.trim())return{key:t,value:n.trim()};if(typeof n==`number`||typeof n==`boolean`)return{key:t,value:String(n)}}}function Km(e){let t=Rm(e),n=Vm(t).join(` `).toLowerCase(),r=typeof t.tool==`string`?t.tool.toLowerCase():``,i=r||n;return Du(e)?`think`:r.startsWith(`learn_`)||n.includes(`learn_`)?`skill`:r===`discover_tools`?`discover`:e.type===Q.THOUGHT&&!r?`think`:i.includes(`search`)||i.includes(`web`)||i.includes(`fetch`)?`search`:i.includes(`read`)||i.includes(`document`)||i.includes(`file`)?`read`:i.includes(`edit`)||i.includes(`write`)||i.includes(`patch`)||i.includes(`create`)?`edit`:i.includes(`bash`)||i.includes(`shell`)||i.includes(`command`)||i.includes(`terminal`)?`command`:e.type===Q.THOUGHT&&n.length===0?`think`:`tool`}function qm(e){switch(e){case`search`:return`Search`;case`read`:return`Read`;case`edit`:return`Edit`;case`command`:return`Bash`;case`skill`:return`Skill`;case`discover`:return`Tool`;case`think`:return`Thought`;default:return`Tool`}}function Jm(e){let t=Gm(e);if(t)return t.value;let n=e.files??e.outputFiles;if(Array.isArray(n)&&n.length>0)return n.map(e=>Am(e)).join(`, `)}function Ym(e,t){switch(e){case`denied`:case`denied_with_feedback`:return`User declined to use ${t}.`;case`timeout`:return`Approval timed out for ${t}.`;case`reviewer_denied`:return`Approval reviewer denied ${t}.`;case`cancelled_after_denial`:return`Cancelled ${t} after another tool was denied.`;default:return}}function Xm(e){switch(e){case`denied`:case`denied_with_feedback`:return`Declined by user`;case`timeout`:return`Approval timed out`;case`reviewer_denied`:return`Denied by reviewer`;case`cancelled_after_denial`:return`Cancelled after denial`;default:return}}function Zm(e){let t=Rm(e).tool_approval;return Tm(t)?t:void 0}function Qm(e){let t=e?.approval_key;return typeof t==`string`&&t.trim()?t.trim():void 0}function $m(e){if(e.type!==Q.QUESTION)return;let t=sm(e).trim().toLowerCase();if(t===`allow_once`||t===`allow_for_run`||t===`deny`)return t}function eh(e){let t=e.tool_title;if(typeof t==`string`&&t.trim())return t.trim();let n=e.tool_name;return typeof n==`string`&&n.trim()?Bm(n.trim()):`tool action`}function th(e,t){let n=[];return e.forEach((r,i)=>{if(r.type!==Q.REQUEST_INPUT)return;let a=Zm(r),o=Qm(a);if(!a||!o||t.has(o))return;let s=_u(r),c;for(let t=i+1;t<e.length;t+=1){let n=e[t];if(_u(n)===s){if(n.type===Q.REQUEST_INPUT)break;if(n.type===Q.QUESTION){c=n;break}}}if(!c||$m(c)!==`deny`)return;let l=typeof a.tool_name==`string`&&a.tool_name.trim()?a.tool_name.trim():`tool_action`,u=eh(a),d=typeof a.target==`string`&&a.target.trim()?a.target:``,f={tool_name:l,tool_title:a.tool_title,action_summary:a.action_summary,target:a.target,approval_key:o};n.push({timestamp:c.timestamp??r.timestamp,workflow_run_id:c.workflow_run_id||r.workflow_run_id,type:Q.THOUGHT,message:Ym(`denied`,u)??`User declined to use ${u}.`,workstream_id:s,details:{event_class:`activity`,tool:l,tool_run_id:`approval:${o}`,tool_use_id:`approval:${o}`,tool_status:`error`,tool_event:`failed`,activity_group_id:`approval:${o}`,approval_decision:`denied`,approval_request:f,input:a.input,target:d,observation:`The user declined this tool action.`,source:`synthetic_tool_approval_decision`}})}),n.length===0?e:[...e,...n].sort((e,t)=>Kp(e.timestamp)-Kp(t.timestamp))}function nh(e,t=160){let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1)}...`:n}const rh=[`batch_id`,`activity_group_id`,`activity_id`,`tool_run_id`,`tool_use_id`,`streaming_id`,`chunk_index`,`tool_iteration`,`tool_event`];function ih(e){for(let t of rh){let n=e[t];if(typeof n==`string`&&n.trim())return`${t}:${n.trim()}`;if(typeof n==`number`||typeof n==`boolean`)return`${t}:${n}`}}function ah(e,t=`message`){let n=ih(Rm(e)),r=nh(sm(e),96);return[t,e.workstream_id||`main`,e.workflow_run_id,e.timestamp,e.type,n??r].filter(Boolean).join(`:`)}function oh(e){if(e.type===`single`)return ah(e.message);if(e.type===`streaming`)return`streaming:${e.streamingId}:${e.startTimestamp}:${e.workstreamId||`main`}`;let t=e.messages[0],n=e.messages[e.messages.length-1],r=t?ah(t,`first`):e.firstTimestamp,i=n?ah(n,`last`):e.firstTimestamp;return[`group`,e.toolRunId,e.firstTimestamp,r,i].filter(Boolean).join(`:`)}function sh(e,t){for(let n=t-1;n>=0;n--){let t=e[n];if(t.type===`single`)return t.message.timestamp;if(t.type===`tool_group`)return t.firstTimestamp;if(t.type===`streaming`)return t.startTimestamp}}function ch(e){let t=Am(e).trim();return t.length>2400?`${t.slice(0,2400)}\n...`:t}function lh(e,t,n,r){if(n!=null&&n!==``&&!(Array.isArray(n)&&n.length===0)&&!(Tm(n)&&Object.keys(n).length===0))return{key:e,label:t,value:n,tone:r}}function uh(e,t){let n=Object.entries(e).reduce((e,[n,r])=>(Lm.has(n)||t.has(n)||r==null||r===``||(e[n]=r),e),{});return Object.keys(n).length>0?n:void 0}function dh(e){let t=Rm(e),n=new Set,r=[],i=Gm(t),a=(e,i,a)=>{for(let o of i){let i=lh(o,e,t[o],a);if(i){n.add(o),r.push(i);return}}};a(`Query`,[`query`]),a(`Input`,[`input`,`params`,`arguments`,`args`]),a(`Output`,[`output`,`stdout`,`result`,`results`,`content`,`result_summary`,`observation`,`display_message`],typeof t.approval_decision==`string`?`error`:void 0),a(`Files`,[`files`,`outputFiles`]),a(`Error`,[`error`,`stderr`],`error`),i&&n.add(i.key);let o=uh(t,n);return r.length===0&&o&&r.push({key:`details`,label:`Details`,value:o}),r}function fh(e,t){if(e.type===Q.REQUEST_INPUT)return;let n=sm(e),r=Rm(e),i=Du(e),a=Km(e),o=Vm(r),s=Jm(r),c=typeof r.command==`string`&&r.command.trim()?r.command.trim():void 0,l=o[0]?Bm(o[0]):Qp(e),u=Ym(r.approval_decision,l),d=Xm(r.approval_decision),f=typeof r.message_to_human==`string`&&r.message_to_human.trim()?r.message_to_human.trim():void 0,p=a===`think`?n||l:nh(a===`command`?f||(u?``:n)||c||l:f||s||(u?``:n)||l),m=n?a===`think`?n:nh(n,420):void 0,h=m&&m!==p&&!u;if(!(!p&&!h))return{key:`${e.timestamp}-${r.activity_id||r.tool_run_id||t}`,kind:a,label:qm(a),title:p,isPreamble:i,command:c,text:h?m:void 0,toolName:Hm(r),startedAt:Um(r[Fm])??e.timestamp,finishedAt:Um(r[Im])??e.timestamp,status:u?`error`:r.tool_status,decisionText:d,resources:Fi(e),workflowRunId:e.workflow_run_id,sections:dh(e)}}function ph(e){let t=Rm(e);return t.tool===`plan`||t.tool===`update_plan`}function mh(e){let t=Rm(e);return e.type===Q.UPDATE&&Array.isArray(t.updates)?!0:e.type===Q.PLAN&&Array.isArray(t.plan)}function hh(e){return typeof e.activity_group_id==`string`&&e.activity_group_id.trim()?e.activity_group_id.trim():void 0}function gh(e){if(typeof e.tool_use_id==`string`&&e.tool_use_id.trim())return e.tool_use_id.trim();if(typeof e.tool_run_id==`string`&&e.tool_run_id.trim())return e.tool_run_id.trim();if(typeof e.tool==`string`&&e.tool.trim())return e.tool.trim()}function _h(e){let t=new Map,n=new Map,r=(e,t,n)=>{if(!t||!n)return;let r=e.get(t)??new Set;r.add(n),e.set(t,r)};for(let i of e){let e=Rm(i),a=hh(e),o=gh(e);e.tool_event===`started`&&r(t,a,o),typeof e.approval_decision==`string`&&r(n,a,o)}return new Set([...t.entries(),...n.entries()].filter(([,e])=>e.size>1).map(([e])=>e))}function vh(e,t){let n=hh(e),r=gh(e);if(n)return r&&t.has(n)?`activity:${n}:tool:${r}`:`activity:${n}`;if(typeof e.tool_use_id==`string`&&e.tool_use_id.trim())return`tool-use:${e.tool_use_id.trim()}`;if(typeof e.tool_run_id==`string`&&e.tool_run_id.trim())return`run:${e.tool_run_id.trim()}`}function yh(e){let t=new Map,n=[],r,i=_h(e);e.forEach((e,a)=>{let o=Rm(e);if(Du(e)){n.push({index:a,message:e}),r=void 0;return}let s=vh(o,i),c=!s&&mh(e)?r:void 0,l=s??c;if(!l){n.push({index:a,message:e});return}let u=t.get(l);u?u.messages.push(e):t.set(l,{index:a,messages:[e]}),ph(e)?r=l:e.type===Q.PLAN&&(r=void 0)});let a=Array.from(t.values()).map(({index:e,messages:t})=>{let n=[...t].sort((e,t)=>Kp(e.timestamp)-Kp(t.timestamp)),r=n[n.length-1],i=n.find(e=>Rm(e).tool_event===`started`),a=n.find(e=>sm(e)),o=n.findLast(e=>typeof Rm(e).approval_decision==`string`&&!!sm(e)),s=n.findLast(e=>sm(e).startsWith(`$ `)),c=n.findLast(e=>(e.type===Q.ERROR||e.type===Q.WARNING)&&sm(e)),l={};for(let e of n)Object.assign(l,Rm(e));c&&l.error===void 0&&l.stderr===void 0&&(l.error=sm(c)),!c&&n.some(e=>e.type===Q.PLAN&&Array.isArray(e.details?.plan))&&(l.tool_status=`completed`),s&&l.command===void 0&&(l.command=sm(s)),l[Fm]=n[0]?.timestamp,l[Im]=n[n.length-1]?.timestamp;let u=typeof i?.details?.message_to_human==`string`?i.details.message_to_human:``;return{index:e,message:{...r,message:o?.message||u||(a?a.message:r.message),details:l}}});return[...n,...a].sort((e,t)=>e.index-t.index).map(({message:e})=>e)}function bh(e){let t=new Set,n=[];return yh(e).forEach((e,r)=>{let i=fh(e,r);if(!i)return;let a=`${i.kind}:${i.label}:${i.title}:${i.text??``}`;t.has(a)||(t.add(a),n.push(i))}),n}function xh({kind:e,status:n}){if(n===`error`||n===`warning`)return t(Vt,{className:`size-3.5`});switch(e){case`search`:return t(Br,{className:`size-3.5`});case`read`:return t(Ln,{className:`size-3.5`});case`edit`:return t(Tr,{className:`size-3.5`});case`command`:return t(Qr,{className:`size-3.5`});case`skill`:return t(Yt,{className:`size-3.5`});case`discover`:return t(si,{className:`size-3.5`});case`think`:return t(Yt,{className:`size-3.5`});default:return t(si,{className:`size-3.5`})}}function Sh(e){let t=[],n=Xp(e.startedAt),r=Xp(e.finishedAt),i=Zp(e.startedAt),a=Zp(e.finishedAt);return e.toolName&&t.push({label:`Tool`,value:e.toolName}),i&&a&&n!==void 0&&r!==void 0&&n!==r?(t.push({label:`Started`,value:i}),t.push({label:`Ended`,value:a}),t.push({label:`Duration`,value:Yp(Jp(e.startedAt,e.finishedAt))})):(i||a)&&t.push({label:`Time`,value:i??a??``}),t}function Ch({hasDetailContent:e,item:r}){let i=Sh(r);return i.length===0?null:t(`dl`,{className:H(`flex flex-wrap gap-x-4 gap-y-1 text-xs`,e&&`mb-3 border-b border-border/60 pb-2`),children:i.map(e=>n(`div`,{className:`flex min-w-0 items-baseline gap-1.5`,children:[t(`dt`,{className:`shrink-0 text-muted`,children:e.label}),t(`dd`,{className:`min-w-0 wrap-break-word font-medium text-foreground/80`,children:e.value})]},e.label))})}function wh({section:e}){let r=e.value,i=typeof r==`string`||typeof r==`number`||typeof r==`boolean`,a=e.label===`Files`&&Array.isArray(r),o=e.label===`Output`;if(a)return t(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,children:Array.from(new Set(r.map(e=>Am(e)))).map(e=>t(`span`,{className:`rounded-md bg-mixer-muted/15 px-1.5 py-0.5 font-mono text-[11px] text-muted`,children:nh(e,64)},e))});let s=H(`text-xs font-medium`,e.tone===`error`?`text-destructive`:`text-muted`),c=i&&!String(r).includes(`
|
|
56
|
-
`)&&String(r).length<180?t(`div`,{className:H(`break-words text-xs`,e.tone===`error`?`text-destructive`:`text-foreground/75`),children:String(r)}):t(`pre`,{className:H(`max-h-52 overflow-auto whitespace-pre-wrap rounded-lg px-3 py-2 font-mono text-[11px] leading-relaxed`,e.tone===`error`?`bg-destructive/5 text-destructive`:`bg-mixer-muted/10 text-foreground/75`),children:
|
|
53
|
+
`}),!b&&t(`div`,{className:`group`,children:v.map((e,n)=>{let r=y[n]??Vf(e);return t(Zf,{message:e,isExpanded:S.has(r),onToggle:()=>R(r),artifactRunId:k,classNames:{toolBadgeClassName:m,itemClassName:h,itemHeaderClassName:g,itemContentClassName:_}},r)})})]})}const tp=ct(ep,(e,t)=>e.messages.length!==t.messages.length||e.showPulsatingCircle!==t.showPulsatingCircle||e.toolRunId!==t.toolRunId||e.toolStatus!==t.toolStatus||e.preambleText!==t.preambleText||e.rootClassName!==t.rootClassName||e.headerClassName!==t.headerClassName||e.senderClassName!==t.senderClassName||e.toolSummaryClassName!==t.toolSummaryClassName||e.toolBadgeClassName!==t.toolBadgeClassName||e.itemClassName!==t.itemClassName||e.itemHeaderClassName!==t.itemHeaderClassName||e.itemContentClassName!==t.itemContentClassName?!1:e.messages.every((e,n)=>Hf(e,t.messages[n]))),np=`flex items-center gap-1.5 px-2 py-1 text-xs font-medium whitespace-nowrap transition-colors border-b-2 shrink-0 cursor-pointer`,rp=`border-transparent text-muted hover:bg-muted`,ip=`border-info bg-info text-info`;function ap(e){return e.length>20?`${e.substring(0,18)}...`:e}function op({items:e,current:r,onSelect:i,label:a,active:o,count:s,completionStatus:c}){return t(V,{label:a,triggerClassName:H(np,o?ip:rp),icon:t(un,{className:`ms-0.5 size-3.5`}),children:e.map(([e,a])=>{let o=(s?.get(e)??0)>0;return n(D,{onClick:()=>i(e),className:H(`flex items-center gap-2`,e===r&&`text-info`),children:[t(`span`,{className:`truncate`,children:a}),o&&n(`span`,{className:`ms-auto inline-flex items-center gap-1`,children:[t(`span`,{className:`inline-flex items-center justify-center rounded-full bg-muted px-1.5 text-[10px] text-muted`,children:s?.get(e)}),c&&e!==`all`&&(c.get(e)?t(on,{className:`size-3 text-success`}):t(wn,{className:`size-3 text-attention`}))]})]},e)})})}function sp({entries:r,activeWorkstream:i,onSelectWorkstream:a,count:o,completionStatus:s}){let{t:c}=Z(),{containerRef:l,setItemRef:u,setMoreRef:d,visible:f,overflow:p,activeInOverflow:m}=Je(r,([e])=>e===i),h=c(`agent.moreTabs`),g=(r,i,a)=>{let c=(o?.get(r)??0)>0;return n(e,{children:[ap(i),c&&n(`span`,{className:`flex items-center gap-1`,children:[t(`span`,{className:H(`inline-flex items-center justify-center p-1 text-xs rounded-full`,a?`bg-info text-info`:`bg-muted text-muted`),children:o?.get(r)}),s&&r!==`all`&&(s.get(r)?t(on,{className:`size-3 text-success`}):t(wn,{className:`size-3 text-attention`}))]})]})};return n(`div`,{ref:l,className:`relative mb-1 bg-muted border-b border-muted/20`,children:[n(`div`,{"aria-hidden":!0,className:`pointer-events-none invisible absolute start-0 top-0 flex w-max gap-1`,children:[r.map(([e,n],r)=>t(`button`,{type:`button`,tabIndex:-1,ref:u(r),className:H(np,rp),children:g(e,n,!1)},e)),n(`button`,{type:`button`,tabIndex:-1,ref:d,className:H(np,rp),children:[h,t(un,{className:`ms-0.5 size-3.5`})]})]}),n(`div`,{className:`flex gap-1 overflow-hidden`,children:[f.map(([e,n])=>{let r=i===e;return t(`button`,{type:`button`,"aria-current":r?`page`:void 0,onClick:()=>a(e),title:n.length>20?n:void 0,className:H(np,r?ip:rp),children:g(e,n,r)},e)}),p.length>0&&t(op,{items:p,current:i,onSelect:a,label:h,active:m,count:o,completionStatus:s})]})]})}function cp({workstreams:e,activeWorkstream:n,onSelectWorkstream:r,count:i,completionStatus:a}){let{t:o}=Z(),s=new Map;s.set(`all`,o(`agent.allMessages`)),s.set(`main`,o(`agent.main`)),e.forEach((e,t)=>{t!==`all`&&t!==`main`&&t!==`research_france`&&t!==`statistics`&&s.set(t,e)}),e=s;let c=Array.from(e.entries()).sort(([e],[t])=>e===`all`?-1:t===`all`?1:e===`main`?-1:t===`main`?1:e.localeCompare(t));return c.length>2?t(sp,{entries:c,activeWorkstream:n,onSelectWorkstream:r,count:i,completionStatus:a}):t(`div`,{className:`py-0.5`})}function lp(e){let t=new Map,n=Vt.getFixedT(null,Bt);return t.set(`all`,n(`agent.allMessages`)),t.set(`main`,n(`agent.main`)),e.forEach(e=>{e.workstream_id&&e.workstream_id!==`main`&&e.workstream_id!==`all`&&!t.has(e.workstream_id)&&t.set(e.workstream_id,e.workstream_id)}),t}function up(e,t){return t===`all`?[...e]:t===`main`?e.filter(e=>Pl(e)===`main`):e.filter(e=>Pl(e)===t)}const dp=e=>e.type===$.BATCH_PROGRESS&&!!e.details?.batch_id;function fp(e){if(e==null||e===``)return Date.now();let t=typeof e==`number`?e:new Date(e).getTime();return Number.isFinite(t)?t:Date.now()}function pp(e){let t=Date.now()-fp(e);return Math.max(0,Math.round(t/1e3))}function mp(e,t){let n=fp(t)-fp(e);return Math.max(0,Math.round(n/1e3))}function hp(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function gp(e){if(e==null||e===``)return;let t=typeof e==`number`?e:new Date(e).getTime();return Number.isFinite(t)?t:void 0}function _p(e){let t=gp(e);if(t!==void 0)return new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}).format(new Date(t))}function vp(e){let t=e.details,n=t?.tool||``,r=Array.isArray(t?.tools)?t.tools.map(e=>typeof e==`string`?e:e.name||e.tool||``).filter(Boolean):[],i=[n,...r].join(` `).toLowerCase(),a=n.toLowerCase(),o=typeof e.message==`string`?e.message.trim():``;return t?.display_role===`tool_preamble`?i.includes(`search`)||i.includes(`web`)||i.includes(`fetch`)?`Preparing search`:r.length>0?`Preparing tools`:`Thinking`:a.includes(`search`)?`Searching`:a.includes(`fetch`)||a.includes(`web`)?`Searching the web`:a.includes(`read`)||a.includes(`document`)?`Reading`:a.includes(`edit`)||a.includes(`write`)||a.includes(`create`)?`Editing`:a.includes(`bash`)||a.includes(`shell`)||a.includes(`command`)?`Running command`:o||`Using tool`}function yp(e){return e?`Working`:`Worked`}function bp(e){return e.length>0&&e.every(gf)}function xp(e){return yp(e)}function Sp(e){let t=e.filter(e=>Pl(e)===`main`);return(t[t.length-1]??e[e.length-1])?.type===$.QUESTION}function Cp(e,t){let n=e.filter(e=>Pl(e)===`main`),r=n[n.length-1]??e[e.length-1];if(!r||!Mu(r,t))return!1;let i=ym(r);return i===`allow_once`||i===`allow_for_run`}function wp(e){if(e.type!==$.UPDATE)return;let t=im(e);if(t.tool!==void 0||t.activity_group_id!==void 0)return;let n=typeof t.path==`string`&&t.path.trim()?t.path.trim():void 0;if(n)return Dp(e)===`Prepared and saved artifact to ${n}`?n:void 0}function Tp(e,t){let n=Pl(e[t]);for(let r=t-1;r>=0;--r){let t=e[r];if(Pl(t)!==n)continue;let i=im(t);if(i.tool===`write_artifact`&&typeof i.activity_group_id==`string`)return t;if(t.type!==$.REQUEST_INPUT&&!ym(t)&&i.display_role!==`thinking`&&(typeof i.tool==`string`&&i.tool!==`write_artifact`||t.type===$.ANSWER||t.type===$.COMPLETE||t.type===$.IDLE||t.type===$.TERMINATED))return}}function Ep(e){return e.map((t,n)=>{let r=wp(t);if(!r)return t;let i=Tp(e,n),a=i?im(i):void 0;if(!a)return t;let o=typeof a.activity_group_id==`string`?a.activity_group_id:void 0,s=typeof a.tool_run_id==`string`?a.tool_run_id:void 0,c=typeof a.tool_use_id==`string`?a.tool_use_id:void 0,l=typeof a.tool_iteration==`number`?a.tool_iteration:void 0;return o?{...t,details:{...t.details,event_class:`activity`,tool:`write_artifact`,tool_run_id:s??`write_artifact`,tool_use_id:c??s??`write_artifact`,tool_iteration:l,tool_status:`completed`,tool_event:`progress`,activity_group_id:o,output:Dp(t),path:r}}:t})}function Dp(e){return e.message?typeof e.message==`object`?JSON.stringify(e.message,null,2):String(e.message).trim():``}function Op({message:e,details:r,onSelectWorkstream:i}){let{t:a}=Z(),o=hl(r.workstreamId,r.interaction),s=r.interaction?pl(r.interaction):``,c=s&&s!==o?s:void 0;return t(`div`,{className:`mx-auto w-full max-w-3xl px-1`,"data-workstream-id":r.workstreamId,children:n(`button`,{type:`button`,className:H(`group flex w-full items-start gap-3 border-b border-border/70 py-2 text-start text-sm text-muted`,`transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2`,`focus-visible:ring-focus focus-visible:ring-offset-2 focus-visible:ring-offset-background`),onClick:()=>i?.(r.workstreamId),children:[t(Zt,{className:`mt-0.5 size-4 shrink-0 text-muted`,"aria-hidden":`true`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1`,children:[t(`span`,{className:`font-medium text-muted`,children:a(`agent.workstreams`)}),t(`span`,{className:`min-w-0 truncate text-foreground/85`,children:o})]}),c&&t(`div`,{className:`mt-0.5 truncate text-xs text-muted/75`,children:c}),t(`span`,{className:`sr-only`,children:Dp(e)})]}),t(pn,{className:`mt-0.5 size-4 shrink-0 text-muted transition-transform group-hover:translate-x-0.5 rtl:rotate-180 rtl:group-hover:-translate-x-0.5`})]})})}const kp=/\[[^\]]+\]\((?:\/store\/(?:objects|collections)\/|store:|document:|document:\/\/|collection:)[^)]+\)/,Ap={table:zp};function jp(e){if(!e||typeof e!=`object`)return``;let t=e;return typeof t.value==`string`?t.value:Array.isArray(t.children)?t.children.map(jp).join(``):``}function Mp(e,t){if(!e||typeof e!=`object`)return[];let n=e.children;return Array.isArray(n)?n.filter(e=>{if(!e||typeof e!=`object`)return!1;let n=e;return t?n.tagName===t:typeof n.tagName==`string`}):[]}function Np(e){return Mp(e).filter(e=>e.tagName===`thead`||e.tagName===`tbody`).flatMap(e=>Mp(e,`tr`).map(e=>Mp(e).filter(e=>e.tagName===`th`||e.tagName===`td`).map(e=>jp(e).replace(/\s+/g,` `).trim())))}function Pp(e){return Mp(e,`tbody`).flatMap(e=>Mp(e,`tr`).map(e=>Mp(e,`td`).map(e=>jp(e).replace(/\s+/g,` `).trim())))}function Fp(e){let t=Np(e),n=Pp(e),r=Math.max(0,...t.map(e=>e.length));if(r<=1)return new Set;let i=new Set;for(let e=0;e<r;e+=1){let t=n.map(t=>t[e]||``).map(e=>e.trim()).filter(Boolean);if(t.length===0)continue;let r=t.map(e=>e.length),a=Math.max(...r),o=r.reduce((e,t)=>e+t,0)/r.length,s=t.some(e=>/\S{12,}/.test(e));a<=16&&o<=10&&!s&&i.add(e)}return i.size>=r?new Set:i}function Ip(e,t,n){return Math.min(n,Math.max(t,e))}function Lp(e){return e.reduce((e,t)=>{let n=t.match(/\S+/g)||[];return Math.max(e,...n.map(e=>e.length))},0)}function Rp(e){let t=Np(e),n=Math.max(0,...t.map(e=>e.length));if(n<=1)return[];let r=Fp(e),i=Array.from({length:n},(e,n)=>{if(r.has(n))return 8;let i=t.map(e=>e[n]||``).map(e=>e.trim()).filter(Boolean);if(i.length===0)return 18;let a=i.map(e=>e.length),o=Math.max(...a),s=a.reduce((e,t)=>e+t,0)/a.length,c=Lp(i);return Ip(s*.7+o*.25+c*.45,18,90)}),a=i.reduce((e,t)=>e+t,0);return a<=0?[]:i.map((e,t)=>{let n=`${(e/a*100).toFixed(3)}%`;return{key:`agent-markdown-table-column-${t}`,compact:r.has(t),width:n}})}function zp({node:e,className:r,children:i,...a}){let o=Rp(e);return n(`table`,{...a,className:r,children:[o.length>0?t(`colgroup`,{children:o.map(e=>t(`col`,{className:e.compact?`agent-markdown-table-compact-col`:void 0,style:{"--agent-markdown-table-column-width":e.width}},e.key))}):null,i]})}function Bp(e){if(e==null||typeof e==`boolean`)return 0;if(typeof e==`string`||typeof e==`number`)return String(e).length;if(Array.isArray(e))return e.reduce((e,t)=>e+Bp(t),0);if(G.isValidElement(e)){let t=e.props;return Bp(t.children)}return 0}function Vp(e,t){let[n,r]=X(()=>pp(e));return q(()=>{if(!t){r(pp(e));return}let n=()=>r(pp(e));n();let i=window.setInterval(n,1e3);return()=>window.clearInterval(i)},[t,e]),n}function Hp(e=!0){let[t,n]=X(0);return q(()=>{if(!e)return;let t=window.setInterval(()=>{n(()=>Math.floor(Math.random()*nd.length))},4e3);return()=>window.clearInterval(t)},[e]),t}function Up({children:e,message:r,workstreamId:i,className:a,artifactRunId:o,onOpenArtifact:s,markdownComponents:c}){let{t:l}=Z(),[u,d]=X(!1),f=J(()=>Bp(e),[e])>520,p=typeof e==`string`||typeof e==`number`,m=p?String(e):``,h=typeof e==`string`&&kp.test(e),g=r?jd(r):void 0;return q(()=>{!f&&u&&d(!1)},[u,f]),t(`div`,{className:`mx-auto flex w-full max-w-3xl justify-end px-1`,children:n(`div`,{className:H(`max-w-[min(44rem,82%)] rounded-[1.35rem] bg-mixer-muted/35 px-4 py-2.5`,`text-sm font-normal leading-6 text-foreground/90 shadow-sm shadow-black/5 dark:bg-mixer-muted/15 dark:text-foreground/88 dark:shadow-none`,`break-words [overflow-wrap:anywhere]`,a),"data-workstream-id":i,children:[t(`div`,{className:H(p&&!h&&`whitespace-pre-wrap`,f&&!u&&`max-h-72 overflow-hidden [mask-image:linear-gradient(to_bottom,black_76%,transparent_100%)]`),children:h?t(wt,{artifactRunId:o,onArtifactOpen:s,components:c,className:H(`agent-markdown vprose prose max-w-none break-words text-sm leading-6 text-foreground/90`,`prose-p:my-0 prose-p:leading-6 prose-a:text-foreground prose-a:underline prose-a:decoration-muted prose-a:underline-offset-4`,`[&_p+_p]:mt-2`),children:m}):e}),f&&n(`button`,{type:`button`,"aria-expanded":u,className:`mt-2 inline-flex items-center gap-1 text-sm font-medium text-muted transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,onClick:()=>d(e=>!e),children:[l(u?`agent.showLess`:`agent.showMore`),t(un,{className:H(`size-4 transition-transform`,u&&`rotate-180`),"aria-hidden":`true`})]}),r&&g?t(`div`,{className:`mt-1.5 flex justify-end`,children:t(Nd,{message:r,className:`h-4 w-4`})}):null]})})}function Wp({message:r,onSendMessage:i,onOpenArtifact:a,onSelectWorkstream:o,requestInputAnswered:s=!1,StoreLinkComponent:c,CollectionLinkComponent:l}){let{router:u}=va(),d=r.type===$.REQUEST_INPUT?tu(r):Dp(r),f=Cl(r)??wl(r),p=Pl(r),m=r.workflow_run_id,h=J(()=>r.type===$.QUESTION?Td(d):null,[d,r.type]),g=J(()=>r.type===$.QUESTION?Yu(r.details?.editing_action):void 0,[r.details,r.type]),_=J(()=>({...Ap,a:id({StoreLinkComponent:c,CollectionLinkComponent:l,addStickyParams:e=>u.getTopRouter().navigator.addStickyParams(e)})}),[c,l,u]);if(f)return t(Op,{message:r,details:f,onSelectWorkstream:o});if(r.type===$.QUESTION){let i=h?.body??d,o=h?.attachments??[];return n(e,{children:[o.length>0&&t(`div`,{className:`mx-auto flex w-full max-w-3xl justify-end px-1`,children:t(bd,{items:o,artifactRunId:m,onOpenArtifact:a,align:`end`,variant:`message`,StoreLinkComponent:c,CollectionLinkComponent:l})}),i&&t(Up,{message:r,workstreamId:p,artifactRunId:m,onOpenArtifact:a,markdownComponents:_,className:g?`max-w-[min(44rem,90%)]`:void 0,children:g?t(td,{action:g}):i})]})}let v=r.details;if(r.type===$.REQUEST_INPUT&&v?.ux){let e=v.ux;return t(`div`,{className:`mx-auto w-full max-w-3xl px-1`,children:t(dl,{question:d,options:e.options,variant:e.variant,multiSelect:e.multiSelect,onSelect:e=>vu(i,r,e,wu(r,e)),onMultiSelect:e=>vu(i,r,e.join(`, `)),allowFreeResponse:!e.options?.length||!!e.free_response,placeholder:e.free_response?.placeholder,submitLabel:e.free_response?.submit_label,onSubmit:t=>vu(i,r,t,e.free_response?.metadata),hideBorder:!0,compact:!0,answered:s})})}let y=r.type===$.ERROR||r.type===$.WARNING;return n(`div`,{className:`mx-auto w-full max-w-3xl px-1`,"data-workstream-id":p,children:[y&&t(`div`,{className:`mb-2 text-xs font-medium text-destructive`,children:r.type===$.WARNING?`Warning`:`Error`}),d&&t(`div`,{className:H(Uu,y&&`rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2`),style:{overflowWrap:`anywhere`},children:t(wt,{artifactRunId:m,onArtifactOpen:a,onProposalSelect:e=>i?.(e),onProposalSubmit:e=>i?.(e),components:_,children:d})})]})}function Gp(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Kp(e){return e==null?!1:typeof e==`string`?e.trim().length>0:Array.isArray(e)?e.length>0:typeof e!=`object`||Object.keys(e).length>0}function qp(e){return e==null||e===!1?!1:typeof e!=`string`||e.trim().length>0}function Jp(e){if(!e||!Gp(e))return{};let t=e.properties;return Gp(t)?t:{}}function Yp(e,t){let n=e&&Gp(e)?e.title:void 0;return typeof n==`string`&&n.trim()?n:t.replace(/[_-]+/g,` `).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/\b\w/g,e=>e.toUpperCase())}function Xp(e){if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Zp(e){return e==null||e===``?t(`span`,{className:`text-muted`,children:`Not provided`}):typeof e==`boolean`?e?`Yes`:`No`:typeof e==`number`?String(e):typeof e==`string`?t(`span`,{className:`whitespace-pre-wrap`,children:e}):Array.isArray(e)&&e.every(e=>typeof e!=`object`||!e)?e.map(e=>Xp(e)).join(`, `):t(`pre`,{className:`max-h-40 overflow-auto whitespace-pre-wrap rounded-md bg-background/55 px-2 py-1.5 font-mono text-[12px] leading-relaxed text-foreground/80`,children:Xp(e)})}function Qp(e,r,i){if(!Kp(e))return null;if(!Gp(e))return Zp(e);let a=Jp(r),o=[...Object.keys(a),...Object.keys(e).filter(e=>!(e in a))].map(t=>({key:t,label:Yp(a[t],t),value:e[t]})).filter(e=>Kp(e.value));return o.length===0?null:n(`div`,{className:`space-y-2 text-start`,children:[i?t(`div`,{className:`text-xs font-medium uppercase tracking-normal text-muted`,children:i}):null,t(`dl`,{className:`space-y-2`,children:o.map(e=>n(`div`,{className:`grid gap-1 sm:grid-cols-[minmax(7rem,32%)_1fr] sm:gap-3`,children:[t(`dt`,{className:`text-xs font-medium text-muted`,children:e.label}),t(`dd`,{className:`min-w-0 break-words text-sm text-foreground`,children:Zp(e.value)})]},e.key))})]})}function $p({data:e,schema:n,title:r,template:i,prependFriendlyMessage:a,timestamp:o,isSummaryView:s,messageItemClassNames:c,messageStyleOverrides:l,StoreLinkComponent:u,CollectionLinkComponent:d}){let f=a?.trim()||(typeof e==`string`?e.trim():``),p=i?.({data:e??a,schema:n,title:r});if(!qp(p)&&f){let e={type:$.QUESTION,message:f,timestamp:fp(o),workflow_run_id:``,workstream_id:`main`};return s?t(Wp,{message:e,StoreLinkComponent:u,CollectionLinkComponent:d}):t(Qd,{...c,messageStyleOverrides:l,message:e})}let m=qp(p)?p:Qp(e,n,r);return qp(m)?t(Up,{className:`py-3`,children:m}):null}function em({label:e,timestamp:r,className:i}){let a=Hp(),o=Vp(r,!0);return t(`div`,{className:H(`mx-auto w-full max-w-3xl px-1`,i),children:n(`div`,{className:`border-b border-border/70 pb-4 text-sm text-muted`,children:[n(`div`,{className:`flex items-center gap-3`,children:[t(Ru,{size:`sm`,color:`blue`}),n(`div`,{className:`min-w-0`,children:[n(`div`,{children:[t(`span`,{className:`font-medium`,children:e}),n(`span`,{className:`ms-2 text-muted/75`,children:[`for `,hp(o)]})]}),t(`div`,{className:`mt-1 truncate text-muted/80`,children:nd[a]})]})]}),t(`div`,{className:`mt-3 ps-6`,children:t(Lu,{color:`blue`})})]})})}const tm=`_summary_started_at`,nm=`_summary_finished_at`,rm=new Set([`account_id`,`activity_group_id`,`activity_id`,`channel_id`,`collection_id`,`document_id`,`display_role`,`duration_ms`,`event_class`,`id`,`object_id`,`project_id`,`run_id`,`streamed`,`tenant_id`,`thread_id`,`tool`,`tool_event`,`tool_iteration`,`tool_run_id`,`tool_use_id`,`tool_status`,`tools`,`message_to_human`,`progress_messages`,`resources`,`source`,`token_usage`,`checkpoint_at`,`checkpoint_threshold`,`approval_decision`,`approval_request`,`cancellation_reason`,tm,nm,`workflow_run_id`]);function im(e){return Gp(e.details)?e.details:{}}function am(e){if(e.type!==$.UPDATE)return!1;let t=im(e).event_class;return t===`document_created`||t===`document_updated`}function om(e){return e.replace(/[_-]+/g,` `).replace(/\s+/g,` `).trim().replace(/\b\w/g,e=>e.toUpperCase())}function sm(e){let t=[];if(typeof e.tool==`string`&&e.tool.trim()&&t.push(e.tool.trim()),Array.isArray(e.tools)){for(let n of e.tools)if(typeof n==`string`&&n.trim())t.push(n.trim());else if(Gp(n)){let e=typeof n.name==`string`?n.name:n.tool;typeof e==`string`&&e.trim()&&t.push(e.trim())}}return t}function cm(e){let t=Array.from(new Set(sm(e)));return t.length>0?t.join(`, `):void 0}function lm(e){return typeof e==`number`||typeof e==`string`?e:void 0}const um=[`query`,`path`,`file`,`file_name`,`fileName`,`filename`,`name`,`title`,`artifact`,`artifact_path`,`url`,`command`];function dm(e){for(let t of um){let n=e[t];if(typeof n==`string`&&n.trim())return{key:t,value:n.trim()};if(typeof n==`number`||typeof n==`boolean`)return{key:t,value:String(n)}}}function fm(e){let t=im(e),n=sm(t).join(` `).toLowerCase(),r=typeof t.tool==`string`?t.tool.toLowerCase():``,i=r||n;return Gl(e)?`think`:r.startsWith(`learn_`)||n.includes(`learn_`)?`skill`:r===`discover_tools`?`discover`:e.type===$.THOUGHT&&!r?`think`:i.includes(`search`)||i.includes(`web`)||i.includes(`fetch`)?`search`:i.includes(`read`)||i.includes(`document`)||i.includes(`file`)?`read`:i.includes(`edit`)||i.includes(`write`)||i.includes(`patch`)||i.includes(`create`)?`edit`:i.includes(`bash`)||i.includes(`shell`)||i.includes(`command`)||i.includes(`terminal`)?`command`:e.type===$.THOUGHT&&n.length===0?`think`:`tool`}function pm(e){switch(e){case`search`:return`Search`;case`read`:return`Read`;case`edit`:return`Edit`;case`command`:return`Bash`;case`skill`:return`Skill`;case`discover`:return`Tool`;case`think`:return`Thought`;default:return`Tool`}}function mm(e){let t=dm(e);if(t)return t.value;let n=e.files??e.outputFiles;if(Array.isArray(n)&&n.length>0)return n.map(e=>Xp(e)).join(`, `)}function hm(e,t){switch(e){case`denied`:case`denied_with_feedback`:return`User declined to use ${t}.`;case`timeout`:return`Approval timed out for ${t}.`;case`reviewer_denied`:return`Approval reviewer denied ${t}.`;case`cancelled_after_denial`:return`Cancelled ${t} after another tool was denied.`;default:return}}function gm(e){switch(e){case`denied`:case`denied_with_feedback`:return`Declined by user`;case`timeout`:return`Approval timed out`;case`reviewer_denied`:return`Denied by reviewer`;case`cancelled_after_denial`:return`Cancelled after denial`;default:return}}function _m(e){let t=im(e).tool_approval;return Gp(t)?t:void 0}function vm(e){let t=e?.approval_key;return typeof t==`string`&&t.trim()?t.trim():void 0}function ym(e){if(e.type!==$.QUESTION)return;let t=Dp(e).trim().toLowerCase();if(t===`allow_once`||t===`allow_for_run`||t===`deny`)return t}function bm(e){let t=e.tool_title;if(typeof t==`string`&&t.trim())return t.trim();let n=e.tool_name;return typeof n==`string`&&n.trim()?om(n.trim()):`tool action`}function xm(e,t){let n=[];return e.forEach((r,i)=>{if(r.type!==$.REQUEST_INPUT)return;let a=_m(r),o=vm(a);if(!a||!o||t.has(o))return;let s=Pl(r),c;for(let t=i+1;t<e.length;t+=1){let n=e[t];if(Pl(n)===s){if(n.type===$.REQUEST_INPUT)break;if(n.type===$.QUESTION){c=n;break}}}if(!c||ym(c)!==`deny`)return;let l=typeof a.tool_name==`string`&&a.tool_name.trim()?a.tool_name.trim():`tool_action`,u=bm(a),d=typeof a.target==`string`&&a.target.trim()?a.target:``,f={tool_name:l,tool_title:a.tool_title,action_summary:a.action_summary,target:a.target,approval_key:o};n.push({timestamp:c.timestamp??r.timestamp,workflow_run_id:c.workflow_run_id||r.workflow_run_id,type:$.THOUGHT,message:hm(`denied`,u)??`User declined to use ${u}.`,workstream_id:s,details:{event_class:`activity`,tool:l,tool_run_id:`approval:${o}`,tool_use_id:`approval:${o}`,tool_status:`error`,tool_event:`failed`,activity_group_id:`approval:${o}`,approval_decision:`denied`,approval_request:f,input:a.input,target:d,observation:`The user declined this tool action.`,source:`synthetic_tool_approval_decision`}})}),n.length===0?e:[...e,...n].sort((e,t)=>fp(e.timestamp)-fp(t.timestamp))}function Sm(e,t=160){let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1)}...`:n}const Cm=[`batch_id`,`activity_group_id`,`activity_id`,`tool_run_id`,`tool_use_id`,`streaming_id`,`chunk_index`,`tool_iteration`,`tool_event`];function wm(e){for(let t of Cm){let n=e[t];if(typeof n==`string`&&n.trim())return`${t}:${n.trim()}`;if(typeof n==`number`||typeof n==`boolean`)return`${t}:${n}`}}function Tm(e,t=`message`){let n=wm(im(e)),r=Sm(Dp(e),96);return[t,e.workstream_id||`main`,e.workflow_run_id,e.timestamp,e.type,n??r].filter(Boolean).join(`:`)}function Em(e){if(e.type===`single`)return Tm(e.message);if(e.type===`streaming`)return`streaming:${e.streamingId}:${e.startTimestamp}:${e.workstreamId||`main`}`;let t=e.messages[0],n=e.messages[e.messages.length-1],r=t?Tm(t,`first`):e.firstTimestamp,i=n?Tm(n,`last`):e.firstTimestamp;return[`group`,e.toolRunId,e.firstTimestamp,r,i].filter(Boolean).join(`:`)}function Dm(e,t){for(let n=t-1;n>=0;n--){let t=e[n];if(t.type===`single`)return t.message.timestamp;if(t.type===`tool_group`)return t.firstTimestamp;if(t.type===`streaming`)return t.startTimestamp}}function Om(e){let t=Xp(e).trim();return t.length>2400?`${t.slice(0,2400)}\n...`:t}function km(e,t,n,r){if(n!=null&&n!==``&&!(Array.isArray(n)&&n.length===0)&&!(Gp(n)&&Object.keys(n).length===0))return{key:e,label:t,value:n,tone:r}}function Am(e,t){let n=Object.entries(e).reduce((e,[n,r])=>(rm.has(n)||t.has(n)||r==null||r===``||(e[n]=r),e),{});return Object.keys(n).length>0?n:void 0}function jm(e){let t=im(e),n=new Set,r=[],i=dm(t),a=(e,i,a)=>{for(let o of i){let i=km(o,e,t[o],a);if(i){n.add(o),r.push(i);return}}};a(`Query`,[`query`]),a(`Input`,[`input`,`params`,`arguments`,`args`]),a(`Output`,[`output`,`stdout`,`result`,`results`,`content`,`result_summary`,`observation`,`display_message`],typeof t.approval_decision==`string`?`error`:void 0),a(`Files`,[`files`,`outputFiles`]),a(`Error`,[`error`,`stderr`],`error`),i&&n.add(i.key);let o=Am(t,n);return r.length===0&&o&&r.push({key:`details`,label:`Details`,value:o}),r}function Mm(e,t){if(e.type===$.REQUEST_INPUT)return;let n=Dp(e),r=im(e),i=Gl(e),a=fm(e),o=sm(r),s=mm(r),c=typeof r.command==`string`&&r.command.trim()?r.command.trim():void 0,l=o[0]?om(o[0]):vp(e),u=hm(r.approval_decision,l),d=gm(r.approval_decision),f=typeof r.message_to_human==`string`&&r.message_to_human.trim()?r.message_to_human.trim():void 0,p=a===`think`?n||l:Sm(a===`command`?f||(u?``:n)||c||l:f||s||(u?``:n)||l),m=n?a===`think`?n:Sm(n,420):void 0,h=m&&m!==p&&!u;if(!(!p&&!h))return{key:`${e.timestamp}-${r.activity_id||r.tool_run_id||t}`,kind:a,label:pm(a),title:p,isPreamble:i,command:c,text:h?m:void 0,toolName:cm(r),startedAt:lm(r[tm])??e.timestamp,finishedAt:lm(r[nm])??e.timestamp,status:u?`error`:r.tool_status,decisionText:d,resources:Vi(e),workflowRunId:e.workflow_run_id,sections:jm(e)}}function Nm(e){let t=im(e);return t.tool===`plan`||t.tool===`update_plan`}function Pm(e){let t=im(e);return e.type===$.UPDATE&&Array.isArray(t.updates)?!0:e.type===$.PLAN&&Array.isArray(t.plan)}function Fm(e){return typeof e.activity_group_id==`string`&&e.activity_group_id.trim()?e.activity_group_id.trim():void 0}function Im(e){if(typeof e.tool_use_id==`string`&&e.tool_use_id.trim())return e.tool_use_id.trim();if(typeof e.tool_run_id==`string`&&e.tool_run_id.trim())return e.tool_run_id.trim();if(typeof e.tool==`string`&&e.tool.trim())return e.tool.trim()}function Lm(e){let t=new Map,n=new Map,r=(e,t,n)=>{if(!t||!n)return;let r=e.get(t)??new Set;r.add(n),e.set(t,r)};for(let i of e){let e=im(i),a=Fm(e),o=Im(e);e.tool_event===`started`&&r(t,a,o),typeof e.approval_decision==`string`&&r(n,a,o)}return new Set([...t.entries(),...n.entries()].filter(([,e])=>e.size>1).map(([e])=>e))}function Rm(e,t){let n=Fm(e),r=Im(e);if(n)return r&&t.has(n)?`activity:${n}:tool:${r}`:`activity:${n}`;if(typeof e.tool_use_id==`string`&&e.tool_use_id.trim())return`tool-use:${e.tool_use_id.trim()}`;if(typeof e.tool_run_id==`string`&&e.tool_run_id.trim())return`run:${e.tool_run_id.trim()}`}function zm(e){let t=new Map,n=[],r,i=Lm(e);e.forEach((e,a)=>{let o=im(e);if(Gl(e)){n.push({index:a,message:e}),r=void 0;return}let s=Rm(o,i),c=!s&&Pm(e)?r:void 0,l=s??c;if(!l){n.push({index:a,message:e});return}let u=t.get(l);u?u.messages.push(e):t.set(l,{index:a,messages:[e]}),Nm(e)?r=l:e.type===$.PLAN&&(r=void 0)});let a=Array.from(t.values()).map(({index:e,messages:t})=>{let n=[...t].sort((e,t)=>fp(e.timestamp)-fp(t.timestamp)),r=n[n.length-1],i=n.find(e=>im(e).tool_event===`started`),a=n.find(e=>Dp(e)),o=n.findLast(e=>typeof im(e).approval_decision==`string`&&!!Dp(e)),s=n.findLast(e=>Dp(e).startsWith(`$ `)),c=n.findLast(e=>(e.type===$.ERROR||e.type===$.WARNING)&&Dp(e)),l={};for(let e of n)Object.assign(l,im(e));c&&l.error===void 0&&l.stderr===void 0&&(l.error=Dp(c)),!c&&n.some(e=>e.type===$.PLAN&&Array.isArray(e.details?.plan))&&(l.tool_status=`completed`),s&&l.command===void 0&&(l.command=Dp(s)),l[tm]=n[0]?.timestamp,l[nm]=n[n.length-1]?.timestamp;let u=typeof i?.details?.message_to_human==`string`?i.details.message_to_human:``;return{index:e,message:{...r,message:o?.message||u||(a?a.message:r.message),details:l}}});return[...n,...a].sort((e,t)=>e.index-t.index).map(({message:e})=>e)}function Bm(e){let t=new Set,n=[];return zm(e).forEach((e,r)=>{let i=Mm(e,r);if(!i)return;let a=`${i.kind}:${i.label}:${i.title}:${i.text??``}`;t.has(a)||(t.add(a),n.push(i))}),n}function Vm({kind:e,status:n}){if(n===`error`||n===`warning`)return t(Kt,{className:`size-3.5`});switch(e){case`search`:return t(Kr,{className:`size-3.5`});case`read`:return t(Hn,{className:`size-3.5`});case`edit`:return t(jr,{className:`size-3.5`});case`command`:return t(ii,{className:`size-3.5`});case`skill`:return t(en,{className:`size-3.5`});case`discover`:return t(pi,{className:`size-3.5`});case`think`:return t(en,{className:`size-3.5`});default:return t(pi,{className:`size-3.5`})}}function Hm(e){let t=[],n=gp(e.startedAt),r=gp(e.finishedAt),i=_p(e.startedAt),a=_p(e.finishedAt);return e.toolName&&t.push({label:`Tool`,value:e.toolName}),i&&a&&n!==void 0&&r!==void 0&&n!==r?(t.push({label:`Started`,value:i}),t.push({label:`Ended`,value:a}),t.push({label:`Duration`,value:hp(mp(e.startedAt,e.finishedAt))})):(i||a)&&t.push({label:`Time`,value:i??a??``}),t}function Um({hasDetailContent:e,item:r}){let i=Hm(r);return i.length===0?null:t(`dl`,{className:H(`flex flex-wrap gap-x-4 gap-y-1 text-xs`,e&&`mb-3 border-b border-border/60 pb-2`),children:i.map(e=>n(`div`,{className:`flex min-w-0 items-baseline gap-1.5`,children:[t(`dt`,{className:`shrink-0 text-muted`,children:e.label}),t(`dd`,{className:`min-w-0 wrap-break-word font-medium text-foreground/80`,children:e.value})]},e.label))})}function Wm({section:e}){let r=e.value,i=typeof r==`string`||typeof r==`number`||typeof r==`boolean`,a=e.label===`Files`&&Array.isArray(r),o=e.label===`Output`;if(a){let e=Array.from(new Set(r.map(e=>Xp(e))));return t(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,children:e.map(e=>t(`span`,{className:`rounded-md bg-mixer-muted/15 px-1.5 py-0.5 font-mono text-[11px] text-muted`,children:Sm(e,64)},e))})}let s=H(`text-xs font-medium`,e.tone===`error`?`text-destructive`:`text-muted`),c=i&&!String(r).includes(`
|
|
54
|
+
`)&&String(r).length<180?t(`div`,{className:H(`break-words text-xs`,e.tone===`error`?`text-destructive`:`text-foreground/75`),children:String(r)}):t(`pre`,{className:H(`max-h-52 overflow-auto whitespace-pre-wrap rounded-lg px-3 py-2 font-mono text-[11px] leading-relaxed`,e.tone===`error`?`bg-destructive/5 text-destructive`:`bg-mixer-muted/10 text-foreground/75`),children:Om(r)});return n(`div`,{className:`mt-2`,children:[o?null:t(`div`,{className:H(`mb-1`,s),children:e.label}),c]})}function Gm(e){return e.kind===`command`?`Shell`:e.label}function Km(e){if(e.kind!==`command`)return e.title;let t=e.command||e.title;return t.trim().startsWith(`$`)?t:`$ ${t}`}function qm(e){let t=[Gm(e),Km(e)],n=Hm(e).map(e=>`${e.label}: ${e.value}`);n.length>0&&t.push(n.join(`
|
|
57
55
|
`)),e.text&&t.push(e.text),e.resources.length>0&&t.push(`Resources\n${e.resources.map(e=>`${e.label} (${e.type}:${e.id}) — ${e.action}`).join(`
|
|
58
|
-
`)}`);for(let n of e.sections)t.push(`${n.label}\n${
|
|
56
|
+
`)}`);for(let n of e.sections)t.push(`${n.label}\n${Om(n.value)}`);return t.filter(Boolean).join(`
|
|
59
57
|
|
|
60
|
-
`)}async function Oh(e){try{if(navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}if(typeof document>`u`)return!1;let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.style.position=`fixed`,t.style.insetInlineStart=`-9999px`,t.style.top=`0`,document.body.appendChild(t);try{return t.focus(),t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.remove()}}function kh({item:e}){let r=e.kind===`command`&&e.command?Eh(e):void 0,i=!r&&e.sections.length===0?e.text:void 0,a=!!(r||i||e.sections.length),o=Dh(e),[s,c]=Y(`idle`),l=J(void 0);return K(()=>()=>{l.current!==void 0&&window.clearTimeout(l.current)},[]),n(`div`,{className:`relative mt-2 rounded-lg border border-border/70 bg-mixer-muted/10 p-3 shadow-sm`,children:[a?t(`div`,{className:`absolute end-2 top-2`,children:t(`button`,{type:`button`,className:H(`inline-flex size-7 shrink-0 items-center justify-center rounded-md text-muted opacity-70 transition`,`hover:bg-mixer-muted/20 hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,s===`copied`&&`text-success opacity-100`,s===`failed`&&`text-destructive opacity-100`),onClick:()=>{Oh(o).then(e=>{c(e?`copied`:`failed`),l.current!==void 0&&window.clearTimeout(l.current),l.current=window.setTimeout(()=>c(`idle`),2e3)})},"aria-label":`Copy tool details`,title:`Copy tool details`,children:t(s===`copied`?en:Sn,{className:`size-4`})})}):null,n(`div`,{className:H(a&&`pe-7`),children:[t(Ch,{item:e,hasDetailContent:a}),r?t(`pre`,{className:`mb-3 whitespace-pre-wrap break-words font-mono text-sm leading-6 text-foreground/85`,children:r}):null,i?t(`div`,{className:`mb-3 break-words text-sm leading-6 text-foreground/75`,children:i}):null,e.sections.length>0?t(`div`,{className:`space-y-3`,children:e.sections.map(e=>t(wh,{section:e},e.key))}):null]}),s===`failed`&&a?t(`div`,{className:`mt-3 text-xs text-destructive`,children:`Copy failed`}):null]})}function Ah({item:e}){let{t:r}=X(),a=!!e.decisionText,s=!a&&(e.status===`error`||e.status===`warning`),c=Sh(e).length>0,l=!!(e.command||e.text||e.sections.length||c),u=e.resources.length>0,[d,f]=Y(!1),p=a?void 0:e.status,m=r(d?`agent.hideDetails`:`agent.showDetails`),h=u?e.resources.map(e=>e.label).join(`, `):e.title,g=t(`span`,{className:H(`flex size-5 items-center justify-center pt-0.5`,s?`text-attention`:`text-muted`),children:t(xh,{kind:e.kind,status:p})}),_=t(an,{className:H(`size-4 shrink-0 text-muted opacity-50 transition-transform`,!d&&`-rotate-90`),"aria-hidden":`true`});return n(`div`,{className:`min-w-0`,children:[u?n(`div`,{className:`grid w-full grid-cols-[1.5rem_1fr_auto] items-center gap-2 text-start`,children:[g,t(Rf,{resources:e.resources,workflowRunId:e.workflowRunId}),l?t(Re,{description:m,asChild:!0,children:t(o,{variant:`ghost`,size:`xs`,className:`size-6 p-0 text-muted`,onClick:()=>f(e=>!e),"aria-expanded":d,"aria-label":`${m}: ${h}`,children:_})}):null]}):n(`button`,{type:`button`,className:H(`grid w-full grid-cols-[1.5rem_1fr_auto] gap-2 text-start outline-none transition-colors`,`focus-visible:text-foreground focus-visible:underline focus-visible:underline-offset-4`,l?`cursor-pointer hover:text-foreground`:`cursor-default`),onClick:()=>l&&f(e=>!e),"aria-expanded":l?d:void 0,disabled:!l,children:[g,n(`span`,{className:`min-w-0 text-sm text-muted`,children:[t(`span`,{className:`break-words`,children:e.title}),e.decisionText?t(i,{variant:`destructive`,className:`ms-2 rounded-full shadow-sm shadow-destructive/10`,children:e.decisionText}):null]}),l?_:null]}),l&&d?t(`div`,{className:`mt-1`,children:t(kh,{item:e})}):null]})}function jh({item:e,artifactRunId:r,disableCollapse:i}){let{t:a}=X(),o=e.text??e.title,s=o.trim(),[c,l]=Y(!1),u=s?s.split(/\r?\n/).length:0,d=s.length>520||u>6,f=a(c?`agent.showLess`:`agent.showMore`);return n(`div`,{className:`min-w-0 py-1`,children:[t(`div`,{"data-testid":`summary-thought-prose`,className:H(Td,d&&!i&&!c&&`[display:-webkit-box] overflow-hidden [-webkit-box-orient:vertical] [-webkit-line-clamp:6]`),style:{overflowWrap:`anywhere`},children:t(bt,{artifactRunId:r,components:um,children:o})}),d&&!i?t(`div`,{className:`mt-1.5 flex justify-end`,children:n(`button`,{type:`button`,"aria-expanded":c,className:H(`inline-flex items-center gap-1 text-sm font-medium text-muted transition-colors`,`[text-decoration:none] hover:text-foreground hover:[text-decoration:none]`,`focus-visible:text-foreground focus-visible:[text-decoration:none]`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`),onClick:()=>l(e=>!e),children:[f,t(an,{className:H(`size-4 transition-transform`,c&&`rotate-180`),"aria-hidden":`true`})]})}):null]})}function Mh({items:e,artifactRunId:n,disablePreambleCollapse:r}){return t(`div`,{className:`mt-3`,children:t(`div`,{className:`space-y-3`,children:e.map(e=>e.isPreamble||e.kind===`think`?t(jh,{item:e,artifactRunId:n,disableCollapse:r},e.key):t(Ah,{item:e},e.key))})})}function Nh({text:e,artifactRunId:n,workstreamId:r}){return t(`div`,{className:`mx-auto w-full max-w-3xl px-1`,"data-workstream-id":r,children:t(`div`,{className:Td,style:{overflowWrap:`anywhere`},children:t(bt,{artifactRunId:n,components:um,children:e})})})}function Ph({message:e,startTimestamp:r,endTimestamp:i,className:a}){let{t:o}=X(),s=Yp(Jp(r??e.timestamp,i??e.timestamp));return n(`div`,{className:H(`mx-auto w-full max-w-3xl px-1`,a),"data-testid":`summary-stopped-message`,children:[n(`div`,{className:`flex items-center justify-end gap-2 text-sm font-medium text-muted`,children:[t(`span`,{children:o(`agent.youStoppedAfter`,{duration:s})}),t(mf,{message:e,className:`h-4 w-4`})]}),t(`div`,{className:`mt-5 border-b border-border/70`})]})}function Fh({label:r,timestamp:i,durationSeconds:a,showElapsed:o,details:s,emptyDetailsLabel:c,defaultExpanded:l=!1,disablePreambleCollapse:u=!1,className:d,artifactRunId:f,onSendMessage:p,answeredToolApprovalRequestInputKeys:m,resolvedToolApprovalKeys:h}){let[g,_]=Y(l),v=xm(i,o&&a===void 0),y=a??v,b=o&&i!==void 0,x=q(()=>bh(s??[]),[s]),S=q(()=>(s??[]).filter(e=>Hu(e)&&!fd(e,m??new Set,h??new Set)),[m,s,h]),C=x.length>0||S.length>0||!!c;return t(`div`,{className:H(`mx-auto w-full max-w-3xl px-1`,d),children:n(`div`,{className:`border-b border-border/70 pb-3 text-sm text-muted`,children:[n(`button`,{type:`button`,className:H(`inline-flex max-w-full items-center gap-2 text-start outline-none`,`focus-visible:text-foreground focus-visible:underline focus-visible:underline-offset-4`,C?`cursor-pointer hover:text-foreground`:`cursor-default`),onClick:()=>C&&_(e=>!e),"aria-expanded":C?g:void 0,disabled:!C,children:[t(`span`,{className:`min-w-0 truncate font-medium`,children:r}),b?n(`span`,{className:`shrink-0 text-muted/75`,children:[`for `,Yp(y)]}):null,C?t(g?an:cn,{className:`size-4 shrink-0 opacity-50`}):null]}),C&&g?x.length>0||S.length>0?n(e,{children:[x.length>0?t(Mh,{items:x,artifactRunId:f,disablePreambleCollapse:u}):null,S.length>0?t(`div`,{className:`mt-3 space-y-3`,children:S.map(e=>{let n=e.details.ux;return t(Jl,{question:Lu(e),options:n.options,variant:n.variant,multiSelect:n.multiSelect,onSelect:t=>ed(p,e,t,od(e,t)),onMultiSelect:t=>ed(p,e,t.join(`, `)),allowFreeResponse:!n.options?.length||!!n.free_response,placeholder:n.free_response?.placeholder,submitLabel:n.free_response?.submit_label,onSubmit:t=>ed(p,e,t,n.free_response?.metadata),hideBorder:!0,compact:!0,className:`my-0`,cardClassName:`bg-background/60 shadow-none`},ah(e,`work-request-input`))})}):null]}):n(`div`,{className:`mt-3 flex items-center gap-2 text-sm text-muted`,children:[t(Qr,{className:`size-4 opacity-70`,"aria-hidden":`true`}),t(`span`,{children:c})]}):null]})})}function Ih({children:e,status:r}){let i=r===`error`?`bg-destructive`:r===`warning`?`bg-attention`:r===`completed`?`bg-success`:`bg-muted`;return n(`div`,{className:`relative ps-7`,children:[t(`div`,{className:`absolute start-2 top-0 bottom-0 w-px bg-border`}),t(`div`,{className:H(`absolute start-[5px] top-4 size-2.5 rounded-full ring-4 ring-background`,i)}),e]})}var Lh=class extends tt{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return console.error(`Message render error:`,e),{hasError:!0,error:e}}componentDidUpdate(e){this.state.hasError&&e.children!==this.props.children&&this.setState({hasError:!1,error:void 0})}render(){return this.state.hasError?n(`div`,{className:`border-s-4 border-s-destructive bg-destructive/10 px-4 py-2 my-2 rounded-e`,children:[t(`p`,{className:`text-sm text-destructive font-medium`,children:It.getFixedT(null,Ft)(`agent.failedToRenderMessage`)}),t(`p`,{className:`text-xs text-muted mt-1 truncate`,children:this.state.error?.message||`Unknown error`})]}):this.props.children}};function Rh(e,t){let n=[...e.filter(e=>!zm(e)&&!t?.includes(e.type))].sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),r=[];for(let e of n){let t=r[r.length-1];t&&Tu(t,e)||t&&Bh(t,e)||r.push(e)}return r}function zh({messages:r,workstreamSourceMessages:i,bottomRef:a,viewMode:s=`stacked`,isCompleted:c=!1,streamingMessages:l=new Map,onSendMessage:u,onOpenArtifact:d,messageItemClassNames:f,messageStyleOverrides:p,toolCallGroupClassNames:m,hideToolCallsInViewMode:h,streamingMessageClassNames:g,batchProgressPanelClassNames:_,artifactRunId:v,hideWorkstreamTabs:y,workingIndicatorClassName:b,messageListClassName:x,StoreLinkComponent:S,CollectionLinkComponent:C,prependFriendlyMessage:w,initialRequestData:T,initialRequestSchema:E,initialRequestTitle:D,initialRequestTemplate:O,showInitialRequest:k,hiddenMessageTypes:A,disableAutoScroll:j=!1,renderRequestInputControls:M=!0,activeWorkstream:N,onActiveWorkstreamChange:P}){v||console.warn(`[AllMessagesMixed] artifactRunId prop is missing!`);let{t:F}=X(),I=J(null),[L,ee]=Y(`all`),R=N??L,te=G(e=>{N===void 0&&ee(e),P?.(e)},[N,P]),z=J(0),ne=J(null),B=J(!1),re=J(!1),ie=l.size>0,ae=s===`sliding`;K(()=>{let e=I.current;if(!e)return;let t=()=>{if(re.current)return;let{scrollTop:t,scrollHeight:n,clientHeight:r}=e,i=n-t-r;B.current=i>80};return e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[]);let oe=q(()=>{let e=0;return l.forEach(t=>{e+=t.text?.length||0}),Math.floor(e/200)},[l]),se=G(()=>{a.current&&(re.current=!0,a.current.scrollIntoView({behavior:ie?`instant`:`smooth`}),z.current=Date.now(),requestAnimationFrame(()=>{re.current=!1})),ne.current=null},[a,ie]);K(()=>{if(r.length,l.size,j||B.current)return;let e=Date.now()-z.current;if(e>=100)se();else if(ne.current===null){let t=100-e;ne.current=window.setTimeout(se,t)}return()=>{ne.current!==null&&(clearTimeout(ne.current),ne.current=null)}},[r.length,l.size,oe,se,j]);let ce=W.useMemo(()=>Rh(r,A),[r,A]),V=W.useMemo(()=>i?Rh(i,A):ce,[i,A,ce]),le=W.useMemo(()=>{let e=Up(V);return V.forEach(t=>{let n=ou(t)??su(t);n&&e.set(n.workstreamId,Ql(n.workstreamId,n.interaction))}),e},[V]),ue=W.useMemo(()=>{if(R!==`all`)return le.get(R)??Xl(R)},[R,le]),de=G(()=>{let e=I.current;e&&(re.current=!0,typeof e.scrollTo==`function`?e.scrollTo({top:0,behavior:`smooth`}):e.scrollTop=0,requestAnimationFrame(()=>{re.current=!1}))},[]),fe=J(R);K(()=>{fe.current!==R&&(fe.current=R,requestAnimationFrame(de))},[R,de]);let pe=G(e=>{te(e)},[te]),me=G(()=>{te(`all`)},[te]);K(()=>{R!==`all`&&!le.has(R)&&te(`all`)},[R,le,te]);let he=W.useMemo(()=>{let e=new Map;e.set(`all`,V.length);let t=Wp(V,`main`);return e.set(`main`,t.length),V.forEach(t=>{let n=_u(t);n!==`main`&&e.set(n,(e.get(n)||0)+1)}),e},[V]),ge=W.useMemo(()=>om(bu(ce,R)),[ce,R]),_e=W.useMemo(()=>Qu(ge),[ge]),ve=W.useMemo(()=>nd(ge),[ge]),ye=W.useMemo(()=>dd(ge),[ge]),be=W.useMemo(()=>pd(ge),[ge]),xe=W.useMemo(()=>{if(M)return;let e=gd(ge);return e?Uu(e):void 0},[ge,M]),Se=W.useCallback(e=>e.type===Q.REQUEST_INPUT&&(xe===Uu(e)||fd(e,ye,ve)),[ye,xe,ve]),Ce=W.useCallback(e=>md(e,be),[be]),we=W.useMemo(()=>ge.filter(e=>!Ce(e)),[ge,Ce]),Te=J(Date.now()),Ee=(!!w?.trim()||Em(T)||O!==void 0)&&(k??!0),De=q(()=>ge.some(e=>e.type===Q.QUESTION),[ge]),Oe=R===`all`&&Ee&&!De,ke=q(()=>ge.reduce((e,t)=>Math.max(e,Kp(t.timestamp)),-1/0),[ge]),Ae=q(()=>ge.reduce((e,t)=>Yf(t)?e:Math.max(e,Kp(t.timestamp)),-1/0),[ge]),je=q(()=>ge.some(e=>id(e)&&!fd(e,ye,ve)),[ye,ge,ve]),Me=q(()=>rm(ge,be),[ge,be]),Ne=q(()=>je||Me||nm(we)?!1:c||!mu(we),[we,Me,je,c]),Pe=q(()=>{if(V.length===0)return V;let e=r[r.length-1];if(!e)return[];let t=V.indexOf(e);if(t>=0)return t>=V.length-1?V:V.slice(0,t+1);let n=Kp(e.timestamp);return V.filter(e=>Kp(e.timestamp)<=n)},[V,r]),Fe=q(()=>c||Uf(Pe),[c,Pe]),Ie=q(()=>Hf(Pe),[Pe]),{completeStreaming:Le,incompleteStreaming:Re}=W.useMemo(()=>{let e=new Map,t=[];return l.forEach((n,r)=>{if(R&&R!==`all`){let e=n.workstreamId||`main`;if(R!==e)return}n.startTimestamp<=Ae?e.set(r,n):n.text&&t.push({id:r,data:n})}),{completeStreaming:e,incompleteStreaming:t}},[l,R,Ae]),ze=W.useMemo(()=>th(fp(ge,Le),ve),[ge,Le,ve]),Be=W.useMemo(()=>ze.filter(e=>!Se(e)&&!Ce(e)),[ze,Se,Ce]),Ve=q(()=>{if(Re.some(({data:e})=>e.text.trim().length>0))return 1/0;let e=Re.reduce((e,{data:t})=>Math.max(e,t.startTimestamp),-1/0);return Math.max(ke,e)},[Re,ke]),He=W.useMemo(()=>up(Be,Ne,Ve),[Be,Ne,Ve]),Ue=W.useMemo(()=>Wf(He,e=>e.type===`message`&&e.message.type===Q.QUESTION,Ie,Fe),[He,Ie,Fe]),We=W.useMemo(()=>Fu(Nu(ge,Le,R)),[ge,Le,R]),Ge=W.useMemo(()=>Wf(We,e=>e.type===`single`&&e.message.type===Q.QUESTION,Ie,Fe),[We,Ie,Fe]),Ke=q(()=>!Ne||nm(we),[we,Ne]),qe=q(()=>{if(!Ke||Re.length>0)return!1;let e=He[He.length-1],t=we[we.length-1],n=t!==void 0&&(t.details?.display_role===`thinking`||Ou(t)&&t.details?.tool_status===`completed`);return e?.type===`work`&&e.isActive&&n},[we,Re.length,Ke,He]),Je=mp(He,Ke,Re.length>0),Ye=hp(He)?F(`agent.preparing`):F(`agent.working`),Xe=ge.length===0&&Ee&&Ke&&Re.length===0,Ze=q(()=>pp(He,Be,Te.current),[He,Be]),Qe=J(Ze),$e=J(!1),et=q(()=>{if(!Je)return Ze;let e=Kp(Ze),t=Kp(Qe.current);return!$e.current||e<t?Ze:Qe.current},[Ze,Je]);K(()=>{Qe.current=et,$e.current=Je},[et,Je]);let U=q(()=>{let e=new Map,t=new Map;V.forEach(e=>{let n=_u(e);t.has(n)||t.set(n,[]),t.get(n)?.push(e)});for(let[n,r]of t.entries())if(r.length>0){let t=r.some(e=>{if([Q.COMPLETE,Q.IDLE,Q.REQUEST_INPUT,Q.TERMINATED].includes(e.type))return!0;if(e.type===Q.UPDATE&&e.details){let t=e.details;return t.workstream_event===`completed`||t.status===`completed`||t.status===`canceled`}return!1});e.set(n,t)}return e},[V]);return n(`div`,{ref:I,tabIndex:0,className:`flex-1 min-h-0 h-full w-full max-w-full overflow-y-auto overflow-x-hidden px-1.5 sm:px-2.5 lg:px-3 flex flex-col relative focus:outline-none`,"data-testid":`all-messages-mixed`,"data-message-count":r.length,"data-streaming-count":l.size,"data-view-mode":s,children:[t(`style`,{children:`
|
|
58
|
+
`)}async function Jm(e){try{if(navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}if(typeof document>`u`)return!1;let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.style.position=`fixed`,t.style.insetInlineStart=`-9999px`,t.style.top=`0`,document.body.appendChild(t);try{return t.focus(),t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.remove()}}function Ym({item:e}){let r=e.kind===`command`&&e.command?Km(e):void 0,i=!r&&e.sections.length===0?e.text:void 0,a=!!(r||i||e.sections.length),o=qm(e),[s,c]=X(`idle`),l=Y(void 0);return q(()=>()=>{l.current!==void 0&&window.clearTimeout(l.current)},[]),n(`div`,{className:`relative mt-2 rounded-lg border border-border/70 bg-mixer-muted/10 p-3 shadow-sm`,children:[a?t(`div`,{className:`absolute end-2 top-2`,children:t(`button`,{type:`button`,className:H(`inline-flex size-7 shrink-0 items-center justify-center rounded-md text-muted opacity-70 transition`,`hover:bg-mixer-muted/20 hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,s===`copied`&&`text-success opacity-100`,s===`failed`&&`text-destructive opacity-100`),onClick:()=>{Jm(o).then(e=>{c(e?`copied`:`failed`),l.current!==void 0&&window.clearTimeout(l.current),l.current=window.setTimeout(()=>c(`idle`),2e3)})},"aria-label":`Copy tool details`,title:`Copy tool details`,children:t(s===`copied`?on:Dn,{className:`size-4`})})}):null,n(`div`,{className:H(a&&`pe-7`),children:[t(Um,{item:e,hasDetailContent:a}),r?t(`pre`,{className:`mb-3 whitespace-pre-wrap break-words font-mono text-sm leading-6 text-foreground/85`,children:r}):null,i?t(`div`,{className:`mb-3 break-words text-sm leading-6 text-foreground/75`,children:i}):null,e.sections.length>0?t(`div`,{className:`space-y-3`,children:e.sections.map(e=>t(Wm,{section:e},e.key))}):null]}),s===`failed`&&a?t(`div`,{className:`mt-3 text-xs text-destructive`,children:`Copy failed`}):null]})}function Xm({item:e}){let{t:r}=Z(),a=!!e.decisionText,s=!a&&(e.status===`error`||e.status===`warning`),c=Hm(e).length>0,l=!!(e.command||e.text||e.sections.length||c),u=e.resources.length>0,[d,f]=X(!1),p=a?void 0:e.status,m=r(d?`agent.hideDetails`:`agent.showDetails`),h=u?e.resources.map(e=>e.label).join(`, `):e.title,g=t(`span`,{className:H(`flex size-5 items-center justify-center pt-0.5`,s?`text-attention`:`text-muted`),children:t(Vm,{kind:e.kind,status:p})}),_=t(un,{className:H(`size-4 shrink-0 text-muted opacity-50 transition-transform`,!d&&`-rotate-90`),"aria-hidden":`true`});return n(`div`,{className:`min-w-0`,children:[u?n(`div`,{className:`grid w-full grid-cols-[1.5rem_1fr_auto] items-center gap-2 text-start`,children:[g,t(rf,{resources:e.resources,workflowRunId:e.workflowRunId}),l?t(Be,{description:m,asChild:!0,children:t(o,{variant:`ghost`,size:`xs`,className:`size-6 p-0 text-muted`,onClick:()=>f(e=>!e),"aria-expanded":d,"aria-label":`${m}: ${h}`,children:_})}):null]}):n(`button`,{type:`button`,className:H(`grid w-full grid-cols-[1.5rem_1fr_auto] gap-2 text-start outline-none transition-colors`,`focus-visible:text-foreground focus-visible:underline focus-visible:underline-offset-4`,l?`cursor-pointer hover:text-foreground`:`cursor-default`),onClick:()=>l&&f(e=>!e),"aria-expanded":l?d:void 0,disabled:!l,children:[g,n(`span`,{className:`min-w-0 text-sm text-muted`,children:[t(`span`,{className:`break-words`,children:e.title}),e.decisionText?t(i,{variant:`destructive`,className:`ms-2 rounded-full shadow-sm shadow-destructive/10`,children:e.decisionText}):null]}),l?_:null]}),l&&d?t(`div`,{className:`mt-1`,children:t(Ym,{item:e})}):null]})}function Zm({item:e,artifactRunId:r,disableCollapse:i}){let{t:a}=Z(),o=e.text??e.title,s=o.trim(),[c,l]=X(!1),u=s?s.split(/\r?\n/).length:0,d=s.length>520||u>6,f=a(c?`agent.showLess`:`agent.showMore`);return n(`div`,{className:`min-w-0 py-1`,children:[t(`div`,{"data-testid":`summary-thought-prose`,className:H(Uu,d&&!i&&!c&&`[display:-webkit-box] overflow-hidden [-webkit-box-orient:vertical] [-webkit-line-clamp:6]`),style:{overflowWrap:`anywhere`},children:t(wt,{artifactRunId:r,components:Ap,children:o})}),d&&!i?t(`div`,{className:`mt-1.5 flex justify-end`,children:n(`button`,{type:`button`,"aria-expanded":c,className:H(`inline-flex items-center gap-1 text-sm font-medium text-muted transition-colors`,`[text-decoration:none] hover:text-foreground hover:[text-decoration:none]`,`focus-visible:text-foreground focus-visible:[text-decoration:none]`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`),onClick:()=>l(e=>!e),children:[f,t(un,{className:H(`size-4 transition-transform`,c&&`rotate-180`),"aria-hidden":`true`})]})}):null]})}function Qm({items:e,artifactRunId:n,disablePreambleCollapse:r}){return t(`div`,{className:`mt-3`,children:t(`div`,{className:`space-y-3`,children:e.map(e=>e.isPreamble||e.kind===`think`?t(Zm,{item:e,artifactRunId:n,disableCollapse:r},e.key):t(Xm,{item:e},e.key))})})}function $m({text:e,artifactRunId:n,workstreamId:r}){return t(`div`,{className:`mx-auto w-full max-w-3xl px-1`,"data-workstream-id":r,children:t(`div`,{className:Uu,style:{overflowWrap:`anywhere`},children:t(wt,{artifactRunId:n,components:Ap,children:e})})})}function eh({message:e,startTimestamp:r,endTimestamp:i,className:a}){let{t:o}=Z(),s=hp(mp(r??e.timestamp,i??e.timestamp));return n(`div`,{className:H(`mx-auto w-full max-w-3xl px-1`,a),"data-testid":`summary-stopped-message`,children:[n(`div`,{className:`flex items-center justify-end gap-2 text-sm font-medium text-muted`,children:[t(`span`,{children:o(`agent.youStoppedAfter`,{duration:s})}),t(Nd,{message:e,className:`h-4 w-4`})]}),t(`div`,{className:`mt-5 border-b border-border/70`})]})}function th({label:r,timestamp:i,durationSeconds:a,showElapsed:o,details:s,emptyDetailsLabel:c,defaultExpanded:l=!1,disablePreambleCollapse:u=!1,className:d,artifactRunId:f,onSendMessage:p,answeredToolApprovalRequestInputKeys:m,resolvedToolApprovalKeys:h}){let[g,_]=X(l),v=Vp(i,o&&a===void 0),y=a??v,b=o&&i!==void 0,x=J(()=>Bm(s??[]),[s]),S=J(()=>(s??[]).filter(e=>ou(e)&&!Au(e,m??new Set,h??new Set)),[m,s,h]),C=x.length>0||S.length>0||!!c;return t(`div`,{className:H(`mx-auto w-full max-w-3xl px-1`,d),children:n(`div`,{className:`border-b border-border/70 pb-3 text-sm text-muted`,children:[n(`button`,{type:`button`,className:H(`inline-flex max-w-full items-center gap-2 text-start outline-none`,`focus-visible:text-foreground focus-visible:underline focus-visible:underline-offset-4`,C?`cursor-pointer hover:text-foreground`:`cursor-default`),onClick:()=>C&&_(e=>!e),"aria-expanded":C?g:void 0,disabled:!C,children:[t(`span`,{className:`min-w-0 truncate font-medium`,children:r}),b?n(`span`,{className:`shrink-0 text-muted/75`,children:[`for `,hp(y)]}):null,C?t(g?un:pn,{className:`size-4 shrink-0 opacity-50`}):null]}),C&&g?x.length>0||S.length>0?n(e,{children:[x.length>0?t(Qm,{items:x,artifactRunId:f,disablePreambleCollapse:u}):null,S.length>0?t(`div`,{className:`mt-3 space-y-3`,children:S.map(e=>{let n=e.details.ux;return t(dl,{question:tu(e),options:n.options,variant:n.variant,multiSelect:n.multiSelect,onSelect:t=>vu(p,e,t,wu(e,t)),onMultiSelect:t=>vu(p,e,t.join(`, `)),allowFreeResponse:!n.options?.length||!!n.free_response,placeholder:n.free_response?.placeholder,submitLabel:n.free_response?.submit_label,onSubmit:t=>vu(p,e,t,n.free_response?.metadata),hideBorder:!0,compact:!0,className:`my-0`,cardClassName:`bg-background/60 shadow-none`},Tm(e,`work-request-input`))})}):null]}):n(`div`,{className:`mt-3 flex items-center gap-2 text-sm text-muted`,children:[t(ii,{className:`size-4 opacity-70`,"aria-hidden":`true`}),t(`span`,{children:c})]}):null]})})}function nh({children:e,status:r}){let i=r===`error`?`bg-destructive`:r===`warning`?`bg-attention`:r===`completed`?`bg-success`:`bg-muted`;return n(`div`,{className:`relative ps-7`,children:[t(`div`,{className:`absolute start-2 top-0 bottom-0 w-px bg-border`}),t(`div`,{className:H(`absolute start-[5px] top-4 size-2.5 rounded-full ring-4 ring-background`,i)}),e]})}var rh=class extends rt{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return console.error(`Message render error:`,e),{hasError:!0,error:e}}componentDidUpdate(e){this.state.hasError&&e.children!==this.props.children&&this.setState({hasError:!1,error:void 0})}render(){return this.state.hasError?n(`div`,{className:`border-s-4 border-s-destructive bg-destructive/10 px-4 py-2 my-2 rounded-e`,children:[t(`p`,{className:`text-sm text-destructive font-medium`,children:Vt.getFixedT(null,Bt)(`agent.failedToRenderMessage`)}),t(`p`,{className:`text-xs text-muted mt-1 truncate`,children:this.state.error?.message||`Unknown error`})]}):this.props.children}};function ih(e,t){let n=[...e.filter(e=>!am(e)&&!t?.includes(e.type))].sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),r=[];for(let e of n){let t=r[r.length-1];t&&Ul(t,e)||t&&oh(t,e)||r.push(e)}return r}function ah({messages:r,workstreamSourceMessages:i,bottomRef:a,viewMode:s=`stacked`,isCompleted:c=!1,streamingMessages:l=new Map,onSendMessage:u,onOpenArtifact:d,messageItemClassNames:f,messageStyleOverrides:p,toolCallGroupClassNames:m,hideToolCallsInViewMode:h,streamingMessageClassNames:g,batchProgressPanelClassNames:_,artifactRunId:v,hideWorkstreamTabs:y,workingIndicatorClassName:b,messageListClassName:x,StoreLinkComponent:S,CollectionLinkComponent:C,prependFriendlyMessage:w,initialRequestData:T,initialRequestSchema:E,initialRequestTitle:D,initialRequestTemplate:O,showInitialRequest:k,hiddenMessageTypes:A,disableAutoScroll:j=!1,renderRequestInputControls:M=!0,activeWorkstream:N,onActiveWorkstreamChange:P}){v||console.warn(`[AllMessagesMixed] artifactRunId prop is missing!`);let{t:F}=Z(),I=Y(null),[L,ee]=X(`all`),R=N??L,te=K(e=>{N===void 0&&ee(e),P?.(e)},[N,P]),z=Y(0),ne=Y(null),B=Y(!1),re=Y(!1),ie=l.size>0,ae=s===`sliding`;q(()=>{let e=I.current;if(!e)return;let t=()=>{if(re.current)return;let{scrollTop:t,scrollHeight:n,clientHeight:r}=e,i=n-t-r;B.current=i>80};return e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[]);let oe=J(()=>{let e=0;return l.forEach(t=>{e+=t.text?.length||0}),Math.floor(e/200)},[l]),se=K(()=>{a.current&&(re.current=!0,a.current.scrollIntoView({behavior:ie?`instant`:`smooth`}),z.current=Date.now(),requestAnimationFrame(()=>{re.current=!1})),ne.current=null},[a,ie]);q(()=>{if(r.length,l.size,j||B.current)return;let e=Date.now()-z.current;if(e>=100)se();else if(ne.current===null){let t=100-e;ne.current=window.setTimeout(se,t)}return()=>{ne.current!==null&&(clearTimeout(ne.current),ne.current=null)}},[r.length,l.size,oe,se,j]);let ce=G.useMemo(()=>ih(r,A),[r,A]),V=G.useMemo(()=>i?ih(i,A):ce,[i,A,ce]),le=G.useMemo(()=>{let e=lp(V);return V.forEach(t=>{let n=Cl(t)??wl(t);n&&e.set(n.workstreamId,hl(n.workstreamId,n.interaction))}),e},[V]),ue=G.useMemo(()=>{if(R!==`all`)return le.get(R)??pl(R)},[R,le]),de=K(()=>{let e=I.current;e&&(re.current=!0,typeof e.scrollTo==`function`?e.scrollTo({top:0,behavior:`smooth`}):e.scrollTop=0,requestAnimationFrame(()=>{re.current=!1}))},[]),fe=Y(R);q(()=>{fe.current!==R&&(fe.current=R,requestAnimationFrame(de))},[R,de]);let pe=K(e=>{te(e)},[te]),me=K(()=>{te(`all`)},[te]);q(()=>{R!==`all`&&!le.has(R)&&te(`all`)},[R,le,te]);let he=G.useMemo(()=>{let e=new Map;e.set(`all`,V.length);let t=up(V,`main`);return e.set(`main`,t.length),V.forEach(t=>{let n=Pl(t);n!==`main`&&e.set(n,(e.get(n)||0)+1)}),e},[V]),ge=G.useMemo(()=>Ep(Ll(ce,R)),[ce,R]),_e=G.useMemo(()=>gu(ge),[ge]),ve=G.useMemo(()=>bu(ge),[ge]),ye=G.useMemo(()=>ku(ge),[ge]),be=G.useMemo(()=>ju(ge),[ge]),xe=G.useMemo(()=>{if(M)return;let e=Pu(ge);return e?su(e):void 0},[ge,M]),Se=G.useCallback(e=>e.type===$.REQUEST_INPUT&&(xe===su(e)||Au(e,ye,ve)),[ye,xe,ve]),Ce=G.useCallback(e=>Mu(e,be),[be]),we=G.useMemo(()=>ge.filter(e=>!Ce(e)),[ge,Ce]),Te=Y(Date.now()),Ee=(!!w?.trim()||Kp(T)||O!==void 0)&&(k??!0),De=J(()=>ge.some(e=>e.type===$.QUESTION),[ge]),Oe=R===`all`&&Ee&&!De,ke=J(()=>ge.reduce((e,t)=>Math.max(e,fp(t.timestamp)),-1/0),[ge]),Ae=J(()=>ge.reduce((e,t)=>hf(t)?e:Math.max(e,fp(t.timestamp)),-1/0),[ge]),je=J(()=>ge.some(e=>Su(e)&&!Au(e,ye,ve)),[ye,ge,ve]),Me=J(()=>Cp(ge,be),[ge,be]),Ne=J(()=>je||Me||Sp(we)?!1:c||!jl(we),[we,Me,je,c]),Pe=J(()=>{if(V.length===0)return V;let e=r[r.length-1];if(!e)return[];let t=V.indexOf(e);if(t>=0)return t>=V.length-1?V:V.slice(0,t+1);let n=fp(e.timestamp);return V.filter(e=>fp(e.timestamp)<=n)},[V,r]),Fe=J(()=>c||lf(Pe),[c,Pe]),Ie=J(()=>cf(Pe),[Pe]),{completeStreaming:Le,incompleteStreaming:Re}=G.useMemo(()=>{let e=new Map,t=[];return l.forEach((n,r)=>{zl(n,R)&&(n.startTimestamp<=Ae?e.set(r,n):n.text&&t.push({id:r,data:n}))}),{completeStreaming:e,incompleteStreaming:t}},[l,R,Ae]),ze=G.useMemo(()=>xm(Mf(ge,Le),ve),[ge,Le,ve]),Be=G.useMemo(()=>ze.filter(e=>!Se(e)&&!Ce(e)),[ze,Se,Ce]),Ve=J(()=>{if(Re.some(({data:e})=>e.text.trim().length>0))return 1/0;let e=Re.reduce((e,{data:t})=>Math.max(e,t.startTimestamp),-1/0);return Math.max(ke,e)},[Re,ke]),He=G.useMemo(()=>Af(Be,Ne,Ve),[Be,Ne,Ve]),Ue=G.useMemo(()=>uf(He,e=>e.type===`message`&&e.message.type===$.QUESTION,Ie,Fe),[He,Ie,Fe]),We=G.useMemo(()=>$l(Zl(ge,Le,R)),[ge,Le,R]),U=G.useMemo(()=>uf(We,e=>e.type===`single`&&e.message.type===$.QUESTION,Ie,Fe),[We,Ie,Fe]),Ge=J(()=>!Ne||Sp(we),[we,Ne]),Ke=J(()=>{if(!Ge||Re.length>0)return!1;let e=He[He.length-1],t=we[we.length-1],n=t!==void 0&&(t.details?.display_role===`thinking`||Kl(t)&&t.details?.tool_status===`completed`);return e?.type===`work`&&e.isActive&&n},[we,Re.length,Ge,He]),W=Pf(He,Ge,Re.length>0),qe=Ff(He)?F(`agent.preparing`):F(`agent.working`),Je=ge.length===0&&Ee&&Ge&&Re.length===0,Ye=J(()=>Nf(He,Be,Te.current),[He,Be]),Xe=Y(Ye),Ze=Y(!1),Qe=J(()=>{if(!W)return Ye;let e=fp(Ye),t=fp(Xe.current);return!Ze.current||e<t?Ye:Xe.current},[Ye,W]);q(()=>{Xe.current=Qe,Ze.current=W},[Qe,W]);let $e=J(()=>{let e=new Map,t=new Map;V.forEach(e=>{let n=Pl(e);t.has(n)||t.set(n,[]),t.get(n)?.push(e)});for(let[n,r]of t.entries())if(r.length>0){let t=r.some(e=>{if([$.COMPLETE,$.IDLE,$.REQUEST_INPUT,$.TERMINATED].includes(e.type))return!0;if(e.type===$.UPDATE&&e.details){let t=e.details;return t.workstream_event===`completed`||t.status===`completed`||t.status===`canceled`}return!1});e.set(n,t)}return e},[V]);return n(`div`,{ref:I,tabIndex:0,className:`flex-1 min-h-0 h-full w-full max-w-full overflow-y-auto overflow-x-hidden px-1.5 sm:px-2.5 lg:px-3 flex flex-col relative focus:outline-none`,"data-testid":`all-messages-mixed`,"data-message-count":r.length,"data-streaming-count":l.size,"data-view-mode":s,children:[t(`style`,{children:`
|
|
61
59
|
/* Better vertical rhythm for markdown */
|
|
62
60
|
.vprose > * + * {
|
|
63
61
|
margin-top: 0.625rem;
|
|
@@ -312,7 +310,7 @@ $&`)),t.includes(` - `)&&(t=t.replace(/(^|\S)\s+-\s+/g,`$1
|
|
|
312
310
|
.agent-markdown tbody tr:hover {
|
|
313
311
|
background: transparent;
|
|
314
312
|
}
|
|
315
|
-
`}),s===`stacked`&&t(`div`,{className:H(`sticky top-0 z-10`,y&&`hidden`),children:t(Hp,{workstreams:le,activeWorkstream:R,onSelectWorkstream:pe,count:he,completionStatus:U})}),ge.length===0&&!Ee&&!(ae&&Je)?R===`all`&&Ke&&Re.length===0?t(`div`,{className:`flex-1 px-2 py-6 sm:px-4`,children:t(Pm,{label:F(`agent.preparing`),timestamp:Te.current,className:b})}):t(`div`,{className:`flex items-center justify-center h-full text-center py-8`,children:t(`div`,{className:`flex items-center px-3 py-2 text-sm text-muted`,children:F(R===`all`?`agent.waitingForAgentResponse`:`agent.noMessagesInWorkstream`)})}):n(`div`,{className:H(`flex-1 flex flex-col justify-start w-full max-w-full`,ae?`gap-6 px-2 py-6 sm:px-4`:`gap-3 pb-4`,x),children:[ae&&R!==`all`&&ue&&t(`div`,{className:`sticky top-0 z-20 -mx-2 bg-background/95 px-2 pb-2 pt-1 backdrop-blur sm:-mx-4 sm:px-4`,children:n(`div`,{className:`mx-auto flex w-full max-w-3xl items-center gap-2 border-b border-border/70 pb-3`,children:[t(o,{type:`button`,variant:`ghost`,size:`icon`,className:`size-8 shrink-0 text-muted hover:text-foreground`,title:F(`agent.backToMainAgent`),onClick:me,children:t(Ht,{className:`size-4`,"aria-hidden":`true`})}),t(`div`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-foreground`,children:ue})]})}),Oe&&t(Nm,{data:T,schema:E,title:D,template:O,prependFriendlyMessage:w,timestamp:ge[0]?.timestamp??Date.now(),isSummaryView:ae,messageItemClassNames:f,messageStyleOverrides:p,StoreLinkComponent:S,CollectionLinkComponent:C},`initial-request`),Xe&&t(Pm,{label:Ye,timestamp:et,className:b}),s===`stacked`?n(e,{children:[Ge.map((e,n)=>{let r=n===Ge.length-1;if(e.type===`resource_summary`)return t(Bf,{resources:e.resources,workflowRunId:v,className:`my-2`},e.key);if(e.type===`tool_group`){let n=e.messages[e.messages.length-1],i=e.toolStatus===`completed`||e.toolStatus===`error`||e.toolStatus===`warning`,a=!c&&r&&!fu.includes(n.type)&&!i;return h?.includes(s)?null:t(Ih,{status:e.toolStatus,children:t(Lh,{children:t(Fp,{...m,messages:e.messages,showPulsatingCircle:a,toolRunId:e.toolRunId,toolStatus:e.toolStatus,preambleText:e.preambleText,preambleMessage:e.preambleMessage,rootClassName:H(`rounded-lg border border-border bg-background/60 shadow-none`,m?.rootClassName),headerClassName:H(`px-3 py-2`,m?.headerClassName),itemHeaderClassName:H(`hover:bg-mixer-muted/20`,m?.itemHeaderClassName)})})},oh(e))}else if(e.type===`streaming`)return t(Ih,{children:t(Kf,{...g,text:e.text,workstreamId:e.workstreamId,isComplete:e.isComplete,timestamp:e.startTimestamp,artifactRunId:v,cardClassName:H(`rounded-lg border border-border bg-background/60 shadow-none`,g?.cardClassName)})},oh(e));else{let i=e.message;if(Se(i)||Ce(i))return null;if(hu(i))return t(Ih,{children:t(Ph,{message:i,startTimestamp:sh(Ge,n)??i.timestamp,endTimestamp:i.timestamp})},ah(i,`stopped`));let a=!c&&r&&!fu.includes(i.type);return Gp(i)?t(Lh,{children:t(lf,{message:i,batchData:i.details,isRunning:!i.details.completed_at,..._})},`batch-${i.details.batch_id}-${i.timestamp}`):t(Ih,{status:`message`,children:t(Lh,{children:t(Nf,{...f,message:i,showPulsatingCircle:a,onSendMessage:u,onOpenArtifact:d,requestInputAnswered:hd(i,_e),cardClassName:H(`rounded-lg border border-border bg-background/60 shadow-none`,f?.cardClassName),headerClassName:H(`px-3 py-2`,f?.headerClassName),contentClassName:H(`bg-transparent`,f?.contentClassName),messageStyleOverrides:p,StoreLinkComponent:S,CollectionLinkComponent:C})})},ah(i))}}),Re.map(({id:e,data:n})=>t(Ih,{children:t(Kf,{...g,text:n.text,workstreamId:n.workstreamId,isComplete:n.isComplete,timestamp:n.startTimestamp,artifactRunId:v,cardClassName:H(`rounded-lg border border-border bg-background/60 shadow-none`,g?.cardClassName)})},`streaming-incomplete-${e}`)),Ke&&Re.length===0&&!Xe&&t(Ih,{children:n(`div`,{className:H(`flex items-center gap-2 py-2 text-sm text-muted`,b),children:[t(bd,{size:`sm`,color:`blue`}),t(`span`,{children:F(`agent.working`)})]})})]}):n(e,{children:[Ue.map(e=>{if(e.type===`resource_summary`)return t(Bf,{resources:e.resources,workflowRunId:v,className:`my-2`},e.key);if(e.type===`work`){if(h?.includes(s))return null;let n=em(e.messages);return t(Fh,{label:tm(e.isActive),status:e.status,timestamp:e.startTimestamp,durationSeconds:e.isActive?void 0:Jp(e.startTimestamp,e.endTimestamp),showElapsed:!0,details:n?void 0:e.messages,defaultExpanded:e.isActive&&!n,disablePreambleCollapse:e.isActive,className:b,onSendMessage:u,answeredToolApprovalRequestInputKeys:ye,resolvedToolApprovalKeys:ve},`work-${e.id}-${e.isActive?`active`:`done`}-${e.status}`)}if(e.type===`stopped`)return t(Ph,{message:e.message,startTimestamp:e.startTimestamp,endTimestamp:e.endTimestamp},ah(e.message,`stopped-summary`));let n=e.message;return Se(n)||Ce(n)?null:Gp(n)?t(Lh,{children:t(lf,{message:n,batchData:n.details,isRunning:!n.details.completed_at,..._})},ah(n,`batch`)):t(Lh,{children:t(wm,{message:n,onSendMessage:u,onOpenArtifact:d,onSelectWorkstream:pe,requestInputAnswered:hd(n,_e),StoreLinkComponent:S,CollectionLinkComponent:C})},ah(n,`summary`))}),Re.map(({id:e,data:n})=>t(Nh,{text:n.text,workstreamId:n.workstreamId,artifactRunId:v},`streaming-incomplete-${e}`)),qe&&t(`div`,{className:H(`mx-auto w-full max-w-3xl px-1 text-sm text-muted`,b),"data-testid":`post-tool-thinking-indicator`,children:F(`agent.thinking`)}),Je&&!Xe&&t(Fh,{label:Ye,status:`running`,timestamp:et,showElapsed:!0,className:b})]}),t(`div`,{ref:a,className:`h-2`})]})]})}const Bh=(e,t)=>{if(e.type!==t.type||e.message!==t.message)return!1;let n=e.details,r=t.details;if(n?.tool_status!==`completed`||r?.tool_status!==`completed`)return!1;let i=typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime();return(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())-i<2e3},Vh=W.memo(zh);function Hh(e){return e?new Map(e.streamingMessages.map((e,t)=>[e.id??e.activityId??`stream-${t}`,e])):new Map}function Uh(e,t){return e?.find(e=>e.cursor===t)}function Wh(e,t){if(t===0||e===`live`)return`live`;let n=xo(e,t);return n>=t-1?`live`:n+1}function Gh(e){let t=0,n=e.length;for(;t<n&&e[t]===`-`;)t++;for(;n>t&&e[n-1]===`-`;)n--;return e.slice(t,n)}function Kh(e){return Gh(e.trim().replace(/[^a-z0-9-_]+/gi,`-`)).slice(0,80)}function qh(e,t){let n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}function Jh({fixture:e,cursor:r,initialCursor:i,onCursorChange:a,autoStepMs:s,repeat:c=1,viewMode:l,className:u,title:d,showHeader:f=!0}){let{t:p}=X(),m=e.messages,h=i??(m.length>0?0:`live`),[g,_]=Y(()=>bo(h,m.length)),v=r??g,y=l??`sliding`,[b,x]=Y(!!s),[S,C]=Y(0),w=J(null),T=q(()=>wo(m,v,!0),[v,m]),E=T.displayedMessages,D=q(()=>Hh(Uh(e.streamingFrames,T.cursor)),[e.streamingFrames,T.cursor]),O=G(e=>{let t=bo(e,m.length);r===void 0&&_(t),a?.(t)},[r,m.length,a]);K(()=>{let e=bo(v,m.length);e!==v&&O(e)},[v,m.length,O]),K(()=>{if(!s||s<=0||!b)return;let e=window.setInterval(()=>{let e=Wh(v,m.length);if(e===`live`&&v===`live`){C(e=>{let t=e+1;return c>0&&t>=c?(x(!1),t):(O(m.length>0?0:`live`),t)});return}O(e)},s);return()=>window.clearInterval(e)},[s,v,b,m.length,c,O]);let k=E.length>0&&!mu(E),A=q(()=>gd(E),[E]),j=d??e.metadata?.title??p(`agent.rewind.fixtureTitle`),M=G(()=>{let t={...e,metadata:{...e.metadata,title:j,exported_at:e.metadata?.exported_at??new Date().toISOString(),message_count:m.length}},n=e.metadata?.agent_run_id??`fixture`;qh(`${Kh(j)||`agent-chat`}-${Kh(n)}.json`,t)},[e,m.length,j]),N=G(()=>{O(Wh(T.cursor,m.length))},[m.length,T.cursor,O]);return n(`div`,{className:H(`flex h-full min-h-0 w-full flex-col bg-background text-foreground`,u),"data-agent-test-playback-enabled":!0,"data-agent-playback-cursor":T.cursor,"data-agent-live-message-count":m.length,"data-agent-rendered-message-count":T.renderedMessageCount,"data-agent-replay-playing":b||void 0,"data-agent-replay-loop":S,children:[f&&n(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-border px-3 py-2`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`truncate text-sm font-medium`,children:j}),t(`div`,{className:`text-xs text-muted`,children:p(`agent.rewind.fixtureMeta`,{messageCount:m.length,loops:S})})]}),n(`div`,{className:`flex items-center gap-2`,children:[n(o,{type:`button`,variant:`secondary`,size:`sm`,onClick:M,children:[t(En,{className:`size-4`}),t(`span`,{className:`ms-1.5`,children:p(`agent.rewind.exportFixture`)})]}),s&&s>0&&n(o,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>x(e=>!e),children:[t(b?Cr:Dr,{className:`size-4`}),t(`span`,{className:`ms-1.5`,children:p(b?`agent.rewind.pause`:`agent.rewind.resume`)})]})]})]}),t(`div`,{className:`flex flex-shrink-0 justify-end px-2 py-1.5`,children:t(Ao,{cursor:T.cursor,messages:m,onChangeCursor:O})}),t(Vh,{messages:E,isCompleted:k,streamingMessages:D,bottomRef:w,artifactRunId:e.metadata?.agent_run_id??`agent-chat-fixture`,viewMode:y,renderRequestInputControls:!A}),A&&t(vd,{message:A,onSendMessage:N,isLoading:!1})]})}function Yh({className:e,inline:r=!1}){return n(`div`,{className:H(`flex items-center gap-1`,r?`inline-flex`:``,e),children:[t(`div`,{className:`w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_infinite_ease-in-out] hover:bg-blue-600`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}}),t(`div`,{className:`w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_0.3s_infinite_ease-in-out] hover:bg-blue-600`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}}),t(`div`,{className:`w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_0.6s_infinite_ease-in-out] hover:bg-blue-600`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}})]})}function Xh(){let{client:e}=Z(),[t,n]=Y([]),[r,i]=Y(!0),[a,o]=Y(!1),s=J(0),c=G(async()=>{let t=s.current+1;s.current=t,i(!0),o(!1);try{let r=await e.apps.getInstalledApps(`tools`),a=[];for(let e of r){let t=e,n=t.oauth_collection_ids??[],r=t.manifest.oauth_providers??{};if(!t.manifest.tool_collections)continue;let i=t.manifest.tool_collections.map(e=>Ri(e)).filter(e=>e.type===`mcp`&&n.includes(e.id)),o=new Map,s=new Map,c=[];for(let e of i)if(e.oauth_provider){let t=o.get(e.oauth_provider)??[];t.push(e),o.set(e.oauth_provider,t)}else if(e.oauth_app){let t=s.get(e.oauth_app)??[];t.push(e),s.set(e.oauth_app,t)}else c.push(e);for(let[e,n]of o)a.push({key:`${t.id}:provider:${e}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:r[e]?.display_name||e,representativeId:n[0].id,memberIds:n.map(e=>e.id),memberNames:n.map(e=>e.name)});for(let[e,n]of s)a.push({key:`${t.id}:oauthapp:${e}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:e,representativeId:n[0].id,memberIds:n.map(e=>e.id),memberNames:n.map(e=>e.name)});for(let e of c)a.push({key:`${t.id}:individual:${e.id}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:e.name,representativeId:e.id,memberIds:[e.id],memberNames:[e.name]})}if(s.current!==t||(n(a),i(!1),a.length===0))return;o(!0);let c=new Map,l=await Promise.all(a.map(async t=>{try{let n=c.get(t.appId);n||(n=e.remoteMcpConnections.getStatus(t.appId),c.set(t.appId,n));let r=(await n).find(e=>e.collection_id===t.representativeId);return{...t,authStatus:r}}catch{return t}}));if(s.current!==t)return;n(l)}catch(e){s.current===t&&(console.error(`Failed to load MCP tool collections:`,e),n([]))}finally{s.current===t&&(i(!1),o(!1))}},[e]);return K(()=>{c()},[c]),{groups:t,loading:r,statusLoading:a,reload:c}}function Zh(e,t){return t?.length?e.memberIds.every(e=>t.includes(e)):!1}function Qh(e,t,n){let r=new Set(t??[]);if(n)for(let t of e.memberIds)r.delete(t);else for(let t of e.memberIds)r.add(t);return Array.from(r)}function $h(e,t){return e.filter(e=>e.authStatus?.authenticated===!0&&!Zh(e,t)).length}function eg(e,t){return e.filter(e=>e.authStatus?.authenticated===!0&&!Zh(e,t)).map(e=>e.label)}function tg({isOpen:e,onClose:r,groups:i,loading:a,statusLoading:o=!1,reload:s,disabledCollections:c,onChange:l,onConnectionChange:u,readOnly:d=!1}){let{t:f}=X(),p=()=>{s(),u?.()};return n(ms,{isOpen:e,onClose:r,size:`md`,className:`max-w-[92vw] sm:max-w-[620px] lg:max-w-[620px]`,children:[t(hs,{children:f(`mcpConnections.title`)}),n(gs,{children:[t(`p`,{className:`mb-4 text-sm text-muted`,children:f(`mcpConnections.subtitle`)}),a?t(`div`,{className:`flex items-center justify-center py-8`,children:t(sc,{className:`size-5`})}):i.length===0?t(`div`,{className:`py-8 text-center text-sm text-muted`,children:f(`mcpConnections.empty`)}):t(`div`,{className:`space-y-1`,children:i.map(e=>{let r=!Zh(e,c),i=e.authStatus?.authenticated===!0;return n(`div`,{className:`flex items-center justify-between gap-3 py-3`,children:[n(`div`,{className:`flex min-w-0 items-center gap-2`,children:[t(i?ir:ar,{className:`size-4 shrink-0 ${i?`text-success`:`text-muted`}`,"aria-hidden":`true`}),t(zo,{description:n(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`font-medium`,children:e.appName}),e.memberNames.length>1&&t(`div`,{className:`text-xs text-muted`,children:e.memberNames.join(` · `)})]}),placement:`top`,asChild:!0,children:t(`span`,{className:`truncate ${r?`text-foreground`:`text-muted line-through`}`,children:e.label})})]}),n(`div`,{className:`flex shrink-0 items-center gap-3`,children:[o&&!e.authStatus?t(Wo,{variant:`outline`,size:`sm`,disabled:!0,className:`h-6 w-32 justify-center px-2 text-xs`,title:f(`mcpConnections.checkingStatus`),children:t(sc,{className:`size-3`})}):t(uc,{appId:e.appId,collectionId:e.representativeId,collectionName:e.label,authenticated:e.authStatus?.authenticated,onAuthChange:p,variant:`compact`,showDisconnect:!0,readOnly:d}),l&&t($s,{size:`sm`,value:r,onChange:t=>l(Qh(e,c,t)),disabled:d,"aria-label":f(r?`mcpConnections.deactivateAria`:`mcpConnections.activateAria`,{name:e.label})})]})]},e.key)})})]})]})}function ng({disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o=!1,variant:s=`outline`,size:c=`sm`}){let{t:l}=X(),{groups:u,loading:d,statusLoading:f,reload:p}=Xh(),[m,h]=Y(!1);if(!d&&u.length===0)return null;let g=$h(u,r),_=eg(u,r),v=_.slice(0,2),y=_.length-v.length,b=v.length>0?`${v.join(`, `)}${y>0?` +${y}`:``}`:void 0;return n(e,{children:[n(`div`,{className:`flex min-w-0 items-center gap-2`,children:[b&&t(`span`,{className:`max-w-48 truncate text-muted`,title:_.join(`, `),children:b}),n(Wo,{variant:s,size:c,className:`shrink-0`,onClick:()=>h(!0),disabled:d,"aria-label":l(`mcpConnections.manage`),children:[t(`span`,{children:l(`mcpConnections.label`)}),g>0&&t(Jo,{variant:`success`,children:g})]})]}),t(tg,{isOpen:m,onClose:()=>h(!1),groups:u,loading:d,reload:p,statusLoading:f,disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o})]})}function rg({disabledCollections:e,onChange:r,onConnectionChange:i,readOnly:a=!1}){let{t:o}=X(),{groups:s,loading:c,statusLoading:l,reload:u}=Xh();if(!c&&s.length===0)return null;let d=()=>{u(),i?.()};return c&&s.length===0?n(`div`,{className:`flex items-center gap-2 border-y border-border/70 py-2 text-sm text-muted`,children:[t(sc,{className:`size-4`}),t(`span`,{children:o(`mcpConnections.label`)})]}):t(`div`,{className:`space-y-1`,children:s.map(i=>{let s=!Zh(i,e),c=i.authStatus?.authenticated===!0;return n(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 py-2 text-sm`,children:[n(`div`,{className:`flex min-w-36 flex-1 items-center gap-2`,children:[t(c?ir:ar,{className:`size-4 shrink-0 ${c?`text-success`:`text-muted`}`,"aria-hidden":`true`}),t(zo,{description:n(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`font-medium`,children:i.appName}),i.memberNames.length>1&&t(`div`,{className:`text-xs text-muted`,children:i.memberNames.join(` · `)})]}),placement:`top`,asChild:!0,children:t(`span`,{className:`block truncate ${s?`text-foreground`:`text-muted line-through`}`,children:i.label})})]}),l&&!i.authStatus?t(Wo,{variant:`outline`,size:`sm`,disabled:!0,className:`h-6 w-32 justify-center px-2 text-xs`,title:o(`mcpConnections.checkingStatus`),children:t(sc,{className:`size-3`})}):t(uc,{appId:i.appId,collectionId:i.representativeId,collectionName:i.label,authenticated:i.authStatus?.authenticated,onAuthChange:d,variant:`compact`,showDisconnect:!0,readOnly:a}),r&&n(`div`,{className:`flex min-w-24 items-center justify-end gap-2 text-xs`,children:[t(`span`,{className:s?`text-muted`:`text-attention`,children:o(s?`mcpConnections.enabled`:`mcpConnections.disabled`)}),t($s,{size:`sm`,value:s,onChange:t=>r(Qh(i,e,t)),disabled:a,"aria-label":o(s?`mcpConnections.deactivateAria`:`mcpConnections.activateAria`,{name:i.label})})]})]},i.key)})})}function ig({disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o=!1}){let{t:s}=X(),{groups:c,loading:l,statusLoading:u,reload:d}=Xh(),[f,p]=Y(!1);if(!l&&c.length===0)return null;let m=$h(c,r);return n(e,{children:[t(Ls,{align:`left`,trigger:t(Wo,{variant:`ghost`,size:`icon`,className:`size-8 rounded-md text-muted hover:bg-muted`,title:s(`mcpConnections.settings`),disabled:l,children:t(`span`,{className:`flex size-5 items-center justify-center rounded-[3px] border border-muted text-sm font-semibold leading-none`,"aria-hidden":`true`,children:`/`})}),children:n(Rs,{onClick:()=>p(!0),isDisabled:l,children:[t(`span`,{children:s(`mcpConnections.title`)}),m>0&&t(Jo,{variant:`success`,children:m})]})}),t(tg,{isOpen:f,onClose:()=>p(!1),groups:c,loading:l,reload:d,statusLoading:u,disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o})]})}const ag=/(^|\/)(tool-inputs|tool-results|archive)(\/|$)/,og=/(^|\/)process\/(history|state)(\/|$)/,sg=[/conversation\.json$/,/^conversation-checkpoint-\d+\.json$/,/^tools\.json$/,/^tool-input-refs\.json$/,/^toolu[_-]/i];function cg(e){if(ag.test(e)||og.test(e))return!0;let t=e.split(`/`).pop()??e;return sg.some(e=>e.test(t))}function lg(e){let t={name:``,path:``,isDirectory:!0,children:[]};for(let n of e){let e=n.split(`/`),r=t,i=``;for(let t=0;t<e.length;t++){let n=e[t];i=i?`${i}/${n}`:n;let a=t===e.length-1,o=r.children.find(e=>e.name===n);o||(o={name:n,path:i,isDirectory:!a,children:[]},r.children.push(o)),r=o}}let n=e=>{e.children.sort((e,t)=>e.isDirectory===t.isDirectory?e.name.localeCompare(t.name):e.isDirectory?-1:1),e.children.forEach(n)};return n(t),t.children}function ug(e,t){let n=`agents/${t}/`,r=e.indexOf(n);return r===-1?e.split(`/`).pop()??e:e.slice(r+n.length)}function dg(e,t,n=0,r=!1){let[i,a]=Y([]),[o,s]=Y(!1),[c,l]=Y(null),[u,d]=Y(0),f=J(0),p=G(async()=>{if(!t)return;let n=++f.current;s(!0),l(null);try{let r=await e.files.listArtifacts(t);if(n!==f.current)return;let i=r.map(e=>ug(e,t)).filter(e=>!!e);a(i)}catch(e){if(n!==f.current)return;l(e instanceof Error?e.message:`Failed to list artifacts`),a([])}finally{n===f.current&&s(!1)}},[e,t]);K(()=>{p()},[p,n,u]);let m=q(()=>r?i:i.filter(e=>!cg(e)),[i,r]),h=q(()=>lg(m),[m]),g=i.length-m.length,_=G(()=>{d(e=>e+1)},[]);return{tree:h,flatFiles:m,totalCount:i.length,systemHiddenCount:g,isLoading:o,error:c,refresh:_}}const fg=W.lazy(async()=>({default:(await Promise.resolve().then(()=>tx)).UniversalDocumentViewer})),pg=new Set([`md`,`markdown`,`mdx`,`txt`]);function mg(e){let t=e.split(`.`).pop()?.toLowerCase();return t!==void 0&&pg.has(t)}function hg(e){return e.replace(/[_-]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function gg({node:e,depth:r,runId:i,onOpen:a,onDownload:s,downloadingPath:c,forceExpanded:l=!1}){let{t:u}=X(),[d,f]=Y(!1),p=l||d;if(e.isDirectory)return n(`div`,{className:`min-w-0`,children:[n(o,{variant:`unstyled`,className:`flex w-full max-w-full items-center justify-start gap-1.5 rounded px-1 py-1 text-start text-sm hover:bg-muted/30`,style:{paddingInlineStart:`${r*14+4}px`},onClick:()=>f(e=>!e),"aria-expanded":p,children:[p?t(on,{className:`size-3.5 shrink-0 text-muted`}):t(ln,{className:`size-3.5 shrink-0 text-muted cn-rtl-flip`}),t(p?Un:Hn,{className:`size-4 shrink-0 text-info`}),t(`span`,{className:`min-w-0 truncate font-medium`,title:e.path,children:hg(e.name)})]}),p&&e.children.map(e=>t(gg,{node:e,depth:r+1,runId:i,onOpen:a,onDownload:s,downloadingPath:c,forceExpanded:l},`${i}:${e.path}`))]});let m=c===e.path;return n(`div`,{className:`flex min-w-0 items-center gap-1`,children:[n(o,{variant:`unstyled`,className:`flex min-w-0 flex-1 items-center justify-start gap-1.5 rounded px-1 py-1 text-start text-sm hover:bg-muted/30`,style:{paddingInlineStart:`${r*14+4}px`},onClick:()=>a(e.path),title:e.path,children:[t(`span`,{className:`size-3.5 shrink-0`}),t(Nn,{className:`size-4 shrink-0 text-muted`}),t(`span`,{className:`min-w-0 truncate`,children:e.name})]}),t(o,{variant:`ghost`,size:`sm`,className:`h-7 w-7 shrink-0 p-0`,onClick:()=>s(e.path),disabled:m,"aria-label":u(`agent.download`),title:u(`agent.download`),children:m?t(cr,{className:`size-3.5 animate-spin text-info`}):t(Dn,{className:`size-3.5`})})]})}function _g(e){return e.reduce((e,t)=>t.isDirectory?e+_g(t.children):e+1,0)}function vg(e,t){let n=t.trim().toLocaleLowerCase();return n?e.flatMap(e=>{let t=`${e.name} ${e.path}`.toLocaleLowerCase().includes(n);if(!e.isDirectory)return t?[e]:[];let r=vg(e.children,n);return t?[{...e}]:r.length>0?[{...e,children:r}]:[]}):e}function yg(e,t){let n=document.createElement(`a`);n.href=e,n.download=t,n.rel=`noopener noreferrer`,n.style.display=`none`,document.body.appendChild(n),n.click(),n.remove()}function bg(e){switch(e.split(`.`).pop()?.toLowerCase()){case`css`:return`text/css`;case`gif`:return`image/gif`;case`htm`:case`html`:return`text/html`;case`jpeg`:case`jpg`:return`image/jpeg`;case`json`:return`application/json`;case`md`:case`markdown`:return`text/markdown`;case`pdf`:return`application/pdf`;case`png`:return`image/png`;case`svg`:return`image/svg+xml`;case`ts`:case`tsx`:return`text/typescript`;case`txt`:return`text/plain`;case`webp`:return`image/webp`;default:return}}function xg({runId:e,path:r,onBack:i,onDownload:a,refreshKey:s,refreshDetails:c,onSendMessage:l}){let{t:u}=X(),[d,f]=Y(`components`),[p,m]=Y(`idle`);return n(`div`,{className:`flex h-full min-h-0 flex-col`,children:[n(`div`,{className:`flex shrink-0 items-center gap-1 border-b border-border/60 px-2 py-1`,children:[t(o,{variant:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:i,"aria-label":u(`agent.backToArtifacts`),title:u(`agent.backToArtifacts`),children:t(Ut,{className:`size-4 cn-rtl-flip`})}),n(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[t(`span`,{className:`truncate text-sm font-medium`,title:r,children:r.split(`/`).pop()}),p===`saving`?t(Re,{description:u(`agent.savingWorkingCopy`),asChild:!0,children:t(cr,{className:`size-3.5 shrink-0 animate-spin text-muted`,"aria-label":u(`agent.savingWorkingCopy`)})}):p===`saved`?t(Re,{description:u(`agent.savedToWorkingCopy`),asChild:!0,children:t(rn,{className:`size-3.5 shrink-0 text-success`,"aria-label":u(`agent.savedToWorkingCopy`)})}):null]}),n(`div`,{className:`flex items-center gap-0.5`,children:[t(o,{variant:d===`components`?`primary`:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:()=>f(`components`),"aria-label":u(`agent.blockMode`),"aria-pressed":d===`components`,title:u(`agent.blockMode`),children:t(Lr,{className:`size-4`})}),t(o,{variant:d===`document`?`primary`:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:()=>f(`document`),"aria-label":u(`agent.editMode`),"aria-pressed":d===`document`,title:u(`agent.editMode`),children:t(wr,{className:`size-4`})})]}),t(o,{variant:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:()=>a(r),"aria-label":u(`agent.download`),title:u(`agent.download`),children:t(Dn,{className:`size-4`})})]}),t(dt,{runId:e,path:r,viewMode:d,refreshKey:s,refreshDetails:c,readOnly:!l,onAction:e=>{if(!l)return;let t=e.anchor.block_type.replaceAll(`_`,` `);l(e.comment?.trim()||u(`agent.editedSelectionMessage`,{blockType:t}),{editing_action:e})},onSaveStatusChange:m,onSendMessage:l?e=>l(e):void 0,className:H(`relative min-h-0 flex-1`,d===`document`?`overflow-hidden`:`overflow-y-auto px-6 py-5`)})]})}function Sg({icon:e,children:r,action:i}){return n(p,{className:`h-full min-h-[240px] flex-col text-center text-muted`,children:[e,t(`span`,{className:`text-sm`,children:r}),i]})}function Cg({runId:r,refreshKey:i=0,refreshDetails:a,selectedPath:s,onSelectedPathChange:c,onSendMessage:l}){let{t:u}=X(),{client:d}=Z(),[f,m]=Y(!1),{tree:h,flatFiles:g,totalCount:_,systemHiddenCount:v,isLoading:y,error:b,refresh:x}=dg(d,r,i,f),[S,C]=Y(null),[w,T]=Y(null),[E,D]=Y(``),[O,k]=Y(null),A=s===void 0?O:s,j=G(e=>{s===void 0&&k(e),c?.(e)},[c,s]),N=E.trim(),P=q(()=>vg(h,N),[h,N]),F=q(()=>_g(P),[P]),I=ot(),L=G(async e=>{if(r){C(e);try{let{url:t}=await d.files.getArtifactDownloadUrl(r,e,`attachment`);yg(t,e.split(`/`).pop()||`artifact`)}catch(e){console.error(`Failed to get artifact download URL:`,e)}finally{C(null)}}},[d,r]),ee=G(e=>{if(mg(e)){j(e);return}T(e)},[j]),te=r&&w?{title:w.split(`/`).pop()||w,fileName:w.split(`/`).pop()||w,contentType:bg(w),artifact:{runId:r,path:w}}:null;return r?y&&_===0?t(Sg,{icon:t(cr,{className:`mb-2 size-6 animate-spin`}),children:u(`agent.loadingArtifacts`)}):b?t(`div`,{className:`flex flex-col items-center justify-center p-4 text-muted w-full`,children:n(M,{title:`Fail to load Artifacts`,className:`w-full`,action:x,actionLabel:n(e,{children:[t(Pr,{className:`size-3.5 me-1.5`}),u(`agent.retry`)]}),children:[t(`span`,{className:`break-all text-muted`,children:b}),` `,t(`br`,{})]})}):_===0?t(Sg,{icon:t(br,{className:`mb-2 size-8`}),action:n(o,{variant:`ghost`,size:`sm`,className:`mt-2`,onClick:x,children:[t(Pr,{className:`size-3.5 me-1.5`}),u(`agent.refresh`)]}),children:u(`agent.noArtifactsYet`)}):A?t(xg,{runId:r,path:A,refreshKey:i,refreshDetails:a,onBack:()=>j(null),onDownload:e=>void L(e),onSendMessage:l}):n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`flex shrink-0 flex-col gap-2 border-b px-3 py-2`,children:[n(`div`,{className:`flex items-center justify-between gap-2 text-xs text-muted`,children:[n(`span`,{children:[N?`${F} of ${g.length} file${g.length===1?``:`s`}`:`${g.length} file${g.length===1?``:`s`}`,!f&&v>0?` · ${v} hidden`:``]}),n(`div`,{className:`flex items-center gap-1`,children:[t(De,{size:`sm`,value:f,onChange:m,children:t(`span`,{className:`text-xs text-muted`,children:u(`agent.showSystemArtifacts`)})}),t(o,{variant:`ghost`,size:`sm`,onClick:x,disabled:y,className:`h-6 w-6 p-0`,children:t(Pr,{className:`size-3.5 ${y?`animate-spin`:``}`})})]})]}),t(`label`,{htmlFor:I,className:`sr-only`,children:u(`form.filter`)}),t(R,{id:I,type:`text`,role:`searchbox`,autoComplete:`off`,placeholder:u(`store.searchPlaceholder`),value:E,onChange:D,clearable:!0})]}),t(`div`,{className:`flex-1 overflow-y-auto px-3 py-2`,children:P.length>0?t(`div`,{className:`min-w-0`,children:P.map(e=>t(gg,{node:e,depth:0,runId:r,onOpen:ee,onDownload:L,downloadingPath:S,forceExpanded:!!N},`${r}:${e.path}`))}):t(`div`,{className:`px-1 py-6 text-sm text-muted`,children:u(!f&&v>0?`agent.onlySystemArtifacts`:`agent.noContentAvailable`)})}),te&&n(ie,{isOpen:!!w,onClose:()=>T(null),size:`xl`,className:`h-[90vh] p-0`,description:`Artifact preview`,children:[t(se,{show:!1,children:te.fileName}),t(ae,{className:`h-full max-h-none p-0`,children:t(W.Suspense,{fallback:t(p,{className:`h-full`,children:t(cr,{className:`size-6 animate-spin text-muted`})}),children:t(fg,{source:te,className:`h-full`,onDownload:()=>w&&void L(w)})})})]})]}):t(Sg,{icon:t(br,{className:`mb-2 size-8`}),children:`No run selected`})}const wg=W.memo(Cg);function Tg(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Eg(e){if(!Tg(e))return;let t=e.browseruse??e.browser_use;if(!Tg(t))return;let n={widget:typeof t.widget==`string`?t.widget:void 0,browser_workflow_id:typeof t.browser_workflow_id==`string`?t.browser_workflow_id:void 0,workstream_id:typeof t.workstream_id==`string`?t.workstream_id:void 0,phase:typeof t.phase==`string`?t.phase:void 0,url:typeof t.url==`string`?t.url:void 0,title:typeof t.title==`string`?t.title:void 0,screenshot:typeof t.screenshot==`string`?t.screenshot:void 0,raw_screenshot:typeof t.raw_screenshot==`string`?t.raw_screenshot:void 0,prefer_raw_screenshot:typeof t.prefer_raw_screenshot==`boolean`?t.prefer_raw_screenshot:void 0,updated_at:typeof t.updated_at==`number`?t.updated_at:void 0};if(!(n.widget&&n.widget!==`browseruse`)&&!(!n.url&&!n.title&&!n.screenshot&&!n.raw_screenshot))return n}function Dg(e){let t=new Map;for(let n of e){let e=Eg(n.details);if(!e)continue;let r=e.workstream_id||n.workstream_id||`main`,i=e.updated_at??(typeof n.timestamp==`number`?n.timestamp:new Date(n.timestamp).getTime()),a=t.get(r);(!a||i>=a.timestamp)&&t.set(r,{state:{...e,workstream_id:r},timestamp:i})}return new Map(Array.from(t.entries()).map(([e,t])=>[e,t.state]))}function Og(e){return e.replace(/^artifact:\/\//,``).replace(/^artifact:/,``).replace(/^\/+/,``)}function kg(e){return e?e.replace(/_/g,` `):`browser`}function Ag({state:e,runId:r,className:a,compact:o}){let{t:s}=X(),{client:c}=Z(),l=Za(),{openImage:u}=Hd(),[d,f]=Y(),p=e.prefer_raw_screenshot===!1?e.screenshot||e.raw_screenshot:e.raw_screenshot||e.screenshot,m=e.title||e.url||s(`agent.browserUse`),h=q(()=>p&&Og(p).split(`/`).pop()||s(`agent.browserScreenshot`),[p,s]);return K(()=>{if(!p){f(void 0);return}if(p.startsWith(`http://`)||p.startsWith(`https://`)){f(p);return}if(!r){f(void 0);return}let e=!1;return(async()=>{let t=Og(p);try{let n=$a(r,t,`inline`),i=l?await l.getOrFetch(n,async()=>(await c.files.getArtifactDownloadUrl(r,t,`inline`)).url):(await c.files.getArtifactDownloadUrl(r,t,`inline`)).url;e||f(i)}catch(n){console.error(`Failed to resolve browser screenshot ${t}`,n),e||f(void 0)}})(),()=>{e=!0}},[c,r,p,l]),o?n(`div`,{className:H(`overflow-hidden rounded-md border border-border/70 bg-transparent`,a),children:[n(`div`,{className:`flex items-center gap-2 px-2 py-1.5`,children:[t(vr,{className:`size-3.5 shrink-0 text-info`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex min-w-0 items-center gap-1`,children:[t(`span`,{className:`text-xs font-medium text-foreground`,children:s(`agent.browserPreview`)}),e.phase&&n(`span`,{className:`truncate text-[11px] capitalize text-muted`,children:[`· `,kg(e.phase)]})]}),t(`div`,{className:`truncate text-[11px] text-muted`,title:m,children:m})]}),e.url&&t(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,title:s(`agent.openInNewTab`),className:H(`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md`,`text-muted hover:bg-muted hover:text-foreground`),children:t(An,{className:`size-3`})})]}),p&&(d?t(`button`,{type:`button`,className:`block w-full bg-mixer-muted/20 text-start`,onClick:()=>u(d,h),title:s(`agent.clickToEnlarge`),children:t(`img`,{src:d,alt:h,className:`block max-h-32 w-full object-contain`})}):n(`div`,{className:`flex min-h-16 items-center justify-center gap-2 bg-mixer-muted/20 px-3 py-4 text-xs text-muted`,children:[t(Zn,{className:`size-4`}),t(`span`,{children:s(`agent.browserScreenshotPending`)})]}))]}):n(`div`,{className:H(`overflow-hidden rounded-md border border-muted bg-mixer-muted/10`,a),children:[n(`div`,{className:`flex items-start justify-between gap-2 border-b border-muted px-2.5 py-2`,children:[n(`div`,{className:`flex min-w-0 items-start gap-2`,children:[t(vr,{className:`mt-0.5 size-4 shrink-0 text-info`}),n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-xs font-medium text-foreground`,children:s(`agent.browserUse`)}),t(`div`,{className:`truncate text-xs text-muted`,title:m,children:m})]})]}),t(i,{variant:`info`,className:`shrink-0 capitalize`,children:kg(e.phase)})]}),d?t(`button`,{type:`button`,className:`block w-full bg-mixer-muted/20 text-start`,onClick:()=>u(d,h),title:s(`agent.clickToEnlarge`),children:t(`img`,{src:d,alt:h,className:`block max-h-56 w-full object-contain`})}):n(`div`,{className:`flex min-h-28 items-center justify-center gap-2 bg-mixer-muted/20 px-3 py-6 text-xs text-muted`,children:[t(Zn,{className:`size-4`}),t(`span`,{children:s(`agent.browserScreenshotPending`)})]}),e.url&&n(`div`,{className:`flex items-center gap-2 border-t border-muted px-2.5 py-1.5`,children:[t(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`min-w-0 flex-1 truncate text-xs text-info hover:underline`,title:e.url,children:e.url}),t(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,title:s(`agent.openInNewTab`),className:H(`inline-flex h-6 shrink-0 items-center justify-center rounded-md px-1.5`,`text-muted hover:bg-muted hover:text-foreground`),children:t(An,{className:`size-3`})})]})]})}function jg({documents:e,activeId:n,onSelect:r}){return e.length===0?null:t(`div`,{className:`flex items-center gap-1 px-2 py-1.5`,children:t(w,{align:`right`,trigger:t(o,{variant:`ghost`,size:`xs`,title:`All opened documents`,className:`flex items-center gap-1.5 max-w-[220px] text-xs h-7 px-2`,children:t(on,{className:`size-3 shrink-0`})}),children:e.map(e=>t(B,{onClick:()=>r(e.id),className:e.id===n?`font-medium`:``,children:t(`span`,{className:`truncate max-w-[200px]`,children:e.title})},e.id))})})}function Mg({isOpen:e,documents:r,activeDocumentId:i,onSelectDocument:a,onCloseDocument:s,onUpdateDocumentTitle:c,refreshKey:l,runId:u}){let{client:d}=Z(),{t:f}=X(),[p,m]=Y(null),[h,g]=Y(!1),[_,v]=Y(null),[y,b]=Y(null),x=G(async e=>{g(!0),v(null);try{let[t,n]=await Promise.all([d.store.objects.getObjectText(e),d.store.objects.retrieve(e)]);m(t.text??null);let r=n.name;b(r),r&&c?.(e,r)}catch(e){let t=e instanceof Error?e.message:f(`agent.failedToLoadDocument`);v(t),m(null)}finally{g(!1)}},[d,c,f]);return K(()=>{i&&e&&x(i)},[i,l,e,x]),!e||r.length===0?null:n(`div`,{className:`h-full shadow-xl border border-muted/20 overflow-hidden flex flex-col`,children:[n(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-muted/20 shrink-0`,children:[n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(Rn,{className:`size-4 text-muted shrink-0`}),t(`h3`,{className:`font-bold text-sm truncate`,children:y||f(`agent.document`)})]}),n(`div`,{className:`flex items-center gap-1`,children:[t(jg,{documents:r,activeId:i,onSelect:a}),i&&t(ga,{href:`/store/objects/${i}#overview`,topLevelNav:!0,className:`inline-flex items-center justify-center rounded-md text-sm font-medium h-8 w-8 hover:bg-muted/20 text-muted hover:text-foreground`,children:t(Re,{description:f(`agent.openDocument`),placement:`top`,size:`xs`,children:t(An,{className:`size-4`})})}),t(o,{variant:`ghost`,size:`sm`,onClick:()=>i&&s(i),title:f(`agent.close`),children:t(ci,{className:`size-4`})})]})]}),t(`div`,{className:`flex-1 overflow-y-auto px-4 py-4`,children:h?n(`div`,{className:`flex items-center justify-center py-12`,children:[t(cr,{className:`size-5 animate-spin text-muted`}),t(`span`,{className:`ms-2 text-sm text-muted`,children:f(`agent.loadingDocument`)})]}):_?t(`div`,{className:`p-4 rounded-md bg-destructive/10 text-destructive text-sm`,children:_}):p?t(`div`,{className:`prose prose-sm dark:prose-invert max-w-none`,children:t(bt,{artifactRunId:u,children:p})}):n(`div`,{className:`flex flex-col items-center justify-center py-12 text-muted`,children:[t(Rn,{className:`size-8 mb-2`}),t(`span`,{className:`text-sm`,children:f(`agent.noContentAvailable`)})]})})]})}const Ng=W.memo(Mg);function Pg({plan:e,workstreamStatus:r,isOpen:i,onClose:a,plans:s=[],activePlanIndex:c=0,onChangePlan:l=()=>{}}){let{t:u}=X();if(!i)return null;let d=e.plan||[],f=d.length,m=d.reduce((e,t)=>t?.id&&(r.get(t.id.toString())===`completed`||t.status===`completed`)?e+1:e,0),h=f>0?Math.round(m/f*100):0,g=s.length>0?s.length-c:1,_=s[c]?.timestamp;return d.length===0?t(`div`,{className:`h-full overflow-hidden`,children:n(p,{className:`h-full min-h-[240px] flex-col text-center text-muted`,children:[t(vn,{className:`mb-2 size-8`}),t(`span`,{className:`text-sm`,children:u(`agent.noPlanAvailable`)})]})}):t(`div`,{className:`h-full overflow-hidden`,children:n(`div`,{className:`flex h-full flex-col gap-4 overflow-y-auto px-2 py-3`,children:[n(`div`,{className:`space-y-2`,children:[n(`div`,{className:`flex items-start justify-between gap-3`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-sm font-medium text-foreground`,children:u(`agent.taskProgress`)}),t(`div`,{className:`text-xs text-muted`,children:u(`agent.tasksCompleted`,{completed:m,total:f})})]}),s.length>1&&n(`div`,{className:`flex shrink-0 items-center gap-1 text-xs text-muted`,children:[t(o,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>l(Math.min(s.length-1,c+1)),disabled:c>=s.length-1,"aria-label":u(`agent.olderPlan`),title:u(`agent.olderPlan`),children:t(sn,{className:`size-4`,"aria-hidden":`true`})}),n(`div`,{className:`min-w-20 text-center`,children:[n(`div`,{className:`font-medium text-foreground`,children:[g,`/`,s.length]}),t(`div`,{className:`truncate`,children:_?new Date(_).toLocaleTimeString():u(`agent.unknownTime`)})]}),t(o,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>l(Math.max(0,c-1)),disabled:c<=0,"aria-label":u(`agent.newerPlan`),title:u(`agent.newerPlan`),children:t(cn,{className:`size-4`,"aria-hidden":`true`})})]})]}),t(`div`,{className:`h-2 overflow-hidden rounded-full bg-mixer-muted/20`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":f,"aria-valuenow":m,"aria-label":u(`agent.taskProgress`),children:t(`div`,{className:`h-full rounded-full bg-success transition-all duration-300`,style:{width:`${h}%`}})})]}),t(`ol`,{className:`divide-y divide-border/60`,children:d.map((e,i)=>{let a=e.id?e.id.toString():`task-${i}`,o=e.goal||`Task ${i+1}`,s=e.id?`task-${e.id.toString()}`:`task-${o}-${e.status||`pending`}`,c=e.status||`pending`,l=r.get(a);l!==void 0&&(c=l);let d=gn,f=`text-muted`;c===`in_progress`?(d=yn,f=`text-info`):c===`completed`&&(d=en,f=`text-success`);let p=u(c===`completed`?`agent.completed`:c===`in_progress`?`agent.inProgress`:`agent.pending`);return n(`li`,{className:`grid grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 px-1 py-3`,children:[t(`span`,{className:`mt-0.5 min-w-5 text-center text-xs font-medium tabular-nums text-muted/80`,children:a}),t(`span`,{className:`min-w-0 text-sm leading-5 text-foreground/85`,children:o}),n(`span`,{className:H(`flex items-center gap-1.5 text-xs font-medium`,f),children:[t(d,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t(`span`,{children:p})]})]},s)})}),(()=>{let e=new Set(d.filter(e=>e?.id).map(e=>e.id.toString())),i=Array.from(r.entries()).filter(([t])=>t!==`main`&&!e.has(t));return i.length>0?n(`div`,{className:`mt-1 px-1 py-2`,children:[t(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:u(`agent.workstreams`)}),t(`div`,{className:`divide-y divide-border/60`,children:i.map(([e,r])=>{let i=gn,a=`text-muted`,o=u(`agent.pending`);return r===`in_progress`?(i=yn,a=`text-info`,o=u(`agent.inProgress`)):r===`completed`&&(i=en,a=`text-success`,o=u(`agent.completed`)),n(`div`,{className:`flex items-center gap-2 py-2`,children:[t(i,{className:H(`size-3.5 shrink-0`,a)}),t(`span`,{className:`min-w-0 flex-1 truncate text-xs font-medium text-foreground/80`,children:e}),t(`span`,{className:`text-xs font-medium text-muted`,children:o})]},e)})})]}):null})()]})})}const Fg=W.memo(Pg);function Ig({icon:e,children:r}){return n(p,{className:`h-full min-h-[240px] flex-col text-center text-muted`,children:[e,t(`span`,{className:`text-sm`,children:r})]})}function Lg({files:e}){let{t:r}=X(),a=q(()=>e?Array.from(e.values()):[],[e]),o=e=>{switch(e){case Si.UPLOADING:case Si.PROCESSING:return t(cr,{className:`size-4 animate-spin text-info`});case Si.READY:return t(nn,{className:`size-4 text-success`});case Si.ERROR:return t(ui,{className:`size-4 text-destructive`});default:return t(Rn,{className:`size-4 text-muted`})}},s=e=>{switch(e){case Si.UPLOADING:return t(i,{variant:`info`,children:r(`agent.uploading`)});case Si.PROCESSING:return t(i,{variant:`info`,children:r(`agent.processing`)});case Si.READY:return t(i,{variant:`success`,children:r(`agent.ready`)});case Si.ERROR:return t(i,{variant:`destructive`,children:r(`agent.error`)});default:return null}};return t(`div`,{className:`h-full min-h-0`,children:a.length===0?t(Ig,{icon:t(Rn,{className:`mb-2 size-8`}),children:r(`agent.noFilesUploadedYet`)}):t(`div`,{className:`space-y-2 p-2`,children:a.map(e=>n(`div`,{className:`flex items-start gap-2 p-2 border border-muted rounded-md`,children:[t(`div`,{className:`mt-0.5`,children:o(e.status)}),n(`div`,{className:`flex-1 min-w-0`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-sm font-medium truncate`,children:e.name}),s(e.status)]}),e.error&&t(`div`,{className:`text-xs text-destructive mt-1`,children:e.error})]})]},e.id))})})}var Rg=class extends W.Component{state={hasError:!1};static getDerivedStateFromError(e){return{hasError:!0,message:e instanceof Error?e.message:String(e)}}componentDidCatch(e,t){console.error(`Agent right panel section failed to render`,{error:e,componentStack:t.componentStack})}render(){return this.state.hasError?n(`div`,{className:H(`rounded-md border border-destructive bg-mixer-destructive/10 text-destructive`,this.props.compact?`p-2 text-xs`:`m-3 p-3 text-sm`),children:[t(`div`,{className:`font-medium`,children:this.props.title}),t(`div`,{className:`mt-1 text-xs text-muted`,children:this.props.description}),this.state.message&&t(`div`,{className:`mt-1 break-all text-[11px] text-muted`,children:this.state.message})]}):this.props.children}};function zg({workstreams:e,messages:r,runId:a}){let{t:s}=X(),{client:c}=Z(),l=Ye(),u=q(()=>Dg(r),[r]),d=s(`agent.panelRenderErrorDescription`),f=G(e=>{navigator.clipboard.writeText(e),l({status:`success`,title:s(`agent.runIdCopied`),duration:2e3})},[s,l]),p=G(async e=>{try{let t=await xu(c,e);t&&window.open(t,`_blank`)}catch{l({status:`error`,title:s(`agent.failedToDownload`)})}},[c,s,l]);return e.length===0?t(Ig,{icon:t(nr,{className:`mb-2 size-8`}),children:s(`agent.noActiveParallelTasks`)}):n(`div`,{className:`h-full min-h-0 overflow-y-auto px-2 py-2`,children:[t(`div`,{className:`px-1 pb-2 text-xs text-muted`,children:s(`agent.parallelWorkDescription`)}),t(`div`,{className:`divide-y divide-border/60`,children:e.map(e=>{let r=e.status===`running`||e.status===`canceling`,c=Math.round(e.elapsed_ms/1e3),l=Math.max(0,Math.round(e.remaining_ms/1e3)),m=e.deadline_ms>0?Math.min(100,Math.round(e.elapsed_ms/e.deadline_ms*100)):0,h=u.get(e.workstream_id),g=e.deadline_ms>0,_=e.child_workflow_run_id,v=[e.phase?Xl(e.phase):void 0,c>0?s(`agent.elapsed`,{seconds:c}):void 0,g&&l>0?s(`agent.remaining`,{seconds:l}):void 0].filter(Boolean),y=(()=>{switch(e.status){case`running`:return t(i,{variant:`info`,children:s(`agent.running`)});case`canceling`:return t(i,{variant:`attention`,children:s(`agent.canceling`)});case`completed`:return t(i,{variant:`done`,children:s(`agent.completed`)});case`failed`:return t(i,{variant:`destructive`,children:s(`agent.failed`)});case`timeout`:return t(i,{variant:`destructive`,children:s(`agent.timeout`)});case`canceled`:return t(i,{variant:`destructive`,children:s(`agent.canceled`)})}})();return t(Rg,{title:s(`agent.workstreamRenderError`),description:d,compact:!0,children:t(`div`,{className:`py-3`,children:n(`div`,{className:`flex items-start gap-2`,children:[t(`span`,{className:H(`mt-2 size-2 shrink-0 rounded-full`,iu(e.status)),"aria-hidden":`true`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[t(`span`,{className:`min-w-0 truncate text-sm font-medium text-foreground`,title:e.workstream_id,children:Xl(e.workstream_id)}),y]}),v.length>0&&t(`div`,{className:`mt-0.5 truncate text-xs text-muted`,children:v.join(` · `)}),r&&g&&t(`div`,{className:`mt-2 h-1 rounded-full bg-muted`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":m,"aria-valuetext":s(`agent.workstreamProgress`,{percent:m}),children:t(`div`,{className:`h-full rounded-full bg-info transition-all duration-500`,style:{width:`${m}%`}})}),h&&t(Rg,{title:s(`agent.browserWidgetRenderError`),description:d,compact:!0,children:t(Ag,{state:h,runId:a,compact:!0,className:`mt-2`})}),_&&n(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:[n(o,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs text-muted hover:text-foreground`,onClick:()=>f(_),children:[t(_n,{className:`size-3 me-1`}),s(`agent.copyRunId`)]}),n(o,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs text-muted hover:text-foreground`,onClick:()=>p(_),children:[t(En,{className:`size-3 me-1`}),s(`agent.download`)]})]})]})]})})},e.launch_id)})})]})}const Bg=`flex items-center border-b-2 px-2 py-1.5 text-sm font-medium whitespace-nowrap cursor-pointer shrink-0`,Vg=`border-transparent text-muted-foreground hover:border-border hover:text-foreground`,Hg=`border-primary text-primary`;function Ug({tabs:e,current:r,onTabChange:i,label:a,active:o}){let[s,c]=Y(!1),l=J(null),u=J(!1),d=()=>{l.current&&=(clearTimeout(l.current),null)},f=()=>{d(),u.current=!0,c(!0)},p=()=>{d(),l.current=setTimeout(()=>c(!1),150)};return K(()=>()=>clearTimeout(l.current??void 0),[]),n(T,{modal:!1,open:s,onOpenChange:e=>{d(),e&&(u.current=!1),c(e)},children:[t(A,{asChild:!0,children:n(`button`,{type:`button`,onMouseEnter:f,onMouseLeave:p,className:H(Bg,o?Hg:Vg),children:[a,t(on,{className:`ms-1 size-4`})]})}),t(E,{align:`end`,className:`w-max`,onMouseEnter:d,onMouseLeave:p,onCloseAutoFocus:e=>{u.current&&e.preventDefault()},children:e.map(e=>t(D,{disabled:e.disabled,onClick:()=>i(e.name),className:H(e.name===r&&`text-primary`),children:e.label},e.name))})]})}function Wg({tabs:e,current:r,onTabChange:i,className:a}){let{t:o}=X(),s=J(null),c=J([]),l=J(null),[u,d]=Y({count:e.length,promote:!1}),f=()=>{let t=s.current;if(!t)return;let n=t.clientWidth,i=e.map((e,t)=>c.current[t]?.offsetWidth??0),a=i.reduce((e,t)=>e+t,0)+4*Math.max(0,e.length-1),o=(t,n)=>{let r=0,a=0;for(let o=0;o<e.length;o++){if(o===n)continue;let e=r+(a>0?4:0)+i[o];if(e>t)break;r=e,a+=1}return a},u;if(a<=n)u={count:e.length,promote:!1};else{let t=l.current?.offsetWidth??0,a=Math.max(1,o(n-t-4,-1)),s=e.findIndex(e=>e.name===r);u=s<0||s<a?{count:a,promote:!1}:{count:o(n-t-i[s]-8,s),promote:!0}}d(e=>e.count===u.count&&e.promote===u.promote?e:u)},p=J(f);p.current=f,st(()=>{p.current()}),K(()=>{let e=s.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>p.current());return t.observe(e),()=>t.disconnect()},[]);let m=e.findIndex(e=>e.name===r),h,g;if(u.promote&&m>=0){let t=e.filter((e,t)=>t!==m);h=[...t.slice(0,u.count),e[m]],g=t.slice(u.count)}else h=e.slice(0,u.count),g=e.slice(u.count);let _=g.some(e=>e.name===r),v=o(`agent.moreTabs`);return n(`div`,{ref:s,className:H(`relative`,a),children:[n(`div`,{"aria-hidden":!0,className:`pointer-events-none invisible absolute start-0 top-0 flex w-max gap-1`,children:[e.map((e,n)=>t(`button`,{type:`button`,tabIndex:-1,ref:e=>{c.current[n]=e},className:H(Bg,Vg),children:e.label},e.name)),n(`button`,{type:`button`,tabIndex:-1,ref:l,className:H(Bg,Vg),children:[v,t(on,{className:`ms-1 size-4`})]})]}),n(`div`,{className:`-mb-px flex gap-1 overflow-hidden border-b`,children:[h.map(e=>{let n=e.name===r;return t(`button`,{type:`button`,"aria-current":n?`page`:void 0,disabled:e.disabled,onClick:()=>i(e.name),className:H(Bg,n?Hg:Vg,`disabled:pointer-events-none disabled:opacity-50`),children:e.label},e.name)}),g.length>0&&t(Ug,{tabs:g,current:r,onTabChange:i,label:v,active:_})]})]})}function Gg({plan:e,workstreamStatus:r,plans:i=[],activePlanIndex:a=0,onChangePlan:s,activeWorkstreams:c=[],messages:l=[],hideWorkstreams:u=!1,openDocuments:d=[],activeDocumentId:f,onSelectDocument:p,onCloseDocument:m,onUpdateDocumentTitle:h,docRefreshKey:g=0,runId:_,processingFiles:v,showArtifacts:y=!1,artifactRefreshKey:b=0,artifactRefreshDetails:x,selectedArtifactPath:S,onSelectedArtifactPathChange:C,onSendMessage:w,payloadContent:T,conversationContent:E,onClose:D,defaultTab:O,activeTab:k,onTabChange:A}){let{t:j}=X(),[M,N]=Y(O||`plan`),P=k??M,F=e=>{N(e),A?.(e)},I=!u&&c.length>0,L=d.length>0,ee=v?v.size>0:!1,R=G((e,n)=>t(Rg,{title:j(`agent.panelRenderError`,{name:e}),description:j(`agent.panelRenderErrorDescription`),children:n}),[j]),te={name:`conversation`,label:`Conversation`,content:E?R(`Conversation`,t(`div`,{className:`flex flex-col h-full min-h-0`,children:E})):null,is_allowed:!!E},z=[...E?[te]:[],{name:`plan`,label:j(`agent.plan`),content:R(j(`agent.plan`),e?t(Fg,{plan:e,workstreamStatus:r||new Map,isOpen:!0,onClose:D,plans:i,activePlanIndex:a,onChangePlan:s}):t(Ig,{icon:t(nr,{className:`mb-2 size-8`}),children:j(`agent.noPlanAvailable`)})),is_allowed:!0},{name:`workstreams`,label:I?n(`span`,{className:`inline-flex min-w-0 items-center gap-1 whitespace-nowrap`,children:[j(`agent.workstreams`),` `,t(`span`,{className:`inline-flex shrink-0 items-center justify-center rounded-full bg-info px-1.5 py-0.5 text-[10px] text-info`,children:c.length})]}):j(`agent.workstreams`),content:R(j(`agent.workstreams`),t(zg,{workstreams:c,messages:l,runId:_})),is_allowed:!u},{name:`documents`,label:L?n(`span`,{className:`inline-flex min-w-0 items-center gap-1 whitespace-nowrap`,children:[j(`agent.documents`),` `,t(`span`,{className:`inline-flex shrink-0 items-center justify-center rounded-full bg-info px-1.5 py-0.5 text-[10px] text-info`,children:d.length})]}):j(`agent.documents`),content:R(j(`agent.documents`),d.length>0&&p&&m?t(Ng,{isOpen:!0,documents:d,activeDocumentId:f??null,onSelectDocument:p,onCloseDocument:m,onUpdateDocumentTitle:h,refreshKey:g,runId:_}):t(Ig,{icon:t(Rn,{className:`mb-2 size-8`}),children:j(`agent.noDocumentsOpen`)})),is_allowed:!0},{name:`uploads`,label:ee?n(`span`,{className:`inline-flex min-w-0 items-center gap-1 whitespace-nowrap`,children:[j(`agent.uploads`),` `,t(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-info`})]}):j(`agent.uploads`),content:R(j(`agent.uploads`),t(Lg,{files:v})),is_allowed:!0},{name:`artifacts`,label:j(`agent.artifacts`),content:R(j(`agent.artifacts`),t(wg,{runId:_,refreshKey:b,refreshDetails:x,selectedPath:S,onSelectedPathChange:C,onSendMessage:w})),is_allowed:y},{name:`payload`,label:j(`agent.payload`),content:T?R(j(`agent.payload`),t(`div`,{className:`overflow-y-auto`,children:T})):null,is_allowed:!!T}];return n(Ne,{tabs:z,current:P,onTabChange:F,fullHeight:!0,className:`px-0`,children:[n(`div`,{className:`flex items-end justify-between shrink-0 px-1 py-1 gap-1`,children:[t(Wg,{tabs:z.filter(e=>e.is_allowed===void 0||e.is_allowed===!0),current:P,onTabChange:F,className:`min-w-0 flex-1`}),!E&&t(o,{variant:`ghost`,size:`sm`,className:`shrink-0 ms-1`,onClick:D,title:`Close Right Panel`,children:t(di,{className:`size-4`})})]}),t(Fe,{className:`flex-1 min-h-0 pt-0 pb-0`})]})}const Kg=W.memo(Gg);function qg(e){if(!e)return[];let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r.kind!==`file`)continue;let i=r.getAsFile();if(i)if(r.type.startsWith(`image/`)&&(!i.name||i.name===`image.png`)){let e=r.type.split(`/`)[1]||`png`;t.push(new File([i],`pasted-image-${Date.now()}.${e}`,{type:i.type}))}else t.push(i)}return t}function Jg(e,t,n=!1){let[r,i]=Y([]),[a,o]=Y(0),[s,c]=Y(new Map),[l,u]=Y(t),[d,f]=Y(!n),p=J(-1),m=J(new Set);K(()=>{e.length===0&&(i([]),o(0),c(new Map),f(!n),p.current=-1,m.current.clear())},[e.length,n]);let h=G(e=>{let n=e[e.length-1];n&&(n.type===Q.TERMINATED?u(!1):u(t?!0:n.type===Q.REQUEST_INPUT))},[t]);return K(()=>{if(e.length===0)return;let t=p.current+1;if(t>=e.length){h(e);return}let n=!1,r=[],a=[];for(let i=t;i<e.length;i++){let t=e[i];if(t.type===Q.PLAN)try{let e=null;if(t.details&&typeof t.details==`object`&&t.details.plan&&Array.isArray(t.details.plan)&&(e={plan:t.details.plan}),e){let i=typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime();if(!m.current.has(i)){m.current.add(i),n=!0,r.push({plan:e,timestamp:i});let t=new Map;t.set(`main`,`in_progress`),Array.isArray(e.plan)&&e.plan.forEach(e=>{if(e&&typeof e==`object`&&e.id){let n=e.id.toString();t.set(n,e.status||`pending`)}}),a.push({timestamp:i,statusMap:t})}}}catch(e){console.error(`Failed to parse plan from message:`,e)}}p.current=e.length-1,n&&r.length>0&&(i(e=>[...[...r].reverse(),...e]),o(0),f(!0),a.length>0&&c(e=>{let t=new Map(e);for(let e of a)t.set(e.timestamp,e.statusMap);return t})),h(e)},[e,h]),K(()=>{if(r.length===1&&!d&&!sessionStorage.getItem(`plan-panel-shown`)){let e=setTimeout(()=>{f(!0),sessionStorage.setItem(`plan-panel-shown`,`true`)},500);return()=>clearTimeout(e)}},[r.length,d]),{plans:r,activePlanIndex:a,setActivePlanIndex:o,workstreamStatusMap:s,showInput:l,showSlidingPanel:d,setShowSlidingPanel:f}}function Yg(e,t){return{...e,details:{...e.details??{},_deliveryStatus:t}}}function Xg(e){let t=e.details,n=t?._messageId;if(typeof n==`string`&&n)return n;let r=t?.ack;return typeof r==`string`&&r?r:void 0}function Zg(e,t){let n=e?.[t];return typeof n==`string`&&n?n:void 0}function Qg(e){return e?.streaming_id_scope===`workflow_run`}function $g(e){return[Q.COMPLETE,Q.IDLE,Q.TERMINATED,Q.REQUEST_INPUT].includes(e.type)}function e_(e){if(e.type===Q.STREAMING_CHUNK)return!1;if(e.type===Q.UPDATE&&typeof e.details?.event_class==`string`)return!0;if(e.type===Q.SYSTEM){let t=e.details;if(t?.system_type===`file_processing`&&t.files)return!1}return!!e.message||$g(e)||Fi(e).length>0}function t_(e){if(e)return{type:e.type,timestamp:e.timestamp,workstream_id:e.workstream_id,text:typeof e.message==`string`?e.message.slice(0,80):e.message?`[non-string]`:``,display_role:e.details?.display_role,source:e.details?.source}}function n_(e,t){if(e.find(e=>e.timestamp===t.timestamp))return e;if(!t.details?._optimistic&&(t.type===Q.QUESTION||hu(t))){let n=typeof t.details?.ack==`string`?t.details.ack:void 0,r=n?Yg(t,`consumed`):t;if(n){let i=e.filter(e=>!((e.type===t.type||hu(e))&&e.details?._optimistic&&Xg(e)===n));return du(i,r),i}if(t.type===Q.QUESTION){let n=e.filter(e=>e.type===Q.QUESTION&&e.details?._optimistic&&e.message===t.message&&(e.workstream_id??`main`)===(t.workstream_id??`main`));if(n.length===1){let r=e.filter(e=>e!==n[0]);return du(r,t),r}}}let n=[...e];return du(n,t),n}function r_(e){let t=e.details,n=Zg(t,`streaming_id`),r=Zg(t,`activity_id`);return n&&Qg(t)?n:r??n}function i_(e){let t=e.details,n=Zg(t,`streaming_id`),r=Zg(t,`activity_id`),i=[];return n&&Qg(t)&&i.push(n),r&&i.push(r),[...new Set(i)]}function a_(e,t,n){let[r,i]=Y([]),[a,o]=Y(!1),[s,c]=Y(`loading`),[l,u]=Y(null),[d,f]=Y(null),p=J(n);p.current=n;let[m,h]=Y(new Map),[g,_]=Y(0),v=G(()=>_(e=>e+1),[]),y=J(null),b=J(0),[x,S]=Y(new Map),C=J(new Map),w=J(null),[T,E]=Y(!1),D=J(null),O=G(()=>{let e=w.current;e&&(e.mode===`raf`?cancelAnimationFrame(e.id):clearTimeout(e.id),w.current=null)},[]),k=G(()=>{C.current.size>0&&(S(new Map(C.current)),E(!0),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>E(!1),50)),w.current=null},[]);return K(()=>{o(!mu(r))},[r]),K(()=>{uu(`stream state`,{agentRunId:t,messageCount:r.length,streamingCount:x.size,initialHistoryStatus:s,isCompleted:a,lastDeliveredTs:b.current,first:t_(r[0]),last:t_(r[r.length-1])})},[t,s,a,r,x.size]),K(()=>{let n=y.current!==t;y.current=t,n&&(i([]),c(`loading`),u(null),f(null),S(new Map),h(new Map),b.current=0);let r=new AbortController,a=n?void 0:b.current||void 0;return uu(`stream start`,{agentRunId:t,isNewConversation:n,since:a,streamNonce:g}),e.agents.getInternals(t).then(e=>{r.signal.aborted||(uu(`internals loaded`,{agentRunId:t,status:e.status,first_workflow_run_id:e.first_workflow_run_id}),u(e.status?.toUpperCase()??null),f(e.first_workflow_run_id??null))}).catch(e=>{r.signal.aborted||console.error(`Failed to check agent run status:`,e)}),e.agents.streamMessages(t,e=>{if(r.signal.aborted)return;let n=!!(e.timestamp&&e.timestamp<=b.current);if(n||p.current?.(e),uu(`stream message`,{agentRunId:t,type:e.type,timestamp:e.timestamp,workstream_id:e.workstream_id,hasMessage:!!e.message,display_role:e.details?.display_role,source:e.details?.source}),e.timestamp&&e.timestamp>b.current&&(b.current=e.timestamp),e.type===Q.STREAMING_CHUNK){let t=e.details,n=r_(e);if(!n)return;let r=C.current.get(n)||{text:``,workstreamId:e.workstream_id,startTimestamp:Date.now(),activityId:t?.activity_id,streamingId:t?.streaming_id},i=r.text+(e.message||``);C.current.set(n,{text:i,workstreamId:e.workstream_id,isComplete:t.is_final,startTimestamp:r.startTimestamp,activityId:t?.activity_id,streamingId:t?.streaming_id}),w.current===null&&(document.hidden?w.current={mode:`timeout`,id:window.setTimeout(k,16)}:w.current={mode:`raf`,id:requestAnimationFrame(k)});return}if(e.type===Q.SYSTEM){let t=e.details;if(t?.system_type===`file_processing`&&t.files){n||h(new Map(t.files.map(e=>[e.id,e])));return}}if(e.type===Q.THOUGHT||e.type===Q.ANSWER){let t=i_(e);if(t.length>0){for(let e of t)C.current.delete(e);S(e=>{let n=new Map(e),r=!1;for(let e of t)r=n.delete(e)||r;return r?n:e})}}(e.type===Q.COMPLETE||e.type===Q.IDLE)&&C.current.size>0&&k(),e_(e)&&i(t=>n_(t,e))},a,r.signal,{onHistoryLoaded:e=>{if(r.signal.aborted)return;let n=e.filter(e_),o,s=-1/0;for(let t of e)if(t.timestamp&&t.timestamp>b.current&&(b.current=t.timestamp),t.type===Q.SYSTEM){let e=t.details;if(e?.system_type===`file_processing`&&e.files){let n=t.timestamp??-1/0;(!o||n>=s)&&(o=e,s=n)}}o&&h(new Map(o.files.map(e=>[e.id,e]))),uu(`history loaded`,{agentRunId:t,count:e.length,timelineCount:n.length,since:a,first:t_(e[0]),last:t_(e[e.length-1])}),c(e.length>0?`has_messages`:`empty`),n.length>0&&i(e=>n.reduce((e,t)=>n_(e,t),e))},onHistoryError:e=>{r.signal.aborted||(uu(`history error`,{agentRunId:t,error:e instanceof Error?e.message:String(e)}),c(`error`))}}).then(()=>{if(!r.signal.aborted)return uu(`stream resolved`,{agentRunId:t}),e.agents.getInternals(t).then(e=>{r.signal.aborted||(uu(`internals refreshed after stream end`,{agentRunId:t,status:e.status}),u(e.status?.toUpperCase()??null))}).catch(e=>{r.signal.aborted||console.error(`Failed to refresh agent run status on stream end:`,e)})}).catch(e=>{r.signal.aborted||(uu(`stream failed`,{agentRunId:t,error:e instanceof Error?e.message:String(e)}),console.error(`Failed to stream agent messages:`,e))}),()=>{uu(`stream cleanup`,{agentRunId:t,streamNonce:g}),r.abort(),O(),C.current.clear(),D.current&&=(clearTimeout(D.current),null)}},[t,g,e.agents,k,O]),K(()=>{let e=()=>{!document.hidden&&C.current.size>0&&(O(),k())};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[k,O]),{messages:r,streamingMessages:x,isCompleted:a,initialHistoryStatus:s,debugChunkFlash:T,addOptimisticMessage:G(e=>{i(t=>{let n=[...t,e];return n.sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),n})},[]),updateOptimisticMessageStatus:G((e,t)=>{i(n=>n.map(n=>n.details?._optimistic&&Xg(n)===e?Yg(n,t):n))},[]),removeOptimisticMessages:G(e=>{i(t=>t.filter(t=>!e(t)))},[]),reconnect:v,agentRunStatus:l,workflowRunId:d,serverFileUpdates:m}}function o_(e){if(typeof e==`string`&&e.trim().length>0)return e}function s_(e,t){let n=o_(e.revision_root_id)||o_(e.revision_root)||o_(e.root_document_id)||o_(e.root_id);if(n)return n;let r=e.revision_info;if(r&&typeof r==`object`){let e=o_(r.root);if(e)return e}return t}function c_(e,t){return e.revisionRootId&&t.revisionRootId?e.revisionRootId===t.revisionRootId:t.revisionRootId?e.id===t.revisionRootId:e.revisionRootId?e.revisionRootId===t.id:e.id===t.id}function l_(e){let[t,n]=Y([]),[r,i]=Y(null),[a,o]=Y(!1),[s,c]=Y(0),l=J(-1);return K(()=>{e.length===0&&(n([]),i(null),o(!1),c(0),l.current=-1)},[e.length]),K(()=>{let t=l.current+1;if(!(t>=e.length)){for(let r=t;r<e.length;r++){let t=e[r];if(t.type===Q.UPDATE&&t.details){let e=t.details;if(e.event_class===`document_created`||e.event_class===`document_updated`){let t=o_(e.document_id),r=o_(e.updated_document_id)||t,a=e.title;if(r){let s=s_(e,t||r),l={id:r,title:a||`Document`,revisionRootId:s};n(e=>{let t=e.findIndex(e=>c_(e,l));if(t<0)return[...e,l];let n=e[t];if(n.id===l.id&&n.title===l.title&&n.revisionRootId===l.revisionRootId)return e;let r=[...e];return r[t]=l,r}),i(l.id),o(!0),e.event_class===`document_updated`&&c(e=>e+1)}}}}l.current=e.length-1}},[e]),{openDocuments:t,activeDocumentId:r,isDocPanelOpen:a,docRefreshKey:s,closeDocPanel:G(()=>{o(!1)},[]),closeDocument:G(e=>{n(t=>{let n=t.filter(t=>t.id!==e);return n.length===0?(o(!1),i(null)):i(t=>t===e?n[0].id:t),n})},[]),selectDocument:G(e=>{i(e)},[]),openDocInPanel:G(e=>{n(t=>t.some(t=>t.id===e)?t:[...t,{id:e,title:`Document`,revisionRootId:e}]),i(e),o(!0)},[]),updateDocumentTitle:G((e,t)=>{n(n=>n.map(n=>n.id===e?{...n,title:t}:n))},[])}}function u_(e){return e.type.startsWith(`image/`)}function d_(e){if(!(!u_(e)||typeof URL>`u`||!URL.createObjectURL))return URL.createObjectURL(e)}function f_(e){typeof URL<`u`&&URL.revokeObjectURL&&URL.revokeObjectURL(e)}function p_(e,t,n,r,i){let a=It.getFixedT(null,Ft),[o,s]=Y(new Map),[c,l]=Y(new Set),u=J(new Set),d=J(new Map),f=J(t),p=J(o);p.current=o;let m=J(n);m.current=n;let h=G(e=>{let t=d.current.get(e);t&&(f_(t),d.current.delete(e))},[]);K(()=>{if(f.current!==t){f.current=t,d.current.forEach(f_),d.current.clear(),s(new Map);let e=new Set;u.current=e,l(e)}},[t]),K(()=>()=>{d.current.forEach(f_),d.current.clear()},[]);let g=q(()=>{let e=new Map;if(o.forEach((t,n)=>{c.has(n)||e.set(n,t)}),n.forEach((t,n)=>{if(t.consumed_at){e.delete(n);return}if(!c.has(n)){let r=o.get(n);e.set(n,{...t,artifact_path:t.artifact_path??r?.artifact_path,reference:t.reference??r?.reference,...r?.preview_url?{preview_url:r.preview_url}:{}})}}),i&&i.size>0)for(let[t,n]of e)(n.reference&&i.has(n.reference)||n.artifact_path&&i.has(n.artifact_path))&&e.delete(t);return e},[o,c,n,i]);return{processingFiles:g,hasProcessingFiles:q(()=>Array.from(g.values()).some(e=>e.status===Si.UPLOADING||e.status===Si.PROCESSING),[g]),handleFileUpload:G(async n=>{for(let i of n){let n=`file-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,o=`files/${i.name}`,c=d_(i);c&&d.current.set(n,c);let l={id:n,name:i.name,content_type:i.type||`application/octet-stream`,size:i.size,status:Si.UPLOADING,started_at:Date.now(),preview_url:c};s(e=>new Map(e).set(n,l));try{if(await e.agents.uploadArtifact(t,o,i),s(e=>{let t=new Map(e),r=t.get(n);return r&&(r.status=Si.PROCESSING,r.artifact_path=o,r.reference=`artifact:${o}`),t}),u.current.has(n))continue;await e.agents.sendSignal(t,`FileUploaded`,{id:n,name:i.name,content_type:i.type||`application/octet-stream`,reference:`artifact:${o}`,artifact_path:o})}catch(e){if(u.current.has(n))continue;s(t=>{let r=new Map(t),i=r.get(n);return i&&(i.status=Si.ERROR,i.error=e instanceof Error?e.message:`Upload failed`,i.completed_at=Date.now()),r}),r({status:`error`,title:a(`agent.uploadFailed`),description:e instanceof Error?e.message:`Failed to upload file`,duration:3e3})}}},[e,t,r,a]),removeProcessingFile:G(async n=>{l(e=>{if(e.has(n))return e;let t=new Set(e);return t.add(n),u.current=t,t}),s(e=>{if(!e.has(n))return e;let t=new Map(e);return t.delete(n),t}),h(n);try{await e.agents.sendSignal(t,`FileRemoved`,{id:n})}catch(e){r({status:`error`,title:a(`agent.removeFileFailed`),description:e instanceof Error?e.message:`Failed to remove file`,duration:3e3})}},[t,e,h,a,r]),clearProcessingFiles:G(()=>{d.current.forEach(f_),d.current.clear(),l(e=>{let t=new Set(e);for(let e of m.current.keys())t.add(e);for(let e of p.current.keys())t.add(e);return u.current=t,t}),s(new Map)},[])}}function m_({activeWorkstreams:r,onSelectWorkstream:i,className:a}){let{t:s}=X(),[c,l]=Y(!1),u=ot(),d=q(()=>r.filter(e=>e.status===`running`||e.status===`canceling`),[r]),f=c?d:d.slice(0,3),p=Math.max(0,d.length-f.length),m=d.length>3;return K(()=>{m||l(!1)},[m]),d.length===0?null:t(`div`,{className:H(`mx-auto mb-2 w-full max-w-3xl px-1`,a),"data-agent-active-workstreams":!0,children:n(`output`,{className:`flex flex-col gap-1.5 rounded-2xl border border-border/70 bg-background/95 p-2 text-xs text-muted shadow-lg shadow-black/5`,"aria-live":`polite`,children:[n(`div`,{className:`flex min-w-0 items-center gap-2 px-1 font-medium`,children:[t(Kt,{className:`size-3.5 shrink-0 text-muted`,"aria-hidden":`true`}),t(`span`,{className:`truncate`,children:s(`agent.activeWorkstreams`,{count:d.length})})]}),t(`div`,{id:u,className:`flex flex-col gap-0.5`,children:f.map(r=>{let a=Ql(r.workstream_id,r.interaction),s=n(e,{children:[t(`span`,{className:H(`size-1.5 shrink-0 rounded-full`,iu(r.status)),"aria-hidden":`true`}),t(`span`,{className:`truncate font-medium`,children:a}),r.phase&&t(`span`,{className:`truncate text-xs text-muted/75`,children:Xl(r.phase)})]});return i?n(o,{type:`button`,variant:`ghost`,className:`h-auto min-w-0 justify-start gap-2 rounded-lg px-1 py-1 text-sm text-foreground/80`,title:a,onClick:()=>{l(!1),i(r.workstream_id)},children:[s,t(cn,{className:`ms-auto size-3.5 shrink-0 rtl:rotate-180`,"aria-hidden":`true`})]},r.launch_id||r.workstream_id):t(`div`,{className:`flex min-w-0 items-center gap-2 rounded-lg px-1 py-1 text-sm text-foreground/80`,title:a,children:s},r.launch_id||r.workstream_id)})}),m&&n(o,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-fit shrink-0 gap-1 rounded-xl px-2.5 text-xs text-muted`,"aria-expanded":c,"aria-controls":u,onClick:()=>l(e=>!e),children:[!c&&n(`span`,{children:[`+`,p]}),s(c?`agent.showLess`:`agent.showMore`),t(an,{className:H(`size-3.5 transition-transform`,c&&`rotate-180`),"aria-hidden":`true`})]})]})})}var h_=class{_listeners=new Set;snapshot;constructor(e){this.snapshot=new g_(e,this)}subscribe=e=>(this._listeners.add(e),()=>{this._listeners.delete(e)});getSnapshot=()=>this.snapshot;notify(){this._listeners.forEach(e=>{e()})}},g_=class e{vertesia;_interactive=!0;_debug_mode=!1;_non_blocking_subagents=!0;_checkpoint_tokens;_visibility;_user_channels;_collection;_disabled_mcp_collections;_start=!1;_preserveRunValues=!1;_interaction;_environment;_model=``;_model_options;_tool_names=[];_data;_mode=`start`;_scheduledWorkflowConfig;_interactionParamsSchema;_schemaVersion=0;_inputValidator;_store;constructor(e,t){this.vertesia=e,this._store=t}onStateChanged(){let e=this.clone();this._store.snapshot=e,this._store.notify()}clone(){let t=new e(this.vertesia,this._store);return t._interactionParamsSchema=this._interactionParamsSchema,t._schemaVersion=this._schemaVersion,t._interaction=this._interaction,t._data=this._data,t._environment=this._environment,t._model=this._model,t._model_options=this._model_options?{...this._model_options}:void 0,t._tool_names=[...this._tool_names],t._interactive=this._interactive,t._debug_mode=this._debug_mode,t._non_blocking_subagents=this._non_blocking_subagents,t._checkpoint_tokens=this._checkpoint_tokens,t._visibility=this._visibility,t._user_channels=this._user_channels?[...this._user_channels]:void 0,t._inputValidator=this._inputValidator,t._start=this._start,t._collection=this._collection,t._disabled_mcp_collections=this._disabled_mcp_collections?[...this._disabled_mcp_collections]:void 0,t._preserveRunValues=this._preserveRunValues,t._mode=this._mode,t._scheduledWorkflowConfig=this._scheduledWorkflowConfig,t}set mode(e){e!==this._mode&&(this._mode=e,e===`schedule`&&!this._scheduledWorkflowConfig&&(this._scheduledWorkflowConfig={name:``,description:``,cron_expression:`0 9 * * *`,timezone:`UTC`}),this.onStateChanged())}get mode(){return this._mode}set scheduledWorkflowConfig(e){this._scheduledWorkflowConfig=e,this.onStateChanged()}get scheduledWorkflowConfig(){return this._scheduledWorkflowConfig}updateScheduledWorkflowConfig(e){this._scheduledWorkflowConfig={...this._scheduledWorkflowConfig,...e},this.onStateChanged()}get interactive(){return this._interactive}set interactive(e){e!==this._interactive&&(this._interactive=e,this.onStateChanged())}get debug_mode(){return this._debug_mode}set debug_mode(e){e!==this._debug_mode&&(this._debug_mode=e,this.onStateChanged())}get non_blocking_subagents(){return this._non_blocking_subagents}set non_blocking_subagents(e){e!==this._non_blocking_subagents&&(this._non_blocking_subagents=e,this.onStateChanged())}get checkpoint_tokens(){return this._checkpoint_tokens}set checkpoint_tokens(e){e!==this._checkpoint_tokens&&(this._checkpoint_tokens=e,this.onStateChanged())}get visibility(){return this._visibility}set visibility(e){e!==this._visibility&&(this._visibility=e,this.onStateChanged())}get user_channels(){return this._user_channels}set user_channels(e){this._user_channels=e,this.onStateChanged()}get collection(){return this._collection}set collection(e){e!==this._collection&&(this._collection=e,this.onStateChanged())}get disabled_mcp_collections(){return this._disabled_mcp_collections}set disabled_mcp_collections(e){this._disabled_mcp_collections=e&&e.length>0?e:void 0,this.onStateChanged()}get search_scope(){return this._collection?vi.Collection:void 0}async restoreConversation(e){let t=e.interaction;e.version&&(/^[a-fA-F0-9]{24}$/.test(t)||(t=`${t}@${e.version}`));let n=await this.vertesia.interactions.catalog.resolve(t),r=n.runtime?.environment||e.config?.environment,i=e.config?.model,a=await(r?this.vertesia.environments.retrieve(r).catch(()=>void 0):Promise.resolve(void 0));this._data=e.data,this.interaction=n,e.interactionParamsSchema!=null&&(this.interactionParamsSchema=e.interactionParamsSchema),this._tool_names=e.tool_names||[],this._interactive=e.interactive,this._debug_mode=e.debug_mode??!1,this._non_blocking_subagents=e.non_blocking_subagents??!0,this._checkpoint_tokens=e.checkpoint_tokens,this._user_channels=e.user_channels,this._disabled_mcp_collections=e.disabled_mcp_collections,this._model_options=e.config?.model_options,this.collection=e.collection_id??void 0,this._model_options=e.config?.model_options,this.environment=a,i&&(this._model=i),this.onStateChanged()}get interaction(){return this._interaction}set interaction(e){if(e?.id!==this._interaction?.id){if(this._interaction=e,this.interactionParamsSchema=e?Ii(e.prompts):void 0,this._inputValidator=void 0,e&&!this._preserveRunValues&&(this._model_options=e.model_options,e.runtime?.environment)){let t=e.runtime.environment;this.vertesia.environments.retrieve(t).then(e=>this.environment=e)}this.onStateChanged()}}get environment(){return this._environment}set environment(e){if(e?.id!==this._environment?.id){if(this._environment=e,!this._preserveRunValues){let t=this.interaction?.runtime?.model;t&&e&&zi(t,e.provider)?this._model=t:this._model=e?.default_model&&zi(e.default_model,e.provider)?e.default_model:``}this.onStateChanged()}}get model(){return this._model}set model(e){e!==this._model&&(this._model=e||``,this.onStateChanged())}get model_options(){return this._model_options}set model_options(e){JSON.stringify(e)!==JSON.stringify(this._model_options)&&(this._model_options=e,this.onStateChanged())}get tool_names(){return this._tool_names}set tool_names(e){this._tool_names=e,this.onStateChanged()}get data(){return this._data}set data(e){this._data=e,this.onStateChanged()}set run(e){console.log(`run`,e),this.onStateChanged()}set start(e){this._start!==e&&(this._start=e,this.onStateChanged())}markStarted(){this.start=!0}setMode(e){this.mode=e}setInteraction(e){this.interaction=e}setEnvironment(e){this.environment=e}setModel(e){this.model=e}setModelOptions(e){this.model_options=e}setToolNames(e){this.tool_names=e}setCollection(e){this.collection=e}setDisabledMcpCollections(e){this.disabled_mcp_collections=e}setInteractive(e){this.interactive=e}setDebugMode(e){this.debug_mode=e}setUserChannels(e){this.user_channels=e}setCheckpointTokens(e){this.checkpoint_tokens=e}setVisibility(e){this.visibility=e}setData(e){this.data=e}setPreserveRunValues(e){this.preserveRunValues=e}get start(){return this._start}get preserveRunValues(){return this._preserveRunValues}set preserveRunValues(e){this._preserveRunValues=e}get schemaVersion(){return this._schemaVersion}get interactionParamsSchema(){return this._interactionParamsSchema}set interactionParamsSchema(e){this._interactionParamsSchema!==e&&(this._interactionParamsSchema=e,this._schemaVersion+=1,e&&(this._data=this.initializeBooleanDefaults(this._data||{},e)),this.onStateChanged())}initializeBooleanDefaults(e,t){if(!t.properties)return e;let n={...e};for(let[e,r]of Object.entries(t.properties)){let t=r;t.type===`boolean`&&n[e]===void 0?n[e]=!1:t.type===`object`&&t.properties&&(n[e]=this.initializeBooleanDefaults(n[e]||{},t))}return n}reset(){if(this._start=!1,this._interactive=!0,this._debug_mode=!1,this._non_blocking_subagents=!0,this._checkpoint_tokens=void 0,this._visibility=void 0,this._user_channels=void 0,this._collection=void 0,this._disabled_mcp_collections=void 0,this._preserveRunValues=!1,this._model=``,this._model_options=void 0,this._environment=void 0,this._tool_names=[],this._interaction=void 0,this._data=void 0,this._interactionParamsSchema=null,this._inputValidator=void 0,this.model=void 0,this.environment=void 0,this.onStateChanged(),location.hash){let e=window.location.origin+window.location.pathname+window.location.search;history.replaceState(null,``,e),location.hash=``}}validateInput(){if(!this._interactionParamsSchema)return{isValid:!0};if(!this._inputValidator||this._inputValidator.schema!==this._interactionParamsSchema){let e=new ya({strict:!1});this._inputValidator={validate:e.compile(this._interactionParamsSchema),schema:this._interactionParamsSchema}}let e=this._data||{};return this._inputValidator.validate(e)?{isValid:!0}:{isValid:!1,errorMessage:this._inputValidator.validate.errors?this._inputValidator.validate.errors.map(e=>`${e.instancePath}: ${e.message}`).join(`, `):`Invalid payload data`}}};const __=nt(void 0);function v_({children:e}){let{client:n}=Z(),[r]=Y(()=>new h_(n)),i=ct(r.subscribe,r.getSnapshot);return t(__.Provider,{value:i,children:e})}function y_(){let e=at(__);if(!e)throw Error(`usePayloadBuilder must be used within a PayloadProvider`);return e}function b_({title:e,variant:r=`full`,isTerminal:i=!1,onClose:a,isModal:s,agentRunId:c,workflowRunId:l,viewMode:u,onViewModeChange:d,showPlanPanel:f,showPlanButton:p=!0,onTogglePlanPanel:m,showPlaybackButton:h=!1,isPlaybackEnabled:g=!1,onTogglePlayback:_,onDownload:v,onExportFixture:y,resetWorkflow:b,onExportPdf:x,onShowDetails:S,allowWorkflowControl:C=!0,onClone:w,isReceivingChunks:T=!1,className:E}){let{t:D}=X(),O=r===`compact`,k=u===`sliding`?`stacked`:`sliding`,A=D(`agent.verbose`),j=D(`agent.summary`),M=k===`stacked`?A:j,N=n(`div`,{className:H(O?`flex flex-row items-center gap-1 lg:flex-col`:`flex justify-end items-center gap-2 ms-auto`),children:[p&&t(`div`,{className:`relative`,children:n(o,{size:r===`compact`?`icon`:`sm`,variant:f?`primary`:`ghost`,onClick:m,className:H(`transition-all duration-200 rounded-md`,r===`compact`&&`size-8 rounded-lg`),title:D(`agent.toggleRightSidebar`),children:[t(vn,{className:H(`size-4`,r===`full`&&`me-1.5`)}),r===`full`?t(`span`,{className:`font-medium text-xs`,children:D(f?`agent.hideSidebar`:`agent.showSidebar`)}):t(`span`,{className:`sr-only`,children:D(f?`agent.hideSidebar`:`agent.showSidebar`)})]})}),O?t(o,{variant:`ghost`,size:`icon`,onClick:()=>d(k),className:`size-8 rounded-lg`,title:M,"aria-label":M,children:t(k===`stacked`?Ir:mr,{className:`size-4`})}):n(`div`,{className:`flex items-center gap-1 bg-muted rounded p-0.5 mt-2 lg:mt-0`,children:[n(o,{variant:u===`stacked`?`outline`:`ghost`,size:`xs`,onClick:()=>d(`stacked`),"aria-pressed":u===`stacked`,className:`gap-1.5`,children:[t(Ir,{className:`size-3.5`}),A]}),n(o,{variant:u===`sliding`?`outline`:`ghost`,size:`xs`,onClick:()=>d(`sliding`),"aria-pressed":u===`sliding`,className:`gap-1.5`,children:[t(mr,{className:`size-3.5`}),j]})]}),h&&_&&n(o,{type:`button`,size:r===`compact`?`icon`:`sm`,variant:g?`primary`:`ghost`,onClick:_,"aria-pressed":g,title:D(`agent.rewind.label`),className:H(`transition-all duration-200 rounded-md`,r===`compact`&&`size-8 rounded-lg`),children:[t(Zt,{className:H(`size-4`,r===`full`&&`me-1.5`)}),r===`full`?t(`span`,{className:`font-medium text-xs`,children:D(`agent.rewind.label`)}):t(`span`,{className:`sr-only`,children:D(`agent.rewind.label`)})]}),t(x_,{compact:O,agentRunId:c,workflowRunId:l,isModal:s,isTerminal:i,onClose:a,onDownload:v,onExportFixture:y,resetWorkflow:b,onExportPdf:x,onShowDetails:S,allowWorkflowControl:C,onClone:w}),a&&!s&&t(o,{size:`xs`,variant:`ghost`,onClick:a,"aria-label":D(`agent.close`),children:t(di,{className:`size-4`})})]});return r===`compact`?t(v_,{children:t(`div`,{className:H(`inline-flex items-center rounded-xl border border-border/70 bg-background/90 p-1 shadow-lg shadow-black/10 backdrop-blur`,E),children:N})}):t(v_,{children:n(`div`,{className:H(`flex flex-wrap items-end justify-between py-1.5 px-2 border-b shadow-sm flex-shrink-0`,E),children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n(`div`,{className:`flex items-center gap-1`,children:[t(Kt,{className:`size-5 text-muted`}),t(`span`,{className:`font-medium`,children:e})]}),n(`span`,{className:`text-xs text-muted ms-1 flex items-center gap-1.5`,children:[`(Agent Run ID: `,c,`)`,t(`span`,{className:H(`w-2 h-2 rounded-full transition-colors duration-200`,T?`bg-purple-500 shadow-[0_0_6px_2px_rgba(168,85,247,0.6)]`:`bg-gray-400`)})]})]}),N]})})}function x_({compact:e=!1,agentRunId:r,workflowRunId:i,isModal:a,isTerminal:s,onClose:c,onDownload:l,onExportFixture:u,resetWorkflow:d,onExportPdf:f,onShowDetails:p,allowWorkflowControl:m=!0,onClone:h}){let{t:g}=X(),_=Ye(),{client:v}=Z(),y=y_(),{router:b}=va(),x=async()=>{try{return await v.agents.terminate(r,`cancel`),_({status:`success`,title:g(`agent.workflowCancelled`),duration:2e3}),y.reset(),d?.(),!0}catch{return _({status:`error`,title:g(`agent.failedToCancelWorkflow`),duration:2e3}),!1}},S=async()=>{try{let e=await v.agents.fork(r);_({status:`success`,title:g(`agent.conversationCloned`),duration:2e3}),h?.(e)}catch{_({status:`error`,title:g(`agent.failedToCloneConversation`),duration:2e3})}},C=e=>{let t=e.startsWith(`/`)?b.getTopRouter().navigator.addStickyParams(e):e;return window.open(t,`_blank`),t};return t(w,{align:`right`,trigger:t(o,{size:e?`icon`:`xs`,variant:`ghost`,title:g(`agent.moreActions`),className:e?`size-8 rounded-lg`:void 0,children:t(yr,{className:`size-4`})}),children:n(ne,{label:`Actions`,children:[a&&n(B,{onClick:()=>C(`/store/agent-runner/${r}`),children:[t(kn,{className:`size-3.5 text-muted`}),` `,g(`agent.openInNewTab`)]}),n(B,{onClick:()=>{navigator.clipboard.writeText(r),_({status:`success`,title:g(`agent.agentRunIdCopied`),duration:2e3})},children:[t(Sn,{className:`size-3.5 text-muted`}),` `,g(`agent.copyAgentRunId`)]}),n(B,{onClick:()=>{navigator.clipboard.writeText(i),_({status:`success`,title:g(`agent.workflowRunIdCopied`),duration:2e3})},children:[t(Sn,{className:`size-3.5 text-muted`}),` `,g(`agent.copyWorkflowRunId`)]}),p&&n(B,{onClick:p,children:[t($n,{className:`size-3.5 text-muted`}),` `,g(`agent.details`)]}),n(B,{onClick:()=>{l?l():xu(v,r).then(e=>window.open(e,`_blank`))},children:[t(En,{className:`size-3.5 text-muted`}),` `,g(`agent.downloadConversation`)]}),f&&n(B,{onClick:f,children:[t(En,{className:`size-3.5 text-muted`}),` `,g(`agent.exportAsPdf`)]}),u&&n(B,{onClick:u,children:[t(En,{className:`size-3.5 text-muted`}),` `,g(`agent.rewind.exportFixture`)]}),c&&a&&n(B,{onClick:c,children:[t(di,{className:`size-3.5 text-muted`}),` `,g(`agent.close`)]}),h&&n(B,{onClick:S,children:[t(Kn,{className:`size-3.5 text-muted`}),` `,g(`agent.cloneConversation`)]}),m&&!s&&n(B,{onClick:x,variant:`destructive`,children:[t(di,{className:`size-3.5`}),` `,g(`agent.cancelWorkflow`)]})]})})}function S_(e){return typeof e==`object`&&!!e&&`value`in e}function C_(e){return S_(e)?e.value:e}function w_(e){if(e.type===`stringList`)return e.value.map(e=>typeof e==`string`?e:C_(e));if(e.multiple)return e.value.map(C_);let t=e.value[0];return t===void 0?void 0:C_(t)}function T_(e,t,n){e.query[t]=n}function E_({buckets:e,name:r,placeholder:a}){let o=e.map(e=>({label:`(${e.count})`,value:e._id}));return{name:r,placeholder:a||`${r.charAt(0).toUpperCase()+r.slice(1)}`,options:o,type:`select`,labelRenderer:r=>{let a=e.find(e=>e._id===r),o=a?.name||r,s=`success`;if(a?.status)switch(a.status){case wi.published:s=`success`;break;case wi.archived:s=`destructive`;break;case wi.code:s=`info`;break}let c=a?.version&&a?.status?`v${a.version} ${a.status===wi.unknown?``:a.status}`:a?.status||(a?.version?`v${a.version}`:``);return n(`div`,{className:`w-full flex items-center justify-between`,children:[n(`div`,{className:`flex flex-row flex-wrap items-center gap-2 min-w-0 flex-1`,children:[t(`span`,{className:`text-sm truncate`,children:o}),c&&t(i,{variant:s,className:`text-xs w-fit`,children:c})]}),(a?.count??0)>0&&n(`span`,{className:`ms-2 text-xs shrink-0`,children:[`(`,a?.count,`)`]})]})},filterBy:(t,n)=>(e.find(e=>e._id===t)?.name||t).toLowerCase().includes(n.toLowerCase())}}function D_(e){return`${e._id} (${e.count})`}function O_(e){return`${e.name} (${e.count})`}function k_({buckets:e,name:t,placeholder:n,type:r=`select`,multiple:i=!1}){return{name:t,options:e.map(e=>({label:D_(e),value:e._id})),type:r,multiple:i,placeholder:`${n??`${t.charAt(0).toUpperCase()+t.slice(1)}`}`,allowCreate:!1}}function A_({buckets:e,name:t,placeholder:n,type:r,multiple:i}){return k_({buckets:e,name:t,placeholder:n,type:r,multiple:i})}const j_={},M_={},N_={};function P_(e){return typeof e==`object`&&!!e&&`status`in e&&e.status===404}function F_(e,t,n){let r=e[t];return r||(r=n().catch(n=>{throw P_(n)||delete e[t],n}),e[t]=r),r}function I_(e){let{client:t}=Z();return Ue(()=>F_(j_,e,()=>t.users.retrieve(e)),{deps:[e],condition:()=>!!e})}function L_(e){let{client:t}=Z();return Ue(()=>F_(M_,e,()=>t.iam.groups.retrieve(e)),{deps:[e],condition:()=>!!e})}function R_(e){let{client:t}=Z();return Ue(()=>F_(N_,e,()=>t.apikeys.retrieve(e)),{deps:[e],condition:()=>!!e})}function z_(){return t(`div`,{className:`size-8`})}function B_({showTitle:e=!1,size:i=`md`}){let{t:a}=X();return t(Q_,{title:a(`user.systemUser`),description:a(`user.systemUserDescription`),children:n(`div`,{className:`flex gap-2 items-center`,children:[t(r,{src:`/icon.svg`,size:i}),e&&t(`div`,{className:`text-sm font-semibold ps-2`,children:a(`user.systemUser`)})]})})}function V_({showTitle:e=!1,size:r=`md`}){let{t:i}=X();return t(Q_,{title:i(`user.allProjectMembers`),description:i(`user.allProjectMembersDescription`),children:n(`div`,{className:`flex gap-2 items-center`,children:[t(ii,{className:`size-4`,size:r}),e&&t(`div`,{className:`text-sm font-semibold ps-2`,children:i(`user.allProjectMembers`)})]})})}function H_({accountId:i,showTitle:a=!1,size:o=`md`}){let{t:s}=X(),c=i.split(`:`)[0],l=i.split(`:`)[1],u=n(e,{children:[t(`div`,{children:s(`user.serviceAccountDescription`)}),n(`div`,{className:`text-muted text-sm`,children:[t(`span`,{className:`font-semibold`,children:`Type:`}),` `,c]}),n(`div`,{className:`text-muted text-sm`,children:[t(`span`,{className:`font-semibold`,children:`ID:`}),` `,l]})]});return t(Q_,{title:s(`user.serviceAccount`),description:u,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(r,{src:`/cloud.svg`,name:`SA`,color:`bg-amber-500`,className:`px-[5px] text-white`,size:o}),a&&n(`div`,{className:`text-sm font-semibold ps-2 truncate`,children:[s(`user.serviceAccount`),` : ~`,l.slice(-6)]})]})})}function U_({email:i,showTitle:a=!1,size:o=`md`}){let{t:s}=X();return t(Q_,{title:`Email Agent`,description:n(e,{children:[t(`div`,{children:s(`user.agentOnBehalfOf`)}),n(`div`,{className:`text-muted text-sm`,children:[t(`span`,{className:`font-semibold`,children:`Email:`}),` `,i]})]}),children:n(`div`,{className:`flex items-center gap-2`,children:[n(`div`,{className:`flex items-center -space-x-2`,children:[t(r,{src:`/cloud.svg`,color:`bg-amber-500`,className:`px-[5px] text-white border-2 border-white dark:border-gray-800`,size:o}),t(r,{name:i,size:o,className:`border-2 border-white dark:border-gray-800`})]}),a&&n(`div`,{className:`text-sm font-semibold truncate`,children:[`Agent (`,i,`)`]})]})})}function W_({agentId:i,onBehalfOfType:a,onBehalfOfId:o,showTitle:s=!1,size:c=`md`,isScheduleAgent:l=!1}){let{t:u}=X(),d=a===`user`&&o,f=a===`apikey`&&o,p=I_(o||``),m=R_(o||``),h=d?p.data:void 0,g=f?m.data:void 0,_=i.slice(-6),v=h?u(`user.agentOnBehalfOf`):g?u(`user.agentOnBehalfOfApiKey`):`${u(`user.serviceAccount`)}~${_}`;return t(Q_,{title:l?u(`user.schedule`,{title:v}):v,description:n(`div`,{className:`space-y-2`,children:[h&&n(`div`,{className:`flex items-center gap-2`,children:[t(r,{src:h.picture,name:h.name,size:`sm`}),n(`div`,{children:[t(`div`,{className:`font-medium`,children:h.name||h.email}),h.email&&h.name&&t(`div`,{className:`text-xs text-muted`,children:h.email})]})]}),g&&n(`div`,{children:[t(`div`,{className:`font-medium`,children:g.name}),n(`div`,{className:`text-xs text-muted-foreground`,children:[`Key ID: `,g.id]})]}),!h&&!g&&n(e,{children:[t(`div`,{children:u(`user.serviceAccountDescription`)}),n(`div`,{className:`text-gray-800 dark:text-gray-500 text-sm`,children:[t(`span`,{className:`font-semibold`,children:`ID:`}),` `,i]})]})]}),children:n(`div`,{className:`flex items-center gap-2`,children:[n(`div`,{className:`flex items-center -space-x-2`,children:[t(r,{src:`/cloud.svg`,color:`bg-amber-500`,className:`px-[5px] text-white border-2 border-white dark:border-gray-800`,size:c}),h&&t(r,{src:h.picture,name:h.name,size:c,className:`border-2 border-white dark:border-gray-800`}),g&&t(r,{name:`API`,color:`bg-gray-400`,size:c,className:`border-2 border-white dark:border-gray-800`})]}),s&&t(`div`,{className:`text-sm font-semibold truncate`,children:h?`Agent (${h.name||h.email})`:g?`Agent (${g.name})`:v})]})})}function G_({title:e=`Error`,error:n,showTitle:r=!1,size:i=`md`}){return t(J_,{title:e,message:ze(n),color:`bg-red-500`,showTitle:r,size:i})}function K_({showTitle:e=!1,size:n=`md`,color:r}){let{t:i}=X();return t(J_,{title:i(`user.unknownUser`),message:i(`user.unknownUserDescription`),color:r,showTitle:e,size:n})}function q_({userRef:e,showTitle:n=!1,size:r=`md`}){let{t:i}=X();if(!e)return t(J_,{title:i(`user.unknownUser`),message:i(`user.unknownUserDescription`),showTitle:n,size:r});let a=e.split(`:`),o=a[0];switch(o){case ki.User:return t(X_,{userId:a[1],showTitle:n,size:r});case ki.Group:return t(Y_,{userId:a[1],showTitle:n,size:r});case`system`:return t(B_,{showTitle:n,size:r});case ki.ServiceAccount:return t(H_,{accountId:a.slice(1).join(`:`),showTitle:n,size:r});case ki.Agent:{let e,i,o;return a[1]===`agent`?(e=a.slice(2,5).join(`:`),i=a[5],o=a[6]):(e=a.slice(1,4).join(`:`),i=a[4],o=a[5]),t(W_,{agentId:e,onBehalfOfType:i,onBehalfOfId:o,showTitle:n,size:r})}case ki.Schedule:{let e=a[2]===`agent`?a.slice(3,6).join(`:`):`unknown-agent`,i=a[6],o=a[7];return t(W_,{agentId:e,onBehalfOfType:i,onBehalfOfId:o,showTitle:n,size:r,isScheduleAgent:!0})}case`email`:return t(U_,{email:a[1],showTitle:n,size:r});case ki.ApiKey:return t(Z_,{keyId:a[1],size:r,showTitle:n});case`project`:if(a[1]===`*`)return t(V_,{showTitle:n,size:r});break;default:return t(G_,{title:i(`user.unknownUser`),error:`Invalid user ref type: ${o}`,showTitle:n,size:r})}}function J_({title:e,message:i,color:a,size:o=`md`,showTitle:s=!1}){return t(Q_,{title:e,description:i,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(r,{color:a,size:o}),s&&t(`div`,{className:`text-sm font-semibold ps-1`,children:e})]})})}function Y_({userId:e,showTitle:r=!1,size:i=`md`}){let{t:a}=X(),{data:o,error:s}=L_(e);if(s)return P_(s)?t(K_,{showTitle:r,size:i,color:`bg-indigo-500`}):t(G_,{title:a(`user.failedToFetchGroup`),error:s,showTitle:r,size:i});if(!o)return t(z_,{});let c=n(`div`,{className:`space-y-1`,children:[o.description&&t(`div`,{className:`text-sm`,children:o.description}),t(`div`,{className:`text-xs text-muted-foreground`,children:a(`user.groupId`,{id:o.id})}),o.tags&&o.tags.length>0&&t(`div`,{className:`flex flex-wrap gap-1`,children:o.tags.map(e=>t(`span`,{className:`px-1.5 py-0.5 bg-muted rounded text-xs`,children:e},e))})]});return t(Q_,{title:o.name||a(`user.unnamedGroup`),description:c,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(ri,{className:`size-6 text-indigo-500`,size:i}),r&&t(`div`,{className:`text-sm font-semibold ps-2`,children:o.name||a(`user.unnamedGroup`)})]})})}function X_({userId:e,showTitle:i=!1,size:a=`md`}){let{t:o}=X(),{data:s,error:c}=I_(e);if(c)return P_(c)?t(K_,{showTitle:i,size:a,color:`bg-indigo-500`}):t(G_,{title:o(`user.failedToFetchUser`),error:c,showTitle:i,size:a});if(!s)return t(z_,{});let l=t(`div`,{className:`truncate`,title:s.email,children:s.email});return t(Q_,{title:s.name||s.email||s.username||o(`user.unknown`),description:l,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(r,{src:s.picture,name:s.name,color:`bg-indigo-500`,size:a}),i&&t(`div`,{className:`text-sm font-semibold ps-2`,children:s.name||s.email||s.username||o(`user.unknown`)})]})})}function Z_({keyId:e,showTitle:i=!1,size:a=`md`}){let{t:o}=X(),{data:s,error:c}=R_(e);if(c)return P_(c)?t(K_,{showTitle:i,size:a,color:`bg-pink-500`}):t(G_,{title:o(`user.failedToFetchApiKey`),error:c,showTitle:i,size:a});if(!s)return t(z_,{});let l=o(`user.privateKey`),u=t(r,{name:`PK`,color:`bg-pink-500`,size:a});return t(Q_,{title:l,description:n(je,{className:`dark:bg-gray-800 dark:text-gray-200 table-fixed w-full`,children:[n(`tr`,{children:[t(`td`,{className:`font-semibold w-20`,children:o(`user.key`)}),t(`td`,{className:`truncate max-w-0`,children:s?.name})]}),n(`tr`,{children:[t(`td`,{className:`font-semibold w-20`,children:o(`user.account`)}),t(`td`,{className:`truncate max-w-0`,children:s?.account})]}),n(`tr`,{children:[t(`td`,{className:`font-semibold w-20`,children:o(`user.project`)}),t(`td`,{className:`truncate max-w-0`,children:s?.project.name})]})]}),children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[u,i&&t(`div`,{className:`text-sm font-semibold`,children:s?.name||s?.account||s?.project.name||o(`user.unknown`)})]})})}function Q_({title:e,description:r,children:i}){return n(le,{hover:!0,children:[t(de,{className:`cursor-pointer flex items-center inline-block`,children:t(`div`,{children:i})}),t(ue,{align:`center`,sideOffset:8,side:`right`,children:n(`div`,{className:`flex flex-col gap-1 rounded-md shadow-md p-2`,children:[t(`div`,{className:`text-md font-semibold`,children:e}),r]})})]})}function $_({buckets:e,name:r,placeholder:i}){let a=e.map(e=>({value:e._id,label:`(${e.count})`}));return{name:r,placeholder:i||`${r.charAt(0).toUpperCase()+r.slice(1)}`,options:a,labelRenderer:r=>{if(r===`Unknown User`||!r)return`Unknown User (${e.find(e=>e._id===r)?.count||0})`;let i=e.find(e=>e._id===r);return n(`div`,{className:`flex items-center w-full gap-2`,children:[t(`div`,{className:`flex-1 min-w-0 flex items-center truncate`,children:t(q_,{userRef:r,showTitle:!0,size:`sm`})}),n(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`(`,i?.count||0,`)`]})]})}}}function ev({buckets:e,name:t,placeholder:n}){return $_({buckets:e,name:t,placeholder:n})}function tv(e){let t=[];return t.push({name:`id`,placeholder:`Agent Run ID`,type:`text`,multiple:!1}),t.push(E_({buckets:e.interactions||[],name:`interaction`,placeholder:`Interaction`})),t.push(A_({buckets:e.statuses||[],name:`status`,placeholder:`Status`})),t.push(ev({buckets:e.initiated_by||[],name:`initiated_by`,placeholder:`Initiated By`})),t.push({name:`start`,placeholder:`Started After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Started Before`,type:`date`,multiple:!1}),t}function nv(e){return t=>{e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){let n=t.name;T_(e,n,w_(t))}}),e.search()}}function rv({facets:e,search:r,selectionCount:i,actions:a,filters:s,setFilters:c,filterGroups:l}){let[u,d]=Y([]),f=s??u,p=c??d,m=J(!1),h=J(typeof window<`u`&&!!new URLSearchParams(window.location.search).get(`filters`)),g=tv(e),_=l??g,v=q(()=>nv(r),[r]);return K(()=>{if(!m.current){m.current=!0;return}if(h.current){h.current=!1;return}v(f)},[f,v]),t(I,{filterGroups:_,filters:f,setFilters:p,children:n(`div`,{className:`gap-2 items-center w-full`,children:[n(`div`,{className:`flex justify-between mb-1`,children:[t(P,{}),n(`div`,{className:`flex justify-end`,children:[!i&&t(`div`,{className:`flex items-center justify-between px-2 py-1`,children:t(`div`,{className:`text-sm text-muted-foreground`,children:r.initialized?`${r.totalCount} agent runs`:`Loading agent runs...`})}),a&&a.length>0?t(`div`,{className:`flex items-center gap-2 mb-1 me-2`,children:a.map((e,n)=>t(`div`,{children:e},`action-${n}`))}):null,t(o,{onClick:()=>{r.search()},variant:`outline`,title:`Refresh`,children:t(Nr,{className:`size-5`})})]})]}),f.length>0&&n(`div`,{className:`flex items-center gap-2 mb-1`,children:[t(N,{}),t(F,{})]})]})})}var iv=class{types;map={};constructor(e){this.types=e,e.sort((e,t)=>e.name.localeCompare(t.name));for(let t of e)this.map[t.id]=t}getType(e){return this.map[e]}getTypeLayout(e){let t=this.map[e];return t?t.table_layout:void 0}getTypeName(e){let t=this.map[e];return t?t.name:void 0}};const av=nt({registry:void 0,isLoading:!1,load:()=>Promise.resolve(),reload:()=>Promise.resolve()});function ov({children:e}){let{store:n,project:r}=Z(),[i,a]=Y(),[o,s]=Y(!1),c=J(!1),l=J(r?.id),u=G(async()=>{if(!(!r||c.current)){c.current=!0,s(!0);try{let e=await n.types.catalog.list({layout:!0});a(new iv(e))}catch(e){console.error(`Failed to fetch types`,e)}finally{s(!1),c.current=!1}}},[n,r]),d=G(async()=>(c.current=!1,u()),[u]);return K(()=>{l.current!==r?.id&&(l.current=r?.id,a(void 0),c.current=!1)}),t(av.Provider,{value:{registry:i,isLoading:o,load:u,reload:d},children:e})}function sv(){let e=at(av);return K(()=>{!e.registry&&!e.isLoading&&e.load()},[e.registry,e.isLoading,e.load]),e}function cv(e){let{registry:t}=sv(),n=[];if(n.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t){let e=t.types.map(e=>({label:e.name,value:e.id})),r={name:`types`,placeholder:`Type`,type:`select`,multiple:!0,options:e,filterBy:(t,n)=>e.find(e=>e.value===t)?.label?.toLowerCase().includes(n.toLowerCase())??!1};n.push(r)}return n}function lv(e){return t=>{if(t.length===0){e.clearFilters(!0);return}e.clearFilters(!1),t.forEach(t=>{if(t.value&&t.value.length>0){let n=t.name;T_(e,n,w_(t))}}),e.search()}}function uv({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=Y([]),l=cv(e),u=lv(r),d=i!==void 0&&a!==void 0;return t(I,{filterGroups:o??l,filters:d?i:s,setFilters:e=>{if(d){a(e);return}let t=typeof e==`function`?e(s):e;c(t),u(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function dv({buckets:e,typeRegistry:r,type:i=`select`,multiple:a=!1}){let o=new Map;return r||console.warn(`Type names cannot be resolved`),e.forEach(e=>{let t,n=e._id;e._id==null?(n=`Document`,t=`Document`):(t=r?.getTypeName(e._id),t||=(console.warn(`Content Object Type not found`,e._id),e._id)),o.set(n,{name:t,count:e.count})}),{name:`types`,placeholder:`Types`,type:i,multiple:a,options:e.map(e=>{let t=e._id,n=t||`Document`,r=o.get(n);return{value:t,label:r?`${r.name} (${r.count})`:`Unknown (${e.count})`}}),labelRenderer:e=>{let r=o.get(e);return r?n(`div`,{className:`w-full flex items-center`,children:[t(`span`,{className:`text-sm truncate`,children:r.name}),n(`span`,{className:`ms-2 text-xs`,children:[`(`,r.count,`)`]})]}):(console.warn(`Type data not found for ${e}`),e)},filterBy:(e,t)=>{let n=o.get(e);return n?n.name.toLowerCase().includes(t.toLowerCase()):(console.warn(`Type name not found for ${e}`),!1)}}}function fv(e){return Array.isArray(e)?e:[]}function pv(e){let{registry:t}=sv(),n=[];if(n.push({placeholder:`ID`,name:`id`,type:`text`,options:[]}),n.push({placeholder:`Name`,name:`name`,type:`text`,options:[]}),e.type){let r=dv({buckets:fv(e.type),typeRegistry:t,type:`select`,multiple:!0});n.push(r)}if(e.status){let t=A_({buckets:fv(e.status),name:`status`,placeholder:`Status`,type:`select`,multiple:!0});n.push(t)}return e.tags&&n.push({name:`tags`,placeholder:`Tags`,type:`stringList`,options:fv(e.tags).map(e=>({label:e._id,value:e._id}))}),n.push({name:`created_at`,placeholder:`Created Date`,type:`date`,multiple:!0,options:[]}),n.push({name:`updated_at`,placeholder:`Updated Date`,type:`date`,multiple:!0,options:[]}),n}function mv(e){return t=>{if(t.length===0){e.clearFilters();return}e.clearFilters(!1),t.forEach(t=>{if(t.value&&t.value.length>0){let n=t.name,r;if(t.type===`date`&&t.multiple){if(Array.isArray(t.value)&&t.value.length>0)if(t.value.length===1){let e=C_(t.value[0]);r={gte:e,lte:e}}else t.value.length===2&&(r={gte:C_(t.value[0]),lte:C_(t.value[1])})}else r=w_(t);n===`name`?T_(e,`name`,r):n===`id`?T_(e,`id`,r):T_(e,n,r)}}),e.search()}}function hv({facets:e,search:r}){let[i,a]=Y([]),o=pv(e),s=mv(r);return t(I,{filterGroups:o,filters:i,setFilters:e=>{let t=typeof e==`function`?e(i):e;a(t),s(t)},inModal:qe(),children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function gv({search:e,buckets:n,placeholder:r=`All Environments`,className:i}){let{client:a}=Z(),[o,s]=Y([]),c=e.getFilterValue(`environment`),l=t=>{e.setFilterValue(`environment`,t?._id)};K(()=>{if(a){let e=n.map(async e=>{let t;return await a.environments.retrieve(e._id).then(e=>{t=e.name}).catch(()=>{t=`${e._id} (deleted)`}),t||=e._id,{...e,name:t}});Promise.all(e).then(e=>{e.sort((e,t)=>e.name.localeCompare(t.name)),s(e)})}},[n,a]);let u=o?.find(e=>e._id===c);return t(ve,{filterBy:`name`,className:i,isClearable:!0,optionLabel:O_,options:o,value:u,onChange:l,by:`_id`,placeholder:r})}function _v(e){let t=[];return t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t.push({name:`prompt`,placeholder:`Prompt Name`,type:`text`,multiple:!1}),t.push({name:`model`,placeholder:`Model`,type:`text`,multiple:!1}),t.push({name:`tags`,placeholder:`Tags`,type:`stringList`,multiple:!0}),t}function vv(e){return t=>{if(t.length===0){e.clearFilters(!0,!0);return}e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){let n=t.name;T_(e,n,w_(t))}}),e.search(!0)}}function yv({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=Y([]),l=_v(e),u=vv(r),d=i!==void 0&&a!==void 0;return t(I,{filterGroups:o??l,filters:d?i:s,setFilters:e=>{if(d){a(e);return}let t=typeof e==`function`?e(s):e;c(t),u(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function bv(e){let t=[];return t.push(A_({buckets:e.statuses||[],name:`status`,placeholder:`Status`,multiple:!1})),t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function xv({facets:e,filters:r,setFilters:i}){return t(I,{filterGroups:bv(e),filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function Sv(e){let t=[];return t.push(A_({buckets:e.statuses||[],name:`status`,placeholder:`Status`,multiple:!0})),t.push(ev({buckets:e.started_by||[],name:`started_by`,placeholder:`Started By`})),t.push(A_({buckets:e.run_type||[],name:`run_type`,placeholder:`Mode`,multiple:!0})),t.push(A_({buckets:e.processes||[],name:`process`,placeholder:`Process`,multiple:!0})),t.push({name:`start`,placeholder:`Started After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Started Before`,type:`date`,multiple:!1}),t}function Cv({facets:e,filters:r,setFilters:i}){return t(I,{filterGroups:Sv(e),filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function wv(e,t){let n=e[t];return Array.isArray(n)?n:[]}function Tv(e){let t=wv(e,`role`),n=[];if(n.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t.length>0){let e={name:`role`,placeholder:`Role`,type:`select`,options:t.map(e=>({label:e._id,value:e._id,count:e.count}))};n.push(e)}let r={name:`tags`,placeholder:`Tags`,type:`stringList`,multiple:!0,options:wv(e,`tags`).map(e=>({label:e._id,value:e._id}))};return n.push(r),n}function Ev(e){return t=>{if(t.length===0){e.clearFilters(!0,!1);return}e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){let n=t.name;T_(e,n,w_(t))}}),e.search()}}function Dv({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=Y([]),l=Tv(e),u=Ev(r),d=i!==void 0&&a!==void 0;return t(I,{filterGroups:o??l,filters:d?i:s,setFilters:e=>{if(d){a(e);return}let t=typeof e==`function`?e(s):e;c(t),u(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function Ov({buckets:e,name:r}){let i=e.map(e=>({label:`(${e.count})`,value:e._id}));return{name:`environment`,placeholder:r.charAt(0).toUpperCase()+r.slice(1),options:i,type:`select`,labelRenderer:r=>{let i=e.find(e=>e._id===r);return n(`div`,{className:`w-full flex items-center`,children:[t(`span`,{className:`text-sm truncate`,children:i?.name||r}),n(`span`,{className:`ms-2 text-xs`,children:[`(`,i?.count||0,`)`]})]})},filterBy:(t,n)=>(e.find(e=>e._id===t)?.name||t).toLowerCase().includes(n.toLowerCase())}}function kv(e){let t=[];if(t.push({name:`run_ids`,placeholder:`Run ID`,type:`text`,multiple:!1}),e.interactions){let n=E_({buckets:e.interactions||[],name:`interaction`,placeholder:`Interactions`});t.push(n)}if(e.environments){let n=Ov({buckets:e.environments||[],name:`environments`});t.push(n)}if(t.push({name:`tags`,placeholder:`Tags`,type:`stringList`,multiple:!0}),e.models){let n=A_({buckets:e.models||[],name:`model`});t.push(n)}if(e.statuses){let n=A_({buckets:e.statuses||[],name:`status`});t.push(n)}if(e.finish_reason){let n=A_({buckets:e.finish_reason.map(e=>({...e,_id:e._id===null?`none`:e._id})),name:`finish_reason`,placeholder:`Finish Reason`});t.push(n)}if(e.created_by){let n=ev({buckets:e.created_by||[],name:`created_by`,placeholder:`Created By`});t.push(n)}return t.push({name:`start`,placeholder:`Date After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Date Before`,type:`date`,multiple:!1}),t.push({name:`workflow_run_ids`,placeholder:`Workflow Run ID`,type:`text`,multiple:!1}),t.push({name:`workflow_ids`,placeholder:`Workflow ID`,type:`text`,multiple:!1}),t}function Av(e){return t=>{if(t.length===0){e.clearFilters(!0,!1);return}e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){let n=t.name,r=w_(t);(n===`run_ids`||n===`workflow_run_ids`||n===`workflow_ids`)&&!Array.isArray(r)&&(r=[r]),T_(e,n,r)}}),e.search()}}function jv({facets:e,search:r,actions:i,selectionCount:a,filters:s,setFilters:c,filterGroups:l}){let[u,d]=Y([]),f=kv(e),p=Av(r),m=s!==void 0&&c!==void 0,h=m?s:u;return t(I,{filterGroups:l??f,filters:h,setFilters:e=>{if(m){c(e);return}let t=typeof e==`function`?e(u):e;d(t),p(t)},children:n(`div`,{className:`gap-2 items-center w-full`,children:[n(`div`,{className:`flex justify-between mb-1`,children:[t(P,{}),n(`div`,{className:`flex justify-end`,children:[!a&&t(`div`,{className:`flex items-center justify-between px-2 py-1`,children:t(`div`,{className:`text-sm text-muted`,children:r.initialized?`${r.totalCount} calls`:`Loading calls...`})}),i&&i.length>0?t(`div`,{className:`flex items-center gap-2 mb-1 me-2`,children:i.map((e,n)=>t(`div`,{children:e},`action-${n}`))}):null,t(o,{onClick:()=>{r.search()},variant:`outline`,title:`Refresh`,children:t(Nr,{className:`size-5`})})]})]}),h.length>0&&n(`div`,{className:`flex items-center gap-2 mb-1`,children:[t(N,{}),t(F,{})]})]})})}function Mv({search:e,buckets:n,name:r,placeholder:i,className:a}){let o=e.getFilterValue(r),s=t=>{e.setFilterValue(r,t?._id)},c=n?.find(e=>JSON.stringify(e._id)===JSON.stringify(o));return t(ve,{filterBy:`_id`,className:a,isClearable:!0,optionLabel:D_,options:n,value:c,onChange:s,by:`_id`,placeholder:i})}function Nv({search:e,name:n,placeholder:r,className:i}){let[a,o]=Y([]);return K(()=>{e.setFilterValue(n,a)},[n,e,a]),t(te,{className:i,value:a,onChange:o,placeholder:r})}function Pv(e){return`${e.name} (${e.count})`}function Fv({search:e,buckets:n,placeholder:r=`Filter by Type`,className:i}){let[a,o]=Y([]),{registry:s}=sv(),c=e.getFilterValue(`type`),l=t=>{e.setFilterValue(`type`,t?._id)};K(()=>{if(s){let e=n.map(e=>{let t;return e._id==null?(e._id=`Document`,t=`Document`):(t=s.getTypeName(e._id),t||=(console.warn(`Content Object Type not found`,e._id),e._id)),{...e,name:t}});e.sort((e,t)=>e.name.localeCompare(t.name)),o(e)}},[n,s]);let u=a?.find(e=>e._id===c);return t(ve,{filterBy:`name`,className:i,isClearable:!0,optionLabel:Pv,options:a,value:u,onChange:l,by:`_id`,placeholder:r})}function Iv(e){let t=[];return t.push(A_({buckets:e.tags||[],name:`tags`,placeholder:`Tags`,multiple:!0})),t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function Lv({facets:e,filters:r,setFilters:i}){return t(I,{filterGroups:Iv(e),filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function Rv(e){let t=[];if(t.push({placeholder:`Workflow Name or Workflow Run ID`,name:`name`,type:`text`,options:[]}),e.status){let n=A_({buckets:e.status||[],name:`status`,placeholder:`Status`});t.push(n)}if(e.initiated_by){let n=ev({buckets:e.initiated_by||[],name:`initiated_by`,placeholder:`Initiated By`});t.push(n)}return t.push({name:`start`,placeholder:`Date After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Date Before`,type:`date`,multiple:!1}),t.push({name:`has_reported_errors`,placeholder:`Has Reported Errors`,type:`select`,multiple:!1,options:[{label:`Yes`,value:`true`},{label:`No`,value:`false`}]}),t}function zv(e){return t=>{if(t.length===0){e.clearFilters();return}e.clearFilters(!1),t.forEach(t=>{if(t.value&&t.value.length>0){let n=t.name,r=w_(t);if(n===`name`)T_(e,`search_term`,r),T_(e,`name`,r);else if(n===`has_reported_errors`){let t=Array.isArray(r)?r[0]:r;(t===`true`||t===`false`)&&T_(e,n,t===`true`)}else T_(e,n,r)}}),e.search()}}function Bv({facets:e,search:r}){let[i,a]=Y([]),o=Rv(e),s=zv(r);return t(I,{filterGroups:o,filters:i,setFilters:e=>{let t=typeof e==`function`?e(i):e;a(t),s(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function Vv(e){let t=[];return t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function Hv({facets:e,filters:r,setFilters:i}){return t(I,{filterGroups:Vv(e),filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}var Uv=class e{object;objects;setState;collectionId;singleSelection=!1;constructor(e,t,n,r){this.object=e,this.objects=n,this.setState=r,this.singleSelection=Object.keys(this.objects).length===0,this.collectionId=t}isSingleSelection(){return this.singleSelection}hasSelection(){return this.object!==void 0||this.size()!==0}size(){return Object.keys(this.objects).length}getObjectIds(){return Object.keys(this.objects)}getObjectId(){return this.object?.id}clone(){return new e(this.object,this.collectionId,this.objects,this.setState)}add(e){this.objects[e.id]=e,this.singleSelection=Object.keys(this.objects).length===0,this.setState(this.clone())}remove(e){delete this.objects[e],this.singleSelection=Object.keys(this.objects).length===0,this.setState(this.clone())}addAll(e){for(let t of e)this.objects[t.id]=t;this.setState(this.clone())}isSelected(e){return this.objects[e]!==void 0}removeAll(){this.objects={},this.singleSelection=!0,this.setState(this.clone())}};const Wv=nt(void 0);function Gv(){let e=at(Wv);if(!e)throw Error(`useObjectSelection must be used within a ObjectSelectionProvider`);return e}function Kv(){return at(Wv)}function qv({value:e,collectionId:n,children:r}){let[i,a]=Y();return K(()=>{let t=new Uv(e,n,{},a);a(t)},[n,e]),i&&t(Wv.Provider,{value:i,children:r})}const Jv=nt(void 0);function Yv({onFilter:e,children:n}){return t(Jv.Provider,{value:e,children:n})}function Xv(){return at(Jv)}const Zv=`h-6 w-6 p-0 opacity-0 group-hover/field:opacity-100 text-muted hover:text-foreground transition-opacity shrink-0`;function Qv({field:r,value:i,label:a,copyContent:s}){let c=Xv(),l=Array.isArray(i)?i.length>0:i!==void 0&&i!==``;return n(e,{children:[s!==void 0&&s!==``&&t(x,{content:s,className:Zv}),l&&i!==void 0&&t(o,{variant:`ghost`,size:`sm`,title:`Filter by ${a}`,className:Zv,onClick:e=>{e.stopPropagation(),c?.(r,i)},children:t(Bn,{className:`size-3`})})]})}const $v=`text/csv`,ey=`image/`,ty=`application/pdf`,ny=`video/`,ry=[`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/msword`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`,`application/vnd.ms-powerpoint`],iy=e=>e===$v||$v.includes(e),ay=e=>e.startsWith(ey)||ey.includes(e),oy=e=>e===ty||ty.includes(e),sy=e=>e.startsWith(ny)||ny.includes(e),cy=e=>ry.includes(e);function ly(e,t){if(typeof window>`u`||typeof document>`u`)return!1;let n=document.createElement(`iframe`);n.style.position=`fixed`,n.style.right=`0`,n.style.bottom=`0`,n.style.width=`0`,n.style.height=`0`,n.style.border=`0`,n.style.visibility=`hidden`,document.body.appendChild(n);let r=n.contentWindow;if(!r)return n.parentNode?.removeChild(n),!1;let i=r.document;i.open(),i.write(`<!doctype html><html><head><title></title></head><body></body></html>`),i.close(),i.title=t,document.querySelectorAll(`link[rel="stylesheet"], style`).forEach(e=>{i.head.appendChild(e.cloneNode(!0))});let a=i.createElement(`style`);return a.textContent=`
|
|
313
|
+
`}),s===`stacked`&&t(`div`,{className:H(`sticky top-0 z-10`,y&&`hidden`),children:t(cp,{workstreams:le,activeWorkstream:R,onSelectWorkstream:pe,count:he,completionStatus:$e})}),ge.length===0&&Re.length===0&&!Ee&&!(ae&&W)?R===`all`&&Ge?t(`div`,{className:`flex-1 px-2 py-6 sm:px-4`,children:t(em,{label:F(`agent.preparing`),timestamp:Te.current,className:b})}):t(`div`,{className:`flex items-center justify-center h-full text-center py-8`,children:t(`div`,{className:`flex items-center px-3 py-2 text-sm text-muted`,children:F(R===`all`?`agent.waitingForAgentResponse`:`agent.noMessagesInWorkstream`)})}):n(`div`,{className:H(`flex-1 flex flex-col justify-start w-full max-w-full`,ae?`gap-6 px-2 py-6 sm:px-4`:`gap-3 pb-4`,x),children:[ae&&R!==`all`&&ue&&t(`div`,{className:`sticky top-0 z-20 -mx-2 bg-background/95 px-2 pb-2 pt-1 backdrop-blur sm:-mx-4 sm:px-4`,children:n(`div`,{className:`mx-auto flex w-full max-w-3xl items-center gap-2 border-b border-border/70 pb-3`,children:[t(o,{type:`button`,variant:`ghost`,size:`icon`,className:`size-8 shrink-0 text-muted hover:text-foreground`,title:F(`agent.backToMainAgent`),onClick:me,children:t(qt,{className:`size-4`,"aria-hidden":`true`})}),t(`div`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-foreground`,children:ue})]})}),Oe&&t($p,{data:T,schema:E,title:D,template:O,prependFriendlyMessage:w,timestamp:ge[0]?.timestamp??Date.now(),isSummaryView:ae,messageItemClassNames:f,messageStyleOverrides:p,StoreLinkComponent:S,CollectionLinkComponent:C},`initial-request`),Je&&t(em,{label:qe,timestamp:Qe,className:b}),s===`stacked`?n(e,{children:[U.map((e,n)=>{let r=n===U.length-1;if(e.type===`resource_summary`)return t(of,{resources:e.resources,workflowRunId:v,className:`my-2`},e.key);if(e.type===`tool_group`){let n=e.messages[e.messages.length-1],i=e.toolStatus===`completed`||e.toolStatus===`error`||e.toolStatus===`warning`,a=!c&&r&&!kl.includes(n.type)&&!i;return h?.includes(s)?null:t(nh,{status:e.toolStatus,children:t(rh,{children:t(tp,{...m,messages:e.messages,showPulsatingCircle:a,toolRunId:e.toolRunId,toolStatus:e.toolStatus,preambleText:e.preambleText,preambleMessage:e.preambleMessage,rootClassName:H(`rounded-lg border border-border bg-background/60 shadow-none`,m?.rootClassName),headerClassName:H(`px-3 py-2`,m?.headerClassName),itemHeaderClassName:H(`hover:bg-mixer-muted/20`,m?.itemHeaderClassName)})})},Em(e))}if(e.type===`streaming`)return t(nh,{children:t(ff,{...g,text:e.text,workstreamId:e.workstreamId,isComplete:e.isComplete,timestamp:e.startTimestamp,artifactRunId:v,cardClassName:H(`rounded-lg border border-border bg-background/60 shadow-none`,g?.cardClassName)})},Em(e));{let i=e.message;if(Se(i)||Ce(i))return null;if(Ml(i))return t(nh,{children:t(eh,{message:i,startTimestamp:Dm(U,n)??i.timestamp,endTimestamp:i.timestamp})},Tm(i,`stopped`));let a=!c&&r&&!kl.includes(i.type);return dp(i)?t(rh,{children:t(Od,{message:i,batchData:i.details,isRunning:!i.details.completed_at,..._})},`batch-${i.details.batch_id}-${i.timestamp}`):t(nh,{status:`message`,children:t(rh,{children:t(Qd,{...f,message:i,showPulsatingCircle:a,onSendMessage:u,onOpenArtifact:d,requestInputAnswered:Nu(i,_e),cardClassName:H(`rounded-lg border border-border bg-background/60 shadow-none`,f?.cardClassName),headerClassName:H(`px-3 py-2`,f?.headerClassName),contentClassName:H(`bg-transparent`,f?.contentClassName),messageStyleOverrides:p,StoreLinkComponent:S,CollectionLinkComponent:C})})},Tm(i))}}),Re.map(({id:e,data:n})=>t(nh,{children:t(ff,{...g,text:n.text,workstreamId:n.workstreamId,isComplete:n.isComplete,timestamp:n.startTimestamp,artifactRunId:v,cardClassName:H(`rounded-lg border border-border bg-background/60 shadow-none`,g?.cardClassName)})},`streaming-incomplete-${e}`)),Ge&&Re.length===0&&!Je&&t(nh,{children:n(`div`,{className:H(`flex items-center gap-2 py-2 text-sm text-muted`,b),children:[t(Ru,{size:`sm`,color:`blue`}),t(`span`,{children:F(`agent.working`)})]})})]}):n(e,{children:[Ue.map(e=>{if(e.type===`resource_summary`)return t(of,{resources:e.resources,workflowRunId:v,className:`my-2`},e.key);if(e.type===`work`){if(h?.includes(s))return null;let n=bp(e.messages);return t(th,{label:xp(e.isActive),status:e.status,timestamp:e.startTimestamp,durationSeconds:e.isActive?void 0:mp(e.startTimestamp,e.endTimestamp),showElapsed:!0,details:n?void 0:e.messages,defaultExpanded:e.isActive&&!n,disablePreambleCollapse:e.isActive,className:b,onSendMessage:u,answeredToolApprovalRequestInputKeys:ye,resolvedToolApprovalKeys:ve},`work-${e.id}-${e.isActive?`active`:`done`}-${e.status}`)}if(e.type===`stopped`)return t(eh,{message:e.message,startTimestamp:e.startTimestamp,endTimestamp:e.endTimestamp},Tm(e.message,`stopped-summary`));let n=e.message;return Se(n)||Ce(n)?null:dp(n)?t(rh,{children:t(Od,{message:n,batchData:n.details,isRunning:!n.details.completed_at,..._})},Tm(n,`batch`)):t(rh,{children:t(Wp,{message:n,onSendMessage:u,onOpenArtifact:d,onSelectWorkstream:pe,requestInputAnswered:Nu(n,_e),StoreLinkComponent:S,CollectionLinkComponent:C})},Tm(n,`summary`))}),Re.map(({id:e,data:n})=>t($m,{text:n.text,workstreamId:n.workstreamId,artifactRunId:v},`streaming-incomplete-${e}`)),Ke&&t(`div`,{className:H(`mx-auto w-full max-w-3xl px-1 text-sm text-muted`,b),"data-testid":`post-tool-thinking-indicator`,children:F(`agent.thinking`)}),W&&!Je&&t(th,{label:qe,status:`running`,timestamp:Qe,showElapsed:!0,className:b})]}),t(`div`,{ref:a,className:`h-2`})]})]})}const oh=(e,t)=>{if(e.type!==t.type||e.message!==t.message)return!1;let n=e.details,r=t.details;if(n?.tool_status!==`completed`||r?.tool_status!==`completed`)return!1;let i=typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime();return(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())-i<2e3},sh=G.memo(ah);function ch(e){return e?new Map(e.streamingMessages.map((e,t)=>[e.id??e.activityId??`stream-${t}`,e])):new Map}function lh(e,t){return e?.find(e=>e.cursor===t)}function uh(e,t){if(t===0||e===`live`)return`live`;let n=yo(e,t);return n>=t-1?`live`:n+1}function dh(e){let t=0,n=e.length;for(;t<n&&e[t]===`-`;)t++;for(;n>t&&e[n-1]===`-`;)n--;return e.slice(t,n)}function fh(e){return dh(e.trim().replace(/[^a-z0-9-_]+/gi,`-`)).slice(0,80)}function ph(e,t){let n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}function mh({fixture:e,cursor:r,initialCursor:i,onCursorChange:a,autoStepMs:s,repeat:c=1,viewMode:l,className:u,title:d,showHeader:f=!0}){let{t:p}=Z(),m=e.messages,h=i??(m.length>0?0:`live`),[g,_]=X(()=>vo(h,m.length)),v=r??g,y=l??`sliding`,[b,x]=X(!!s),[S,C]=X(0),w=Y(null),T=J(()=>So(m,v,!0),[v,m]),E=T.displayedMessages,D=J(()=>ch(lh(e.streamingFrames,T.cursor)),[e.streamingFrames,T.cursor]),O=K(e=>{let t=vo(e,m.length);r===void 0&&_(t),a?.(t)},[r,m.length,a]);q(()=>{let e=vo(v,m.length);e!==v&&O(e)},[v,m.length,O]),q(()=>{if(!s||s<=0||!b)return;let e=window.setInterval(()=>{let e=uh(v,m.length);if(e===`live`&&v===`live`){C(e=>{let t=e+1;return c>0&&t>=c?(x(!1),t):(O(m.length>0?0:`live`),t)});return}O(e)},s);return()=>window.clearInterval(e)},[s,v,b,m.length,c,O]);let k=E.length>0&&!jl(E),A=J(()=>Pu(E),[E]),j=d??e.metadata?.title??p(`agent.rewind.fixtureTitle`),M=K(()=>{let t={...e,metadata:{...e.metadata,title:j,exported_at:e.metadata?.exported_at??new Date().toISOString(),message_count:m.length}},n=e.metadata?.agent_run_id??`fixture`;ph(`${fh(j)||`agent-chat`}-${fh(n)}.json`,t)},[e,m.length,j]),N=K(()=>{O(uh(T.cursor,m.length))},[m.length,T.cursor,O]);return n(`div`,{className:H(`flex h-full min-h-0 w-full flex-col bg-background text-foreground`,u),"data-agent-test-playback-enabled":!0,"data-agent-playback-cursor":T.cursor,"data-agent-live-message-count":m.length,"data-agent-rendered-message-count":T.renderedMessageCount,"data-agent-replay-playing":b||void 0,"data-agent-replay-loop":S,children:[f&&n(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-border px-3 py-2`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`truncate text-sm font-medium`,children:j}),t(`div`,{className:`text-xs text-muted`,children:p(`agent.rewind.fixtureMeta`,{messageCount:m.length,loops:S})})]}),n(`div`,{className:`flex items-center gap-2`,children:[n(o,{type:`button`,variant:`secondary`,size:`sm`,onClick:M,children:[t(jn,{className:`size-4`}),t(`span`,{className:`ms-1.5`,children:p(`agent.rewind.exportFixture`)})]}),s&&s>0&&n(o,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>x(e=>!e),children:[t(b?kr:Nr,{className:`size-4`}),t(`span`,{className:`ms-1.5`,children:p(b?`agent.rewind.pause`:`agent.rewind.resume`)})]})]})]}),t(`div`,{className:`flex flex-shrink-0 justify-end px-2 py-1.5`,children:t(Oo,{cursor:T.cursor,messages:m,onChangeCursor:O})}),t(sh,{messages:E,isCompleted:k,streamingMessages:D,bottomRef:w,artifactRunId:e.metadata?.agent_run_id??`agent-chat-fixture`,viewMode:y,renderRequestInputControls:!A}),A&&t(Iu,{message:A,onSendMessage:N,isLoading:!1})]})}function hh({className:e,inline:r=!1}){return n(`div`,{className:H(`flex items-center gap-1`,r?`inline-flex`:``,e),children:[t(`div`,{className:`w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_infinite_ease-in-out] hover:bg-blue-600`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}}),t(`div`,{className:`w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_0.3s_infinite_ease-in-out] hover:bg-blue-600`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}}),t(`div`,{className:`w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_0.6s_infinite_ease-in-out] hover:bg-blue-600`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}})]})}function gh(){let{client:e}=Q(),[t,n]=X([]),[r,i]=X(!0),[a,o]=X(!1),s=Y(0),c=K(async()=>{let t=s.current+1;s.current=t,i(!0),o(!1);try{let r=await e.apps.getInstalledApps(`tools`),a=[];for(let e of r){let t=e,n=t.oauth_collection_ids??[],r=t.manifest.oauth_providers??{};if(!t.manifest.tool_collections)continue;let i=t.manifest.tool_collections.map(e=>Wi(e)).filter(e=>e.type===`mcp`),o=i.filter(e=>e.auth!==`api_key`&&n.includes(e.id)),s=i.filter(e=>e.auth===`api_key`),c=new Map,l=new Map,u=[];for(let e of o)if(e.oauth_provider){let t=c.get(e.oauth_provider)??[];t.push(e),c.set(e.oauth_provider,t)}else if(e.oauth_app){let t=l.get(e.oauth_app)??[];t.push(e),l.set(e.oauth_app,t)}else u.push(e);for(let[e,n]of c)a.push({key:`${t.id}:provider:${e}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:r[e]?.display_name||e,representativeId:n[0].id,memberIds:n.map(e=>e.id),memberNames:n.map(e=>e.name),authType:`oauth`});for(let[e,n]of l)a.push({key:`${t.id}:oauthapp:${e}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:e,representativeId:n[0].id,memberIds:n.map(e=>e.id),memberNames:n.map(e=>e.name),authType:`oauth`});for(let e of u)a.push({key:`${t.id}:individual:${e.id}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:e.name,representativeId:e.id,memberIds:[e.id],memberNames:[e.name],authType:`oauth`});for(let e of s)a.push({key:`${t.id}:api-key:${e.id}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:e.name,representativeId:e.id,memberIds:[e.id],memberNames:[e.name],authType:`api_key`})}if(s.current!==t||(n(a),i(!1),a.length===0))return;o(!0);let c=new Map,l=await Promise.all(a.map(async t=>{try{let n=c.get(t.appId);n||(n=e.remoteMcpConnections.getStatus(t.appId),c.set(t.appId,n));let r=(await n).find(e=>e.collection_id===t.representativeId);return{...t,authStatus:r}}catch{return t}}));if(s.current!==t)return;n(l)}catch(e){s.current===t&&(console.error(`Failed to load MCP tool collections:`,e),n([]))}finally{s.current===t&&(i(!1),o(!1))}},[e]);return q(()=>{c()},[c]),{groups:t,loading:r,statusLoading:a,reload:c}}function _h(e,t){return t?.length?e.memberIds.every(e=>t.includes(e)):!1}function vh(e,t,n){let r=new Set(t??[]);if(n)for(let t of e.memberIds)r.delete(t);else for(let t of e.memberIds)r.add(t);return Array.from(r)}function yh(e,t){return e.filter(e=>e.authStatus?.authenticated===!0&&!_h(e,t)).length}function bh(e,t){return e.filter(e=>e.authStatus?.authenticated===!0&&!_h(e,t)).map(e=>e.label)}function xh({isOpen:e,onClose:r,groups:i,loading:a,statusLoading:o=!1,reload:s,disabledCollections:c,onChange:l,onConnectionChange:u,readOnly:d=!1}){let{t:f}=Z(),p=()=>{s(),u?.()};return n(Jo,{isOpen:e,onClose:r,size:`md`,className:`max-w-[92vw] sm:max-w-[620px] lg:max-w-[620px]`,children:[t(Yo,{children:f(`mcpConnections.title`)}),n(Xo,{children:[t(`p`,{className:`mb-4 text-sm text-muted`,children:f(`mcpConnections.subtitle`)}),a?t(`div`,{className:`flex items-center justify-center py-8`,children:t(gs,{className:`size-5`})}):i.length===0?t(`div`,{className:`py-8 text-center text-sm text-muted`,children:f(`mcpConnections.empty`)}):t(`div`,{className:`space-y-1`,children:i.map(e=>{let r=!_h(e,c),i=e.authStatus?.authenticated===!0;return n(`div`,{className:`flex items-center justify-between gap-3 py-3`,children:[n(`div`,{className:`flex min-w-0 items-center gap-2`,children:[t(i?lr:ur,{className:`size-4 shrink-0 ${i?`text-success`:`text-muted`}`,"aria-hidden":`true`}),t(Fo,{description:n(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`font-medium`,children:e.appName}),e.memberNames.length>1&&t(`div`,{className:`text-xs text-muted`,children:e.memberNames.join(` · `)})]}),placement:`top`,asChild:!0,children:t(`span`,{className:`truncate ${r?`text-foreground`:`text-muted line-through`}`,children:e.label})})]}),n(`div`,{className:`flex shrink-0 items-center gap-3`,children:[o&&!e.authStatus?t(Bo,{variant:`outline`,size:`sm`,disabled:!0,className:`h-6 w-32 justify-center px-2 text-xs`,title:f(`mcpConnections.checkingStatus`),children:t(gs,{className:`size-3`})}):e.authType===`oauth`?t(ys,{appId:e.appId,collectionId:e.representativeId,collectionName:e.label,authenticated:e.authStatus?.authenticated,onAuthChange:p,variant:`compact`,showDisconnect:!0,readOnly:d}):null,l&&t(ms,{size:`sm`,value:r,onChange:t=>l(vh(e,c,t)),disabled:d,"aria-label":f(r?`mcpConnections.deactivateAria`:`mcpConnections.activateAria`,{name:e.label})})]})]},e.key)})})]})]})}function Sh({disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o=!1,variant:s=`outline`,size:c=`sm`}){let{t:l}=Z(),{groups:u,loading:d,statusLoading:f,reload:p}=gh(),[m,h]=X(!1);if(!d&&u.length===0)return null;let g=yh(u,r),_=bh(u,r),v=_.slice(0,2),y=_.length-v.length,b=v.length>0?`${v.join(`, `)}${y>0?` +${y}`:``}`:void 0;return n(e,{children:[n(`div`,{className:`flex min-w-0 items-center gap-2`,children:[b&&t(`span`,{className:`max-w-48 truncate text-muted`,title:_.join(`, `),children:b}),n(Bo,{variant:s,size:c,className:`shrink-0`,onClick:()=>h(!0),disabled:d,"aria-label":l(`mcpConnections.manage`),children:[t(`span`,{children:l(`mcpConnections.label`)}),g>0&&t(Wo,{variant:`success`,children:g})]})]}),t(xh,{isOpen:m,onClose:()=>h(!1),groups:u,loading:d,reload:p,statusLoading:f,disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o})]})}function Ch({disabledCollections:e,onChange:r,onConnectionChange:i,readOnly:a=!1}){let{t:o}=Z(),{groups:s,loading:c,statusLoading:l,reload:u}=gh();if(!c&&s.length===0)return null;let d=()=>{u(),i?.()};return c&&s.length===0?n(`div`,{className:`flex items-center gap-2 border-y border-border/70 py-2 text-sm text-muted`,children:[t(gs,{className:`size-4`}),t(`span`,{children:o(`mcpConnections.label`)})]}):t(`div`,{className:`space-y-1`,children:s.map(i=>{let s=!_h(i,e),c=i.authStatus?.authenticated===!0;return n(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 py-2 text-sm`,children:[n(`div`,{className:`flex min-w-36 flex-1 items-center gap-2`,children:[t(c?lr:ur,{className:`size-4 shrink-0 ${c?`text-success`:`text-muted`}`,"aria-hidden":`true`}),t(Fo,{description:n(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`font-medium`,children:i.appName}),i.memberNames.length>1&&t(`div`,{className:`text-xs text-muted`,children:i.memberNames.join(` · `)})]}),placement:`top`,asChild:!0,children:t(`span`,{className:`block truncate ${s?`text-foreground`:`text-muted line-through`}`,children:i.label})})]}),l&&!i.authStatus?t(Bo,{variant:`outline`,size:`sm`,disabled:!0,className:`h-6 w-32 justify-center px-2 text-xs`,title:o(`mcpConnections.checkingStatus`),children:t(gs,{className:`size-3`})}):i.authType===`oauth`?t(ys,{appId:i.appId,collectionId:i.representativeId,collectionName:i.label,authenticated:i.authStatus?.authenticated,onAuthChange:d,variant:`compact`,showDisconnect:!0,readOnly:a}):t(Wo,{variant:`outline`,className:`h-6 w-32 justify-center px-2 text-xs`,children:o(`mcpConnections.apiKey`)}),r&&n(`div`,{className:`flex min-w-24 items-center justify-end gap-2 text-xs`,children:[t(`span`,{className:s?`text-muted`:`text-attention`,children:o(s?`mcpConnections.enabled`:`mcpConnections.disabled`)}),t(ms,{size:`sm`,value:s,onChange:t=>r(vh(i,e,t)),disabled:a,"aria-label":o(s?`mcpConnections.deactivateAria`:`mcpConnections.activateAria`,{name:i.label})})]})]},i.key)})})}function wh({disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o=!1}){let{t:s}=Z(),{groups:c,loading:l,statusLoading:u,reload:d}=gh(),[f,p]=X(!1);if(!l&&c.length===0)return null;let m=yh(c,r);return n(e,{children:[t(us,{align:`left`,trigger:t(Bo,{variant:`ghost`,size:`icon`,className:`size-8 rounded-md text-muted hover:bg-muted`,title:s(`mcpConnections.settings`),disabled:l,children:t(`span`,{className:`flex size-5 items-center justify-center rounded-[3px] border border-muted text-sm font-semibold leading-none`,"aria-hidden":`true`,children:`/`})}),children:n(ds,{onClick:()=>p(!0),isDisabled:l,children:[t(`span`,{children:s(`mcpConnections.title`)}),m>0&&t(Wo,{variant:`success`,children:m})]})}),t(xh,{isOpen:f,onClose:()=>p(!1),groups:c,loading:l,reload:d,statusLoading:u,disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o})]})}const Th=/(^|\/)(tool-inputs|tool-results|archive)(\/|$)/,Eh=/(^|\/)process\/(history|state)(\/|$)/,Dh=[/conversation\.json$/,/^conversation-checkpoint-\d+\.json$/,/^tools\.json$/,/^tool-input-refs\.json$/,/^toolu[_-]/i];function Oh(e){if(Th.test(e)||Eh.test(e))return!0;let t=e.split(`/`).pop()??e;return Dh.some(e=>e.test(t))}function kh(e){let t={name:``,path:``,isDirectory:!0,children:[]};for(let n of e){let e=n.split(`/`),r=t,i=``;for(let t=0;t<e.length;t++){let n=e[t];i=i?`${i}/${n}`:n;let a=t===e.length-1,o=r.children.find(e=>e.name===n);o||(o={name:n,path:i,isDirectory:!a,children:[]},r.children.push(o)),r=o}}let n=e=>{e.children.sort((e,t)=>e.isDirectory===t.isDirectory?e.name.localeCompare(t.name):e.isDirectory?-1:1),e.children.forEach(n)};return n(t),t.children}function Ah(e,t){let n=`agents/${t}/`,r=e.indexOf(n);return r===-1?e.split(`/`).pop()??e:e.slice(r+n.length)}function jh(e,t,n=0,r=!1){let[i,a]=X([]),[o,s]=X(!1),[c,l]=X(null),[u,d]=X(0),f=Y(0),p=K(async()=>{if(!t)return;let n=++f.current;s(!0),l(null);try{let r=await e.files.listArtifacts(t);if(n!==f.current)return;let i=r.map(e=>Ah(e,t)).filter(e=>!!e);a(i)}catch(e){if(n!==f.current)return;l(e instanceof Error?e.message:`Failed to list artifacts`),a([])}finally{n===f.current&&s(!1)}},[e,t]);q(()=>{p()},[p,n,u]);let m=J(()=>r?i:i.filter(e=>!Oh(e)),[i,r]),h=J(()=>kh(m),[m]),g=i.length-m.length,_=K(()=>{d(e=>e+1)},[]);return{tree:h,flatFiles:m,totalCount:i.length,systemHiddenCount:g,isLoading:o,error:c,refresh:_}}function Mh(){return Nh||=import(`react-pdf`).then(e=>{let{pdfjs:t}=e;return t.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${t.version}/build/pdf.worker.min.mjs`,e}),Nh}var Nh,Ph,Fh,Ih=Da((()=>{Ph=st(()=>Mh().then(({Document:e})=>({default:e}))),Fh=st(()=>Mh().then(({Page:e})=>({default:e})))}));function Lh({className:e,size:n=`md`}){return t(`div`,{className:`flex items-center justify-center ${e||``}`,children:t(fr,{className:`${{sm:`w-4 h-4`,md:`w-6 h-6`,lg:`w-8 h-8`}[n]} animate-spin text-muted-foreground`})})}function Rh({pdfUrl:e,pageNumber:r,width:i,className:a,renderTextLayer:o=!1,renderAnnotationLayer:s=!1,onLoadSuccess:c,onError:l}){let[u,d]=X(!0),[f,p]=X(null);return f?t(`div`,{className:`flex items-center justify-center text-destructive text-sm ${a||``}`,children:`Failed to load PDF`}):n(`div`,{className:a,children:[u&&t(Lh,{className:`py-4`,size:`md`}),t(at,{fallback:null,children:t(Ph,{file:e,onLoadSuccess:({numPages:e})=>{d(!1),c?.(e)},onLoadError:e=>{d(!1),p(e),l?.(e)},loading:null,children:t(Fh,{pageNumber:r,width:i,renderTextLayer:o,renderAnnotationLayer:s,loading:t(Lh,{className:`py-4`,size:`sm`})})})})]})}function zh({pdfUrl:e,urlLoading:n=!1,children:r,onLoadSuccess:i}){let[a,o]=X(0),[s,c]=X(!0),[l,u]=X(null),[d,f]=X(null),p=async e=>{o(e.numPages),i?.(e.numPages);try{let t=(await e.getPage(1)).getViewport({scale:1});f({width:t.width,height:t.height,aspectRatio:t.width/t.height})}catch(e){console.error(`Failed to get page dimensions:`,e)}c(!1)},m=e=>{c(!1),u(e)},h={pdfUrl:e,numPages:a,loading:n||!e||s,error:l,pageDimensions:d};return l?t(`div`,{className:`flex items-center justify-center text-destructive text-sm py-4`,children:`Failed to load PDF`}):t(Kh.Provider,{value:h,children:e?t(at,{fallback:t(Lh,{className:`py-4`,size:`md`}),children:t(Ph,{file:e,onLoadSuccess:p,onLoadError:m,loading:t(Lh,{className:`py-4`,size:`md`}),children:r((e,n)=>t(Fh,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(Lh,{className:`py-4`,size:`sm`})},e))})}):t(Lh,{className:`py-4`,size:`md`})})}function Bh(){return lt(Kh)}function Vh({pageNumber:e,width:n,className:r}){let i=Bh(),a=i?.pageDimensions?.aspectRatio??qh,o=n?Math.round(n/a):200;return i?.loading?t(`div`,{className:`flex items-center justify-center bg-muted ${r||``}`,style:{height:o,width:n||`100%`},children:t(Lh,{size:`md`})}):t(`div`,{className:r,children:t(Fh,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(Lh,{className:`py-4`,size:`sm`})})})}function Hh({pageNumber:e,width:n,isSelected:r,onSelect:i,renderThumbnail:a,aspectRatio:o=qh,rootMargin:s=`200px 0px`}){let c=Y(null),[l,u]=X(!1);q(()=>{let e=c.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0]?.isIntersecting&&u(!0)},{rootMargin:s,threshold:0});return t.observe(e),()=>t.disconnect()},[s]);let d=n?Math.round(n/o):200,f=l?t(Fh,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(`div`,{className:`flex items-center justify-center bg-muted`,style:{height:d},children:t(Lh,{size:`sm`})})}):t(`div`,{className:`flex items-center justify-center bg-muted`,style:{height:d,width:n||`100%`},children:t(`span`,{className:`text-muted-foreground text-xs`,children:e})});return t(`div`,{ref:c,children:a({pageNumber:e,isSelected:r,pageElement:f,onSelect:i})})}function Uh(e){if(!e)return null;let t=e.parentElement;for(;t;){let e=window.getComputedStyle(t).overflowY;if(e===`auto`||e===`scroll`)return t;t=t.parentElement}return null}function Wh({pdfUrl:r,urlLoading:i=!1,pageCount:a,currentPage:o,thumbnailWidth:s,onPageSelect:c,renderThumbnail:l,scrollContainerRef:u,onAspectRatioChange:d,onItemHeightChange:f,calculateItemHeight:p,onPageCountChange:m}){let[h,g]=X(null),[_,v]=X({start:0,end:Math.min(15,a)}),[y,b]=X(null),x=Y(null),S=K(e=>{g(e)},[]),C=K(async e=>{m?.(e.numPages);try{let t=(await e.getPage(1)).getViewport({scale:1}),n=t.width/t.height;b(n),d?.(n)}catch(e){console.error(`Failed to get page dimensions:`,e),b(qh),d?.(qh)}},[d,m]),w=y??qh,T=s?Math.round(s/w):200,E=p?p(T):T+16+24+8;if(q(()=>{E>0&&y!==null&&f?.(E)},[E,y,f]),q(()=>{let e=u?.current||Uh(x.current);if(!e)return;let t=()=>{let t=e.scrollTop,n=e.clientHeight,r=Math.floor(t/E),i=Math.ceil((t+n)/E),o=Math.max(0,r-5),s=Math.min(a,i+5);v(e=>e.start!==o||e.end!==s?{start:o,end:s}:e)};return t(),e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[E,a,u]),h)return t(`div`,{className:`flex items-center justify-center text-destructive text-sm py-4`,children:`Failed to load PDF`});if(i||!r)return t(Lh,{className:`py-4`,size:`md`});let D=_.start*E,O=(a-_.end)*E,k=y!==null;return t(`div`,{ref:x,children:t(at,{fallback:t(Lh,{className:`py-4`,size:`md`}),children:t(Ph,{file:r,onLoadSuccess:C,onLoadError:S,loading:t(Lh,{className:`py-4`,size:`md`}),children:k?n(e,{children:[D>0&&t(`div`,{style:{height:D}}),Array.from({length:_.end-_.start},(e,n)=>{let r=_.start+n+1;return t(`div`,{"data-page-index":r-1,style:{height:E,overflow:`hidden`},children:t(Hh,{pageNumber:r,width:s,isSelected:r===o,onSelect:()=>c(r),renderThumbnail:l,aspectRatio:w})},r)}),O>0&&t(`div`,{style:{height:O}})]}):t(Lh,{className:`py-4`,size:`md`})})})})}function Gh({pdfUrl:e,pageNumber:r,width:i,height:a,className:o,renderTextLayer:s=!1,renderAnnotationLayer:c=!1,onPageChange:l}){let[u,d]=X(0),[f,p]=X(!0),[m,h]=X(null);return q(()=>{u>0&&l?.(r,u)},[r,u,l]),m?t(`div`,{className:`flex items-center justify-center text-destructive ${o||``}`,children:n(`span`,{children:[`Failed to load PDF: `,m.message]})}):n(`div`,{className:o,children:[f&&t(Lh,{className:`py-8`,size:`lg`}),t(at,{fallback:null,children:t(Ph,{file:e,onLoadSuccess:({numPages:e})=>{d(e),p(!1)},onLoadError:e=>{p(!1),h(e)},loading:null,children:t(Fh,{pageNumber:Math.min(r,u||1),width:i,height:a,renderTextLayer:s,renderAnnotationLayer:c,loading:t(Lh,{className:`py-8`,size:`md`})})})})]})}var Kh,qh,Jh=Da((()=>{Ih(),Kh=ot(null),qh=210/297}));function Yh({pdfUrl:r,pdfUrlLoading:i=!1,pageCount:a,currentPage:s,onChange:c,onPageCountChange:l,className:u,compact:d=!1,headerExtra:f}){let{t:m}=Z(),h=Y(null),g=Y(null),[_,v]=X(void 0),[y,b]=X(eg),[x,S]=X(Qh),[C,w]=X(null),T=Y(null),E=_?Math.round(_*y/100):void 0,D=K(()=>{let e=$h.findIndex(e=>e>=y);e===-1&&(e=$h.length-1);let t=Math.min(e+1,$h.length-1);b($h[t])},[y]),O=K(()=>{let e=$h.findIndex(e=>e>=y);e===-1&&(e=$h.length-1);let t=Math.max(e-1,0);b($h[t])},[y]),k=K(()=>{b(eg)},[]),A=K(e=>e+(d?28:48),[d]),j=K((e,t)=>{let n=e?Math.round(e/t):200;return A(n)},[A]);q(()=>{let e=g.current;if(!e)return;let t=null,n=()=>e.clientWidth-16-16-4,r=()=>{let t=n();if(t<=0)return;let r=T.current;if(r&&r>0){let n=e.scrollTop,i=Math.round(n/r),a=j(t,x),o=i*a;v(t),requestAnimationFrame(()=>{e.scrollTo({top:o,behavior:`instant`})}),T.current=a}else v(t),T.current=j(t,x)},i=n();i>0&&(v(i),T.current=j(i,x));let a=new ResizeObserver(()=>{t&&clearTimeout(t),t=setTimeout(r,150)});return a.observe(e),()=>{t&&clearTimeout(t),a.disconnect()}},[x,j]);let M=Y(!1),N=Y(null),P=Y(y);q(()=>{P.current!==y&&(P.current=y,N.current={targetPage:s},M.current=!0)},[y,s]),q(()=>{let e=g.current,t=N.current;if(t&&e&&C){N.current=null;let n=(t.targetPage-1)*C;requestAnimationFrame(()=>{e.scrollTo({top:n,behavior:`instant`}),requestAnimationFrame(()=>{M.current=!1})})}},[C]);let F=Y(!1);q(()=>{let e=g.current;if(!(!e||!C||F.current)){if(s>1){F.current=!0,M.current=!0;let t=(s-1)*C;e.scrollTo({top:t,behavior:`instant`}),requestAnimationFrame(()=>{M.current=!1})}else F.current=!0}},[C,s]);let I=Y(s);return q(()=>{let e=g.current;if(!(!e||!C)&&I.current!==s){I.current=s,M.current=!0;let t=(s-1)*C;e.scrollTo({top:t,behavior:`instant`}),requestAnimationFrame(()=>{M.current=!1})}},[s,C]),q(()=>{let e=g.current;if(!e||!C)return;let t=null,n=()=>{M.current||(t&&clearTimeout(t),t=setTimeout(()=>{let t=e.scrollTop,n=Math.round(t/C)+1,r=Math.max(1,Math.min(n,a));r!==s&&(I.current=r,c(r))},50))};return e.addEventListener(`scroll`,n,{passive:!0}),()=>{t&&clearTimeout(t),e.removeEventListener(`scroll`,n)}},[C,a,s,c]),n(`div`,{ref:h,className:Qe(`flex flex-col items-stretch`,d?`gap-y-1`:`gap-y-2`,u),children:[n(`div`,{className:Qe(`relative flex items-center justify-center px-2`,d?`h-6`:`h-9`),children:[t(o,{variant:`ghost`,size:`xs`,onClick:()=>{s>1&&c(s-1)},title:m(`pdf.previousPage`),children:t(yn,{className:`size-4`})}),n(`div`,{className:`absolute start-2 flex items-center gap-x-1`,children:[t(Zh,{zoom:y,onZoomIn:D,onZoomOut:O,onFitToView:k,canZoomIn:y<$h[$h.length-1],canZoomOut:y>$h[0]}),f&&n(e,{children:[t(`div`,{className:`w-px h-4 bg-border mx-1`}),f]})]}),t(`div`,{className:`absolute end-2`,children:t(Xh,{currentPage:s,totalPages:a,onChange:c})})]}),t(`div`,{ref:g,className:Qe(`flex flex-col items-center flex-1 overflow-y-auto px-2`,d?`gap-1`:`gap-2`),children:t(Wh,{pdfUrl:r,urlLoading:i,pageCount:a,currentPage:s,thumbnailWidth:E,onPageSelect:c,onPageCountChange:l,scrollContainerRef:g,onAspectRatioChange:S,onItemHeightChange:w,calculateItemHeight:A,renderThumbnail:({pageNumber:e,isSelected:r,pageElement:i,onSelect:a})=>n(`div`,{className:Qe(`hover:bg-muted rounded-md w-full`,d?`p-1`:`p-2`),children:[t(o,{variant:`unstyled`,size:`none`,"aria-pressed":r,"aria-label":`Page ${e}`,className:Qe(`relative border-[2px] cursor-pointer overflow-hidden`,r?`border-primary`:`border-border`),onClick:a,children:i}),t(p,{className:Qe(`text-muted-foreground font-semibold`,d?`text-xs pt-0.5`:`text-sm pt-1`),children:e})]},e)})}),t(`div`,{className:Qe(`flex items-center justify-center`,d?`h-6`:`h-9`),children:t(o,{variant:`ghost`,size:`xs`,onClick:()=>{s<a&&c(s+1)},title:m(`pdf.nextPage`),children:t(gn,{className:`size-4`})})})]})}function Xh({currentPage:e,totalPages:r,onChange:i}){let{t:a}=Z(),o=Y(null),[s,c]=X(String(e));q(()=>{c(String(e))},[e]);let l=()=>{let t=parseInt(s,10);!Number.isNaN(t)&&t>=1&&t<=r?i(t):c(String(e))};return n(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[t(`span`,{children:a(`pdf.page`)}),t(`input`,{ref:o,type:`text`,value:s,onChange:e=>c(e.target.value),onKeyDown:t=>{t.key===`Enter`?(l(),o.current?.blur()):t.key===`Escape`&&(c(String(e)),o.current?.blur())},onBlur:()=>{l()},className:`w-8 h-5 text-center text-xs px-1 py-0 bg-background border border-border rounded focus:outline-none focus:border-primary`}),n(`span`,{children:[`/ `,r]})]})}function Zh({zoom:e,onZoomIn:r,onZoomOut:i,onFitToView:a,canZoomIn:s,canZoomOut:c}){let{t:l}=Z();return n(`div`,{className:`flex items-center gap-x-0.5`,children:[t(o,{variant:`ghost`,size:`xs`,onClick:i,isDisabled:!c,title:l(`pdf.zoomOut`),children:t(Cr,{})}),n(`span`,{className:`text-xs text-muted-foreground min-w-[32px] text-center`,children:[e,`%`]}),t(o,{variant:`ghost`,size:`xs`,onClick:r,isDisabled:!s,title:l(`pdf.zoomIn`),children:t(Fr,{})}),t(o,{variant:`ghost`,size:`xs`,onClick:a,title:l(`pdf.fitToWidth`),className:e===eg?`text-muted-foreground/40`:void 0,children:t(gr,{})})]})}var Qh,$h,eg,tg=Da((()=>{Jh(),Qh=210/297,$h=[50,75,100,125,150,200,300],eg=100}));function ng({object:e,url:r,source:i,className:a}){let{t:s}=Z(),{client:c}=Q(),[l,u]=X(1),[d,f]=X(r||``),[p,m]=X(!r),[h,g]=X(0),[_,v]=X(!1);q(()=>{if(r){f(r),m(!1);return}let t=i||e?.content?.source;if(!t){m(!1);return}m(!0),c.files.getDownloadUrl(t).then(e=>{f(e.url)}).catch(e=>{console.error(`Failed to get PDF URL:`,e)}).finally(()=>{m(!1)})},[r,i,e?.content?.source,c]),q(()=>{let t=e?.metadata,n=t?.pages||t?.page_count||0;n>0&&g(n)},[e?.metadata]);let y=e=>{g(e)};return p?t(`div`,{className:`flex items-center justify-center h-full`,children:t(De,{size:`lg`})}):d?_?n(`div`,{className:`fixed inset-0 bg-background z-50 flex flex-col overflow-hidden`,children:[t(`div`,{className:`flex h-9 items-center justify-end shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:t(o,{variant:`ghost`,size:`xs`,onClick:()=>v(!1),title:s(`pdf.closeFullscreen`),children:t(mi,{className:`size-4`})})}),t(Yh,{pdfUrl:d,pdfUrlLoading:p,pageCount:h||100,currentPage:l,onChange:u,onPageCountChange:y,className:`flex-1 min-h-0`})]}):t(`div`,{className:`relative h-full flex flex-col`,children:t(Yh,{pdfUrl:d,pdfUrlLoading:p,pageCount:h||100,currentPage:l,onChange:u,onPageCountChange:y,className:a,compact:!0,headerExtra:t(o,{title:s(`pdf.fullscreen`),tooltipPlacement:`bottom`,variant:`unstyled`,className:`p-1 rounded cursor-pointer transition-colors text-muted-foreground hover:text-foreground hover:bg-muted`,onClick:()=>v(!0),children:t(_r,{className:`size-4`})})})}):t(`div`,{className:`flex items-center justify-center h-full text-muted`,children:s(`pdf.noPdfAvailable`)})}var rg=Da((()=>{tg()})),ig=Oa({UniversalDocumentViewer:()=>kg});function ag(e){return e.fileName||e.title||e.artifact?.path.split(`/`).pop()||e.sourcePath?.split(`/`).pop()||`Document`}function og(e){let t=e.split(`?`)[0]||e;return t.includes(`.`)&&t.split(`.`).pop()?.toLowerCase()||``}function sg(e){return e.contentType===`application/pdf`||e.extension===`pdf`}function cg(e){return[`md`,`markdown`].includes(e.extension)||[`text/markdown`,`text/x-markdown`].includes(e.contentType||``)}function lg(e){return e.contentType?.startsWith(`image/`)||[`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`].includes(e.extension)}function ug(e){return e.contentType===`text/html`||[`html`,`htm`].includes(e.extension)}function dg(e){return[`application/xml`,`text/xml`].includes(e.contentType||``)||e.extension===`xml`}function fg(e){return e.contentType?.startsWith(`text/`)||[`css`,`csv`,`json`,`txt`,`tsx`,`ts`,`jsx`,`js`,`xml`,`yaml`,`yml`].includes(e.extension)}function pg(e){return[`tsx`,`jsx`].includes(e.extension)}function mg(e){return[`doc`,`docx`,`ppt`,`pptx`].includes(e.extension)||[`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-powerpoint`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`].includes(e.contentType||``)}function hg({content:e,extension:n}){return t(`pre`,{className:`h-full overflow-auto rounded-md bg-muted/10 p-3 text-xs leading-5`,children:t(`code`,{className:n?`language-${n}`:void 0,children:e||``})})}function gg({message:e}){return n(`div`,{className:`flex h-full min-h-64 flex-col items-center justify-center gap-2 text-muted`,children:[t(Rn,{className:`size-8`}),t(`span`,{className:`text-sm`,children:e})]})}function _g(e,n){if(e.Component){let r=e.Component;return t(r,{context:n})}return e.render?.(n)??null}function vg(e,t){return e.includes(`.`)?e.replace(/\.[^/.]+$/,t):`${e}${t}`}function yg(e){return e.split(`/`).pop()||e}function bg(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function xg(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function Sg(e){if(e!==void 0)return e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(+(e<1e4))} s`}function Cg(e){return Array.isArray(e)?e.length:0}function wg(e){try{let t=bg(JSON.parse(e));if(!t)return;let n=bg(t.viewport);return{ok:typeof t.ok==`boolean`?t.ok:void 0,source_artifact:typeof t.source_artifact==`string`?t.source_artifact:void 0,screenshot_artifact:typeof t.screenshot_artifact==`string`?t.screenshot_artifact:void 0,rendered_at:typeof t.rendered_at==`string`?t.rendered_at:void 0,viewport:n?{width:xg(n.width),height:xg(n.height)}:void 0,dependencies_reused:typeof t.dependencies_reused==`boolean`?t.dependencies_reused:void 0,status:xg(t.status),title:typeof t.title==`string`?t.title:void 0,console_errors:Array.isArray(t.console_errors)?t.console_errors:void 0,page_errors:Array.isArray(t.page_errors)?t.page_errors:void 0,failed_requests:Array.isArray(t.failed_requests)?t.failed_requests:void 0,bad_responses:Array.isArray(t.bad_responses)?t.bad_responses:void 0,timings_ms:bg(t.timings_ms),error:t.error}}catch{return}}async function Tg(e,t){let n=await fetch(e);if(!n.ok)throw Error(`Failed to load ${t}: ${n.statusText}`);return n.text()}function Eg({metadata:e,sourcePath:t,fallbackPath:n,artifactMode:r}){let i=e?.screenshot_artifact?.replace(/^\/+/,``);if(!i)return n;if(r)return i;let a=e?.source_artifact?.replace(/^\/+/,``),o=t.replace(/^\/+/,``);if(a&&o.endsWith(a)){let e=o.slice(0,-a.length).replace(/\/+$/,``);return e?`${e}/${i}`:i}let s=o.includes(`/`)?o.slice(0,o.lastIndexOf(`/`)+1):``;return s?`${s}${yg(i)}`:n}function Dg({metadata:e}){if(!e)return null;let r=xg(e.timings_ms?.total_before_cleanup),a=Cg(e.console_errors)+Cg(e.page_errors)+Cg(e.failed_requests)+Cg(e.bad_responses);return n(`div`,{className:`grid gap-2 border-b p-3 text-xs`,children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.ok!==void 0&&t(i,{variant:e.ok?`success`:`destructive`,children:e.ok?`render ok`:`render failed`}),e.dependencies_reused!==void 0&&n(i,{variant:e.dependencies_reused?`info`:`secondary`,children:[`deps `,e.dependencies_reused?`reused`:`installed`]}),e.status&&n(i,{variant:`secondary`,children:[`HTTP `,e.status]}),a>0&&n(i,{variant:`attention`,children:[a,` browser issue(s)`]})]}),n(`div`,{className:`grid gap-1 text-muted sm:grid-cols-2`,children:[e.viewport?.width&&e.viewport.height&&n(`div`,{children:[`Viewport `,e.viewport.width,` x `,e.viewport.height]}),Sg(r)&&n(`div`,{children:[`Total `,Sg(r)]}),e.rendered_at&&n(`div`,{children:[`Rendered `,new Date(e.rendered_at).toLocaleString()]}),e.title&&n(`div`,{className:`truncate`,children:[`Title `,e.title]})]}),typeof e.error==`string`&&t(`div`,{className:`text-destructive`,children:e.error})]})}function Og({context:e}){let{client:r}=Q(),a=e.source.artifact,o=a?.path||e.source.sourcePath,s=!!a,c=e.content||``,[l,u]=X({isLoading:!1}),d=K(async(e,t)=>a?(await r.files.getArtifactDownloadUrl(a.runId,e,t)).url:(await r.files.getDownloadUrl(e,yg(e),t)).url,[a,r]);return q(()=>{if(!o){u({isLoading:!1,previewError:`No source path is available for this TSX artifact.`});return}let e=o,t=!1,n=vg(e,`.png`),r=vg(e,`.render.json`);async function i(){u({isLoading:!0});let i,a,o=n;try{i=wg(await Tg(await d(r,`inline`),yg(r))),o=Eg({metadata:i,sourcePath:e,fallbackPath:n,artifactMode:s})}catch(e){a=e instanceof Error?e.message:`Render metadata is not available`}let c,l;try{c=await d(o,`inline`)}catch(e){l=e instanceof Error?e.message:`Sandbox render image is not available`}t||u({isLoading:!1,imageUrl:c,metadata:i,metadataError:a,previewError:l})}return i(),()=>{t=!0}},[s,d,o]),n(`div`,{className:`flex h-full min-h-0 flex-col`,children:[n(`div`,{className:`flex min-h-10 flex-wrap items-center gap-2 border-b px-3 py-2 text-sm`,children:[t(nr,{className:`size-4 text-info`}),t(`span`,{className:`font-medium`,children:`Sandbox render`}),l.isLoading?t(i,{variant:`secondary`,children:`loading`}):l.imageUrl?t(i,{variant:`success`,children:`PNG preview`}):t(i,{variant:`attention`,children:`source only`}),l.metadata?.rendered_at&&t(`span`,{className:`text-xs text-muted`,children:new Date(l.metadata.rendered_at).toLocaleString()})]}),l.isLoading?n(`div`,{className:`flex h-full min-h-64 items-center justify-center gap-2 text-muted`,children:[t(pr,{className:`size-5 animate-spin`}),t(`span`,{className:`text-sm`,children:`Loading sandbox render...`})]}):l.imageUrl?n(`div`,{className:`grid min-h-0 flex-1 xl:grid-cols-[minmax(0,1fr)_minmax(24rem,0.7fr)]`,children:[t(`div`,{className:`flex min-h-0 items-center justify-center overflow-auto bg-muted/10 p-3`,children:t(`img`,{src:l.imageUrl,alt:`${e.fileName} sandbox render`,className:`max-h-full max-w-full rounded-md object-contain`})}),n(`div`,{className:`min-h-0 overflow-auto border-t xl:border-s xl:border-t-0`,children:[t(Dg,{metadata:l.metadata}),t(`div`,{className:`p-3`,children:t(hg,{content:c,extension:e.extension})})]})]}):n(`div`,{className:`grid min-h-0 flex-1 grid-rows-[auto_minmax(0,1fr)]`,children:[n(`div`,{className:`border-b px-3 py-2 text-xs text-muted`,children:[`No sandbox-rendered PNG was found for this TSX artifact. Showing the source without executing it in Studio.`,l.previewError&&n(`span`,{className:`ms-1`,children:[`Preview lookup: `,l.previewError]}),!l.previewError&&l.metadataError&&n(`span`,{className:`ms-1`,children:[`Metadata lookup: `,l.metadataError]})]}),n(`div`,{className:`min-h-0 overflow-auto p-3`,children:[t(Dg,{metadata:l.metadata}),t(hg,{content:c,extension:e.extension})]})]})]})}function kg({source:e,className:r,bodyClassName:i,renderers:a=[],converters:s=[],resolveUrl:c,loadText:l,createRendition:u,markdownComponents:d,showHeader:f=!1,onDownload:p}){let{client:m}=Q(),h=J(()=>ag(e),[e]),g=J(()=>og(h),[h]),[_,v]=X(e.url),[y,b]=X(e.content),[x,S]=X(null),[C,w]=X(!1),[T,E]=X(null),[D,O]=X(0),k=[e.id,e.title,e.fileName,e.contentType,e.url,e.sourcePath,e.content,e.artifact?.runId,e.artifact?.path].join(`\0`),A=K(async(e,t)=>e.url?e.url:e.artifact?(await m.files.getArtifactDownloadUrl(e.artifact.runId,e.artifact.path,t)).url:e.sourcePath?(await m.files.getDownloadUrl(e.sourcePath,e.fileName,t)).url:``,[m]),j=c||A,M=K(async e=>{if(e.content!==void 0)return e.content;let t=await j(e,`inline`);if(!t)return``;let n=await fetch(t);if(!n.ok)throw Error(`Failed to load ${ag(e)}: ${n.statusText}`);return n.text()},[j]),N=l||M,P={source:e,fileName:h,extension:g,contentType:e.contentType||x?.contentType,url:x?.url||_,content:x?.content||y,isLoading:C,error:T,reload:()=>O(e=>e+1)},F=a.find(e=>e.canRender(P)),I=!F&&(cg(P)||ug(P)||dg(P)||fg(P)),L=!F&&(sg(P)||lg(P)),ee={source:e,fileName:h,extension:g,contentType:e.contentType,target:`pdf`},R=!F&&!P.url?s.find(e=>e.target===`pdf`&&e.canConvert(ee)):void 0,te=!F&&!P.url&&(mg(P)||!!R)&&(!!R||!!u);q(()=>{let t=!1,n=e;E(null),v(n.url),b(n.content),S(null);async function r(){if(!(!I&&!L&&!te)){w(!0);try{if(te){let e=R?await R.convert({source:n,fileName:h,extension:g,contentType:n.contentType,target:`pdf`}):await u?.(n,`pdf`);t||S(e??null);return}if(I){let e=await N(n);t||b(e);return}if(L){let e=await j(n,`inline`);t||v(e)}}catch(e){t||E(e instanceof Error?e.message:`Failed to load document`)}finally{t||w(!1)}}}return r(),()=>{t=!0}},[u,g,h,N,te,I,L,D,j,R,e,k]);let z={...P,url:x?.url||_,content:x?.content||y,contentType:x?.contentType||e.contentType,isLoading:C,error:T},ne;return ne=C?n(`div`,{className:`flex h-full min-h-64 items-center justify-center gap-2 text-muted`,children:[t(pr,{className:`size-5 animate-spin`}),t(`span`,{className:`text-sm`,children:`Loading preview...`})]}):T?n(`div`,{className:`flex h-full min-h-64 flex-col items-center justify-center gap-2 text-destructive`,children:[t(Gt,{className:`size-7`}),t(`span`,{className:`max-w-xl text-center text-sm`,children:T}),t(o,{variant:`outline`,size:`sm`,onClick:z.reload,children:`Retry`})]}):F?_g(F,z):(sg(z)||x?.contentType===`application/pdf`)&&z.url?t(ng,{url:z.url,className:`h-full`}):lg(z)&&z.url?t(`div`,{className:`flex h-full min-h-0 items-center justify-center overflow-auto bg-muted/10 p-3`,children:t(`img`,{src:z.url,alt:h,className:`max-h-full max-w-full rounded-md object-contain`})}):cg(z)?t(`div`,{className:`prose prose-sm dark:prose-invert max-w-none px-5 py-4`,children:t(wt,{artifactRunId:e.artifact?.runId,components:d,children:z.content||``})}):ug(z)?t(`iframe`,{title:h,className:`h-full min-h-96 w-full bg-white`,sandbox:``,srcDoc:z.content||``}):dg(z)?t(`div`,{className:`px-4 py-2`,children:t(kt,{xml:z.content||``,collapsible:!0})}):pg(z)?t(Og,{context:z}):fg(z)?t(hg,{content:z.content,extension:g}):mg(z)&&!R&&!u?t(gg,{message:`This file needs a PDF rendition before it can be previewed.`}):t(gg,{message:`Preview is not available for this file type.`}),n(`div`,{className:H(`flex h-full min-h-0 flex-col overflow-hidden`,r),children:[f&&n(`div`,{className:`flex min-h-10 items-center justify-between gap-3 border-b py-2 ps-3 pe-16`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`truncate text-sm font-medium`,title:h,children:h}),z.contentType&&t(`div`,{className:`truncate text-xs text-muted`,children:z.contentType})]}),p&&t(o,{variant:`outline`,size:`sm`,onClick:()=>p(e),children:`Download`})]}),t(`div`,{className:H(`min-h-0 flex-1 overflow-auto`,i),children:ne})]})}var Ag=Da((()=>{rg()}));const jg=G.lazy(async()=>({default:(await Promise.resolve().then(()=>(Ag(),ig))).UniversalDocumentViewer})),Mg=new Set([`md`,`markdown`,`mdx`,`txt`]);function Ng(e){let t=e.split(`.`).pop()?.toLowerCase();return t!==void 0&&Mg.has(t)}function Pg(e){return e.replace(/[_-]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Fg({node:e,depth:r,runId:i,onOpen:a,onDownload:s,downloadingPath:c,forceExpanded:l=!1}){let{t:u}=Z(),[d,f]=X(!1),p=l||d;if(e.isDirectory)return n(`div`,{className:`min-w-0`,children:[n(o,{variant:`unstyled`,className:`flex w-full max-w-full items-center justify-start gap-1.5 rounded px-1 py-1 text-start text-sm hover:bg-muted/30`,style:{paddingInlineStart:`${r*14+4}px`},onClick:()=>f(e=>!e),"aria-expanded":p,children:[p?t(dn,{className:`size-3.5 shrink-0 text-muted`}):t(mn,{className:`size-3.5 shrink-0 text-muted cn-rtl-flip`}),t(p?Jn:qn,{className:`size-4 shrink-0 text-info`}),t(`span`,{className:`min-w-0 truncate font-medium`,title:e.path,children:Pg(e.name)})]}),p&&e.children.map(e=>t(Fg,{node:e,depth:r+1,runId:i,onOpen:a,onDownload:s,downloadingPath:c,forceExpanded:l},`${i}:${e.path}`))]});let m=c===e.path;return n(`div`,{className:`flex min-w-0 items-center gap-1`,children:[n(o,{variant:`unstyled`,className:`flex min-w-0 flex-1 items-center justify-start gap-1.5 rounded px-1 py-1 text-start text-sm hover:bg-muted/30`,style:{paddingInlineStart:`${r*14+4}px`},onClick:()=>a(e.path),title:e.path,children:[t(`span`,{className:`size-3.5 shrink-0`}),t(Rn,{className:`size-4 shrink-0 text-muted`}),t(`span`,{className:`min-w-0 truncate`,children:e.name})]}),t(o,{variant:`ghost`,size:`sm`,className:`h-7 w-7 shrink-0 p-0`,onClick:()=>s(e.path),disabled:m,"aria-label":u(`agent.download`),title:u(`agent.download`),children:m?t(pr,{className:`size-3.5 animate-spin text-info`}):t(Mn,{className:`size-3.5`})})]})}function Ig(e){return e.reduce((e,t)=>t.isDirectory?e+Ig(t.children):e+1,0)}function Lg(e,t){let n=t.trim().toLocaleLowerCase();return n?e.flatMap(e=>{let t=`${e.name} ${e.path}`.toLocaleLowerCase().includes(n);if(!e.isDirectory)return t?[e]:[];let r=Lg(e.children,n);return t?[{...e}]:r.length>0?[{...e,children:r}]:[]}):e}function Rg(e,t){let n=document.createElement(`a`);n.href=e,n.download=t,n.rel=`noopener noreferrer`,n.style.display=`none`,document.body.appendChild(n),n.click(),n.remove()}function zg(e){switch(e.split(`.`).pop()?.toLowerCase()){case`css`:return`text/css`;case`gif`:return`image/gif`;case`htm`:case`html`:return`text/html`;case`jpeg`:case`jpg`:return`image/jpeg`;case`json`:return`application/json`;case`md`:case`markdown`:return`text/markdown`;case`pdf`:return`application/pdf`;case`png`:return`image/png`;case`svg`:return`image/svg+xml`;case`ts`:case`tsx`:return`text/typescript`;case`txt`:return`text/plain`;case`webp`:return`image/webp`;default:return}}function Bg({runId:e,path:r,onBack:i,onDownload:a,refreshKey:s,refreshDetails:c,onSendMessage:l}){let{t:u}=Z(),[d,f]=X(`components`),[p,m]=X(`idle`);return n(`div`,{className:`flex h-full min-h-0 flex-col`,children:[n(`div`,{className:`flex shrink-0 items-center gap-1 border-b border-border/60 px-2 py-1`,children:[t(o,{variant:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:i,"aria-label":u(`agent.backToArtifacts`),title:u(`agent.backToArtifacts`),children:t(Jt,{className:`size-4 cn-rtl-flip`})}),n(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[t(`span`,{className:`truncate text-sm font-medium`,title:r,children:r.split(`/`).pop()}),p===`saving`?t(Be,{description:u(`agent.savingWorkingCopy`),asChild:!0,children:t(pr,{className:`size-3.5 shrink-0 animate-spin text-muted`,"aria-label":u(`agent.savingWorkingCopy`)})}):p===`saved`?t(Be,{description:u(`agent.savedToWorkingCopy`),asChild:!0,children:t(ln,{className:`size-3.5 shrink-0 text-success`,"aria-label":u(`agent.savedToWorkingCopy`)})}):null]}),n(`div`,{className:`flex items-center gap-0.5`,children:[t(o,{variant:d===`components`?`primary`:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:()=>f(`components`),"aria-label":u(`agent.blockMode`),"aria-pressed":d===`components`,title:u(`agent.blockMode`),children:t(Ur,{className:`size-4`})}),t(o,{variant:d===`document`?`primary`:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:()=>f(`document`),"aria-label":u(`agent.editMode`),"aria-pressed":d===`document`,title:u(`agent.editMode`),children:t(Ar,{className:`size-4`})})]}),t(o,{variant:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:()=>a(r),"aria-label":u(`agent.download`),title:u(`agent.download`),children:t(Mn,{className:`size-4`})})]}),t(ht,{runId:e,path:r,viewMode:d,refreshKey:s,refreshDetails:c,readOnly:!l,onAction:e=>{if(!l)return;let t=e.anchor.block_type.replaceAll(`_`,` `);l(e.comment?.trim()||u(`agent.editedSelectionMessage`,{blockType:t}),{editing_action:e})},onSaveStatusChange:m,onSendMessage:l?e=>l(e):void 0,className:H(`relative min-h-0 flex-1`,d===`document`?`overflow-hidden`:`overflow-y-auto px-6 py-5`)})]})}function Vg({icon:e,children:r,action:i}){return n(p,{className:`h-full min-h-[240px] flex-col text-center text-muted`,children:[e,t(`span`,{className:`text-sm`,children:r}),i]})}function Hg({runId:r,refreshKey:i=0,refreshDetails:a,selectedPath:s,onSelectedPathChange:c,onSendMessage:l}){let{t:u}=Z(),{client:d}=Q(),[f,m]=X(!1),{tree:h,flatFiles:g,totalCount:_,systemHiddenCount:v,isLoading:y,error:b,refresh:x}=jh(d,r,i,f),[S,C]=X(null),[w,T]=X(null),[E,D]=X(``),[O,k]=X(null),A=s===void 0?O:s,j=K(e=>{s===void 0&&k(e),c?.(e)},[c,s]),N=E.trim(),P=J(()=>Lg(h,N),[h,N]),F=J(()=>Ig(P),[P]),I=ut(),L=K(async e=>{if(r){C(e);try{let{url:t}=await d.files.getArtifactDownloadUrl(r,e,`attachment`);Rg(t,e.split(`/`).pop()||`artifact`)}catch(e){console.error(`Failed to get artifact download URL:`,e)}finally{C(null)}}},[d,r]),ee=K(e=>{if(Ng(e)){j(e);return}T(e)},[j]),te=r&&w?{title:w.split(`/`).pop()||w,fileName:w.split(`/`).pop()||w,contentType:zg(w),artifact:{runId:r,path:w}}:null;return r?y&&_===0?t(Vg,{icon:t(pr,{className:`mb-2 size-6 animate-spin`}),children:u(`agent.loadingArtifacts`)}):b?t(`div`,{className:`flex flex-col items-center justify-center p-4 text-muted w-full`,children:n(M,{title:`Fail to load Artifacts`,className:`w-full`,action:x,actionLabel:n(e,{children:[t(Br,{className:`size-3.5 me-1.5`}),u(`agent.retry`)]}),children:[t(`span`,{className:`break-all text-muted`,children:b}),` `,t(`br`,{})]})}):_===0?t(Vg,{icon:t(Er,{className:`mb-2 size-8`}),action:n(o,{variant:`ghost`,size:`sm`,className:`mt-2`,onClick:x,children:[t(Br,{className:`size-3.5 me-1.5`}),u(`agent.refresh`)]}),children:u(`agent.noArtifactsYet`)}):A?t(Bg,{runId:r,path:A,refreshKey:i,refreshDetails:a,onBack:()=>j(null),onDownload:e=>void L(e),onSendMessage:l}):n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`flex shrink-0 flex-col gap-2 border-b px-3 py-2`,children:[n(`div`,{className:`flex items-center justify-between gap-2 text-xs text-muted`,children:[n(`span`,{children:[N?`${F} of ${g.length} file${g.length===1?``:`s`}`:`${g.length} file${g.length===1?``:`s`}`,!f&&v>0?` · ${v} hidden`:``]}),n(`div`,{className:`flex items-center gap-1`,children:[t(ke,{size:`sm`,value:f,onChange:m,children:t(`span`,{className:`text-xs text-muted`,children:u(`agent.showSystemArtifacts`)})}),t(o,{variant:`ghost`,size:`sm`,onClick:x,disabled:y,className:`h-6 w-6 p-0`,children:t(Br,{className:`size-3.5 ${y?`animate-spin`:``}`})})]})]}),t(`label`,{htmlFor:I,className:`sr-only`,children:u(`form.filter`)}),t(R,{id:I,type:`text`,role:`searchbox`,autoComplete:`off`,placeholder:u(`store.searchPlaceholder`),value:E,onChange:D,clearable:!0})]}),t(`div`,{className:`flex-1 overflow-y-auto px-3 py-2`,children:P.length>0?t(`div`,{className:`min-w-0`,children:P.map(e=>t(Fg,{node:e,depth:0,runId:r,onOpen:ee,onDownload:L,downloadingPath:S,forceExpanded:!!N},`${r}:${e.path}`))}):t(`div`,{className:`px-1 py-6 text-sm text-muted`,children:u(!f&&v>0?`agent.onlySystemArtifacts`:`agent.noContentAvailable`)})}),te&&n(ie,{isOpen:!!w,onClose:()=>T(null),size:`xl`,className:`h-[90vh] p-0`,description:`Artifact preview`,children:[t(se,{show:!1,children:te.fileName}),t(ae,{className:`h-full max-h-none p-0`,children:t(G.Suspense,{fallback:t(p,{className:`h-full`,children:t(pr,{className:`size-6 animate-spin text-muted`})}),children:t(jg,{source:te,className:`h-full`,showHeader:!0,onDownload:()=>w&&void L(w)})})})]})]}):t(Vg,{icon:t(Er,{className:`mb-2 size-8`}),children:`No run selected`})}const Ug=G.memo(Hg);function Wg(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Gg(e){if(!Wg(e))return;let t=e.browseruse??e.browser_use;if(!Wg(t))return;let n={widget:typeof t.widget==`string`?t.widget:void 0,browser_workflow_id:typeof t.browser_workflow_id==`string`?t.browser_workflow_id:void 0,workstream_id:typeof t.workstream_id==`string`?t.workstream_id:void 0,phase:typeof t.phase==`string`?t.phase:void 0,url:typeof t.url==`string`?t.url:void 0,title:typeof t.title==`string`?t.title:void 0,screenshot:typeof t.screenshot==`string`?t.screenshot:void 0,raw_screenshot:typeof t.raw_screenshot==`string`?t.raw_screenshot:void 0,prefer_raw_screenshot:typeof t.prefer_raw_screenshot==`boolean`?t.prefer_raw_screenshot:void 0,updated_at:typeof t.updated_at==`number`?t.updated_at:void 0};if(!(n.widget&&n.widget!==`browseruse`)&&!(!n.url&&!n.title&&!n.screenshot&&!n.raw_screenshot))return n}function Kg(e){let t=new Map;for(let n of e){let e=Gg(n.details);if(!e)continue;let r=e.workstream_id||n.workstream_id||`main`,i=e.updated_at??(typeof n.timestamp==`number`?n.timestamp:new Date(n.timestamp).getTime()),a=t.get(r);(!a||i>=a.timestamp)&&t.set(r,{state:{...e,workstream_id:r},timestamp:i})}return new Map(Array.from(t.entries()).map(([e,t])=>[e,t.state]))}function qg(e){return e.replace(/^artifact:\/\//,``).replace(/^artifact:/,``).replace(/^\/+/,``)}function Jg(e){return e?e.replace(/_/g,` `):`browser`}function Yg({state:e,runId:r,className:a,compact:o}){let{t:s}=Z(),{client:c}=Q(),l=qa(),{openImage:u}=od(),[d,f]=X(),p=e.prefer_raw_screenshot===!1?e.screenshot||e.raw_screenshot:e.raw_screenshot||e.screenshot,m=e.title||e.url||s(`agent.browserUse`),h=J(()=>p&&qg(p).split(`/`).pop()||s(`agent.browserScreenshot`),[p,s]);return q(()=>{if(!p){f(void 0);return}if(p.startsWith(`http://`)||p.startsWith(`https://`)){f(p);return}if(!r){f(void 0);return}let e=!1;return(async()=>{let t=qg(p);try{let n=Ya(r,t,`inline`),i=l?await l.getOrFetch(n,async()=>(await c.files.getArtifactDownloadUrl(r,t,`inline`)).url):(await c.files.getArtifactDownloadUrl(r,t,`inline`)).url;e||f(i)}catch(n){console.error(`Failed to resolve browser screenshot ${t}`,n),e||f(void 0)}})(),()=>{e=!0}},[c,r,p,l]),o?n(`div`,{className:H(`overflow-hidden rounded-md border border-border/70 bg-transparent`,a),children:[n(`div`,{className:`flex items-center gap-2 px-2 py-1.5`,children:[t(wr,{className:`size-3.5 shrink-0 text-info`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex min-w-0 items-center gap-1`,children:[t(`span`,{className:`text-xs font-medium text-foreground`,children:s(`agent.browserPreview`)}),e.phase&&n(`span`,{className:`truncate text-[11px] capitalize text-muted`,children:[`· `,Jg(e.phase)]})]}),t(`div`,{className:`truncate text-[11px] text-muted`,title:m,children:m})]}),e.url&&t(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,title:s(`agent.openInNewTab`),className:H(`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md`,`text-muted hover:bg-muted hover:text-foreground`),children:t(Fn,{className:`size-3`})})]}),p&&(d?t(`button`,{type:`button`,className:`block w-full bg-mixer-muted/20 text-start`,onClick:()=>u(d,h),title:s(`agent.clickToEnlarge`),children:t(`img`,{src:d,alt:h,className:`block max-h-32 w-full object-contain`})}):n(`div`,{className:`flex min-h-16 items-center justify-center gap-2 bg-mixer-muted/20 px-3 py-4 text-xs text-muted`,children:[t(nr,{className:`size-4`}),t(`span`,{children:s(`agent.browserScreenshotPending`)})]}))]}):n(`div`,{className:H(`overflow-hidden rounded-md border border-muted bg-mixer-muted/10`,a),children:[n(`div`,{className:`flex items-start justify-between gap-2 border-b border-muted px-2.5 py-2`,children:[n(`div`,{className:`flex min-w-0 items-start gap-2`,children:[t(wr,{className:`mt-0.5 size-4 shrink-0 text-info`}),n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-xs font-medium text-foreground`,children:s(`agent.browserUse`)}),t(`div`,{className:`truncate text-xs text-muted`,title:m,children:m})]})]}),t(i,{variant:`info`,className:`shrink-0 capitalize`,children:Jg(e.phase)})]}),d?t(`button`,{type:`button`,className:`block w-full bg-mixer-muted/20 text-start`,onClick:()=>u(d,h),title:s(`agent.clickToEnlarge`),children:t(`img`,{src:d,alt:h,className:`block max-h-56 w-full object-contain`})}):n(`div`,{className:`flex min-h-28 items-center justify-center gap-2 bg-mixer-muted/20 px-3 py-6 text-xs text-muted`,children:[t(nr,{className:`size-4`}),t(`span`,{children:s(`agent.browserScreenshotPending`)})]}),e.url&&n(`div`,{className:`flex items-center gap-2 border-t border-muted px-2.5 py-1.5`,children:[t(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`min-w-0 flex-1 truncate text-xs text-info hover:underline`,title:e.url,children:e.url}),t(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,title:s(`agent.openInNewTab`),className:H(`inline-flex h-6 shrink-0 items-center justify-center rounded-md px-1.5`,`text-muted hover:bg-muted hover:text-foreground`),children:t(Fn,{className:`size-3`})})]})]})}function Xg({documents:e,activeId:n,onSelect:r}){return e.length===0?null:t(`div`,{className:`flex items-center gap-1 px-2 py-1.5`,children:t(w,{align:`right`,trigger:t(o,{variant:`ghost`,size:`xs`,title:`All opened documents`,className:`flex items-center gap-1.5 max-w-[220px] text-xs h-7 px-2`,children:t(dn,{className:`size-3 shrink-0`})}),children:e.map(e=>t(B,{onClick:()=>r(e.id),className:e.id===n?`font-medium`:``,children:t(`span`,{className:`truncate max-w-[200px]`,children:e.title})},e.id))})})}function Zg({isOpen:e,documents:r,activeDocumentId:i,onSelectDocument:a,onCloseDocument:s,onUpdateDocumentTitle:c,refreshKey:l,runId:u}){let{client:d}=Q(),{t:f}=Z(),[p,m]=X(null),[h,g]=X(!1),[_,v]=X(null),[y,b]=X(null),x=K(async e=>{g(!0),v(null);try{let[t,n]=await Promise.all([d.store.objects.getObjectText(e),d.store.objects.retrieve(e)]);m(t.text??null);let r=n.name;b(r),r&&c?.(e,r)}catch(e){let t=e instanceof Error?e.message:f(`agent.failedToLoadDocument`);v(t),m(null)}finally{g(!1)}},[d,c,f]);return q(()=>{i&&e&&x(i)},[i,l,e,x]),!e||r.length===0?null:n(`div`,{className:`h-full shadow-xl border border-muted/20 overflow-hidden flex flex-col`,children:[n(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-muted/20 shrink-0`,children:[n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(Un,{className:`size-4 text-muted shrink-0`}),t(`h3`,{className:`font-bold text-sm truncate`,children:y||f(`agent.document`)})]}),n(`div`,{className:`flex items-center gap-1`,children:[t(Xg,{documents:r,activeId:i,onSelect:a}),i&&t(ga,{href:`/store/objects/${i}#overview`,topLevelNav:!0,className:`inline-flex items-center justify-center rounded-md text-sm font-medium h-8 w-8 hover:bg-muted/20 text-muted hover:text-foreground`,children:t(Be,{description:f(`agent.openDocument`),placement:`top`,size:`xs`,children:t(Fn,{className:`size-4`})})}),t(o,{variant:`ghost`,size:`sm`,onClick:()=>i&&s(i),title:f(`agent.close`),children:t(mi,{className:`size-4`})})]})]}),t(`div`,{className:`flex-1 overflow-y-auto px-4 py-4`,children:h?n(`div`,{className:`flex items-center justify-center py-12`,children:[t(pr,{className:`size-5 animate-spin text-muted`}),t(`span`,{className:`ms-2 text-sm text-muted`,children:f(`agent.loadingDocument`)})]}):_?t(`div`,{className:`p-4 rounded-md bg-destructive/10 text-destructive text-sm`,children:_}):p?t(`div`,{className:`prose prose-sm dark:prose-invert max-w-none`,children:t(wt,{artifactRunId:u,children:p})}):n(`div`,{className:`flex flex-col items-center justify-center py-12 text-muted`,children:[t(Un,{className:`size-8 mb-2`}),t(`span`,{className:`text-sm`,children:f(`agent.noContentAvailable`)})]})})]})}const Qg=G.memo(Zg);function $g({plan:e,workstreamStatus:r,isOpen:i,onClose:a,plans:s=[],activePlanIndex:c=0,onChangePlan:l=()=>{}}){let{t:u}=Z();if(!i)return null;let d=e.plan||[],f=d.length,m=d.reduce((e,t)=>t?.id&&(r.get(t.id.toString())===`completed`||t.status===`completed`)?e+1:e,0),h=f>0?Math.round(m/f*100):0,g=s.length>0?s.length-c:1,_=s[c]?.timestamp;return d.length===0?t(`div`,{className:`h-full overflow-hidden`,children:n(p,{className:`h-full min-h-[240px] flex-col text-center text-muted`,children:[t(Cn,{className:`mb-2 size-8`}),t(`span`,{className:`text-sm`,children:u(`agent.noPlanAvailable`)})]})}):t(`div`,{className:`h-full overflow-hidden`,children:n(`div`,{className:`flex h-full flex-col gap-4 overflow-y-auto px-2 py-3`,children:[n(`div`,{className:`space-y-2`,children:[n(`div`,{className:`flex items-start justify-between gap-3`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-sm font-medium text-foreground`,children:u(`agent.taskProgress`)}),t(`div`,{className:`text-xs text-muted`,children:u(`agent.tasksCompleted`,{completed:m,total:f})})]}),s.length>1&&n(`div`,{className:`flex shrink-0 items-center gap-1 text-xs text-muted`,children:[t(o,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>l(Math.min(s.length-1,c+1)),disabled:c>=s.length-1,"aria-label":u(`agent.olderPlan`),title:u(`agent.olderPlan`),children:t(fn,{className:`size-4`,"aria-hidden":`true`})}),n(`div`,{className:`min-w-20 text-center`,children:[n(`div`,{className:`font-medium text-foreground`,children:[g,`/`,s.length]}),t(`div`,{className:`truncate`,children:_?new Date(_).toLocaleTimeString():u(`agent.unknownTime`)})]}),t(o,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>l(Math.max(0,c-1)),disabled:c<=0,"aria-label":u(`agent.newerPlan`),title:u(`agent.newerPlan`),children:t(pn,{className:`size-4`,"aria-hidden":`true`})})]})]}),t(`div`,{className:`h-2 overflow-hidden rounded-full bg-mixer-muted/20`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":f,"aria-valuenow":m,"aria-label":u(`agent.taskProgress`),children:t(`div`,{className:`h-full rounded-full bg-success transition-all duration-300`,style:{width:`${h}%`}})})]}),t(`ol`,{className:`divide-y divide-border/60`,children:d.map((e,i)=>{let a=e.id?e.id.toString():`task-${i}`,o=e.goal||`Task ${i+1}`,s=e.id?`task-${e.id.toString()}`:`task-${o}-${e.status||`pending`}`,c=e.status||`pending`,l=r.get(a);l!==void 0&&(c=l);let d=xn,f=`text-muted`;c===`in_progress`?(d=wn,f=`text-info`):c===`completed`&&(d=on,f=`text-success`);let p=u(c===`completed`?`agent.completed`:c===`in_progress`?`agent.inProgress`:`agent.pending`);return n(`li`,{className:`grid grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 px-1 py-3`,children:[t(`span`,{className:`mt-0.5 min-w-5 text-center text-xs font-medium tabular-nums text-muted/80`,children:a}),t(`span`,{className:`min-w-0 text-sm leading-5 text-foreground/85`,children:o}),n(`span`,{className:H(`flex items-center gap-1.5 text-xs font-medium`,f),children:[t(d,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t(`span`,{children:p})]})]},s)})}),(()=>{let e=new Set(d.filter(e=>e?.id).map(e=>e.id.toString())),i=Array.from(r.entries()).filter(([t])=>t!==`main`&&!e.has(t));return i.length>0?n(`div`,{className:`mt-1 px-1 py-2`,children:[t(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:u(`agent.workstreams`)}),t(`div`,{className:`divide-y divide-border/60`,children:i.map(([e,r])=>{let i=xn,a=`text-muted`,o=u(`agent.pending`);return r===`in_progress`?(i=wn,a=`text-info`,o=u(`agent.inProgress`)):r===`completed`&&(i=on,a=`text-success`,o=u(`agent.completed`)),n(`div`,{className:`flex items-center gap-2 py-2`,children:[t(i,{className:H(`size-3.5 shrink-0`,a)}),t(`span`,{className:`min-w-0 flex-1 truncate text-xs font-medium text-foreground/80`,children:e}),t(`span`,{className:`text-xs font-medium text-muted`,children:o})]},e)})})]}):null})()]})})}const e_=G.memo($g);function t_({icon:e,children:r}){return n(p,{className:`h-full min-h-[240px] flex-col text-center text-muted`,children:[e,t(`span`,{className:`text-sm`,children:r})]})}function n_({files:e}){let{t:r}=Z(),a=J(()=>e?Array.from(e.values()):[],[e]),o=e=>{switch(e){case Di.UPLOADING:case Di.PROCESSING:return t(pr,{className:`size-4 animate-spin text-info`});case Di.READY:return t(cn,{className:`size-4 text-success`});case Di.ERROR:return t(gi,{className:`size-4 text-destructive`});default:return t(Un,{className:`size-4 text-muted`})}},s=e=>{switch(e){case Di.UPLOADING:return t(i,{variant:`info`,children:r(`agent.uploading`)});case Di.PROCESSING:return t(i,{variant:`info`,children:r(`agent.processing`)});case Di.READY:return t(i,{variant:`success`,children:r(`agent.ready`)});case Di.ERROR:return t(i,{variant:`destructive`,children:r(`agent.error`)});default:return null}};return t(`div`,{className:`h-full min-h-0`,children:a.length===0?t(t_,{icon:t(Un,{className:`mb-2 size-8`}),children:r(`agent.noFilesUploadedYet`)}):t(`div`,{className:`space-y-2 p-2`,children:a.map(e=>n(`div`,{className:`flex items-start gap-2 p-2 border border-muted rounded-md`,children:[t(`div`,{className:`mt-0.5`,children:o(e.status)}),n(`div`,{className:`flex-1 min-w-0`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-sm font-medium truncate`,children:e.name}),s(e.status)]}),e.error&&t(`div`,{className:`text-xs text-destructive mt-1`,children:e.error})]})]},e.id))})})}var r_=class extends G.Component{state={hasError:!1};static getDerivedStateFromError(e){return{hasError:!0,message:e instanceof Error?e.message:String(e)}}componentDidCatch(e,t){console.error(`Agent right panel section failed to render`,{error:e,componentStack:t.componentStack})}render(){return this.state.hasError?n(`div`,{className:H(`rounded-md border border-destructive bg-mixer-destructive/10 text-destructive`,this.props.compact?`p-2 text-xs`:`m-3 p-3 text-sm`),children:[t(`div`,{className:`font-medium`,children:this.props.title}),t(`div`,{className:`mt-1 text-xs text-muted`,children:this.props.description}),this.state.message&&t(`div`,{className:`mt-1 break-all text-[11px] text-muted`,children:this.state.message})]}):this.props.children}};function i_({workstreams:e,messages:r,runId:a}){let{t:s}=Z(),{client:c}=Q(),l=Xe(),u=J(()=>Kg(r),[r]),d=s(`agent.panelRenderErrorDescription`),f=K(e=>{navigator.clipboard.writeText(e),l({status:`success`,title:s(`agent.runIdCopied`),duration:2e3})},[s,l]),p=K(async e=>{try{let t=await Rl(c,e);t&&window.open(t,`_blank`)}catch{l({status:`error`,title:s(`agent.failedToDownload`)})}},[c,s,l]);return e.length===0?t(t_,{icon:t(sr,{className:`mb-2 size-8`}),children:s(`agent.noActiveParallelTasks`)}):n(`div`,{className:`h-full min-h-0 overflow-y-auto px-2 py-2`,children:[t(`div`,{className:`px-1 pb-2 text-xs text-muted`,children:s(`agent.parallelWorkDescription`)}),t(`div`,{className:`divide-y divide-border/60`,children:e.map(e=>{let r=e.status===`running`||e.status===`canceling`,c=Math.round(e.elapsed_ms/1e3),l=Math.max(0,Math.round(e.remaining_ms/1e3)),m=e.deadline_ms>0?Math.min(100,Math.round(e.elapsed_ms/e.deadline_ms*100)):0,h=u.get(e.workstream_id),g=e.deadline_ms>0,_=e.child_workflow_run_id,v=[e.phase?pl(e.phase):void 0,c>0?s(`agent.elapsed`,{seconds:c}):void 0,g&&l>0?s(`agent.remaining`,{seconds:l}):void 0].filter(Boolean),y=(()=>{switch(e.status){case`running`:return t(i,{variant:`info`,children:s(`agent.running`)});case`canceling`:return t(i,{variant:`attention`,children:s(`agent.canceling`)});case`completed`:return t(i,{variant:`done`,children:s(`agent.completed`)});case`failed`:return t(i,{variant:`destructive`,children:s(`agent.failed`)});case`timeout`:return t(i,{variant:`destructive`,children:s(`agent.timeout`)});case`canceled`:return t(i,{variant:`destructive`,children:s(`agent.canceled`)})}})();return t(r_,{title:s(`agent.workstreamRenderError`),description:d,compact:!0,children:t(`div`,{className:`py-3`,children:n(`div`,{className:`flex items-start gap-2`,children:[t(`span`,{className:H(`mt-2 size-2 shrink-0 rounded-full`,xl(e.status)),"aria-hidden":`true`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[t(`span`,{className:`min-w-0 truncate text-sm font-medium text-foreground`,title:e.workstream_id,children:pl(e.workstream_id)}),y]}),v.length>0&&t(`div`,{className:`mt-0.5 truncate text-xs text-muted`,children:v.join(` · `)}),r&&g&&t(`div`,{className:`mt-2 h-1 rounded-full bg-muted`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":m,"aria-valuetext":s(`agent.workstreamProgress`,{percent:m}),children:t(`div`,{className:`h-full rounded-full bg-info transition-all duration-500`,style:{width:`${m}%`}})}),h&&t(r_,{title:s(`agent.browserWidgetRenderError`),description:d,compact:!0,children:t(Yg,{state:h,runId:a,compact:!0,className:`mt-2`})}),_&&n(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:[n(o,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs text-muted hover:text-foreground`,onClick:()=>f(_),children:[t(Sn,{className:`size-3 me-1`}),s(`agent.copyRunId`)]}),n(o,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs text-muted hover:text-foreground`,onClick:()=>p(_),children:[t(jn,{className:`size-3 me-1`}),s(`agent.download`)]})]})]})]})})},e.launch_id)})})]})}function a_({plan:e,workstreamStatus:r,plans:i=[],activePlanIndex:a=0,onChangePlan:s,activeWorkstreams:c=[],messages:l=[],hideWorkstreams:u=!1,openDocuments:d=[],activeDocumentId:f,onSelectDocument:p,onCloseDocument:m,onUpdateDocumentTitle:h,docRefreshKey:g=0,runId:_,processingFiles:v,showArtifacts:y=!1,artifactRefreshKey:b=0,artifactRefreshDetails:x,selectedArtifactPath:S,onSelectedArtifactPathChange:C,onSendMessage:w,payloadContent:T,conversationContent:E,onClose:D,defaultTab:O,activeTab:k,onTabChange:A}){let{t:j}=Z(),[M,N]=X(O||`plan`),P=k??M,F=e=>{N(e),A?.(e)},I=!u&&c.length>0,L=d.length>0,ee=v?v.size>0:!1,R=K((e,n)=>t(r_,{title:j(`agent.panelRenderError`,{name:e}),description:j(`agent.panelRenderErrorDescription`),children:n}),[j]),te={name:`conversation`,label:`Conversation`,content:E?R(`Conversation`,t(`div`,{className:`flex flex-col h-full min-h-0`,children:E})):null,is_allowed:!!E},z=[...E?[te]:[],{name:`plan`,label:j(`agent.plan`),content:R(j(`agent.plan`),e?t(e_,{plan:e,workstreamStatus:r||new Map,isOpen:!0,onClose:D,plans:i,activePlanIndex:a,onChangePlan:s}):t(t_,{icon:t(sr,{className:`mb-2 size-8`}),children:j(`agent.noPlanAvailable`)})),is_allowed:!0},{name:`workstreams`,label:I?n(`span`,{className:`inline-flex min-w-0 items-center gap-1 whitespace-nowrap`,children:[j(`agent.workstreams`),` `,t(`span`,{className:`inline-flex shrink-0 items-center justify-center rounded-full bg-info px-1.5 py-0.5 text-[10px] text-info`,children:c.length})]}):j(`agent.workstreams`),content:R(j(`agent.workstreams`),t(i_,{workstreams:c,messages:l,runId:_})),is_allowed:!u},{name:`documents`,label:L?n(`span`,{className:`inline-flex min-w-0 items-center gap-1 whitespace-nowrap`,children:[j(`agent.documents`),` `,t(`span`,{className:`inline-flex shrink-0 items-center justify-center rounded-full bg-info px-1.5 py-0.5 text-[10px] text-info`,children:d.length})]}):j(`agent.documents`),content:R(j(`agent.documents`),d.length>0&&p&&m?t(Qg,{isOpen:!0,documents:d,activeDocumentId:f??null,onSelectDocument:p,onCloseDocument:m,onUpdateDocumentTitle:h,refreshKey:g,runId:_}):t(t_,{icon:t(Un,{className:`mb-2 size-8`}),children:j(`agent.noDocumentsOpen`)})),is_allowed:!0},{name:`uploads`,label:ee?n(`span`,{className:`inline-flex min-w-0 items-center gap-1 whitespace-nowrap`,children:[j(`agent.uploads`),` `,t(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-info`})]}):j(`agent.uploads`),content:R(j(`agent.uploads`),t(n_,{files:v})),is_allowed:!0},{name:`artifacts`,label:j(`agent.artifacts`),content:R(j(`agent.artifacts`),t(Ug,{runId:_,refreshKey:b,refreshDetails:x,selectedPath:S,onSelectedPathChange:C,onSendMessage:w})),is_allowed:y},{name:`payload`,label:j(`agent.payload`),content:T?R(j(`agent.payload`),t(`div`,{className:`overflow-y-auto`,children:T})):null,is_allowed:!!T}],ne=z.filter(e=>e.is_allowed===void 0||e.is_allowed===!0);return n(Fe,{tabs:z,current:P,onTabChange:F,fullHeight:!0,className:`px-0`,children:[n(`div`,{className:`flex items-end justify-between shrink-0 px-1 py-1 gap-1`,children:[t(le,{tabs:ne,current:P,onTabChange:F,className:`min-w-0 flex-1`}),!E&&t(o,{variant:`ghost`,size:`sm`,className:`shrink-0 ms-1`,onClick:D,title:`Close Right Panel`,children:t(_i,{className:`size-4`})})]}),t(Le,{className:`flex-1 min-h-0 pt-0 pb-0`})]})}const o_=G.memo(a_);function s_(e){if(!e)return[];let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r.kind!==`file`)continue;let i=r.getAsFile();if(i){if(r.type.startsWith(`image/`)&&(!i.name||i.name===`image.png`)){let e=r.type.split(`/`)[1]||`png`;t.push(new File([i],`pasted-image-${Date.now()}.${e}`,{type:i.type}))}else t.push(i)}}return t}function c_(e,t,n=!1){let[r,i]=X([]),[a,o]=X(0),[s,c]=X(new Map),[l,u]=X(t),[d,f]=X(!n),p=Y(-1),m=Y(new Set);q(()=>{e.length===0&&(i([]),o(0),c(new Map),f(!n),p.current=-1,m.current.clear())},[e.length,n]);let h=K(e=>{let n=e[e.length-1];n&&(n.type===$.TERMINATED?u(!1):u(t?!0:n.type===$.REQUEST_INPUT))},[t]);return q(()=>{if(e.length===0)return;let t=p.current+1;if(t>=e.length){h(e);return}let n=!1,r=[],a=[];for(let i=t;i<e.length;i++){let t=e[i];if(t.type===$.PLAN)try{let e=null;if(t.details&&typeof t.details==`object`&&t.details.plan&&Array.isArray(t.details.plan)&&(e={plan:t.details.plan}),e){let i=typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime();if(!m.current.has(i)){m.current.add(i),n=!0,r.push({plan:e,timestamp:i});let t=new Map;t.set(`main`,`in_progress`),Array.isArray(e.plan)&&e.plan.forEach(e=>{if(e&&typeof e==`object`&&e.id){let n=e.id.toString();t.set(n,e.status||`pending`)}}),a.push({timestamp:i,statusMap:t})}}}catch(e){console.error(`Failed to parse plan from message:`,e)}}p.current=e.length-1,n&&r.length>0&&(i(e=>[...[...r].reverse(),...e]),o(0),f(!0),a.length>0&&c(e=>{let t=new Map(e);for(let e of a)t.set(e.timestamp,e.statusMap);return t})),h(e)},[e,h]),q(()=>{if(r.length===1&&!d&&!sessionStorage.getItem(`plan-panel-shown`)){let e=setTimeout(()=>{f(!0),sessionStorage.setItem(`plan-panel-shown`,`true`)},500);return()=>clearTimeout(e)}},[r.length,d]),{plans:r,activePlanIndex:a,setActivePlanIndex:o,workstreamStatusMap:s,showInput:l,showSlidingPanel:d,setShowSlidingPanel:f}}function l_(e,t){return{...e,details:{...e.details??{},_deliveryStatus:t}}}function u_(e){let t=e.details,n=t?._messageId;if(typeof n==`string`&&n)return n;let r=t?.ack;return typeof r==`string`&&r?r:void 0}function d_(e,t){let n=e?.[t];return typeof n==`string`&&n?n:void 0}function f_(e){return e?.streaming_id_scope===`workflow_run`}function p_(e){return[$.COMPLETE,$.IDLE,$.TERMINATED,$.REQUEST_INPUT].includes(e.type)}function m_(e){if(e.type===$.STREAMING_CHUNK)return!1;if(e.type===$.UPDATE&&typeof e.details?.event_class==`string`)return!0;if(e.type===$.SYSTEM){let t=e.details;if(t?.system_type===`file_processing`&&t.files)return!1}return!!e.message||p_(e)||Vi(e).length>0}function h_(e){if(e)return{type:e.type,timestamp:e.timestamp,workstream_id:e.workstream_id,text:typeof e.message==`string`?e.message.slice(0,80):e.message?`[non-string]`:``,display_role:e.details?.display_role,source:e.details?.source}}function g_(e,t){if(e.find(e=>e.timestamp===t.timestamp))return e;if(!t.details?._optimistic&&(t.type===$.QUESTION||Ml(t))){let n=typeof t.details?.ack==`string`?t.details.ack:void 0,r=n?l_(t,`consumed`):t;if(n){let i=e.filter(e=>!((e.type===t.type||Ml(e))&&e.details?._optimistic&&u_(e)===n));return Ol(i,r),i}if(t.type===$.QUESTION){let n=e.filter(e=>e.type===$.QUESTION&&e.details?._optimistic&&e.message===t.message&&(e.workstream_id??`main`)===(t.workstream_id??`main`));if(n.length===1){let r=e.filter(e=>e!==n[0]);return Ol(r,t),r}}}let n=[...e];return Ol(n,t),n}function __(e){let t=e.details,n=d_(t,`streaming_id`),r=d_(t,`activity_id`);return n&&f_(t)?n:r??n}function v_(e){let t=e.details,n=d_(t,`streaming_id`),r=d_(t,`activity_id`),i=[];return n&&f_(t)&&i.push(n),r&&i.push(r),[...new Set(i)]}function y_(e,t,n){let[r,i]=X([]),[a,o]=X(!1),[s,c]=X(`loading`),[l,u]=X(null),[d,f]=X(null),p=Y(n);p.current=n;let[m,h]=X(new Map),[g,_]=X(0),v=K(()=>_(e=>e+1),[]),y=Y(null),b=Y(0),[x,S]=X(new Map),C=Y(new Map),w=Y(null),[T,E]=X(!1),D=Y(null),O=K(()=>{let e=w.current;e&&(e.mode===`raf`?cancelAnimationFrame(e.id):clearTimeout(e.id),w.current=null)},[]),k=K(()=>{C.current.size>0&&(S(new Map(C.current)),E(!0),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>E(!1),50)),w.current=null},[]);return q(()=>{o(!jl(r))},[r]),q(()=>{Dl(`stream state`,{agentRunId:t,messageCount:r.length,streamingCount:x.size,initialHistoryStatus:s,isCompleted:a,lastDeliveredTs:b.current,first:h_(r[0]),last:h_(r[r.length-1])})},[t,s,a,r,x.size]),q(()=>{let n=y.current!==t;y.current=t,n&&(i([]),c(`loading`),u(null),f(null),S(new Map),h(new Map),b.current=0);let r=new AbortController,a=n?void 0:b.current||void 0;return Dl(`stream start`,{agentRunId:t,isNewConversation:n,since:a,streamNonce:g}),e.agents.getInternals(t).then(e=>{r.signal.aborted||(Dl(`internals loaded`,{agentRunId:t,status:e.status,first_workflow_run_id:e.first_workflow_run_id}),u(e.status?.toUpperCase()??null),f(e.first_workflow_run_id??null))}).catch(e=>{r.signal.aborted||console.error(`Failed to check agent run status:`,e)}),e.agents.streamMessages(t,e=>{if(r.signal.aborted)return;let n=!!(e.timestamp&&e.timestamp<=b.current);if(n||p.current?.(e),Dl(`stream message`,{agentRunId:t,type:e.type,timestamp:e.timestamp,workstream_id:e.workstream_id,hasMessage:!!e.message,display_role:e.details?.display_role,source:e.details?.source}),e.timestamp&&e.timestamp>b.current&&(b.current=e.timestamp),e.type===$.STREAMING_CHUNK){let t=e.details,n=__(e);if(!n)return;let r=C.current.get(n)||{text:``,workstreamId:e.workstream_id,startTimestamp:Date.now(),activityId:t?.activity_id,streamingId:t?.streaming_id},i=r.text+(e.message||``);C.current.set(n,{text:i,workstreamId:e.workstream_id,isComplete:t.is_final,startTimestamp:r.startTimestamp,activityId:t?.activity_id,streamingId:t?.streaming_id}),w.current===null&&(document.hidden?w.current={mode:`timeout`,id:window.setTimeout(k,16)}:w.current={mode:`raf`,id:requestAnimationFrame(k)});return}if(e.type===$.SYSTEM){let t=e.details;if(t?.system_type===`file_processing`&&t.files){n||h(new Map(t.files.map(e=>[e.id,e])));return}}if(e.type===$.THOUGHT||e.type===$.ANSWER){let t=v_(e);if(t.length>0){for(let e of t)C.current.delete(e);S(e=>{let n=new Map(e),r=!1;for(let e of t)r=n.delete(e)||r;return r?n:e})}}(e.type===$.COMPLETE||e.type===$.IDLE)&&C.current.size>0&&k(),m_(e)&&i(t=>g_(t,e))},a,r.signal,{closeOnIdle:!1,onHistoryLoaded:e=>{if(r.signal.aborted)return;let n=e.filter(m_),o,s=-1/0;for(let t of e)if(t.timestamp&&t.timestamp>b.current&&(b.current=t.timestamp),t.type===$.SYSTEM){let e=t.details;if(e?.system_type===`file_processing`&&e.files){let n=t.timestamp??-1/0;(!o||n>=s)&&(o=e,s=n)}}o&&h(new Map(o.files.map(e=>[e.id,e]))),Dl(`history loaded`,{agentRunId:t,count:e.length,timelineCount:n.length,since:a,first:h_(e[0]),last:h_(e[e.length-1])}),c(e.length>0?`has_messages`:`empty`),n.length>0&&i(e=>n.reduce((e,t)=>g_(e,t),e))},onHistoryError:e=>{r.signal.aborted||(Dl(`history error`,{agentRunId:t,error:e instanceof Error?e.message:String(e)}),c(`error`))}}).then(()=>{if(!r.signal.aborted)return Dl(`stream resolved`,{agentRunId:t}),e.agents.getInternals(t).then(e=>{r.signal.aborted||(Dl(`internals refreshed after stream end`,{agentRunId:t,status:e.status}),u(e.status?.toUpperCase()??null))}).catch(e=>{r.signal.aborted||console.error(`Failed to refresh agent run status on stream end:`,e)})}).catch(e=>{r.signal.aborted||(Dl(`stream failed`,{agentRunId:t,error:e instanceof Error?e.message:String(e)}),console.error(`Failed to stream agent messages:`,e))}),()=>{Dl(`stream cleanup`,{agentRunId:t,streamNonce:g}),r.abort(),O(),C.current.clear(),D.current&&=(clearTimeout(D.current),null)}},[t,g,e.agents,k,O]),q(()=>{let e=()=>{!document.hidden&&C.current.size>0&&(O(),k())};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[k,O]),{messages:r,streamingMessages:x,isCompleted:a,initialHistoryStatus:s,debugChunkFlash:T,addOptimisticMessage:K(e=>{i(t=>{let n=[...t,e];return n.sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),n})},[]),updateOptimisticMessageStatus:K((e,t)=>{i(n=>n.map(n=>n.details?._optimistic&&u_(n)===e?l_(n,t):n))},[]),removeOptimisticMessages:K(e=>{i(t=>t.filter(t=>!e(t)))},[]),reconnect:v,agentRunStatus:l,workflowRunId:d,serverFileUpdates:m}}function b_(e){if(typeof e==`string`&&e.trim().length>0)return e}function x_(e,t){let n=b_(e.revision_root_id)||b_(e.revision_root)||b_(e.root_document_id)||b_(e.root_id);if(n)return n;let r=e.revision_info;if(r&&typeof r==`object`){let e=b_(r.root);if(e)return e}return t}function S_(e,t){return e.revisionRootId&&t.revisionRootId?e.revisionRootId===t.revisionRootId:t.revisionRootId?e.id===t.revisionRootId:e.revisionRootId?e.revisionRootId===t.id:e.id===t.id}function C_(e){let[t,n]=X([]),[r,i]=X(null),[a,o]=X(!1),[s,c]=X(0),l=Y(-1);return q(()=>{e.length===0&&(n([]),i(null),o(!1),c(0),l.current=-1)},[e.length]),q(()=>{let t=l.current+1;if(!(t>=e.length)){for(let r=t;r<e.length;r++){let t=e[r];if(t.type===$.UPDATE&&t.details){let e=t.details;if(e.event_class===`document_created`||e.event_class===`document_updated`){let t=b_(e.document_id),r=b_(e.updated_document_id)||t,a=e.title;if(r){let s=x_(e,t||r),l={id:r,title:a||`Document`,revisionRootId:s};n(e=>{let t=e.findIndex(e=>S_(e,l));if(t<0)return[...e,l];let n=e[t];if(n.id===l.id&&n.title===l.title&&n.revisionRootId===l.revisionRootId)return e;let r=[...e];return r[t]=l,r}),i(l.id),o(!0),e.event_class===`document_updated`&&c(e=>e+1)}}}}l.current=e.length-1}},[e]),{openDocuments:t,activeDocumentId:r,isDocPanelOpen:a,docRefreshKey:s,closeDocPanel:K(()=>{o(!1)},[]),closeDocument:K(e=>{n(t=>{let n=t.filter(t=>t.id!==e);return n.length===0?(o(!1),i(null)):i(t=>t===e?n[0].id:t),n})},[]),selectDocument:K(e=>{i(e)},[]),openDocInPanel:K(e=>{n(t=>t.some(t=>t.id===e)?t:[...t,{id:e,title:`Document`,revisionRootId:e}]),i(e),o(!0)},[]),updateDocumentTitle:K((e,t)=>{n(n=>n.map(n=>n.id===e?{...n,title:t}:n))},[])}}function w_(e){return e.type.startsWith(`image/`)}function T_(e){if(!(!w_(e)||typeof URL>`u`||!URL.createObjectURL))return URL.createObjectURL(e)}function E_(e){typeof URL<`u`&&URL.revokeObjectURL&&URL.revokeObjectURL(e)}function D_(e,t,n,r,i){let a=Vt.getFixedT(null,Bt),[o,s]=X(new Map),[c,l]=X(new Set),u=Y(new Set),d=Y(new Map),f=Y(t),p=Y(o);p.current=o;let m=Y(n);m.current=n;let h=K(e=>{let t=d.current.get(e);t&&(E_(t),d.current.delete(e))},[]);q(()=>{if(f.current!==t){f.current=t,d.current.forEach(E_),d.current.clear(),s(new Map);let e=new Set;u.current=e,l(e)}},[t]),q(()=>()=>{d.current.forEach(E_),d.current.clear()},[]);let g=J(()=>{let e=new Map;if(o.forEach((t,n)=>{c.has(n)||e.set(n,t)}),n.forEach((t,n)=>{if(t.consumed_at){e.delete(n);return}if(!c.has(n)){let r=o.get(n);e.set(n,{...t,artifact_path:t.artifact_path??r?.artifact_path,reference:t.reference??r?.reference,...r?.preview_url?{preview_url:r.preview_url}:{}})}}),i&&i.size>0)for(let[t,n]of e)(n.reference&&i.has(n.reference)||n.artifact_path&&i.has(n.artifact_path))&&e.delete(t);return e},[o,c,n,i]);return{processingFiles:g,hasProcessingFiles:J(()=>Array.from(g.values()).some(e=>e.status===Di.UPLOADING||e.status===Di.PROCESSING),[g]),handleFileUpload:K(async n=>{for(let i of n){let n=`file-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,o=`files/${i.name}`,c=T_(i);c&&d.current.set(n,c);let l={id:n,name:i.name,content_type:i.type||`application/octet-stream`,size:i.size,status:Di.UPLOADING,started_at:Date.now(),preview_url:c};s(e=>new Map(e).set(n,l));try{if(await e.agents.uploadArtifact(t,o,i),s(e=>{let t=new Map(e),r=t.get(n);return r&&(r.status=Di.PROCESSING,r.artifact_path=o,r.reference=`artifact:${o}`),t}),u.current.has(n))continue;await e.agents.sendSignal(t,`FileUploaded`,{id:n,name:i.name,content_type:i.type||`application/octet-stream`,reference:`artifact:${o}`,artifact_path:o})}catch(e){if(u.current.has(n))continue;s(t=>{let r=new Map(t),i=r.get(n);return i&&(i.status=Di.ERROR,i.error=e instanceof Error?e.message:`Upload failed`,i.completed_at=Date.now()),r}),r({status:`error`,title:a(`agent.uploadFailed`),description:e instanceof Error?e.message:`Failed to upload file`,duration:3e3})}}},[e,t,r,a]),removeProcessingFile:K(async n=>{l(e=>{if(e.has(n))return e;let t=new Set(e);return t.add(n),u.current=t,t}),s(e=>{if(!e.has(n))return e;let t=new Map(e);return t.delete(n),t}),h(n);try{await e.agents.sendSignal(t,`FileRemoved`,{id:n})}catch(e){r({status:`error`,title:a(`agent.removeFileFailed`),description:e instanceof Error?e.message:`Failed to remove file`,duration:3e3})}},[t,e,h,a,r]),clearProcessingFiles:K(()=>{d.current.forEach(E_),d.current.clear(),l(e=>{let t=new Set(e);for(let e of m.current.keys())t.add(e);for(let e of p.current.keys())t.add(e);return u.current=t,t}),s(new Map)},[])}}function O_({activeWorkstreams:r,onSelectWorkstream:i,className:a}){let{t:s}=Z(),[c,l]=X(!1),[u,d]=X(!1),f=ut(),p=J(()=>r.filter(e=>e.status===`running`||e.status===`canceling`),[r]),m=c?p:p.slice(0,3),h=Math.max(0,p.length-m.length),g=p.length>3;return q(()=>{g||l(!1)},[g]),p.length===0?null:t(`div`,{className:H(`mx-auto mb-2 w-full max-w-3xl px-1`,a),"data-agent-active-workstreams":!0,children:n(`output`,{className:`flex flex-col gap-1.5 rounded-2xl border border-border/70 bg-background/95 p-2 text-xs text-muted shadow-lg shadow-black/5`,"aria-live":`polite`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[n(`div`,{className:`flex min-w-0 items-center gap-2 px-1 font-medium`,children:[t(Zt,{className:`size-3.5 shrink-0 text-muted`,"aria-hidden":`true`}),t(`span`,{className:`truncate`,children:s(`agent.activeWorkstreams`,{count:p.length})})]}),n(o,{variant:`ghost`,size:`icon`,onClick:()=>d(!u),title:s(u?`agent.showActiveWorkstreams`:`agent.hideActiveWorkstreams`),children:[t(u?hn:un,{className:`size-4`}),s(u?`agent.showActiveWorkstreams`:`agent.hideActiveWorkstreams`)]})]}),u?null:n(e,{children:[t(`div`,{id:f,className:`flex flex-col gap-0.5`,children:m.map(r=>{let a=hl(r.workstream_id,r.interaction),s=n(e,{children:[t(`span`,{className:H(`size-1.5 shrink-0 rounded-full`,xl(r.status)),"aria-hidden":`true`}),t(`span`,{className:`truncate font-medium`,children:a}),r.phase&&t(`span`,{className:`truncate text-xs text-muted/75`,children:pl(r.phase)})]});return i?n(o,{type:`button`,variant:`ghost`,className:`h-auto min-w-0 justify-start gap-2 rounded-lg px-1 py-1 text-sm text-foreground/80`,title:a,onClick:()=>{l(!1),i(r.workstream_id)},children:[s,t(pn,{className:`ms-auto size-3.5 shrink-0 rtl:rotate-180`,"aria-hidden":`true`})]},r.launch_id||r.workstream_id):t(`div`,{className:`flex min-w-0 items-center gap-2 rounded-lg px-1 py-1 text-sm text-foreground/80`,title:a,children:s},r.launch_id||r.workstream_id)})}),g&&n(o,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-fit shrink-0 gap-1 rounded-xl px-2.5 text-xs text-muted`,"aria-expanded":c,"aria-controls":f,onClick:()=>l(e=>!e),children:[!c&&n(`span`,{children:[`+`,h]}),s(c?`agent.showLess`:`agent.showMore`),t(un,{className:H(`size-3.5 transition-transform`,c&&`rotate-180`),"aria-hidden":`true`})]})]})]})})}const k_=new ya({strict:!1,validateFormats:!1});function A_(e){if(e!==Ri.virtual_lb&&e!==Ri.virtual_mediator&&e!==Ri.test)return e}var j_=class{_listeners=new Set;snapshot;constructor(e){this.snapshot=new M_(e,this)}subscribe=e=>(this._listeners.add(e),()=>{this._listeners.delete(e)});getSnapshot=()=>this.snapshot;notify(){this._listeners.forEach(e=>{e()})}},M_=class e{vertesia;_interactive=!0;_debug_mode=!1;_non_blocking_subagents=!0;_checkpoint_tokens;_visibility;_user_channels;_collection;_disabled_mcp_collections;_start=!1;_preserveRunValues=!1;_interaction;_environment;_model=``;_model_options;_tool_names=[];_data;_mode=`start`;_scheduledWorkflowConfig;_interactionParamsSchema;_schemaVersion=0;_inputValidator;_store;constructor(e,t){this.vertesia=e,this._store=t}onStateChanged(){let e=this.clone();this._store.snapshot=e,this._store.notify()}clone(){let t=new e(this.vertesia,this._store);return t._interactionParamsSchema=this._interactionParamsSchema,t._schemaVersion=this._schemaVersion,t._interaction=this._interaction,t._data=this._data,t._environment=this._environment,t._model=this._model,t._model_options=this._model_options?{...this._model_options}:void 0,t._tool_names=[...this._tool_names],t._interactive=this._interactive,t._debug_mode=this._debug_mode,t._non_blocking_subagents=this._non_blocking_subagents,t._checkpoint_tokens=this._checkpoint_tokens,t._visibility=this._visibility,t._user_channels=this._user_channels?[...this._user_channels]:void 0,t._inputValidator=this._inputValidator,t._start=this._start,t._collection=this._collection,t._disabled_mcp_collections=this._disabled_mcp_collections?[...this._disabled_mcp_collections]:void 0,t._preserveRunValues=this._preserveRunValues,t._mode=this._mode,t._scheduledWorkflowConfig=this._scheduledWorkflowConfig,t}set mode(e){e!==this._mode&&(this._mode=e,e===`schedule`&&!this._scheduledWorkflowConfig&&(this._scheduledWorkflowConfig={name:``,description:``,cron_expression:`0 9 * * *`,timezone:`UTC`}),this.onStateChanged())}get mode(){return this._mode}set scheduledWorkflowConfig(e){this._scheduledWorkflowConfig=e,this.onStateChanged()}get scheduledWorkflowConfig(){return this._scheduledWorkflowConfig}updateScheduledWorkflowConfig(e){this._scheduledWorkflowConfig={...this._scheduledWorkflowConfig,...e},this.onStateChanged()}get interactive(){return this._interactive}set interactive(e){e!==this._interactive&&(this._interactive=e,this.onStateChanged())}get debug_mode(){return this._debug_mode}set debug_mode(e){e!==this._debug_mode&&(this._debug_mode=e,this.onStateChanged())}get non_blocking_subagents(){return this._non_blocking_subagents}set non_blocking_subagents(e){e!==this._non_blocking_subagents&&(this._non_blocking_subagents=e,this.onStateChanged())}get checkpoint_tokens(){return this._checkpoint_tokens}set checkpoint_tokens(e){e!==this._checkpoint_tokens&&(this._checkpoint_tokens=e,this.onStateChanged())}get visibility(){return this._visibility}set visibility(e){e!==this._visibility&&(this._visibility=e,this.onStateChanged())}get user_channels(){return this._user_channels}set user_channels(e){this._user_channels=e,this.onStateChanged()}get collection(){return this._collection}set collection(e){e!==this._collection&&(this._collection=e,this.onStateChanged())}get disabled_mcp_collections(){return this._disabled_mcp_collections}set disabled_mcp_collections(e){this._disabled_mcp_collections=e&&e.length>0?e:void 0,this.onStateChanged()}get search_scope(){return this._collection?Ci.Collection:void 0}async restoreConversation(e){let t=e.interaction;e.version&&(/^[a-fA-F0-9]{24}$/.test(t)||(t=`${t}@${e.version}`));let n=await this.vertesia.interactions.catalog.resolve(t),r=n.runtime?.environment||e.config?.environment,i=e.config?.model,a=await(r?this.vertesia.environments.retrieve(r).catch(()=>void 0):Promise.resolve(void 0));this._data=e.data,this.interaction=n,e.interactionParamsSchema!=null&&(this.interactionParamsSchema=e.interactionParamsSchema),this._tool_names=e.tool_names||[],this._interactive=e.interactive,this._debug_mode=e.debug_mode??!1,this._non_blocking_subagents=e.non_blocking_subagents??!0,this._checkpoint_tokens=e.checkpoint_tokens,this._user_channels=e.user_channels,this._disabled_mcp_collections=e.disabled_mcp_collections,this._model_options=e.config?.model_options,this.collection=e.collection_id??void 0,this._model_options=e.config?.model_options,this.environment=a,i&&(this._model=i),this.onStateChanged()}get interaction(){return this._interaction}set interaction(e){if(e?.id!==this._interaction?.id){if(this._interaction=e,this.interactionParamsSchema=e?Hi(e.prompts):void 0,this._inputValidator=void 0,e&&!this._preserveRunValues&&(this._model_options=e.model_options,e.runtime?.environment)){let t=e.runtime.environment;this.vertesia.environments.retrieve(t).then(e=>this.environment=e)}this.onStateChanged()}}get environment(){return this._environment}set environment(e){if(e?.id!==this._environment?.id){if(this._environment=e,!this._preserveRunValues){let t=e?A_(e.provider):void 0,n=this.interaction?.runtime?.model;this._model=n&&t&&Gi(n,t)?n:e?.default_model&&t&&Gi(e.default_model,t)?e.default_model:``}this.onStateChanged()}}get model(){return this._model}set model(e){e!==this._model&&(this._model=e||``,this.onStateChanged())}get model_options(){return this._model_options}set model_options(e){JSON.stringify(e)!==JSON.stringify(this._model_options)&&(this._model_options=e,this.onStateChanged())}get tool_names(){return this._tool_names}set tool_names(e){this._tool_names=e,this.onStateChanged()}get data(){return this._data}set data(e){this._data=e,this.onStateChanged()}set run(e){console.log(`run`,e),this.onStateChanged()}set start(e){this._start!==e&&(this._start=e,this.onStateChanged())}markStarted(){this.start=!0}setMode(e){this.mode=e}setInteraction(e){this.interaction=e}setEnvironment(e){this.environment=e}setModel(e){this.model=e}setModelOptions(e){this.model_options=e}setToolNames(e){this.tool_names=e}setCollection(e){this.collection=e}setDisabledMcpCollections(e){this.disabled_mcp_collections=e}setInteractive(e){this.interactive=e}setDebugMode(e){this.debug_mode=e}setUserChannels(e){this.user_channels=e}setCheckpointTokens(e){this.checkpoint_tokens=e}setVisibility(e){this.visibility=e}setData(e){this.data=e}setDraftData(e){this._data=e}setPreserveRunValues(e){this.preserveRunValues=e}get start(){return this._start}get preserveRunValues(){return this._preserveRunValues}set preserveRunValues(e){this._preserveRunValues=e}get schemaVersion(){return this._schemaVersion}get interactionParamsSchema(){return this._interactionParamsSchema}set interactionParamsSchema(e){this._interactionParamsSchema!==e&&(this._interactionParamsSchema=e,this._schemaVersion+=1,e&&(this._data=this.initializeBooleanDefaults(this._data||{},e)),this.onStateChanged())}initializeBooleanDefaults(e,t){if(!t.properties)return e;let n={...e};for(let[e,r]of Object.entries(t.properties)){let t=r;t.type===`boolean`&&n[e]===void 0?n[e]=!1:t.type===`object`&&t.properties&&(n[e]=this.initializeBooleanDefaults(n[e]||{},t))}return n}reset(){if(this._start=!1,this._interactive=!0,this._debug_mode=!1,this._non_blocking_subagents=!0,this._checkpoint_tokens=void 0,this._visibility=void 0,this._user_channels=void 0,this._collection=void 0,this._disabled_mcp_collections=void 0,this._preserveRunValues=!1,this._model=``,this._model_options=void 0,this._environment=void 0,this._tool_names=[],this._interaction=void 0,this._data=void 0,this._interactionParamsSchema=null,this._inputValidator=void 0,this.model=void 0,this.environment=void 0,this.onStateChanged(),location.hash){let e=window.location.origin+window.location.pathname+window.location.search;history.replaceState(null,``,e),location.hash=``}}validateInput(){if(!this._interactionParamsSchema)return{isValid:!0};(!this._inputValidator||this._inputValidator.schema!==this._interactionParamsSchema)&&(this._inputValidator={validate:k_.compile(this._interactionParamsSchema),schema:this._interactionParamsSchema});let e=this._data||{};return this._inputValidator.validate(e)?{isValid:!0}:{isValid:!1,errorMessage:this._inputValidator.validate.errors?this._inputValidator.validate.errors.map(e=>`${e.instancePath}: ${e.message}`).join(`, `):`Invalid payload data`}}};const N_=ot(void 0);function P_({children:e}){let{client:n}=Q(),[r]=X(()=>new j_(n)),i=ft(r.subscribe,r.getSnapshot);return t(N_.Provider,{value:i,children:e})}function F_(){let e=lt(N_);if(!e)throw Error(`usePayloadBuilder must be used within a PayloadProvider`);return e}function I_({title:e,variant:r=`full`,isTerminal:i=!1,onClose:a,isModal:s,agentRunId:c,workflowRunId:l,viewMode:u,onViewModeChange:d,showPlanPanel:f,showPlanButton:p=!0,onTogglePlanPanel:m,showPlaybackButton:h=!1,isPlaybackEnabled:g=!1,onTogglePlayback:_,onDownload:v,onExportFixture:y,resetWorkflow:b,onExportPdf:x,onShowDetails:S,allowWorkflowControl:C=!0,onClone:w,isReceivingChunks:T=!1,className:E}){let{t:D}=Z(),O=r===`compact`,k=u===`sliding`?`stacked`:`sliding`,A=D(`agent.verbose`),j=D(`agent.summary`),M=k===`stacked`?A:j,N=n(`div`,{className:H(O?`flex flex-row items-center gap-1 lg:flex-col`:`flex justify-end items-center gap-2 ms-auto`),children:[p&&t(`div`,{className:`relative`,children:n(o,{size:r===`compact`?`icon`:`sm`,variant:f?`primary`:`ghost`,onClick:m,className:H(`transition-all duration-200 rounded-md`,r===`compact`&&`size-8 rounded-lg`),title:D(`agent.toggleRightSidebar`),children:[t(Cn,{className:H(`size-4`,r===`full`&&`me-1.5`)}),r===`full`?t(`span`,{className:`font-medium text-xs`,children:D(f?`agent.hideSidebar`:`agent.showSidebar`)}):t(`span`,{className:`sr-only`,children:D(f?`agent.hideSidebar`:`agent.showSidebar`)})]})}),O?t(o,{variant:`ghost`,size:`icon`,onClick:()=>d(k),className:`size-8 rounded-lg`,title:M,"aria-label":M,children:t(k===`stacked`?Hr:br,{className:`size-4`})}):n(`div`,{className:`flex items-center gap-1 bg-muted rounded p-0.5 mt-2 lg:mt-0`,children:[n(o,{variant:u===`stacked`?`outline`:`ghost`,size:`xs`,onClick:()=>d(`stacked`),"aria-pressed":u===`stacked`,className:`gap-1.5`,children:[t(Hr,{className:`size-3.5`}),A]}),n(o,{variant:u===`sliding`?`outline`:`ghost`,size:`xs`,onClick:()=>d(`sliding`),"aria-pressed":u===`sliding`,className:`gap-1.5`,children:[t(br,{className:`size-3.5`}),j]})]}),h&&_&&n(o,{type:`button`,size:r===`compact`?`icon`:`sm`,variant:g?`primary`:`ghost`,onClick:_,"aria-pressed":g,title:D(`agent.rewind.label`),className:H(`transition-all duration-200 rounded-md`,r===`compact`&&`size-8 rounded-lg`),children:[t(nn,{className:H(`size-4`,r===`full`&&`me-1.5`)}),r===`full`?t(`span`,{className:`font-medium text-xs`,children:D(`agent.rewind.label`)}):t(`span`,{className:`sr-only`,children:D(`agent.rewind.label`)})]}),b&&t(o,{type:`button`,size:r===`compact`?`icon`:`sm`,variant:`ghost`,onClick:b,title:D(`agent.startNewConversation`),className:H(`transition-all duration-200 rounded-md`,r===`compact`&&`size-8 rounded-lg`),children:t(vr,{className:H(`size-4`,r===`full`&&`me-1.5`)})}),t(L_,{compact:O,agentRunId:c,workflowRunId:l,isModal:s,isTerminal:i,onClose:a,onDownload:v,onExportFixture:y,resetWorkflow:b,onExportPdf:x,onShowDetails:S,allowWorkflowControl:C,onClone:w}),a&&!s&&t(o,{size:`xs`,variant:`ghost`,onClick:a,"aria-label":D(`agent.close`),children:t(_i,{className:`size-4`})})]});return r===`compact`?t(P_,{children:t(`div`,{className:H(`inline-flex items-center rounded-xl border border-border/70 bg-background/90 p-1 shadow-lg shadow-black/10 backdrop-blur`,E),children:N})}):t(P_,{children:n(`div`,{className:H(`flex flex-wrap items-center justify-between py-1.5 px-2 border-b shadow-sm flex-shrink-0`,E),children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n(`div`,{className:`flex items-center gap-1`,children:[t(Zt,{className:`size-5 text-muted`}),t(`span`,{className:`font-medium`,children:e})]}),n(`span`,{className:`text-xs text-muted ms-1 flex items-center gap-1.5`,children:[`(Agent Run ID: `,c,`)`,t(`span`,{className:H(`w-2 h-2 rounded-full transition-colors duration-200`,T?`bg-purple-500 shadow-[0_0_6px_2px_rgba(168,85,247,0.6)]`:`bg-gray-400`)})]})]}),N]})})}function L_({compact:e=!1,agentRunId:r,workflowRunId:i,isModal:a,isTerminal:s,onClose:c,onDownload:l,onExportFixture:u,resetWorkflow:d,onExportPdf:f,onShowDetails:p,allowWorkflowControl:m=!0,onClone:h}){let{t:g}=Z(),_=Xe(),{client:v}=Q(),y=F_(),{router:b}=va(),x=async()=>{try{return await v.agents.terminate(r,`cancel`),_({status:`success`,title:g(`agent.workflowCancelled`),duration:2e3}),y.reset(),d?.(),!0}catch{return _({status:`error`,title:g(`agent.failedToCancelWorkflow`),duration:2e3}),!1}},S=async()=>{try{let e=await v.agents.fork(r);_({status:`success`,title:g(`agent.conversationCloned`),duration:2e3}),h?.(e)}catch{_({status:`error`,title:g(`agent.failedToCloneConversation`),duration:2e3})}},C=e=>{let t=e.startsWith(`/`)?b.getTopRouter().navigator.addStickyParams(e):e;return window.open(t,`_blank`),t};return t(w,{align:`right`,trigger:t(o,{size:e?`icon`:`xs`,variant:`ghost`,title:g(`agent.moreActions`),className:e?`size-8 rounded-lg`:void 0,children:t(Tr,{className:`size-4`})}),children:n(ne,{label:`Actions`,children:[a&&n(B,{onClick:()=>C(`/store/agent-runner/${r}`),children:[t(Pn,{className:`size-3.5 text-muted`}),` `,g(`agent.openInNewTab`)]}),n(B,{onClick:()=>{navigator.clipboard.writeText(r),_({status:`success`,title:g(`agent.agentRunIdCopied`),duration:2e3})},children:[t(Dn,{className:`size-3.5 text-muted`}),` `,g(`agent.copyAgentRunId`)]}),n(B,{onClick:()=>{navigator.clipboard.writeText(i),_({status:`success`,title:g(`agent.workflowRunIdCopied`),duration:2e3})},children:[t(Dn,{className:`size-3.5 text-muted`}),` `,g(`agent.copyWorkflowRunId`)]}),p&&n(B,{onClick:p,children:[t(ir,{className:`size-3.5 text-muted`}),` `,g(`agent.details`)]}),n(B,{onClick:()=>{l?l():Rl(v,r).then(e=>window.open(e,`_blank`))},children:[t(jn,{className:`size-3.5 text-muted`}),` `,g(`agent.downloadConversation`)]}),f&&n(B,{onClick:f,children:[t(jn,{className:`size-3.5 text-muted`}),` `,g(`agent.exportAsPdf`)]}),u&&n(B,{onClick:u,children:[t(jn,{className:`size-3.5 text-muted`}),` `,g(`agent.rewind.exportFixture`)]}),c&&a&&n(B,{onClick:c,children:[t(_i,{className:`size-3.5 text-muted`}),` `,g(`agent.close`)]}),h&&n(B,{onClick:S,children:[t(Zn,{className:`size-3.5 text-muted`}),` `,g(`agent.cloneConversation`)]}),m&&!s&&n(B,{onClick:x,variant:`destructive`,children:[t(_i,{className:`size-3.5`}),` `,g(`agent.cancelWorkflow`)]})]})})}function R_(e){return typeof e==`object`&&!!e&&`value`in e}function z_(e){return R_(e)?e.value:e}function B_(e){if(e.type===`stringList`)return e.value.map(e=>typeof e==`string`?e:z_(e));if(e.multiple)return e.value.map(z_);let t=e.value[0];return t===void 0?void 0:z_(t)}function V_(e,t,n){e.query[t]=n}function H_(e){let t=new Set(e);return e=>t.has(e)}function U_({buckets:e,name:r,placeholder:a}){let o=e.map(e=>({label:`(${e.count})`,value:e._id}));return{name:r,placeholder:a||`${r.charAt(0).toUpperCase()+r.slice(1)}`,options:o,type:`select`,labelRenderer:r=>{let a=e.find(e=>e._id===r),o=a?.name||r,s=`success`;if(a?.status)switch(a.status){case ki.published:s=`success`;break;case ki.archived:s=`destructive`;break;case ki.code:s=`info`}let c=a?.version&&a?.status?`v${a.version} ${a.status===ki.unknown?``:a.status}`:a?.status||(a?.version?`v${a.version}`:``);return n(`div`,{className:`w-full flex items-center justify-between`,children:[n(`div`,{className:`flex flex-row flex-wrap items-center gap-2 min-w-0 flex-1`,children:[t(`span`,{className:`text-sm truncate`,children:o}),c&&t(i,{variant:s,className:`text-xs w-fit`,children:c})]}),(a?.count??0)>0&&n(`span`,{className:`ms-2 text-xs shrink-0`,children:[`(`,a?.count,`)`]})]})},filterBy:(t,n)=>(e.find(e=>e._id===t)?.name||t).toLowerCase().includes(n.toLowerCase())}}function W_(e){return`${e._id} (${e.count})`}function G_(e){return`${e.name} (${e.count})`}function K_({buckets:e,name:t,placeholder:n,type:r=`select`,multiple:i=!1}){return{name:t,options:e.map(e=>({label:W_(e),value:e._id})),type:r,multiple:i,placeholder:`${n??`${t.charAt(0).toUpperCase()+t.slice(1)}`}`,allowCreate:!1}}function q_({buckets:e,name:t,placeholder:n,type:r,multiple:i}){return K_({buckets:e,name:t,placeholder:n,type:r,multiple:i})}const J_={},Y_={},X_={};function Z_(e){return typeof e==`object`&&!!e&&`status`in e&&e.status===404}function Q_(e,t,n){let r=e[t];return r||(r=n().catch(n=>{throw Z_(n)||delete e[t],n}),e[t]=r),r}function $_(e){let{client:t}=Q();return U(()=>Q_(J_,e,()=>t.users.retrieve(e)),{deps:[e],condition:()=>!!e})}function ev(e){let{client:t}=Q();return U(()=>Q_(Y_,e,()=>t.iam.groups.retrieve(e)),{deps:[e],condition:()=>!!e})}function tv(e){let{client:t}=Q();return U(()=>Q_(X_,e,()=>t.apikeys.retrieve(e)),{deps:[e],condition:()=>!!e})}function nv(){return t(`div`,{className:`size-8`})}function rv({showTitle:e=!1,size:i=`md`}){let{t:a}=Z();return t(hv,{title:a(`user.systemUser`),description:a(`user.systemUserDescription`),children:n(`div`,{className:`flex gap-2 items-center`,children:[t(r,{src:`/icon.svg`,size:i}),e&&t(`div`,{className:`text-sm font-semibold ps-2`,children:a(`user.systemUser`)})]})})}function iv({showTitle:e=!1,size:r=`md`}){let{t:i}=Z();return t(hv,{title:i(`user.allProjectMembers`),description:i(`user.allProjectMembersDescription`),children:n(`div`,{className:`flex gap-2 items-center`,children:[t(ui,{className:`size-4`,size:r}),e&&t(`div`,{className:`text-sm font-semibold ps-2`,children:i(`user.allProjectMembers`)})]})})}function av({accountId:i,showTitle:a=!1,size:o=`md`}){let{t:s}=Z(),c=n(e,{children:[t(`div`,{children:s(`user.serviceAccountDescription`)}),n(`div`,{className:`text-muted text-sm`,children:[t(`span`,{className:`font-semibold`,children:`ID:`}),` `,i]})]});return t(hv,{title:s(`user.serviceAccount`),description:c,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(r,{src:`/cloud.svg`,name:`SA`,color:`bg-amber-500`,className:`px-[5px] text-white`,size:o}),a&&n(`div`,{className:`text-sm font-semibold ps-2 truncate`,children:[s(`user.serviceAccount`),` : ~`,i.slice(-6)]})]})})}function ov({email:i,showTitle:a=!1,size:o=`md`}){let{t:s}=Z(),c=n(e,{children:[t(`div`,{children:s(`user.agentOnBehalfOf`)}),n(`div`,{className:`text-muted text-sm`,children:[t(`span`,{className:`font-semibold`,children:`Email:`}),` `,i]})]});return t(hv,{title:`Email Agent`,description:c,children:n(`div`,{className:`flex items-center gap-2`,children:[n(`div`,{className:`flex items-center -space-x-2`,children:[t(r,{src:`/cloud.svg`,color:`bg-amber-500`,className:`px-[5px] text-white border-2 border-white dark:border-gray-800`,size:o}),t(r,{name:i,size:o,className:`border-2 border-white dark:border-gray-800`})]}),a&&n(`div`,{className:`text-sm font-semibold truncate`,children:[`Agent (`,i,`)`]})]})})}function sv({agentId:i,onBehalfOfType:a,onBehalfOfId:o,showTitle:s=!1,size:c=`md`,isScheduleAgent:l=!1}){let{t:u}=Z(),d=a===`user`&&o,f=a===`apikey`&&o,p=$_(o||``),m=tv(o||``),h=d?p.data:void 0,g=f?m.data:void 0,_=i.slice(-6),v=h?u(`user.agentOnBehalfOf`):g?u(`user.agentOnBehalfOfApiKey`):`${u(`user.serviceAccount`)}~${_}`,y=l?u(`user.schedule`,{title:v}):v,b=n(`div`,{className:`space-y-2`,children:[h&&n(`div`,{className:`flex items-center gap-2`,children:[t(r,{src:h.picture,name:h.name,size:`sm`}),n(`div`,{children:[t(`div`,{className:`font-medium`,children:h.name||h.email}),h.email&&h.name&&t(`div`,{className:`text-xs text-muted`,children:h.email})]})]}),g&&n(`div`,{children:[t(`div`,{className:`font-medium`,children:g.name}),n(`div`,{className:`text-xs text-muted-foreground`,children:[`Key ID: `,g.id]})]}),!h&&!g&&n(e,{children:[t(`div`,{children:u(`user.serviceAccountDescription`)}),n(`div`,{className:`text-gray-800 dark:text-gray-500 text-sm`,children:[t(`span`,{className:`font-semibold`,children:`ID:`}),` `,i]})]})]});return t(hv,{title:y,description:b,children:n(`div`,{className:`flex items-center gap-2`,children:[n(`div`,{className:`flex items-center -space-x-2`,children:[t(r,{src:`/cloud.svg`,color:`bg-amber-500`,className:`px-[5px] text-white border-2 border-white dark:border-gray-800`,size:c}),h&&t(r,{src:h.picture,name:h.name,size:c,className:`border-2 border-white dark:border-gray-800`}),g&&t(r,{name:`API`,color:`bg-gray-400`,size:c,className:`border-2 border-white dark:border-gray-800`})]}),s&&t(`div`,{className:`text-sm font-semibold truncate`,children:h?`Agent (${h.name||h.email})`:g?`Agent (${g.name})`:v})]})})}function cv({title:e=`Error`,error:n,showTitle:r=!1,size:i=`md`}){return t(dv,{title:e,message:Ve(n),color:`bg-red-500`,showTitle:r,size:i})}function lv({showTitle:e=!1,size:n=`md`,color:r}){let{t:i}=Z();return t(dv,{title:i(`user.unknownUser`),message:i(`user.unknownUserDescription`),color:r,showTitle:e,size:n})}function uv({userRef:e,showTitle:n=!1,size:r=`md`}){let{t:i}=Z();if(!e)return t(dv,{title:i(`user.unknownUser`),message:i(`user.unknownUserDescription`),showTitle:n,size:r});let a=e.split(`:`),o=a[0];switch(o){case Pi.User:return t(pv,{userId:a[1],showTitle:n,size:r});case Pi.Group:return t(fv,{userId:a[1],showTitle:n,size:r});case`system`:return t(rv,{showTitle:n,size:r});case Pi.ServiceAccount:return t(av,{accountId:a.slice(1).join(`:`),showTitle:n,size:r});case Pi.Agent:{let e,i,o;return a[1]===`agent`?(e=a.slice(2,5).join(`:`),i=a[5],o=a[6]):(e=a.slice(1,4).join(`:`),i=a[4],o=a[5]),t(sv,{agentId:e,onBehalfOfType:i,onBehalfOfId:o,showTitle:n,size:r})}case Pi.Schedule:{let e=a[2]===`agent`?a.slice(3,6).join(`:`):`unknown-agent`,i=a[6],o=a[7];return t(sv,{agentId:e,onBehalfOfType:i,onBehalfOfId:o,showTitle:n,size:r,isScheduleAgent:!0})}case`email`:return t(ov,{email:a[1],showTitle:n,size:r});case Pi.ApiKey:return t(mv,{keyId:a[1],size:r,showTitle:n});case`project`:if(a[1]===`*`)return t(iv,{showTitle:n,size:r});break;default:return t(cv,{title:i(`user.unknownUser`),error:`Invalid user ref type: ${o}`,showTitle:n,size:r})}}function dv({title:e,message:i,color:a,size:o=`md`,showTitle:s=!1}){return t(hv,{title:e,description:i,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(r,{color:a,size:o}),s&&t(`div`,{className:`text-sm font-semibold ps-1`,children:e})]})})}function fv({userId:e,showTitle:r=!1,size:i=`md`}){let{t:a}=Z(),{data:o,error:s}=ev(e);if(s)return Z_(s)?t(lv,{showTitle:r,size:i,color:`bg-indigo-500`}):t(cv,{title:a(`user.failedToFetchGroup`),error:s,showTitle:r,size:i});if(!o)return t(nv,{});let c=n(`div`,{className:`space-y-1`,children:[o.description&&t(`div`,{className:`text-sm`,children:o.description}),t(`div`,{className:`text-xs text-muted-foreground`,children:a(`user.groupId`,{id:o.id})}),o.tags&&o.tags.length>0&&t(`div`,{className:`flex flex-wrap gap-1`,children:o.tags.map(e=>t(`span`,{className:`px-1.5 py-0.5 bg-muted rounded text-xs`,children:e},e))})]});return t(hv,{title:o.name||a(`user.unnamedGroup`),description:c,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(li,{className:`size-6 text-indigo-500`,size:i}),r&&t(`div`,{className:`text-sm font-semibold ps-2`,children:o.name||a(`user.unnamedGroup`)})]})})}function pv({userId:e,showTitle:i=!1,size:a=`md`}){let{t:o}=Z(),{data:s,error:c}=$_(e);if(c)return Z_(c)?t(lv,{showTitle:i,size:a,color:`bg-indigo-500`}):t(cv,{title:o(`user.failedToFetchUser`),error:c,showTitle:i,size:a});if(!s)return t(nv,{});let l=t(`div`,{className:`truncate`,title:s.email,children:s.email});return t(hv,{title:s.name||s.email||s.username||o(`user.unknown`),description:l,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(r,{src:s.picture,name:s.name,color:`bg-indigo-500`,size:a}),i&&t(`div`,{className:`text-sm font-semibold ps-2`,children:s.name||s.email||s.username||o(`user.unknown`)})]})})}function mv({keyId:e,showTitle:i=!1,size:a=`md`}){let{t:o}=Z(),{data:s,error:c}=tv(e);if(c)return Z_(c)?t(lv,{showTitle:i,size:a,color:`bg-pink-500`}):t(cv,{title:o(`user.failedToFetchApiKey`),error:c,showTitle:i,size:a});if(!s)return t(nv,{});let l=o(`user.privateKey`),u=t(r,{name:`PK`,color:`bg-pink-500`,size:a}),d=n(Ne,{className:`dark:bg-gray-800 dark:text-gray-200 table-fixed w-full`,children:[n(`tr`,{children:[t(`td`,{className:`font-semibold w-20`,children:o(`user.key`)}),t(`td`,{className:`truncate max-w-0`,children:s?.name})]}),n(`tr`,{children:[t(`td`,{className:`font-semibold w-20`,children:o(`user.account`)}),t(`td`,{className:`truncate max-w-0`,children:s?.account})]}),n(`tr`,{children:[t(`td`,{className:`font-semibold w-20`,children:o(`user.project`)}),t(`td`,{className:`truncate max-w-0`,children:s?.project.name})]})]});return t(hv,{title:l,description:d,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[u,i&&t(`div`,{className:`text-sm font-semibold`,children:s?.name||s?.account||s?.project.name||o(`user.unknown`)})]})})}function hv({title:e,description:r,children:i}){return n(de,{hover:!0,children:[t(pe,{className:`cursor-pointer flex items-center inline-block`,children:t(`div`,{children:i})}),t(fe,{align:`center`,sideOffset:8,side:`right`,children:n(`div`,{className:`flex flex-col gap-1 rounded-md shadow-md p-2`,children:[t(`div`,{className:`text-md font-semibold`,children:e}),r]})})]})}function gv({buckets:e,name:r,placeholder:i}){let a=e.map(e=>({value:e._id,label:`(${e.count})`}));return{name:r,placeholder:i||`${r.charAt(0).toUpperCase()+r.slice(1)}`,options:a,labelRenderer:r=>{if(r===`Unknown User`||!r)return`Unknown User (${e.find(e=>e._id===r)?.count||0})`;let i=e.find(e=>e._id===r);return n(`div`,{className:`flex items-center w-full gap-2`,children:[t(`div`,{className:`flex-1 min-w-0 flex items-center truncate`,children:t(uv,{userRef:r,showTitle:!0,size:`sm`})}),n(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`(`,i?.count||0,`)`]})]})}}}function _v({buckets:e,name:t,placeholder:n}){return gv({buckets:e,name:t,placeholder:n})}const vv=H_([`id`,`run_kind`,`interaction`,`status`,`initiated_by`,`start`,`end`]);function yv(e){let t=[];return t.push({name:`id`,placeholder:`Agent Run ID`,type:`text`,multiple:!1}),t.push(q_({buckets:e.kinds||[],name:`run_kind`,placeholder:`Kind`})),t.push(U_({buckets:e.interactions||[],name:`interaction`,placeholder:`Interaction`})),t.push(q_({buckets:e.statuses||[],name:`status`,placeholder:`Status`})),t.push(_v({buckets:e.initiated_by||[],name:`initiated_by`,placeholder:`Initiated By`})),t.push({name:`start`,placeholder:`Started After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Started Before`,type:`date`,multiple:!1}),t}function bv(e){return t=>{e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!vv(t.name))return;let n=t.name;V_(e,n,B_(t))}}),e.search()}}function xv({facets:e,search:r,selectionCount:i,actions:a,filters:s,setFilters:c,filterGroups:l}){let[u,d]=X([]),f=s??u,p=c??d,m=Y(!1),h=Y(typeof window<`u`&&!!new URLSearchParams(window.location.search).get(`filters`)),g=yv(e),_=l??g,v=J(()=>bv(r),[r]);return q(()=>{if(!m.current){m.current=!0;return}if(h.current){h.current=!1;return}v(f)},[f,v]),t(I,{filterGroups:_,filters:f,setFilters:p,children:n(`div`,{className:`gap-2 items-center w-full`,children:[n(`div`,{className:`flex justify-between mb-1`,children:[t(P,{}),n(`div`,{className:`flex justify-end`,children:[!i&&t(`div`,{className:`flex items-center justify-between px-2 py-1`,children:t(`div`,{className:`text-sm text-muted-foreground`,children:r.initialized?`${r.totalCount} runs`:`Loading runs...`})}),a&&a.length>0?t(`div`,{className:`flex items-center gap-2 mb-1 me-2`,children:a.map((e,n)=>t(`div`,{children:e},`action-${n}`))}):null,t(o,{onClick:()=>{r.search()},variant:`outline`,title:`Refresh`,children:t(zr,{className:`size-5`})})]})]}),f.length>0&&n(`div`,{className:`flex items-center gap-2 mb-1`,children:[t(N,{}),t(F,{})]})]})})}var Sv=class{types;map={};constructor(e){this.types=e,e.sort((e,t)=>e.name.localeCompare(t.name));for(let t of e)this.map[t.id]=t}getType(e){return this.map[e]}getTypeLayout(e){let t=this.map[e];return t?t.table_layout:void 0}getTypeName(e){let t=this.map[e];return t?t.name:void 0}};const Cv=ot({registry:void 0,isLoading:!1,load:()=>Promise.resolve(),reload:()=>Promise.resolve()});function wv({children:e}){let{store:n,project:r}=Q(),[i,a]=X(),[o,s]=X(!1),c=Y(!1),l=Y(r?.id),u=K(async()=>{if(!(!r||c.current)){c.current=!0,s(!0);try{let e=await n.types.catalog.list({layout:!0});a(new Sv(e))}catch(e){console.error(`Failed to fetch types`,e)}finally{s(!1),c.current=!1}}},[n,r]),d=K(async()=>(c.current=!1,u()),[u]);return q(()=>{l.current!==r?.id&&(l.current=r?.id,a(void 0),c.current=!1)}),t(Cv.Provider,{value:{registry:i,isLoading:o,load:u,reload:d},children:e})}function Tv(){let e=lt(Cv);return q(()=>{!e.registry&&!e.isLoading&&e.load()},[e.registry,e.isLoading,e.load]),e}const Ev=H_([`name`,`types`]);function Dv(e){let{registry:t}=Tv(),n=[];if(n.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t){let e=t.types.map(e=>({label:e.name,value:e.id})),r={name:`types`,placeholder:`Type`,type:`select`,multiple:!0,options:e,filterBy:(t,n)=>e.find(e=>e.value===t)?.label?.toLowerCase().includes(n.toLowerCase())??!1};n.push(r)}return n}function Ov(e){return t=>{if(t.length===0){e.clearFilters(!0);return}e.clearFilters(!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!Ev(t.name))return;let n=t.name;V_(e,n,B_(t))}}),e.search()}}function kv({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=X([]),l=Dv(e),u=Ov(r),d=i!==void 0&&a!==void 0;return t(I,{filterGroups:o??l,filters:d?i:s,setFilters:e=>{if(d){a(e);return}let t=typeof e==`function`?e(s):e;c(t),u(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function Av({buckets:e,typeRegistry:r,type:i=`select`,multiple:a=!1}){let o=new Map;return r||console.warn(`Type names cannot be resolved`),e.forEach(e=>{let t,n=e._id;e._id==null?(n=`Document`,t=`Document`):(t=r?.getTypeName(e._id),t||=(console.warn(`Content Object Type not found`,e._id),e._id)),o.set(n,{name:t,count:e.count})}),{name:`types`,placeholder:`Types`,type:i,multiple:a,options:e.map(e=>{let t=e._id,n=t||`Document`,r=o.get(n);return{value:t,label:r?`${r.name} (${r.count})`:`Unknown (${e.count})`}}),labelRenderer:e=>{let r=o.get(e);return r?n(`div`,{className:`w-full flex items-center`,children:[t(`span`,{className:`text-sm truncate`,children:r.name}),n(`span`,{className:`ms-2 text-xs`,children:[`(`,r.count,`)`]})]}):(console.warn(`Type data not found for ${e}`),e)},filterBy:(e,t)=>{let n=o.get(e);return n?n.name.toLowerCase().includes(t.toLowerCase()):(console.warn(`Type name not found for ${e}`),!1)}}}const jv=[`id`,`name`,`types`,`status`],Mv=[`tags`,`created_at`,`updated_at`],Nv=H_(jv),Pv=new Set(Mv);function Fv(e){return Pv.has(e)}function Iv(e){return Array.isArray(e)?e:[]}function Lv(e){let{registry:t}=Tv(),n=[];if(n.push({placeholder:`ID`,name:`id`,type:`text`,options:[]}),n.push({placeholder:`Name`,name:`name`,type:`text`,options:[]}),e.type){let r=Av({buckets:Iv(e.type),typeRegistry:t,type:`select`,multiple:!0});n.push(r)}if(e.status){let t=q_({buckets:Iv(e.status),name:`status`,placeholder:`Status`,type:`select`,multiple:!0});n.push(t)}return e.tags&&n.push({name:`tags`,placeholder:`Tags`,type:`stringList`,options:Iv(e.tags).map(e=>({label:e._id,value:e._id}))}),n.push({name:`created_at`,placeholder:`Created Date`,type:`date`,multiple:!0,options:[]}),n.push({name:`updated_at`,placeholder:`Updated Date`,type:`date`,multiple:!0,options:[]}),n}function Rv(e){return t=>{if(t.length===0){e.clearFilters();return}e.clearFilters(!1),t.forEach(t=>{if(t.value&&t.value.length>0){let n=t.name,r;if(t.type===`date`&&t.multiple){if(Array.isArray(t.value)&&t.value.length>0){if(t.value.length===1){let e=z_(t.value[0]);r={gte:e,lte:e}}else t.value.length===2&&(r={gte:z_(t.value[0]),lte:z_(t.value[1])})}}else r=B_(t);Nv(n)?V_(e,n,r):Fv(n)&&r!==void 0&&(e.query.match={...e.query.match,[n]:r})}}),e.search()}}function zv({facets:e,search:r}){let[i,a]=X([]),o=Lv(e),s=Rv(r),c=qe();return t(I,{filterGroups:o,filters:i,setFilters:e=>{let t=typeof e==`function`?e(i):e;a(t),s(t)},inModal:c,children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function Bv({search:e,buckets:n,placeholder:r=`All Environments`,className:i}){let{client:a}=Q(),[o,s]=X([]),c=e.getFilterValue(`environment`),l=t=>{e.setFilterValue(`environment`,t?._id)};q(()=>{if(a){let e=n.map(async e=>{let t;return await a.environments.retrieve(e._id).then(e=>{t=e.name}).catch(()=>{t=`${e._id} (deleted)`}),t||=e._id,{...e,name:t}});Promise.all(e).then(e=>{e.sort((e,t)=>e.name.localeCompare(t.name)),s(e)})}},[n,a]);let u=o?.find(e=>e._id===c);return t(be,{filterBy:`name`,className:i,isClearable:!0,optionLabel:G_,options:o,value:u,onChange:l,by:`_id`,placeholder:r})}const Vv=H_([`name`,`prompt`,`model`,`tags`]);function Hv(e){let t=[];return t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t.push({name:`prompt`,placeholder:`Prompt Name`,type:`text`,multiple:!1}),t.push({name:`model`,placeholder:`Model`,type:`text`,multiple:!1}),t.push({name:`tags`,placeholder:`Tags`,type:`stringList`,multiple:!0}),t}function Uv(e){return t=>{if(t.length===0){e.clearFilters(!0,!0);return}e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!Vv(t.name))return;let n=t.name;V_(e,n,B_(t))}}),e.search(!0)}}function Wv({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=X([]),l=Hv(e),u=Uv(r),d=i!==void 0&&a!==void 0;return t(I,{filterGroups:o??l,filters:d?i:s,setFilters:e=>{if(d){a(e);return}let t=typeof e==`function`?e(s):e;c(t),u(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function Gv(e){let t=[];return t.push(q_({buckets:e.statuses||[],name:`status`,placeholder:`Status`,multiple:!1})),t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function Kv({facets:e,filters:r,setFilters:i}){let a=Gv(e);return t(I,{filterGroups:a,filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function qv(e){let t=[];return t.push(q_({buckets:e.statuses||[],name:`status`,placeholder:`Status`,multiple:!0})),t.push(_v({buckets:e.started_by||[],name:`started_by`,placeholder:`Started By`})),t.push(q_({buckets:e.run_type||[],name:`run_type`,placeholder:`Mode`,multiple:!0})),t.push(q_({buckets:e.processes||[],name:`process`,placeholder:`Process`,multiple:!0})),t.push({name:`start`,placeholder:`Started After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Started Before`,type:`date`,multiple:!1}),t}function Jv({facets:e,filters:r,setFilters:i}){let a=qv(e);return t(I,{filterGroups:a,filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}const Yv=H_([`name`,`role`,`tags`]);function Xv(e,t){let n=e[t];return Array.isArray(n)?n:[]}function Zv(e){let t=Xv(e,`role`),n=[];if(n.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t.length>0){let e={name:`role`,placeholder:`Role`,type:`select`,options:t.map(e=>({label:e._id,value:e._id,count:e.count}))};n.push(e)}let r={name:`tags`,placeholder:`Tags`,type:`stringList`,multiple:!0,options:Xv(e,`tags`).map(e=>({label:e._id,value:e._id}))};return n.push(r),n}function Qv(e){return t=>{if(t.length===0){e.clearFilters(!0,!1);return}e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!Yv(t.name))return;let n=t.name;V_(e,n,B_(t))}}),e.search()}}function $v({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=X([]),l=Zv(e),u=Qv(r),d=i!==void 0&&a!==void 0;return t(I,{filterGroups:o??l,filters:d?i:s,setFilters:e=>{if(d){a(e);return}let t=typeof e==`function`?e(s):e;c(t),u(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function ey({buckets:e,name:r}){let i=e.map(e=>({label:`(${e.count})`,value:e._id}));return{name:`environment`,placeholder:r.charAt(0).toUpperCase()+r.slice(1),options:i,type:`select`,labelRenderer:r=>{let i=e.find(e=>e._id===r),a=i?.name||r;return n(`div`,{className:`w-full flex items-center`,children:[t(`span`,{className:`text-sm truncate`,children:a}),n(`span`,{className:`ms-2 text-xs`,children:[`(`,i?.count||0,`)`]})]})},filterBy:(t,n)=>(e.find(e=>e._id===t)?.name||t).toLowerCase().includes(n.toLowerCase())}}const ty=H_([`run_ids`,`interaction`,`environment`,`tags`,`model`,`status`,`finish_reason`,`start`,`end`,`workflow_run_ids`,`workflow_ids`]);function ny(e){return e.filter(e=>e._id!==null)}function ry(e){let t=[];if(t.push({name:`run_ids`,placeholder:`Run ID`,type:`text`,multiple:!1}),e.interactions){let n=U_({buckets:ny(e.interactions),name:`interaction`,placeholder:`Interactions`});t.push(n)}if(e.environments){let n=ey({buckets:ny(e.environments),name:`environment`});t.push(n)}if(t.push({name:`tags`,placeholder:`Tags`,type:`stringList`,multiple:!0}),e.models){let n=q_({buckets:ny(e.models),name:`model`});t.push(n)}if(e.statuses){let n=q_({buckets:ny(e.statuses),name:`status`});t.push(n)}if(e.finish_reason){let n=q_({buckets:e.finish_reason.map(e=>({...e,_id:e._id===null?`none`:e._id})),name:`finish_reason`,placeholder:`Finish Reason`});t.push(n)}return t.push({name:`start`,placeholder:`Date After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Date Before`,type:`date`,multiple:!1}),t.push({name:`workflow_run_ids`,placeholder:`Workflow Run ID`,type:`text`,multiple:!1}),t.push({name:`workflow_ids`,placeholder:`Workflow ID`,type:`text`,multiple:!1}),t}function iy(e){return t=>{if(t.length===0){e.clearFilters(!0,!1);return}e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!ty(t.name))return;let n=t.name,r=B_(t);(n===`run_ids`||n===`workflow_run_ids`||n===`workflow_ids`)&&!Array.isArray(r)&&(r=[r]),V_(e,n,r)}}),e.search()}}function ay({facets:e,search:r,actions:i,selectionCount:a,filters:s,setFilters:c,filterGroups:l}){let[u,d]=X([]),f=ry(e),p=iy(r),m=s!==void 0&&c!==void 0,h=m?s:u;return t(I,{filterGroups:l??f,filters:h,setFilters:e=>{if(m){c(e);return}let t=typeof e==`function`?e(u):e;d(t),p(t)},children:n(`div`,{className:`gap-2 items-center w-full`,children:[n(`div`,{className:`flex justify-between mb-1`,children:[t(P,{}),n(`div`,{className:`flex justify-end`,children:[!a&&t(`div`,{className:`flex items-center justify-between px-2 py-1`,children:t(`div`,{className:`text-sm text-muted`,children:r.initialized?`${r.totalCount} calls`:`Loading calls...`})}),i&&i.length>0?t(`div`,{className:`flex items-center gap-2 mb-1 me-2`,children:i.map((e,n)=>t(`div`,{children:e},`action-${n}`))}):null,t(o,{onClick:()=>{r.search()},variant:`outline`,title:`Refresh`,children:t(zr,{className:`size-5`})})]})]}),h.length>0&&n(`div`,{className:`flex items-center gap-2 mb-1`,children:[t(N,{}),t(F,{})]})]})})}function oy({search:e,buckets:n,name:r,placeholder:i,className:a}){let o=e.getFilterValue(r),s=t=>{e.setFilterValue(r,t?._id)},c=n?.find(e=>JSON.stringify(e._id)===JSON.stringify(o));return t(be,{filterBy:`_id`,className:a,isClearable:!0,optionLabel:W_,options:n,value:c,onChange:s,by:`_id`,placeholder:i})}function sy({search:e,name:n,placeholder:r,className:i}){let[a,o]=X([]);return q(()=>{e.setFilterValue(n,a)},[n,e,a]),t(te,{className:i,value:a,onChange:o,placeholder:r})}function cy(e){return`${e.name} (${e.count})`}function ly({search:e,buckets:n,placeholder:r=`Filter by Type`,className:i}){let[a,o]=X([]),{registry:s}=Tv(),c=e.getFilterValue(`type`),l=t=>{e.setFilterValue(`type`,t?._id)};q(()=>{if(s){let e=n.map(e=>{let t;return e._id==null?(e._id=`Document`,t=`Document`):(t=s.getTypeName(e._id),t||=(console.warn(`Content Object Type not found`,e._id),e._id)),{...e,name:t}});e.sort((e,t)=>e.name.localeCompare(t.name)),o(e)}},[n,s]);let u=a?.find(e=>e._id===c);return t(be,{filterBy:`name`,className:i,isClearable:!0,optionLabel:cy,options:a,value:u,onChange:l,by:`_id`,placeholder:r})}function uy(e){let t=[];return t.push(q_({buckets:e.tags||[],name:`tags`,placeholder:`Tags`,multiple:!0})),t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function dy({facets:e,filters:r,setFilters:i}){let a=uy(e);return t(I,{filterGroups:a,filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}const fy=H_([`search_term`,`status`,`initiated_by`,`start`,`end`,`has_reported_errors`]);function py(e){let t=[];if(t.push({placeholder:`Workflow Name or Workflow Run ID`,name:`search_term`,type:`text`,options:[]}),e.status){let n=q_({buckets:e.status||[],name:`status`,placeholder:`Status`});t.push({...n,name:`status`})}if(e.initiated_by){let n=_v({buckets:e.initiated_by||[],name:`initiated_by`,placeholder:`Initiated By`});t.push({...n,name:`initiated_by`})}return t.push({name:`start`,placeholder:`Date After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Date Before`,type:`date`,multiple:!1}),t.push({name:`has_reported_errors`,placeholder:`Has Reported Errors`,type:`select`,multiple:!1,options:[{label:`Yes`,value:`true`},{label:`No`,value:`false`}]}),t}function my(e){return t=>{if(t.length===0){e.clearFilters();return}e.clearFilters(!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!fy(t.name))return;let n=t.name,r=B_(t);if(n===`has_reported_errors`){let t=Array.isArray(r)?r[0]:r;(t===`true`||t===`false`)&&V_(e,n,t===`true`)}else typeof r==`string`&&V_(e,n,r)}}),e.search()}}function hy({facets:e,search:r}){let[i,a]=X([]),o=py(e),s=my(r);return t(I,{filterGroups:o,filters:i,setFilters:e=>{let t=typeof e==`function`?e(i):e;a(t),s(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function gy(e){let t=[];return t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function _y({facets:e,filters:r,setFilters:i}){let a=gy(e);return t(I,{filterGroups:a,filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}var vy=class e{object;objects;setState;collectionId;singleSelection=!1;constructor(e,t,n,r){this.object=e,this.objects=n,this.setState=r,this.singleSelection=Object.keys(this.objects).length===0,this.collectionId=t}isSingleSelection(){return this.singleSelection}hasSelection(){return this.object!==void 0||this.size()!==0}size(){return Object.keys(this.objects).length}getObjectIds(){return Object.keys(this.objects)}getObjectId(){return this.object?.id}clone(){return new e(this.object,this.collectionId,this.objects,this.setState)}add(e){this.objects[e.id]=e,this.singleSelection=Object.keys(this.objects).length===0,this.setState(this.clone())}remove(e){delete this.objects[e],this.singleSelection=Object.keys(this.objects).length===0,this.setState(this.clone())}addAll(e){for(let t of e)this.objects[t.id]=t;this.setState(this.clone())}isSelected(e){return this.objects[e]!==void 0}removeAll(){this.objects={},this.singleSelection=!0,this.setState(this.clone())}};const yy=ot(void 0);function by(){let e=lt(yy);if(!e)throw Error(`useObjectSelection must be used within a ObjectSelectionProvider`);return e}function xy(){return lt(yy)}function Sy({value:e,collectionId:n,children:r}){let[i,a]=X();return q(()=>{let t=new vy(e,n,{},a);a(t)},[n,e]),i&&t(yy.Provider,{value:i,children:r})}const Cy=ot(void 0);function wy({onFilter:e,children:n}){return t(Cy.Provider,{value:e,children:n})}function Ty(){return lt(Cy)}const Ey=`h-6 w-6 p-0 opacity-0 group-hover/field:opacity-100 text-muted hover:text-foreground transition-opacity shrink-0`;function Dy({field:r,value:i,label:a,copyContent:s}){let c=Ty(),l=Array.isArray(i)?i.length>0:i!==void 0&&i!==``;return n(e,{children:[s!==void 0&&s!==``&&t(x,{content:s,className:Ey}),l&&i!==void 0&&t(o,{variant:`ghost`,size:`sm`,title:`Filter by ${a}`,className:Ey,onClick:e=>{e.stopPropagation(),c?.(r,i)},children:t(Gn,{className:`size-3`})})]})}const Oy=`text/csv`,ky=`image/`,Ay=`application/pdf`,jy=`video/`,My=[`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/msword`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`,`application/vnd.ms-powerpoint`],Ny=e=>e===Oy||Oy.includes(e),Py=e=>e.startsWith(ky)||ky.includes(e),Fy=e=>e===Ay||Ay.includes(e),Iy=e=>e.startsWith(jy)||jy.includes(e),Ly=e=>My.includes(e);function Ry(e,t){if(typeof window>`u`||typeof document>`u`)return!1;let n=document.createElement(`iframe`);n.style.position=`fixed`,n.style.right=`0`,n.style.bottom=`0`,n.style.width=`0`,n.style.height=`0`,n.style.border=`0`,n.style.visibility=`hidden`,document.body.appendChild(n);let r=n.contentWindow;if(!r)return n.parentNode?.removeChild(n),!1;let i=r.document;i.open(),i.write(`<!doctype html><html><head><title></title></head><body></body></html>`),i.close(),i.title=t,document.querySelectorAll(`link[rel="stylesheet"], style`).forEach(e=>{i.head.appendChild(e.cloneNode(!0))});let a=i.createElement(`style`);return a.textContent=`
|
|
316
314
|
@media print {
|
|
317
315
|
body {
|
|
318
316
|
margin: 24px;
|
|
@@ -437,30 +435,30 @@ $&`)),t.includes(` - `)&&(t=t.replace(/(^|\S)\s+-\s+/g,`$1
|
|
|
437
435
|
page-break-inside: avoid;
|
|
438
436
|
}
|
|
439
437
|
}
|
|
440
|
-
`,i.head.appendChild(a),i.body.innerHTML=e.innerHTML,r.focus(),r.print(),setTimeout(()=>{n.parentNode?.removeChild(n)},1e3),!0}const uy={max_hw:import.meta.env?.VITE_RENDITION_HW||256,format:Ci.jpeg,generate_if_missing:!0},dy=`vertesia.content_store.renditionId`;async function fy(e,t,n,r,i){if(!t?.content?.type||!(ay(t.content.type)||sy(t.content.type)||oy(t.content.type))){i(`No preview available`);return}i(`Preparing preview...`);let a=Date.now()/1e3,o=localStorage.getItem(`${dy}_${t.id}_${uy.max_hw}`),s=localStorage.getItem(`${dy}_${t.id}_${uy.max_hw}_time`);if(o?.length&&s&&Math.abs(a-parseInt(s,10))<=900)return n(o),r(`${t.name} Rendition`),i(`ready`),o;i(`Preparing preview...`),e.objects.getRendition(t.id,uy).then(a=>{if(a.status===`generating`)i(`Preparing preview...`),n(``),r(``),setTimeout(()=>fy(e,t,n,r,i),6e4);else if(a.status===`failed`){i(`No preview available`),n(``),r(``);return}else{if(!a?.renditions?.length){i(`No preview available`),n(``),r(``);return}let e=a.renditions[0];localStorage.setItem(`${dy}_${t.id}_${uy.max_hw}`,e),localStorage.setItem(`${dy}_${t.id}_${uy.max_hw}_time`,(Date.now()/1e3).toString()),n(e),r(`${t.name} Rendition`),i(`ready`),console.log(`Rendition for document ${t.id} retrieved successfully: ${e}`)}}).catch(e=>{i(`No preview available`),console.warn(`Failed to retrieve rendition:`,e),n(``),r(``)})}function py(e,t=7){return e?`~${e.slice(-t)}`:``}function my(e,t){return e.length>t?`${e.substring(0,t)}...`:e}function hy(e){switch(e){case Ni.RUNNING:return`text-info`;case Ni.COMPLETED:return`text-success`;case Ni.FAILED:return`text-destructive`;case Ni.TERMINATED:case Ni.CANCELED:return`text-attention`;default:return`text-muted`}}function gy(e){switch(e){case Ni.RUNNING:return`Running`;case Ni.COMPLETED:return`Completed`;case Ni.FAILED:return`Failed`;case Ni.CONTINUED_AS_NEW:return`Continued As New`;case Ni.TERMINATED:return`Terminated`;case Ni.TIMED_OUT:return`Timed Out`;case Ni.CANCELED:return`Canceled`;default:return`Unknown`}}Ki.extend(Sa),Ki.extend(xa);function _y(e){return typeof e==`object`&&!!e}function vy(e,t){if(!_y(e))return;let n=e[t];return typeof n==`string`?n:void 0}function yy(e){return typeof e==`string`?e:vy(e,`id`)||``}function by(e){return e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`?e:String(e)}const xy={string(e,r){let i=[];if(e){let t=e.get(`slice`);t&&i.push(e=>e.slice(parseInt(t,10)));let n=e.get(`max_length`);n&&i.push(e=>e.slice(0,parseInt(n,10))),e.has(`upper`)&&i.push(e=>e.toUpperCase()),e.has(`lower`)&&i.push(e=>e.toLowerCase()),e.has(`capitalize`)&&i.push(e=>e[0].toUpperCase()+e.substring(1)),e.has(`ellipsis`)&&i.push(e=>`${e}...`)}return(e,r,a)=>{let o;if(e){if(o=String(e),i.length>0)for(let e of i)o=e(o)}else o=``;return t(`td`,{className:`group/field`,children:a?n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:o}),a]}):o},r)}},fileSize(e,n){return(e,n)=>{let r=``;if(e){let t=Number(e);if(Number.isNaN(t))r=String(e);else{let e=[`Bytes`,`KB`,`MB`,`GB`,`TB`];if(t===0)r=`0 Bytes`;else{let n=Math.floor(Math.log(t)/Math.log(1024));r=`${(t/1024**n).toFixed(2)} ${e[n]}`}}}return t(`td`,{className:`group/field`,children:r},n)}},number(e,n){let r,i;e&&(r=e.get(`currency`)||void 0,i=e.get(`decimals`)||void 0);let a=i?parseInt(i,10):2;return(e,n)=>{let i=Number(e);return t(`td`,{className:`group/field`,children:new Intl.NumberFormat(`en-US`,{style:r?`currency`:`decimal`,currency:r,maximumFractionDigits:a}).format(Number.isFinite(i)?i:0)},n)}},objectId(e,r){let i=[],a=!1;if(e){let t=e.get(`slice`);t&&(a=!0,i.push(e=>e.slice(parseInt(t,10))))}return(e,s,c)=>{let l=yy(e),u=i.reduce((e,t)=>t(e),l);return n(`td`,{className:`flex justify-start items-center gap-2 group/field`,children:[t(o,{variant:`ghost`,title:`Preview Object`,onClick:e=>{e.stopPropagation(),r?.(l)},children:t(jn,{className:`size-4`})}),a?`~`:``,u,c]},s)}},objectName(e,r){let i=`title`;return e&&(i=e.get(`title`)||`title`),(e,r,a)=>{let o=(_y(e)&&_y(e.properties)?e.properties:void 0)?.[i],s=by(o),c=vy(e,`name`),l=vy(e,`id`),u=s||c||(l?py(l):``);return t(`td`,{className:`group/field`,children:a?n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:u}),a]}):u},r)}},objectLink(e,r){let i=[];return i.push(e=>e.slice(-7)),(e,a)=>{let s=yy(e);return n(`td`,{className:`flex justify-between items-center gap-2 max-w-48 group/field`,children:[`~`,i.reduce((e,t)=>t(e),s),t(o,{variant:`ghost`,title:`Preview Object`,onClick:e=>{e.stopPropagation(),r?.(s)},children:t(jn,{className:`size-4`})})]},a)}},typeLink(e,r){return(e,r,i)=>{let a=vy(e,`name`)||`n/a`;return t(`td`,{className:`group/field`,children:i?n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:a}),i]}):a},r)}},revision(e,r){return(e,r)=>{let i=_y(e)&&_y(e.revision)?e.revision:void 0;if(!i)return t(`td`,{},r);let a=vy(i,`root`),o=vy(i,`label`);return t(`td`,{className:`group/field`,children:n(`div`,{className:`flex flex-col gap-0.5`,children:[a&&n(`div`,{className:`flex items-center gap-1`,children:[n(`span`,{className:`text-xs text-muted font-mono`,children:[`root: ~`,a.slice(-7)]}),t(`a`,{href:`/store/objects/${a}`,onClick:e=>e.stopPropagation(),children:t(kn,{className:`size-3 text-muted`})})]}),o&&n(`span`,{className:`text-xs text-muted`,children:[`label: `,o]})]})},r)}},date(e,r){let i=`fromNow`,a;if(e){let t=e.get(`localized`);if(t)i=`format`,a=t;else{let t=e.get(`relative`);t&&(i=t)}}return(e,r,o)=>{let s=typeof e==`string`||typeof e==`number`||e instanceof Date?e:void 0;if(s===void 0)return t(`td`,{children:o},r);let c=Ki(s),l=i===`format`?c.format(a):i===`toNow`?c.toNow():c.fromNow();return t(`td`,{className:`group/field`,children:n(`div`,{className:`flex items-center gap-2`,children:[t(Re,{description:c.format(`LLL`),children:l}),o]})},r)}}},Sy=xy.string();function Cy(e){return typeof e==`object`&&!!e}function wy(e,t){let n=e;if(!n)return;if(!t.length)return n;let r=t.length-1;for(let e=0;e<r;e++)if(!Cy(n)||(n=n[t[e]],!n))return;if(Cy(n))return n[t[r]]}function Ty(e){return!e||e===`.`?[]:e.split(`.`)}var Ey=class{layout;renderer=Sy;path;fallbackPath;previewObject;constructor(e,t){if(this.layout=e,this.path=Ty(e.field||``),this.fallbackPath=e.fallback?Ty(e.fallback):void 0,this.previewObject=t,e.render)this.renderer=(e,t)=>null;else{let t=e.type||`string`,n=t.indexOf(`?`);if(n>0){let e=t.substring(0,n),r=new URLSearchParams(t.substring(n+1));this.renderer=xy[e](r)}else this.renderer=xy[t]()}}get name(){return this.layout.name}resolveValue(e){let t=wy(e,this.path);return t===void 0&&this.fallbackPath&&(t=wy(e,this.fallbackPath)),t===void 0&&(t=this.layout.default),t}render(e,n){if(this.layout.render)return t(`td`,{className:`whitespace-nowrap px-3 py-4 text-sm group`,children:this.layout.render(e)},n);let r=this.layout.type||`string`,i=r.indexOf(`?`)>0?r.substring(0,r.indexOf(`?`)):r,a=this.buildActions(e,i);if((i===`objectId`||i===`objectLink`)&&this.previewObject){let t=r.indexOf(`?`),o=t>0?new URLSearchParams(r.substring(t+1)):void 0;return xy[i](o,t=>{this.previewObject?.(e.id)})(e,n,a)}return this.renderer(this.resolveValue(e),n,a)}buildActions(e,n){let r=this.layout.field;if(n===`objectId`||n===`objectLink`||r===`id`)return t(Qv,{field:`id`,value:e.id,label:e.id,copyContent:e.id});if(n===`objectName`||r===`name`)return t(Qv,{field:`name`,value:e.name,label:e.name??e.id});if(n===`typeLink`||r===`type.name`||r===`type`){let n=e.type?.id;return t(Qv,{field:`type`,value:n,label:e.type?.name??n??`type`})}if(r===`status`)return t(Qv,{field:`status`,value:e.status,label:e.status})}};function Dy({isLoading:e=!1,counts:r=6}){return e?t(`div`,{className:`flex flex-wrap gap-2 justify-between`,children:Array(r).fill(0).map((e,r)=>t(`div`,{className:`w-[15vw] animate-pulse`,children:n(s,{className:`relative flex flex-col border h-fit`,children:[t(`div`,{className:`h-48 bg-muted rounded-t-xl flex items-center justify-center text-muted`,children:`\xA0`}),t(be,{className:`bg-muted h-[2px]`}),n(c,{className:`p-2 flex flex-col`,children:[n(`div`,{className:`flex flex-col overflow-hidden`,children:[t(`div`,{className:`h-5 bg-muted rounded w-3/4 mb-2`}),t(`div`,{className:`h-4 bg-muted rounded w-1/2`})]}),t(`div`,{className:`text-xs text-muted w-full flex justify-end mt-2`,children:t(`div`,{className:`h-3 bg-muted rounded w-1/4`})})]})]})},`skeleton-${r}`))}):null}function Oy({selection:e,document:r,onSelectionChange:i,onRowClick:a,highlightRow:l,previewObject:u,selectedObject:d}){let{client:f}=Z(),[p,m]=Y(void 0),[h,g]=Y(void 0),[_,v]=Y(void 0),y=typeof r.properties?.title==`string`?r.properties.title:r.name,b=e=>{e.stopPropagation(),i(r,e)};K(()=>{r?.content&&fy(f,r,m,g,v)},[f,r]);let x=l?.(r);return n(s,{className:`relative flex flex-col border h-fit w-full ${d?.id===r.id?`border-attention border-4`:``} ${x?`border-blue-400 dark:border-blue-500 bg-blue-50/50 dark:bg-blue-900/20`:``}`,onClick:()=>a?.(r),children:[x&&t(`div`,{className:`absolute top-2 end-8 z-10`,children:t(rn,{className:`size-4 text-blue-600 dark:text-blue-400`})}),e&&t(`div`,{className:`absolute top-2 start-2 z-10 flex flex-col items-center gap-1`,children:t(`input`,{checked:e.isSelected(r.id),type:`checkbox`,onChange:b,onClick:e=>e.stopPropagation()})}),t(`div`,{className:`absolute top-1 end-1 z-10 flex flex-col items-center`,children:t(o,{variant:`ghost`,size:`sm`,title:`Preview Object`,onClick:e=>{e.stopPropagation(),u?.(r.id)},children:t(jn,{className:`size-4 ${_===`ready`?`text-muted`:`text-white`}`})})}),p&&_===`ready`?t(`img`,{src:p,alt:h,className:`w-auto h-48 object-cover rounded-t-xl`}):t(`div`,{className:`h-48 bg-gray-700 rounded-t-xl flex items-center justify-center text-muted`,children:_}),t(be,{className:`bg-gray-200 h-[2px]`}),n(c,{className:`p-2 flex flex-col`,children:[n(`div`,{className:`flex flex-col overflow-hidden`,children:[t(Re,{placement:`top`,description:y,children:t(`h3`,{className:`text-start font-medium leading-none truncate`,children:y})}),r?.type?.name?t(Re,{placement:`bottom`,size:`xs`,description:r?.type?.name,children:t(`p`,{className:`text-start text-xs text-muted truncate`,children:r?.type?.name})}):t(`p`,{className:`text-xs text-muted`,children:` `})]}),r.score&&n(`div`,{className:`text-xs text-muted w-full flex justify-end`,children:[`Score: `,r.score.toFixed(4)??`-`]})]})]})}function ky({objects:e,selection:r,isLoading:i,columns:a,onRowClick:o,highlightRow:s,selectedObject:c,toggleAll:l,onSelectionChange:u}){let{t:d}=X();return n(je,{className:`w-full`,children:[t(ke,{children:n(`tr`,{children:[r&&t(`th`,{children:t(`input`,{type:`checkbox`,onChange:l})}),a.map(e=>t(`th`,{children:e.name},e.name))]})}),n(Oe,{isLoading:i,columns:a.length+1,children:[e?.map(e=>{let i=s?.(e);return n(`tr`,{className:`group cursor-pointer hover:bg-muted ${c?.id===e.id?`bg-muted`:``} ${i?`bg-blue-50 dark:bg-blue-900/20`:``}`,onClick:()=>{o?.(e)},children:[r&&t(`td`,{onClick:e=>e.stopPropagation(),children:t(`input`,{checked:r.isSelected(e.id),type:`checkbox`,className:`${r.isSelected(e.id)?``:`hidden group-hover:block`}`,onChange:t=>u(e,t)})}),a.map((t,n)=>t.render(e,n)),t(`td`,{className:`w-8 text-center`,children:i&&t(rn,{className:`size-4 text-blue-600 dark:text-blue-400 inline-block`})})]},e.id)}),e.length===0&&t(`tr`,{children:t(`td`,{colSpan:a.length+ +!!r,className:`text-center`,children:d(`store.noObjectsDragAndDrop`)})})]})]})}function Ay({objects:r,selection:i,isLoading:a,onSelectionChange:o,onRowClick:s,highlightRow:c,previewObject:l,selectedObject:u}){return n(e,{children:[t(Dy,{isLoading:a}),t(`div`,{className:`w-full gap-2 grid xs:grid-cols-1 sm:grid-cols-2 md:grid-cols-4 lg:grid-cols-6 @xs:grid-cols-1 @sm:grid-cols-2 @md:grid-cols-3 @lg:grid-cols-4`,children:r.map(e=>t(Oy,{document:e,selection:i,onSelectionChange:o,onRowClick:s,highlightRow:c,previewObject:l,selectedObject:u},e.id))})]})}var jy=class{client;limit;collectionId;facets=new xe({});result=new xe({objects:[],isLoading:!1});initialized=!1;facetSpecs=[];query={};constructor(e,t=100){this.client=e,this.limit=t}withFacets(e){return this.facetSpecs=e,this}get objects(){return this.result.value.objects}get error(){return this.result.value.error}get isRunning(){return this.result.value.isLoading}get hasMore(){return this.result.value.hasMore||!1}getFilterValue(e){return this.query[e]}setFilterValue(e,t){this.query[e]=t,this.search()}setDefaultKeys(e){}clearFilters(e=!0){let{parent:t,full_text:n,vector:r,weights:i,score_aggregation:a,dynamic_scaling:o,limit:s,all_revisions:c}=this.query;this.query={parent:t,...n!==void 0&&{full_text:n},...r!==void 0&&{vector:r},...i!==void 0&&{weights:i},...a!==void 0&&{score_aggregation:a},...o!==void 0&&{dynamic_scaling:o},...s!==void 0&&{limit:s},...c!==void 0&&{all_revisions:c}},e&&this.search()}getFacetBuckets(e){let t=this.facets.value[e];return Array.isArray(t)?t:[]}resetFacets(){this.query={}}reset(e=!1){this.initialized=!1,this.result.value={objects:[],isLoading:e,hasMore:!0}}_updateRunningState(e){let t=this.result.value;this.result.value={objects:t.objects,isLoading:e,error:t.error,hasMore:t.hasMore}}_searchRequest(e,t,n,r=!0){let i={limit:t,offset:n,query:e,facets:r?this.facetSpecs:void 0};return this.collectionId?this.client.collections.searchMembers(this.collectionId,i):this.client.objects.search(i)}_facetsRequest(){let e={facets:this.facetSpecs,query:this.query};return this.collectionId?this.client.collections.computeFacets(this.collectionId,e):this.client.objects.computeFacets(e)}computeFacets(e){this._facetsRequest().then(e=>{this.facets.value=e})}async _search(e=!1,t=!1){if(this.isRunning&&e)return!1;let n=this.result.value;e||(this.initialized=!0),this.result.value={isLoading:!0,objects:e?this.objects:[],hasMore:!e||this.result.value.hasMore};let r=this.limit,i=e?this.objects.length:0;try{let n=await this._searchRequest(this.query,r,i,!t),a=n.results||[],o=n.facets||{};return this.result.value={isLoading:!1,objects:e?this.objects.concat(a):a,hasMore:a.length===r},!t&&o&&Object.keys(o).length>0&&(this.facets.value=o),!0}catch(e){if(typeof e==`object`&&e&&`status`in e&&e.status===404)return this.result.value={isLoading:!1,objects:[],hasMore:!1},!1;let t=e instanceof Error?e:Error(String(e));return this.result.value={error:t,isLoading:!1,objects:n.objects,hasMore:!1},!1}}search(e=!1){return this.isRunning?Promise.resolve(!1):this._search(!1,e)}loadMore(e=!1){return this.isRunning||!this.hasMore||this.query.vector?Promise.resolve(!1):(this.objects.length>0&&(e=!0),this._search(!0,e))}};const My=nt(void 0);function Ny(){return at(My)}function Py(){return Xe(Ny().facets)}function Fy(){let e=Ny();return{...Xe(e.result),search:e}}function Iy(){return Xe(Ny().facets).total}const Ly=It.getFixedT(null,Ft);var Ry;(function(e){e.CREATE=`create`,e.SKIP=`skip`,e.UPDATE=`update`})(Ry||={});async function zy(e){try{let t=await e.arrayBuffer(),n=new Ca;return n.appendByteArray(new Uint8Array(t)),n.end()?.toString()}catch(e){console.error(`Error calculating file hash:`,e);return}}async function By(e,t){let n=[];for(let r=0;r<e.length;r+=5){let i=e.slice(r,r+5),a=await Promise.all(i.map(async e=>{let n=t||`/`;if(e.webkitRelativePath){let r=e.webkitRelativePath.split(`/`);if(r.length>1){let e=r.slice(0,-1).join(`/`);n=t?`${t}/${e}`:e}}return{file:e,hash:await zy(e),name:e.name,size:e.size,location:n}}));n.push(...a)}return n}function Vy(){let{client:e}=Z(),t=Ye();return{checkDocumentProcessing:G(async(n,r,i)=>{try{console.log(`Preparing metadata for ${n.length} files...`);let t=await By(n,r);return await(async()=>{let n=t.map(e=>e.hash).filter(Boolean);if(n.length===0)return;let r={"content.etag":{$in:n}},a;if(i){let t={query:{match:r},select:`id content.etag`};a=(await e.store.collections.searchMembers(i,t)).results}else{let t={query:r,select:`id content.etag`};a=await e.store.objects.find(t)}for(let e of a){let n=t.find(t=>t.hash===e.content?.etag);n&&(n.existingId=e.id,n.action=Ry.SKIP)}})(),await(async()=>{let n=t.filter(e=>e.action!==Ry.SKIP),r=n.map(e=>e.location),a=Array.from(new Set(r)),o=[];for(let t of a){let r={"content.name":{$in:n.filter(e=>e.location===t).map(e=>e.name)},location:t||`/`};if(i){let t=e.store.collections.searchMembers(i,{query:{match:r},select:`id content.name location`}).then(e=>e.results);o.push(t)}else{let t=e.store.objects.find({query:r,select:`id content.name location`});o.push(t)}}let s=(await Promise.all(o)).flat();console.log(`Found ${s.length} document to update`,s);for(let e of s){let n=t.find(t=>t.name===e.content?.name&&(t.location?t.location===e.location:e.location===`/`));n&&(n.existingId=e.id,n.action=Ry.UPDATE)}console.log(`Reconciled ${t.filter(e=>e.action===Ry.UPDATE).length}`)})(),t.forEach(e=>{e.action||=Ry.CREATE}),console.log(`Document processing check results:`,{totalFiles:n.length,toCreate:t.filter(e=>e.action===Ry.CREATE).length,toUpdate:t.filter(e=>e.action===Ry.UPDATE).length,toSkip:t.filter(e=>e.action===Ry.SKIP).length}),t}catch(e){throw t({title:Ly(`store.errorInUploadProcessingCheck`),status:`error`,description:ze(e)}),console.log(`Error in file upload processing check`,e),Error(`Error in file upload processing check: ${ze(e)}`,{cause:e})}},[e,t])}}function Hy({isOpen:r,onClose:i,files:a,collectionId:s,selectedFolder:c,title:l,children:u,onUploadComplete:d,hideFileSelection:f=!1,showTypeSelectionOnly:p=!1,allowFolders:m=!0}){let{client:h}=Z(),{registry:g}=sv(),_=Ye(),{t:v}=X(),y=l??v(`upload.uploadFiles`),[b,x]=Y([]),[S,C]=Y([]),[w,T]=Y(!1),[E,D]=Y(null),[O,k]=Y([]),[A,j]=Y(!1),[M,N]=Y(!1),[P,F]=Y(0),[I,L]=Y(Date.now()),[ee,R]=Y(void 0),[te,z]=Y(null),[ne,B]=Y(y),[ce,V]=Y(``);K(()=>{s&&h.store.collections.retrieve(s).then(R)},[h.store.collections.retrieve,s]),K(()=>{A?(B(v(`upload.uploadingFiles`)),V(`${Math.round(P)}% complete`)):M?(B(v(`upload.uploadComplete`)),V(``)):w?(B(v(`upload.fileAnalysisResults`)),V(`${b.length} file${b.length===1?``:`s`}`)):b.length>0?(B(y),V(v(`upload.checkingForDuplicates`))):(B(y),V(``))},[A,M,w,y,P,b.length,v]);let le=()=>!ee&&!c?null:n(re,{className:`mb-4`,status:`default`,icon:t(Hn,{className:`size-5`}),children:[t(`div`,{className:`flex items-center`,children:t(`span`,{className:`font-medium`,children:v(`upload.uploadLocation`)})}),n(`div`,{className:`text-sm mt-1`,children:[ee&&n(`div`,{className:`flex items-center`,children:[t(`span`,{className:`me-1`,children:v(`upload.collectionLabel`)}),t(`span`,{className:`font-medium`,children:ee.name})]}),c&&n(`div`,{className:`flex items-center mt-1`,children:[t(`span`,{className:`me-1`,children:v(`upload.folderLabel`)}),t(`span`,{className:`font-medium`,children:c})]})]})]}),[ue,de]=Y({toCreate:0,toUpdate:0,toSkip:0}),{checkDocumentProcessing:fe}=Vy(),pe=q(()=>g?.types||[],[g?.types]),me=G(async e=>{if(e.length)try{console.log(`Processing ${e.length} files to determine required actions...`);let t=await fe(e,c,s);C(t);let n=t.filter(e=>e.action===Ry.CREATE).length,r=t.filter(e=>e.action===Ry.UPDATE).length,i=t.filter(e=>e.action===Ry.SKIP).length;de({toCreate:n,toUpdate:r,toSkip:i}),_({title:v(`upload.filesAnalyzed`),description:`${e.length} file(s): ${n} new, ${r} to update, ${i} to skip`,status:`info`,duration:4e3}),T(!0)}catch(e){console.error(`Error processing files:`,e),_({title:v(`agent.error`),description:v(`upload.errorAnalyzingFiles`),status:`error`,duration:5e3})}},[fe,s,c,v,_]);K(()=>{r&&(C([]),T(!1),D(null),k([]),j(!1),N(!1),F(0),de({toCreate:0,toUpdate:0,toSkip:0}),z(null),B(y),V(``),a&&a.length>0?(x(a),me(a)):x([]),L(Date.now()))},[r,a,me,y]);let he=()=>{x([]),C([]),T(!1),D(null),k([]),j(!1),N(!1),F(0),de({toCreate:0,toUpdate:0,toSkip:0}),z(null),B(y),V(``),L(Date.now()),i()},ge=e=>{e&&e.length>0&&(x(e),me(e))},_e=async()=>{if(!S.length)return;let e=E?.id||null,t=S.map(e=>({file:e.file,status:`pending`,progress:0,action:e.action===Ry.CREATE?`create`:e.action===Ry.UPDATE?`update`:`skip`}));k(t),j(!0),N(!1);let n=S.filter(e=>e.action===Ry.SKIP),r=S.filter(e=>e.action===Ry.UPDATE),i=S.filter(e=>e.action===Ry.CREATE),a={success:!0,objectIds:[],uploadedFiles:[],skippedFiles:[],failedFiles:[]};for(let t of n)t.existingId&&(a.objectIds.push(t.existingId),a.skippedFiles.push({id:t.existingId,name:t.name,type:e,status:`skipped`,location:t.location}),k(e=>e.map(e=>e.file===t.file?{...e,status:`success`,progress:100,id:t.existingId}:e)));let o=async(t,n)=>{let r=[];for(let e=0;e<t.length;e+=50)r.push(t.slice(e,e+50));for(let i=0;i<r.length;i++){let o=r[i];if(console.log(`Processing ${n} batch ${i+1}/${r.length} (${o.length} files)`),t.length>50){let e=i*50;_({title:v(`upload.processingFilesAction`,{action:n}),description:v(`upload.processedCount`,{processed:e,total:t.length}),status:`info`,duration:2e3})}let c=0;await Promise.all(o.map(async t=>{try{if(k(e=>e.map(e=>e.file===t.file?{...e,status:`uploading`,progress:20}:e)),n===`update`&&t.existingId)await h.store.objects.update(t.existingId,{type:e||void 0,content:t.file,location:t.location,name:t.name},{createRevision:!0,revisionLabel:`upload on ${new Date().toISOString()}`}),k(e=>e.map(e=>e.file===t.file?{...e,status:`success`,progress:100,id:t.existingId}:e)),a.objectIds.push(t.existingId),a.uploadedFiles.push({id:t.existingId,name:t.name,type:e,status:`updated`,location:t.location});else{let n=await h.store.objects.create({type:e||void 0,content:t.file,location:t.location||t.file.webkitRelativePath||t.name},{collection_id:s});k(e=>e.map(e=>e.file===t.file?{...e,status:`success`,progress:100,id:n.id}:e)),a.objectIds.push(n.id),a.uploadedFiles.push({id:n.id,name:t.name,type:e,status:`created`,location:t.location})}}catch(n){console.error(`Failed to process file ${t.name}:`,n),k(e=>e.map(e=>e.file===t.file?{...e,status:`error`,progress:100,message:ze(n,`Unknown error`)}:e)),a.failedFiles.push({name:t.name,error:ze(n,`Unknown error`),status:`failed`,location:t.location,type:e}),a.success=!1}c++,(c%5==0||c===o.length)&&k(e=>{let t=e.filter(e=>e.status===`success`||e.status===`error`).length,n=e.length,r=n>0?Math.round(t/n*100):0;return F(r),e})}))}};r.length>0&&await o(r,`update`),i.length>0&&await o(i,`create`),k(e=>{let t=e.filter(e=>e.status===`pending`).map(e=>({...e,status:`error`,progress:100,message:v(`upload.uploadProcessInterrupted`)}));return t.length>0?(t.forEach(e=>{a.failedFiles.push({name:e.file.name,error:v(`upload.uploadProcessInterrupted`),status:`failed`,type:E?.id||null})}),a.success=!1,e.map(e=>e.status===`pending`?{...e,status:`error`,progress:100,message:v(`upload.uploadProcessInterrupted`)}:e)):e}),j(!1),N(!0);let c=a.uploadedFiles.filter(e=>e.status===`created`).length,l=a.uploadedFiles.filter(e=>e.status===`updated`).length,u=a.skippedFiles.length,d=a.failedFiles.length,f=``;c>0&&(f+=`${c} file${c===1?``:`s`} uploaded`),l>0&&(f+=f?`, `:``,f+=`${l} file${l===1?``:`s`} updated`),u>0&&(f+=f?`, `:``,f+=`${u} file${u===1?``:`s`} skipped`),d>0&&(f+=f?`, `:``,f+=`${d} file${d===1?``:`s`} failed`),_({title:v(`upload.uploadComplete`),description:f,status:d>0?`warning`:`success`,duration:5e3}),z(a)},ye=()=>n(`div`,{className:`mb-4`,children:[n(`div`,{className:`block text-sm font-medium mb-2`,children:[v(`store.contentType`),` `,t(`span`,{className:`text-muted font-normal`,children:v(`store.optional`)}),t(Re,{description:v(`upload.contentTypeTooltip`),placement:`top`,size:`xs`,children:t(Qn,{className:`size-3 ms-2`})})]}),t(ve,{options:pe,value:E,optionLabel:e=>e?e.name:v(`store.selectContentTypeLabel`),placeholder:v(`store.selectContentTypeAuto`),onChange:e=>D(e===void 0?null:e),filterBy:`name`,isClearable:!0}),!E&&t(`div`,{className:`p-2 rounded-md`,children:n(`div`,{className:`flex items-center text-attention`,children:[t(nn,{className:`size-4 me-1`}),v(`store.automaticTypeDetection`),t(Re,{description:v(`store.automaticTypeDetectionDescription`),placement:`top`,size:`xs`,children:t(Qn,{className:`size-3 ms-2`})})]})})]});return n(ie,{isOpen:r,onClose:he,className:`mx-auto`,disableCloseOnClickOutside:!0,children:[t(se,{description:ce,children:ne}),p?n(ae,{children:[u,le(),ye()]}):b.length===0&&!f?n(ae,{className:`flex flex-col items-center justify-center p-8`,children:[le(),t(ht,{onDrop:ge,message:v(`upload.dragAndDrop`),buttonLabel:v(`upload.selectFiles`),className:`w-full h-64`,allowFolders:m}),u]}):!A&&!M?t(ae,{children:w?n(e,{children:[le(),t(`div`,{className:`mb-4`,children:t(`div`,{className:`p-4 rounded-md mb-4`,children:n(`div`,{className:`grid grid-cols-3 gap-4`,children:[n(`div`,{className:`flex flex-col items-center`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(ti,{className:`size-5 text-primary`}),t(`span`,{className:`font-medium`,children:v(`upload.new`)})]}),t(`div`,{className:`text-2xl font-semibold`,children:ue.toCreate})]}),n(`div`,{className:`flex flex-col items-center`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(nn,{className:`size-5 text-success`}),t(`span`,{className:`font-medium`,children:v(`upload.update`)})]}),t(`div`,{className:`text-2xl font-semibold`,children:ue.toUpdate})]}),n(`div`,{className:`flex flex-col items-center`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(Bt,{className:`size-5 text-mixer-attention/40`}),t(`span`,{className:`font-medium`,children:v(`upload.skip`)})]}),t(`div`,{className:`text-2xl font-semibold`,children:ue.toSkip})]})]})})}),ye(),t(re,{className:`mb-4`,status:`info`,children:ue.toCreate+ue.toUpdate>0?n(`div`,{className:`space-y-1`,children:[t(`p`,{children:v(`upload.filesReadyToProcess`,{count:ue.toCreate+ue.toUpdate})}),t(`p`,{children:ue.toSkip>0&&v(`upload.filesToSkip`,{count:ue.toSkip})})]}):ue.toSkip>0?t(`span`,{children:v(`upload.allFilesExist`,{count:ue.toSkip})}):t(`span`,{children:v(`upload.noFilesToProcess`)})})]}):n(`div`,{className:`flex flex-col items-center justify-center py-4`,children:[t(Te,{size:`lg`,className:`mb-4`}),t(`div`,{className:`text-lg font-medium`,children:v(`upload.analyzingFiles`)})]})}):A?n(ae,{children:[le(),t(`div`,{className:`mb-4`,children:t(`div`,{className:`h-2 bg-muted/20 rounded-full overflow-hidden`,children:t(`div`,{className:`h-full bg-primary rounded-full`,style:{width:`${P}%`}})})}),t(`div`,{className:`max-h-96 overflow-y-auto`,children:O.map((e,r)=>n(`div`,{className:`flex items-center py-2 border-b border-border last:border-b-0`,children:[n(`div`,{className:`me-3`,children:[e.status===`pending`&&t(Nn,{className:`size-5 text-muted`}),e.status===`uploading`&&t(Te,{size:`sm`}),e.status===`success`&&t(nn,{className:`size-5 text-success`}),e.status===`error`&&t(ui,{className:`size-5 text-destructive`})]}),n(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`truncate font-medium`,children:e.file.name}),n(`div`,{className:`text-xs text-muted`,children:[e.status===`pending`&&v(`agent.waiting`),e.status===`uploading`&&v(`agent.uploading`),e.status===`success`&&(e.action===`create`?v(`store.created`):e.action===`update`?v(`store.updated`):v(`upload.skip`)),e.status===`error`&&e.message]})]})]},`${e.file.name}-${e.file.size}-${e.file.lastModified}`))})]}):t(ae,{children:n(`div`,{className:`mb-4`,children:[le(),t(wt,{files:O.map(e=>{let t;return t=e.status===`success`?e.action===`create`?`success`:e.action===`update`?`updated`:`skipped`:`failed`,{name:e.file.name,status:t,error:e.status===`error`?e.message:void 0}}),location:c||void 0,collection:ee?.name})]})}),(()=>{if(p)return n(oe,{children:[t(o,{variant:`ghost`,onClick:he,children:v(`modal.cancel`)}),t(o,{onClick:()=>{let e={success:!0,objectIds:[],uploadedFiles:[{name:`type-selection`,type:E?.id||null,status:`created`}],skippedFiles:[],failedFiles:[]};d&&d(e),he()},children:E?v(`upload.useTypeName`,{typeName:E.name}):v(`upload.useAutoDetection`)})]});if(b.length===0&&!f)return t(oe,{children:t(o,{variant:`ghost`,onClick:he,children:v(`modal.cancel`)})});if(!A&&!M){let e=w;return n(oe,{children:[t(o,{variant:`ghost`,onClick:he,children:v(`modal.cancel`)}),t(o,{disabled:!e,onClick:_e,children:ue.toCreate+ue.toUpdate>0?v(`agent.upload`):v(`upload.continue`)})]})}return A?t(oe,{children:t(o,{variant:`ghost`,disabled:!0,children:v(`agent.uploading`)})}):n(oe,{children:[t(o,{variant:`ghost`,onClick:()=>{x([]),C([]),T(!1),D(null),k([]),j(!1),N(!1),F(0),de({toCreate:0,toUpdate:0,toSkip:0})},children:v(`upload.uploadMore`)}),t(o,{onClick:()=>{d&&te&&d(te),he()},children:v(`agent.close`)})]})})()]},I)}function Uy(e){let t=typeof e==`function`?e:e.onUploadDone,{client:n,project:r,store:i}=Z(),a=Ny(),o=Ye(),s=It.getFixedT(null,Ft),{checkDocumentProcessing:c}=Vy();return async(e,l,u)=>{let d={success:!1,objectIds:[],uploadedFiles:[],skippedFiles:[],failedFiles:[]};if(!r)return o({status:`error`,title:s(`store.noProjectSelected`),duration:3e3}),d;if(!e||e.length===0)return o({status:`warning`,title:s(`store.noFilesSelected`),duration:3e3}),d;let f=Array.from(e).filter(e=>e.size>0);if(f.length===0)return o({status:`error`,title:s(`store.noValidFilesSelected`),description:s(`store.pleaseSelectValidFiles`),duration:5e3}),d;let p=[],m=[],h=[];console.log(`Processing ${f.length} files with smart file processing...`);let g=await c(f,null,u),_=g.filter(e=>e.action===Ry.CREATE).length,v=g.filter(e=>e.action===Ry.UPDATE).length,y=g.filter(e=>e.action===Ry.SKIP).length;o({title:s(`store.filesAnalyzedTitle`),description:`${f.length} file(s): ${_} new, ${v} to update, ${y} to skip`,status:`info`,duration:4e3});for(let e of g.filter(e=>e.action===Ry.SKIP&&e.existingId))p.push({id:e.existingId,name:e.name,type:l,status:`skipped`,location:e.location});let b=g.filter(e=>(e.action===Ry.CREATE||e.action===Ry.UPDATE)&&e.file);if(b.length>0){console.log(`Processing ${b.length} files (${b.filter(e=>e.action===Ry.CREATE).length} create, ${b.filter(e=>e.action===Ry.UPDATE).length} update)...`);let e=[];for(let t=0;t<b.length;t+=50)e.push(b.slice(t,t+50));for(let t=0;t<e.length;t++){let r=e[t],a=t*50;console.log(`Processing batch ${t+1}/${e.length} (${r.length} files)`),b.length>50&&o({title:s(`store.processingFiles`),description:`Processed ${a}/${b.length} files...`,status:`info`,duration:2e3});let c=await Promise.all(r.map(async e=>{try{if(e.action===Ry.UPDATE&&e.existingId){let t=await n.store.objects.update(e.existingId,{type:l||void 0,content:e.file,location:e.location,name:e.name},{createRevision:!0,revisionLabel:`upload on ${new Date().toISOString()}`});return m.push({id:e.existingId,name:e.name,type:l,status:`updated`,location:e.location}),d.objectIds.push(e.existingId),{success:!0,id:t.id,name:e.name,action:`update`}}else{let t=u?{collection_id:u}:void 0,n=await i.objects.create({type:l||void 0,content:e.file,location:e.location||e.file.webkitRelativePath||e.name},t);m.push({id:n.id,name:e.name,type:l,status:`created`,location:e.location})}}catch(t){console.error(`Failed to process file ${e.name}:`,t),h.push({name:e.name,error:ze(t,`Unknown error`),status:`failed`,location:e.location,type:l}),o({status:`error`,title:s(`store.processingFailedFor`,{name:e.name}),description:ze(t),duration:4e3})}})),f=m.filter(e=>e.status===`created`),p=m.filter(e=>e.status===`updated`),g=m.filter(e=>e.status===`failed`);console.log(`Batch ${t+1} results:`,{creates:f,updates:p,failures:g,total:c.length})}}let x=m.filter(e=>e.status===`created`).length,S=m.filter(e=>e.status===`updated`).length,C=m.filter(e=>e.status===`failed`).length,w=m.filter(e=>e.status===`skipped`).length;t&&(console.log(`Upload complete:`,{totalObjectIds:d.objectIds.length,uploadedFiles:x,updatedFiles:S,skippedFiles:w,failedFiles:C}),await t(d.objectIds));let T=``;return x>0&&(T+=`${x} file${x===1?``:`s`} uploaded`),S>0&&(T+=T?`, `:``,T+=`${S} file${S===1?``:`s`} updated`),w>0&&(T+=T?`, `:``,T+=`${w} file${w===1?``:`s`} skipped (already existed)`),C>0&&(T+=T?`, `:``,T+=`${C} file${C===1?``:`s`} failed`),T&&o({status:C>0?`warning`:`success`,title:T,duration:4e3}),a.search(),d}}const Wy=[{name:`ID`,field:`id`,type:`objectId?slice=-7`},{name:`Name`,field:`.`,type:`objectName`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Updated At`,field:`updated_at`,type:`date`}];function Gy({isGridView:e=!1,onUpload:n,collectionId:r,...i}){return n?t(Ky,{...i,onUpload:n,isGridView:e,collectionId:r}):t(qy,{...i,isGridView:e})}function Ky({isGridView:e,onUpload:r,collectionId:i,skipTypeModal:a=!1,...o}){let[s,c]=Y(!1),[l,u]=Y([]),[d,f]=Y(!1),[p,m]=Y(null),[h,g]=Y(!1),_=Ny(),v=Ye(),{t:y}=X(),{checkDocumentProcessing:b}=Vy(),x=async(e,t)=>{console.log(`Files dropped on ObjectTable:`,e.length,t),c(!0);try{if(i){let t=await b(e,null,i);m(t);let n=t.filter(e=>e.action===`create`).length,r=t.filter(e=>e.action===`update`).length,a=t.filter(e=>e.action===`skip`).length;v({title:y(`store.filesReadyToProcess`),description:`${e.length} file(s): ${n} new, ${r} to update, ${a} to skip`,status:`info`,duration:4e3})}else m(null)}catch(e){console.error(`Error processing files:`,e),v({title:y(`store.errorProcessingFiles`),description:y(`store.errorCheckingDuplicates`),status:`error`,duration:4e3}),m(null)}finally{if(c(!1),u(e),f(!1),a){console.log(`Skipping type modal and calling onUpload directly`,{filesLength:e.length,processedFilesLength:p?.length});let t=r(e,null,i);t&&typeof t==`object`&&(t.processedFiles=p)}else console.log(`Setting typeSelectionOpen to true`,{filesLength:e.length}),g(!0)}},S=e=>{let t=[...l];u([]),m(null),g(!1),t.length>0&&e!==void 0&&(c(!0),console.log(`Starting upload with`,{typeId:e,filesCount:t.length,hasProcessingResults:!!p,collectionId:i}),r(t,e,i).finally(()=>{c(!1),_.search()}))},C=e=>{e.preventDefault(),e.stopPropagation(),f(!0)};return n(`div`,{className:`min-h-[400px] relative`,onDragOver:C,onDragEnter:C,onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),!e.currentTarget.contains(e.relatedTarget)&&f(!1)},onDrop:e=>{if(e.preventDefault(),e.stopPropagation(),f(!1),e.dataTransfer.items){let t=[];for(let n=0;n<e.dataTransfer.items.length;n++){let r=e.dataTransfer.items[n];if(r.kind===`file`){let e=r.getAsFile();e&&t.push(e)}}if(t.length>0){let e={count:t.length,message:`Preparing to upload ${t.length} file${t.length===1?``:`s`}...`};x(t,e)}}},children:[t(`div`,{className:Ze(`bg-white dark:bg-gray-800 opacity-40 absolute inset-0 z-50 flex justify-center items-center`,s?`block`:`hidden`),children:t(Te,{size:`xl`})}),t(qy,{...o,isGridView:e}),t(`div`,{className:Ze(`absolute inset-0 pointer-events-none`,d?`z-40`:`-z-10`),children:t(`div`,{className:`w-full h-full relative`,children:t(ht,{onDrop:x,message:`Drop files or folders here to upload`,className:Ze(`absolute inset-0 bg-white/90 dark:bg-gray-800/90 pointer-events-auto`,d?`flex`:`hidden`),buttonLabel:`Select Files or Folders`,allowFolders:!0})})}),t(Hy,{isOpen:h&&l.length>0,onClose:()=>{u([]),m(null),g(!1),S(void 0)},files:l,collectionId:i,selectedFolder:null,title:`Upload Files`,onUploadComplete:e=>{if(e){if(e.failedFiles&&e.failedFiles.length>0&&v({title:y(`store.uploadIssues`),description:`${e.failedFiles.length} file(s) failed to upload`,status:`warning`,duration:5e3}),e.success){let t=e.uploadedFiles.filter(e=>e.status===`created`).length,n=e.uploadedFiles.filter(e=>e.status===`updated`).length,r=e.skippedFiles.length;(t>0||n>0)&&v({title:y(`store.uploadComplete`),description:`${t>0?`${t} created`:``}${t>0&&n>0?`, `:``}${n>0?`${n} updated`:``}${r>0?`, ${r} skipped`:``}`,status:`success`,duration:5e3})}_.search()}u([]),m(null),g(!1),e?.success&&e.objectIds.length>0?S(null):S(void 0)}})]})}function qy({objects:e,layout:n=Wy,isLoading:r,onRowClick:i,onSelectionChange:a,highlightRow:o,previewObject:s,selectedObject:c,isGridView:l}){let u=Kv(),d=(t,n)=>{if(u){let r=n.nativeEvent instanceof MouseEvent&&n.nativeEvent.shiftKey;if(!n.target.checked)u.remove(t.id);else if(u.add(t),r){let n=e.findIndex(e=>e.id===t.id),r=Jy(e,n,u);if(r>-1&&r<n-1){let t=[];for(let i=r+1;i<n;i++)t.push(e[i]);u.addAll(t)}else{let t=Yy(e,n,u);if(t>-1&&t>n+1){let r=[];for(let i=n+1;i<t;i++)r.push(e[i]);u.addAll(r)}}}a?.(u)}},f=t=>{u&&(t.target.checked?u.addAll(e):u.removeAll())},p=q(()=>{let e=n.length>0?n:Wy;return console.log(`Using layout with columns:`,e.map(e=>e.name).join(`, `)),e.map(e=>new Ey(e,s))},[n,s]);return t(l?Ay:ky,{objects:e,isLoading:r,columns:p,onRowClick:i,highlightRow:o,previewObject:s,selectedObject:c,selection:u,toggleAll:f,onSelectionChange:d})}function Jy(e,t,n){for(let r=t-1;r>=0;r--)if(n.isSelected(e[r].id))return r;return-1}function Yy(e,t,n){let r=e.length;for(let i=t+1;i<r;i++)if(n.isSelected(e[i].id))return i;return-1}function Xy({children:e,limit:n,parent:r,typeId:i,facets:a,name:o,collectionId:s}){let{store:c}=Z(),l=q(()=>{let e;a?e=a:(e=[{name:`status`,field:`status`},{name:`location`,field:`location`}],i||e.unshift({name:`type`,field:`type`}));let t=new jy(c,n).withFacets(e);return t.collectionId=s,t.query.type=i,t.query.parent=r,t.query.name=o,s&&(t.query.all_revisions=!0),t},[s,a,n,o,r,c,i]);return t(My.Provider,{value:l,children:e})}const Zy=`vertesia.content_store.lastDisplayedView`;function Qy({onUpdate:e}){let{t:n}=X(),[r,i]=Y(localStorage.getItem(Zy)===`grid`),a=()=>{r?c():s()},s=()=>{localStorage.setItem(Zy,`grid`),i(!0),e(!0)},c=()=>{localStorage.setItem(Zy,`table`),i(!1),e(!1)};return t(o,{variant:`outline`,onClick:a,title:n(r?`misc.tableView`:`misc.thumbnailView`),children:t(r?Zr:tr,{})})}Qy.LAST_DISPLAYED_VIEW=Zy;const $y=[{name:`Name`,field:`properties.title`,type:`string`,fallback:`name`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Created At`,field:`created_at`,type:`date`}];function eb({onChange:e,selectedIds:n}){return t(Xy,{children:t(tb,{onRowClick:t=>{e(t||void 0)},selectedIds:n})})}function tb({onRowClick:e,selectedIds:r}){let{t:i}=X(),a=G(e=>!!r?.has(e.id),[r]),[s,c]=Y(!1),[l,u]=Y(localStorage.getItem(`vertesia.content_store.lastDisplayedView`)===`grid`),{search:d,isLoading:f,error:p,objects:m,hasMore:h}=Fy(),g=J(null);Ke(g,()=>{s&&h&&!f&&(c(!1),d.loadMore(!0).finally(()=>{c(!0)}))},{threshold:.1,deps:[s,h,f]}),K(()=>{d.search().finally(()=>{c(!0)})},[d]);let _=Py(),v=Ny();return p?t(M,{title:i(`store.searchFailed`),children:p.message}):n(`div`,{className:`flex flex-col gap-2 h-full w-full`,children:[n(`div`,{className:`flex justify-between items-center flex-shrink-0`,children:[t(hv,{facets:_,search:v}),n(`div`,{className:`flex items-center gap-2`,children:[t(o,{variant:`outline`,onClick:()=>{c(!1),d.search().then(()=>c(!0))},"aria-label":`Refresh`,children:t(Nr,{size:16})}),t(Qy,{onUpdate:u})]})]}),n(`div`,{className:`@container relative flex-1 overflow-y-auto`,children:[t(Gy,{objects:m||[],isLoading:!m.length&&f,layout:$y,onRowClick:e,highlightRow:r?.size?a:void 0,isGridView:l}),t(`div`,{ref:g,className:`h-4 w-full`})]})]})}function nb(e){let t=Math.max(0,e)/1e3,n=+(t>0&&t<10&&!Number.isInteger(t));return`${new Intl.NumberFormat(void 0,{maximumFractionDigits:n}).format(t)}K`}function rb({onSend:e,onStop:r,approvalModeSlot:i,mcpSlot:a,disabled:s=!1,isSending:c=!1,isStopping:l=!1,isStreaming:u=!1,isCompleted:d=!1,contextWindowUsage:f,onCompactContext:p,isCompactingContext:m=!1,activeTaskCount:h=0,activeWorkstreams:g=[],onSelectWorkstream:_,placeholder:v,onFilesSelected:y,uploadedFiles:b=[],onRemoveFile:x,onRemoveProcessingFile:S,acceptedFileTypes:C,maxFiles:T=5,processingFiles:E,artifactRunId:D,hasProcessingFiles:O=!1,renderDocumentSearch:k,selectedDocuments:A=[],onRemoveDocument:j,hideObjectLinking:M=!1,hideFileUpload:N=!1,disableDropZone:P=!1,className:F,inputClassName:I}){let{t:L}=X(),ee=v??L(`agent.typeYourMessage`),R=J(null),te=J(null),[z,ne]=Y(``),[re,oe]=Y(!1),[ce,V]=Y(!1),[le,ue]=Y(!1),de=!!(y&&!N),fe=de&&!P,pe=!M||de||!!k,me=b.length>=T,he=S??x,ge=q(()=>g.filter(e=>e.status===`running`||e.status===`canceling`),[g]),_e=ge.length||h,ve=f?L(`agent.contextUsageCompactLabel`,{percent:f.usedPercent}):void 0,ye=f?L(`agent.contextTokenUsage`,{used:nb(f.usedTokens),limit:nb(f.checkpointTokens)}):void 0,be=q(()=>{let e=[];if(!N&&E)for(let t of E.values()){let n=t.preview_url,r=t.status===Si.UPLOADING?L(`agent.uploading`):t.status===Si.PROCESSING?L(`agent.processing`):t.status===Si.ERROR?L(`agent.error`):t.status===Si.READY?L(`agent.ready`):t.status;e.push({id:t.id,name:t.name,contentType:t.content_type,artifactPath:t.artifact_path,previewUrl:n,removable:!!he,statusLabel:r,statusTone:t.status===Si.ERROR?`destructive`:t.status===Si.READY?`success`:`attention`})}if(!N)for(let t of b)e.push({id:t.id,name:t.name,contentType:t.type,artifactPath:t.artifact_path,previewUrl:t.previewUrl,removable:!!x,statusLabel:L(`agent.ready`),statusTone:`success`});for(let t of A)e.push({id:t.id,name:t.name,href:`/store/objects/${t.id}`,removable:!!j,statusTone:`info`});return e},[he,N,j,x,E,A,L,b]);K(()=>{!s&&d&&R.current?.focus()},[s,d]);let xe=G(e=>{if(!de||!y)return;let t=Array.from(e),n=T-b.length,r=t.slice(0,n);r.length>0&&y(r)},[de,y,T,b.length]),Se=G(e=>{e.preventDefault(),e.stopPropagation(),fe&&ue(!0)},[fe]),Ce=G(e=>{e.preventDefault(),e.stopPropagation(),ue(!1)},[]),we=G(e=>{e.preventDefault(),e.stopPropagation(),ue(!1),fe&&e.dataTransfer?.files&&e.dataTransfer.files.length>0&&xe(e.dataTransfer.files)},[fe,xe]),Ee=G(e=>{if(!de)return;let t=qg(e.clipboardData?.items);t.length>0&&xe(t)},[de,xe]),De=G(e=>{de&&e.target.files&&e.target.files.length>0&&(xe(e.target.files),e.target.value=``)},[de,xe]),Oe=G(()=>{te.current?.click()},[]),ke=G(()=>V(!1),[]),Ae=G(e=>V(!1),[]),je=()=>{let t=z.trim();!t||s||c||O||(e(t),ne(``))},Me=()=>{r&&!l&&r()},Ne=J(0),Pe=e=>{if(e.key===`Enter`){if(!(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)){e.preventDefault(),z.trim().length>0&&je();return}e.shiftKey||(e.preventDefault(),Be(e.currentTarget,ne));return}if(e.key===`Escape`&&u&&r){let e=Date.now();e-Ne.current<500?(Me(),Ne.current=0):Ne.current=e}},Fe=G(()=>{let e=R.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]);return K(()=>{Fe()},[z,Fe]),n(`div`,{className:H(`px-3 py-3 flex-shrink-0 transition-all fixed lg:sticky bottom-0 start-0 end-0 lg:start-auto lg:end-auto w-full bg-background/95 backdrop-blur z-10`,le&&fe&&`bg-info/10 border-info`,F),onDragOver:fe?Se:void 0,onDragLeave:fe?Ce:void 0,onDrop:fe?we:void 0,children:[le&&fe&&t(`div`,{className:`absolute inset-0 flex items-center justify-center bg-blue-100/80 dark:bg-blue-900/40 rounded-lg z-10 pointer-events-none`,children:n(`div`,{className:`text-blue-600 dark:text-blue-400 font-medium flex items-center gap-2`,children:[t(ti,{className:`size-5`}),L(`agent.dropFilesToUpload`)]})}),de&&t(`input`,{ref:te,type:`file`,multiple:!0,accept:C,onChange:De,className:`hidden`}),t(m_,{activeWorkstreams:g,onSelectWorkstream:_}),n(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-2 rounded-2xl border border-border/70 bg-mixer-muted/15 p-2.5 shadow-lg shadow-black/5`,children:[be.length>0&&t(nf,{items:be,artifactRunId:D,variant:`composer`,onRemove:e=>{E?.has(e)?he?.(e):b.some(t=>t.id===e)?x?.(e):j?.(e)},className:`gap-1.5`}),t(`div`,{className:`flex min-w-0 flex-1`,children:t(Le,{ref:R,value:z,onKeyDown:Pe,onChange:e=>ne(e.target.value),onPaste:Ee,disabled:s,"aria-label":ee,placeholder:ee,rows:1,style:{maxHeight:`160px`},className:H(`min-h-[44px] resize-none border-0 bg-transparent px-0 py-0 text-sm leading-6 shadow-none focus-visible:ring-0`,I)})}),n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[pe&&n(w,{align:`left`,trigger:t(o,{variant:`ghost`,size:`icon`,className:`size-8 rounded-full text-muted hover:bg-muted`,title:L(`agent.addAttachment`),children:t(Ar,{className:`size-4`})}),children:[!M&&n(B,{onClick:()=>oe(!0),isDisabled:!d,children:[t(Sr,{className:`size-4`}),L(`agent.linkObject`)]}),de&&n(B,{onClick:Oe,isDisabled:me,children:[t(ti,{className:`size-4`}),L(`agent.upload`)]}),k&&n(B,{onClick:()=>V(!0),children:[t(Rn,{className:`size-4`}),t(`span`,{children:L(`agent.searchDocuments`)}),A.length>0&&t(`span`,{className:`ms-auto inline-flex items-center justify-center rounded-full bg-info/20 px-1.5 py-0.5 text-[10px] font-medium text-info`,children:A.length})]})]}),i,a,f&&t(Re,{asChild:!0,placement:`top`,size:`md`,className:`text-foreground shadow-lg`,description:n(`span`,{className:`block max-w-56 text-start text-sm leading-6`,children:[t(`span`,{className:`block`,children:L(`agent.contextRemainingUntilCompact`,{percent:f.remainingPercent})}),ye&&t(`span`,{className:`mt-1 block text-foreground/80`,children:ye})]}),children:t(o,{type:`button`,variant:`ghost`,size:`icon`,className:H(`size-8 rounded-lg text-info hover:bg-muted hover:text-info disabled:opacity-60`,`focus-visible:ring-2 focus-visible:ring-info/40`),"aria-label":ve,onClick:p,disabled:!p||m,children:m?t(Te,{size:`sm`}):n(`svg`,{viewBox:`0 0 24 24`,className:H(`size-8 -rotate-90`,f.usedPercent>=90?`text-destructive`:f.usedPercent>=70?`text-attention`:`text-info`),"aria-hidden":`true`,children:[t(`circle`,{cx:`12`,cy:`12`,r:`9.75`,fill:`none`,strokeWidth:`4.5`,className:`stroke-current text-muted/50`}),t(`circle`,{cx:`12`,cy:`12`,r:`9.75`,fill:`none`,pathLength:100,strokeWidth:`4.5`,strokeLinecap:`round`,strokeDasharray:100,style:{strokeDashoffset:100-f.usedPercent},className:`stroke-current`})]})})}),ge.length===0&&_e>0&&t(`output`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,"aria-live":`polite`,children:n(`span`,{className:`inline-flex h-8 items-center gap-1 rounded-full px-2 text-xs text-muted`,children:[t(Rt,{className:`size-3 text-attention`}),L(`agent.activeWorkstreams`,{count:_e})]})})]}),u&&r&&!z.trim()?t(o,{onClick:Me,disabled:l,variant:`ghost`,size:`icon`,className:H(`size-9 rounded-full border border-border/60 bg-foreground text-background shadow-sm`,`hover:bg-foreground/90 hover:text-background`,`disabled:bg-mixer-muted/25 disabled:text-muted disabled:opacity-100`,`[&_svg]:text-destructive disabled:[&_svg]:text-muted`),title:L(`agent.stopTooltip`),children:l?t(Te,{size:`sm`}):t(qr,{className:`size-3 fill-current stroke-current`})}):t(o,{onClick:je,disabled:s||c||!z.trim()||O,variant:`ghost`,size:`icon`,className:H(`size-9 rounded-full border border-border/60 bg-foreground text-background shadow-sm`,`hover:bg-foreground/90 hover:text-background`,`disabled:bg-mixer-muted/25 disabled:text-muted disabled:opacity-100`),title:L(O?`agent.waitForFiles`:`agent.sendTooltip`),"aria-label":L(O?`agent.waitForFiles`:`agent.send`),children:c?t(Te,{size:`sm`}):t(Wt,{className:`size-4`})})]})]}),n(ie,{isOpen:re,onClose:()=>oe(!1),className:`min-w-[60vw]`,children:[t(se,{children:L(`agent.linkObject`)}),t(ae,{className:`pb-6`,children:t(eb,{onChange:e=>{let t=`[${e.properties?.title||e.name||`Object`}](store:${e.id})`,n=z||``,r=R.current?.selectionStart||n.length,i=n.substring(0,r)+t+n.substring(r);ne(i),oe(!1),setTimeout(()=>{if(R.current){R.current.focus();let e=r+t.length;R.current.setSelectionRange(e,e)}},100)}})})]}),k?.({isOpen:ce,onClose:ke,onSelect:Ae})]})}function ib({code:e}){let{onProposalSelect:n,onProposalSubmit:r}=Nt(),i=q(()=>At(e),[e]),a=q(()=>{if(i)return null;try{let t=e.trim(),i=JSON.parse(t);if(!i.options||!i.question&&!i.title)return null;let a={question:i.question||i.title||``,description:i.description,options:Array.isArray(i.options)?i.options.map(e=>({id:e.id||e.value||``,label:e.label||``,description:e.description})):void 0,allowFreeResponse:i.allowFreeResponse??i.multiple,variant:i.variant,onSelect:n,onSubmit:r};return!a.question||!a.options?.length?null:a}catch{return null}},[e,n,r,i]);return i?t(pt,{type:`proposal`,message:`Loading options...`}):a?t(ft,{type:`proposal`,fallbackCode:e,children:t(Jl,{...a})}):t(pt,{type:`proposal`,error:`Invalid proposal specification`})}const ab=it(function({code:e}){let n=q(()=>{try{let t=JSON.parse(e);return t?.library===`vega-lite`&&t?.spec&&typeof t.spec==`object`?t:typeof t?.$schema==`string`&&t.$schema.includes(`vega`)?{library:`vega-lite`,spec:t}:null}catch{return null}},[e]);return n?t(ho,{spec:n}):null}),ob=it(function({code:e}){let n=q(()=>{try{return{library:`vega-lite`,spec:JSON.parse(e)}}catch{return null}},[e]);return n?t(ho,{spec:n}):null}),sb={chart:ab,"vega-lite":ob,vegalite:ob,"fusion-fragment":fa,proposal:ib,askuser:ib};function cb({url:e,code:n}){let[r,i]=Y(null);return K(()=>{import(e).then(e=>{i(()=>e.default)}).catch(t=>{console.error(`Failed to load remote widget component from `,e,t)})},[e]),r?t(r,{code:n}):null}async function lb(e){let n=await e.apps.getInstalledApps(`tools`),r=new Set;for(let e of n){if(e.manifest.tool_collections&&e.manifest.tool_collections.length>0)for(let t of e.manifest.tool_collections||[]){let e=Ri(t).url;if(e.startsWith(`http://`)||e.startsWith(`https://`)){let t=e.indexOf(`/api/`);if(t>0){let n=e.substring(0,t);r.add(`${n}/api/widgets`)}}}e.manifest.endpoint&&e.manifest.capabilities?.includes(`tools`)&&r.add(new URL(`/api/widgets`,e.manifest.endpoint).toString())}let i=await Promise.all(Array.from(r).map(e=>fetch(e).then(e=>{if(!e.ok)throw Error(`Failed to fetch widgets: ${e.status} ${e.statusText}`);return e.json()}).then(e=>{let n=[],r=e.widgets;for(let[e,i]of Object.entries(r))n.push({name:e,component:e=>t(cb,{url:i.url,code:e.code})});return n}).catch(()=>(console.error(`Failed to fetch skill widgets from `,e),null)))),a={};for(let e of i.flat())e&&(a[e.name]=e.component);return a}function ub({children:e}){let{client:n}=Z(),[r,i]=Y(sb);return K(()=>{lb(n).then(e=>{i({...sb,...e})})},[n]),t(mt,{components:r,children:e})}const db=new Map;function fb(e){if(typeof e==`number`)return e;if(!e)return Date.now();let t=new Date(e).getTime();return Number.isFinite(t)?t:Date.now()}function pb(e){return e===`running`||e===`canceling`}function mb(e){return!pb(e)}function hb(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function gb(e){for(let t=e.length-1;t>=0;t--){let n=e[t].details;if(!n)continue;let r=n.token_usage,i=hb(r?.prompt),a=i&&i>0?i:hb(r?.total),o=hb(n.checkpoint_threshold)??hb(n.checkpoint_at);if(typeof a!=`number`||typeof o!=`number`||o<=0)continue;let s=Math.max(0,Math.min(100,Math.round(a/o*100)));return{usedTokens:a,checkpointTokens:o,usedPercent:s,remainingPercent:Math.max(0,100-s)}}}function _b(e,t){return!mb(e.status)||!pb(t.status)?{...e,...t}:{...e,interaction:e.interaction??t.interaction,elapsed_ms:Math.max(e.elapsed_ms,t.elapsed_ms),deadline_ms:Math.max(e.deadline_ms,t.deadline_ms),remaining_ms:0,phase:e.phase??t.phase,child_workflow_id:e.child_workflow_id??t.child_workflow_id,child_workflow_run_id:e.child_workflow_run_id??t.child_workflow_run_id}}function vb(e){let t=e.details,n=typeof t?.workstream_id==`string`&&t.workstream_id.trim()?t.workstream_id:_u(e);return n===`main`||n===`all`?null:{workstreamId:n,launchId:typeof t?.launch_id==`string`?t.launch_id:void 0,interaction:typeof t?.interaction==`string`?t.interaction:void 0,childWorkflowId:typeof t?.child_workflow_id==`string`?t.child_workflow_id:void 0,childWorkflowRunId:typeof t?.child_workflow_run_id==`string`?t.child_workflow_run_id:void 0}}function yb(e){if(e.type!==Q.ERROR)return!1;let t=e.details;if(t?.event_class!==`activity`||t.workstream_event)return!1;let n=typeof e.workstream_id==`string`&&e.workstream_id.trim()?e.workstream_id.trim():typeof t.workstream_id==`string`?t.workstream_id.trim():``,r=n.toLowerCase();return!n||r===`main`||r===`all`?!1:!(t.tool||t.tool_status||t.tool_run_id||t.activity_group_id||t.tool_event)}function bb(e,t,n,r,i,a){if(r){let a=t.get(n);if(a?.startsWith(`message-derived:`)){let t=e.get(a);t&&(e.delete(a),e.set(r,{...t,launch_id:r,updated_at:Math.max(t.updated_at,i)}))}t.set(n,r)}let o=r??t.get(n)??`message-derived:${n}`,s=e.get(o);if(s)return s;let c={workstream_id:n,launch_id:o,elapsed_ms:0,deadline_ms:0,remaining_ms:0,status:`running`,started_at:i,updated_at:i,order:a};return e.set(o,c),t.has(n)||t.set(n,o),c}function xb(e){let t=new Map,n=new Map;return e.forEach((e,r)=>{let i=fb(e.timestamp),a=vb(e),o=ou(e),s=o?.workstreamId??a?.workstreamId;if(!s)return;let c=o?.launchId??a?.launchId,l=ru(e);if(!o&&!c&&l&&!n.has(s))return;let u=bb(t,n,s,c,i,r);o?(u.interaction=o.interaction??u.interaction,u.child_workflow_id=o.childWorkflowId??u.child_workflow_id,u.child_workflow_run_id=o.childWorkflowRunId??u.child_workflow_run_id,u.status=`running`):(u.interaction=a?.interaction??u.interaction,u.child_workflow_id=a?.childWorkflowId??u.child_workflow_id,u.child_workflow_run_id=a?.childWorkflowRunId??u.child_workflow_run_id);let d=au(e);d?u.status=d:l||(yb(e)?u.status=`failed`:(e.type===Q.COMPLETE||e.type===Q.IDLE)&&(u.status=`completed`)),!l&&(u.updated_at=Math.max(u.updated_at,i),pb(u.status)?u.elapsed_ms=Math.max(u.elapsed_ms,i-u.started_at):(u.elapsed_ms=Math.max(u.elapsed_ms,i-u.started_at),u.remaining_ms=0))}),Array.from(t.values()).sort((e,t)=>{let n=Number(!pb(e.status))-Number(!pb(t.status));return n===0?pb(e.status)?e.order-t.order:t.updated_at-e.updated_at||e.order-t.order:n}).map(({started_at:e,updated_at:t,order:n,...r})=>r)}function Sb(e){return{workstream_id:e.workstream_id,launch_id:e.launch_id,interaction:e.interaction,elapsed_ms:e.elapsed_ms,deadline_ms:e.deadline_ms,remaining_ms:Math.max(0,e.deadline_ms-e.elapsed_ms),status:e.status,phase:e.latest_progress?.phase,child_workflow_id:e.child_workflow_id,child_workflow_run_id:e.child_workflow_run_id}}function Cb(e){return{workstream_id:e.workstream_id,launch_id:e.launch_id,interaction:e.interaction,elapsed_ms:e.duration_ms??0,deadline_ms:0,remaining_ms:0,status:e.status,phase:e.last_progress?.phase,child_workflow_id:e.child_workflow_id,child_workflow_run_id:e.child_workflow_run_id}}function wb(e,t){let n=e.findIndex(e=>e.launch_id===t.launch_id);if(n>=0){e[n]=_b(e[n],t);return}let r=e.findIndex(e=>e.workstream_id===t.workstream_id&&e.launch_id.startsWith(`message-derived:`));if(r>=0&&!t.launch_id.startsWith(`message-derived:`)){e[r]=_b(e[r],t);return}e.push(t)}function Tb(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function Eb(e,t=!0){let[n,r]=Y(()=>Math.max(0,Math.floor((Date.now()-fb(e))/1e3)));return K(()=>{if(!t)return;let n=()=>{r(Math.max(0,Math.floor((Date.now()-fb(e))/1e3)))};n();let i=window.setInterval(n,1e3);return()=>window.clearInterval(i)},[t,e]),n}function Db(e=!0){let[t,n]=Y(0);return K(()=>{if(!e)return;let t=window.setInterval(()=>{n(()=>Math.floor(Math.random()*Rd.length))},4e3);return()=>window.clearInterval(t)},[e]),t}function Ob({message:e,startedAt:r}){let{t:i}=X(),a=Eb(r),o=Db();return n(`div`,{className:`mx-auto flex min-h-full w-full max-w-3xl flex-col justify-end gap-6 px-1 py-8`,children:[t(`div`,{className:`flex w-full justify-end`,children:t(`div`,{className:H(`max-w-[min(44rem,82%)] rounded-[1.35rem] bg-mixer-muted/35 px-4 py-2.5`,`break-words text-sm font-normal leading-6 text-foreground/90 shadow-sm shadow-black/5`,`dark:bg-mixer-muted/15 dark:text-foreground/88 dark:shadow-none [overflow-wrap:anywhere]`),children:t(`div`,{className:`whitespace-pre-wrap`,children:e})})}),n(`div`,{className:`border-b border-border/70 pb-4 text-sm text-muted`,children:[n(`div`,{className:`flex items-center gap-3`,children:[t(bd,{size:`sm`,color:`blue`}),n(`div`,{className:`min-w-0`,children:[n(`div`,{children:[t(`span`,{className:`font-medium`,children:i(`agent.preparing`)}),n(`span`,{className:`ms-2 text-muted/75`,children:[`for `,Tb(a)]})]}),t(`div`,{className:`mt-1 truncate text-muted/80`,children:Rd[o]})]})]}),t(`div`,{className:`mt-3 ps-6`,children:t(yd,{color:`blue`})})]})]})}function kb(e,t){if(typeof window>`u`||typeof document>`u`)return!1;let n=document.createElement(`iframe`);n.style.position=`fixed`,n.style.right=`0`,n.style.bottom=`0`,n.style.width=`0`,n.style.height=`0`,n.style.border=`0`,n.style.visibility=`hidden`,document.body.appendChild(n);let r=n.contentWindow;if(!r)return n.parentNode?.removeChild(n),!1;let i=r.document;return i.open(),i.write(`<!doctype html><html><head><title></title></head><body></body></html>`),i.close(),i.title=t,document.querySelectorAll(`link[rel="stylesheet"], style`).forEach(e=>{i.head.appendChild(e.cloneNode(!0))}),i.body.innerHTML=e.innerHTML,r.focus(),r.print(),setTimeout(()=>{n.parentNode?.removeChild(n)},1e3),!0}function Ab(e){let t=0,n=e.length;for(;t<n&&e[t]===`-`;)t++;for(;n>t&&e[n-1]===`-`;)n--;return e.slice(t,n)}function jb(e){return Ab(e.trim().replace(/[^a-z0-9-_]+/gi,`-`)).slice(0,80)}function Mb(e,t){let n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}function Nb(e){let{agentRunId:n,startWorkflow:r,resourceResolver:i}=e;if(n){let r=t(ub,{children:t(Ib,{...e,agentRunId:n})});return i?t(ut,{value:i,children:r}):r}else if(r)return t(Fb,{...e});else return t(Pb,{})}function Pb(){let{t:e}=X();return n(re,{status:`info`,icon:t(Kt,{className:`size-16 text-muted mb-4`}),children:[t(`div`,{className:`text-base font-medium text-muted`,children:e(`agent.noAgentRunning`)}),t(`div`,{className:`mt-3 text-sm text-muted`,children:e(`agent.selectInteraction`)})]})}function Fb({initialMessage:e,interactive:r=!0,startWorkflow:i,onClose:a,isModal:s=!1,fullWidth:c=!1,placeholder:l,startButtonText:u,title:d,getAttachedDocs:f,onAttachmentsSent:p,acceptedFileTypes:m,maxFiles:h=5,hideHeader:g=!1,hideFileUpload:_=!1,hideObjectLinking:v,headerVariant:y,startViewVariant:b=`default`,inputContainerClassName:x,inputClassName:S,className:C,allowWorkflowControl:w,initialToolApprovalMode:T,onAgentWorkingChange:E}){let{t:D}=X(),O=b!=="default",k=b===`expanded-composer`,A=!_,j=l??D(`agent.typeYourMessage`),M=u??D(`agent.startAgent`),N=d??D(`agent.startNewConversation`),{client:P}=Z(),[F,I]=Y(``),[L,ee]=Y(!1),[R,te]=Y(null),[z,ne]=Y(null),[B,re]=Y(null),[ie,ae]=Y(()=>Li(T,r)),oe=Ye(),se=J(null),ce=J(null),[V,le]=Y([]),[ue,de]=Y(!1),fe=ue?V:V.slice(0,3),pe=V.length-3;K(()=>{E?.(L)},[L,E]);let[me,he]=Y(!1),ge=J(0),_e=G(e=>{A&&(e.preventDefault(),e.stopPropagation(),ge.current++,e.dataTransfer?.types?.includes(`Files`)&&he(!0))},[A]),ve=G(e=>{A&&(e.preventDefault(),e.stopPropagation())},[A]),ye=G(e=>{A&&(e.preventDefault(),e.stopPropagation(),ge.current--,ge.current===0&&he(!1))},[A]),be=G(e=>{if(A&&(e.preventDefault(),e.stopPropagation(),ge.current=0,he(!1),e.dataTransfer?.files&&e.dataTransfer.files.length>0)){let t=Array.from(e.dataTransfer.files);le(e=>[...e,...t].slice(0,h))}},[h,A]),xe=G(e=>{if(!A)return;let t=qg(e.clipboardData?.items);t.length>0&&le(e=>[...e,...t].slice(0,h))},[A,h]),Se=G(e=>{if(e.target.files&&e.target.files.length>0){let t=Array.from(e.target.files);le(e=>[...e,...t].slice(0,h))}e.target.value=``},[h]),Ce=G(e=>{le(t=>t.filter((t,n)=>n!==e))},[]);K(()=>{V.length<=3&&de(!1)},[V.length]),K(()=>{se.current&&se.current.focus()},[]);let we=async()=>{if(!i)return;let e=F.trim();if(!(!e||L)){ee(!0);try{sessionStorage.removeItem(`plan-panel-shown`),oe({title:A&&V.length>0?D(`agent.startingAgentUploading`):D(`agent.startingAgent`),status:`info`,duration:3e3});let t=f?.()||[],n=e;if(t.length>0&&!/store:\S+/.test(e)&&(n=[e,``,`Attachments:`,...t.map(e=>`[${e.name}](/store/objects/${e.id})`)].join(`
|
|
438
|
+
`,i.head.appendChild(a),i.body.innerHTML=e.innerHTML,r.focus(),r.print(),setTimeout(()=>{n.parentNode?.removeChild(n)},1e3),!0}const zy={max_hw:import.meta.env?.VITE_RENDITION_HW||256,format:Oi.jpeg,generate_if_missing:!0},By=`vertesia.content_store.renditionId`;async function Vy(e,t,n,r,i){if(!t?.content?.type||!(Py(t.content.type)||Iy(t.content.type)||Fy(t.content.type))){i(`No preview available`);return}i(`Preparing preview...`);let a=Date.now()/1e3,o=localStorage.getItem(`${By}_${t.id}_${zy.max_hw}`),s=localStorage.getItem(`${By}_${t.id}_${zy.max_hw}_time`);if(o?.length&&s&&Math.abs(a-parseInt(s,10))<=900)return n(o),r(`${t.name} Rendition`),i(`ready`),o;i(`Preparing preview...`),e.objects.getRendition(t.id,zy).then(a=>{if(a.status===`generating`)i(`Preparing preview...`),n(``),r(``),setTimeout(()=>Vy(e,t,n,r,i),6e4);else if(a.status===`failed`){i(`No preview available`),n(``),r(``);return}else{if(!a?.renditions?.length){i(`No preview available`),n(``),r(``);return}let e=a.renditions[0];localStorage.setItem(`${By}_${t.id}_${zy.max_hw}`,e),localStorage.setItem(`${By}_${t.id}_${zy.max_hw}_time`,(Date.now()/1e3).toString()),n(e),r(`${t.name} Rendition`),i(`ready`),console.log(`Rendition for document ${t.id} retrieved successfully: ${e}`)}}).catch(e=>{i(`No preview available`),console.warn(`Failed to retrieve rendition:`,e),n(``),r(``)})}function Hy(e,t=7){return e?`~${e.slice(-t)}`:``}function Uy(e,t){return e.length>t?`${e.substring(0,t)}...`:e}function Wy(e){switch(e){case zi.RUNNING:return`text-info`;case zi.COMPLETED:return`text-success`;case zi.FAILED:return`text-destructive`;case zi.TERMINATED:case zi.CANCELED:return`text-attention`;default:return`text-muted`}}function Gy(e){switch(e){case zi.RUNNING:return`Running`;case zi.COMPLETED:return`Completed`;case zi.FAILED:return`Failed`;case zi.CONTINUED_AS_NEW:return`Continued As New`;case zi.TERMINATED:return`Terminated`;case zi.TIMED_OUT:return`Timed Out`;case zi.CANCELED:return`Canceled`;default:return`Unknown`}}function Ky(e){return typeof e==`object`&&!!e}function qy(e,t){if(!Ky(e))return;let n=e[t];return typeof n==`string`?n:void 0}function Jy(e){return typeof e==`string`?e:qy(e,`id`)||``}function Yy(e){return e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`?e:String(e)}const Xy={string(e,r){let i=[];if(e){let t=e.get(`slice`);t&&i.push(e=>e.slice(parseInt(t,10)));let n=e.get(`max_length`);n&&i.push(e=>e.slice(0,parseInt(n,10))),e.has(`upper`)&&i.push(e=>e.toUpperCase()),e.has(`lower`)&&i.push(e=>e.toLowerCase()),e.has(`capitalize`)&&i.push(e=>e[0].toUpperCase()+e.substring(1)),e.has(`ellipsis`)&&i.push(e=>`${e}...`)}return(e,r,a)=>{let o;if(e){if(o=String(e),i.length>0)for(let e of i)o=e(o)}else o=``;return t(`td`,{className:`group/field`,children:a?n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:o}),a]}):o},r)}},fileSize(e,n){return(e,n)=>{let r=``;if(e){let t=Number(e);if(Number.isNaN(t))r=String(e);else{let e=[`Bytes`,`KB`,`MB`,`GB`,`TB`];if(t===0)r=`0 Bytes`;else{let n=Math.floor(Math.log(t)/Math.log(1024));r=`${(t/1024**n).toFixed(2)} ${e[n]}`}}}return t(`td`,{className:`group/field`,children:r},n)}},number(e,n){let r,i;e&&(r=e.get(`currency`)||void 0,i=e.get(`decimals`)||void 0);let a=i?parseInt(i,10):2;return(e,n)=>{let i=Number(e),o=new Intl.NumberFormat(`en-US`,{style:r?`currency`:`decimal`,currency:r,maximumFractionDigits:a}).format(Number.isFinite(i)?i:0);return t(`td`,{className:`group/field`,children:o},n)}},objectId(e,r){let i=[],a=!1;if(e){let t=e.get(`slice`);t&&(a=!0,i.push(e=>e.slice(parseInt(t,10))))}return(e,s,c)=>{let l=Jy(e),u=i.reduce((e,t)=>t(e),l);return n(`td`,{className:`flex justify-start items-center gap-2 group/field`,children:[t(o,{variant:`ghost`,title:`Preview Object`,onClick:e=>{e.stopPropagation(),r?.(l)},children:t(In,{className:`size-4`})}),a?`~`:``,u,c]},s)}},objectName(e,r){let i=`title`;return e&&(i=e.get(`title`)||`title`),(e,r,a)=>{let o=(Ky(e)&&Ky(e.properties)?e.properties:void 0)?.[i],s=Yy(o),c=qy(e,`name`),l=qy(e,`id`),u=s||c||(l?Hy(l):``);return t(`td`,{className:`group/field`,children:a?n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:u}),a]}):u},r)}},objectLink(e,r){let i=[];return i.push(e=>e.slice(-7)),(e,a)=>{let s=Jy(e),c=i.reduce((e,t)=>t(e),s);return n(`td`,{className:`flex justify-between items-center gap-2 max-w-48 group/field`,children:[`~`,c,t(o,{variant:`ghost`,title:`Preview Object`,onClick:e=>{e.stopPropagation(),r?.(s)},children:t(In,{className:`size-4`})})]},a)}},typeLink(e,r){return(e,r,i)=>{let a=qy(e,`name`)||`n/a`;return t(`td`,{className:`group/field`,children:i?n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:a}),i]}):a},r)}},revision(e,r){return(e,r)=>{let i=Ky(e)&&Ky(e.revision)?e.revision:void 0;if(!i)return t(`td`,{},r);let a=qy(i,`root`),o=qy(i,`label`);return t(`td`,{className:`group/field`,children:n(`div`,{className:`flex flex-col gap-0.5`,children:[a&&n(`div`,{className:`flex items-center gap-1`,children:[n(`span`,{className:`text-xs text-muted font-mono`,children:[`root: ~`,a.slice(-7)]}),t(`a`,{href:`/store/objects/${a}`,onClick:e=>e.stopPropagation(),children:t(Pn,{className:`size-3 text-muted`})})]}),o&&n(`span`,{className:`text-xs text-muted`,children:[`label: `,o]})]})},r)}},date(e,r){let i=`fromNow`,a;if(e){let t=e.get(`localized`);if(t)i=`format`,a=t;else{let t=e.get(`relative`);t&&(i=t)}}return(e,r,o)=>{let s=typeof e==`string`||typeof e==`number`||e instanceof Date?e:void 0;if(s===void 0)return t(`td`,{children:o},r);let c=fs(s),l=i===`format`?c.format(a):i===`toNow`?c.toNow():c.fromNow();return t(`td`,{className:`group/field`,children:n(`div`,{className:`flex items-center gap-2`,children:[t(Be,{description:c.format(`LLL`),children:l}),o]})},r)}}},Zy=Xy.string();function Qy(e){return typeof e==`object`&&!!e}function $y(e,t){let n=e;if(!n)return;if(!t.length)return n;let r=t.length-1;for(let e=0;e<r;e++)if(!Qy(n)||(n=n[t[e]],!n))return;if(Qy(n))return n[t[r]]}function eb(e){return!e||e===`.`?[]:e.split(`.`)}var tb=class{layout;renderer=Zy;path;fallbackPath;previewObject;constructor(e,t){if(this.layout=e,this.path=eb(e.field||``),this.fallbackPath=e.fallback?eb(e.fallback):void 0,this.previewObject=t,e.render)this.renderer=(e,t)=>null;else{let t=e.type||`string`,n=t.indexOf(`?`);if(n>0){let e=t.substring(0,n),r=new URLSearchParams(t.substring(n+1));this.renderer=Xy[e](r)}else this.renderer=Xy[t]()}}get name(){return this.layout.name}resolveValue(e){let t=$y(e,this.path);return t===void 0&&this.fallbackPath&&(t=$y(e,this.fallbackPath)),t===void 0&&(t=this.layout.default),t}render(e,n){if(this.layout.render)return t(`td`,{className:`whitespace-nowrap px-3 py-4 text-sm group`,children:this.layout.render(e)},n);let r=this.layout.type||`string`,i=r.indexOf(`?`)>0?r.substring(0,r.indexOf(`?`)):r,a=this.buildActions(e,i);if((i===`objectId`||i===`objectLink`)&&this.previewObject){let t=r.indexOf(`?`),o=t>0?new URLSearchParams(r.substring(t+1)):void 0;return Xy[i](o,t=>{this.previewObject?.(e.id)})(e,n,a)}return this.renderer(this.resolveValue(e),n,a)}buildActions(e,n){let r=this.layout.field;if(n===`objectId`||n===`objectLink`||r===`id`)return t(Dy,{field:`id`,value:e.id,label:e.id,copyContent:e.id});if(n===`objectName`||r===`name`)return t(Dy,{field:`name`,value:e.name,label:e.name??e.id});if(n===`typeLink`||r===`type.name`||r===`type`){let n=e.type?.id;return t(Dy,{field:`type`,value:n,label:e.type?.name??n??`type`})}if(r===`status`)return t(Dy,{field:`status`,value:e.status,label:e.status})}};function nb({isLoading:e=!1,counts:r=6}){return e?t(`div`,{className:`flex flex-wrap gap-2 justify-between`,children:Array(r).fill(0).map((e,r)=>t(`div`,{className:`w-[15vw] animate-pulse`,children:n(s,{className:`relative flex flex-col border h-fit`,children:[t(`div`,{className:`h-48 bg-muted rounded-t-xl flex items-center justify-center text-muted`,children:`\xA0`}),t(Se,{className:`bg-muted h-[2px]`}),n(c,{className:`p-2 flex flex-col`,children:[n(`div`,{className:`flex flex-col overflow-hidden`,children:[t(`div`,{className:`h-5 bg-muted rounded w-3/4 mb-2`}),t(`div`,{className:`h-4 bg-muted rounded w-1/2`})]}),t(`div`,{className:`text-xs text-muted w-full flex justify-end mt-2`,children:t(`div`,{className:`h-3 bg-muted rounded w-1/4`})})]})]})},`skeleton-${r}`))}):null}function rb({selection:e,document:r,onSelectionChange:i,onRowClick:a,highlightRow:l,previewObject:u,selectedObject:d}){let{client:f}=Q(),[p,m]=X(void 0),[h,g]=X(void 0),[_,v]=X(void 0),y=typeof r.properties?.title==`string`?r.properties.title:r.name,b=e=>{e.stopPropagation(),i(r,e)};q(()=>{r?.content&&Vy(f,r,m,g,v)},[f,r]);let x=l?.(r);return n(s,{className:`relative flex flex-col border h-fit w-full ${d?.id===r.id?`border-attention border-4`:``} ${x?`border-blue-400 dark:border-blue-500 bg-blue-50/50 dark:bg-blue-900/20`:``}`,onClick:()=>a?.(r),children:[x&&t(`div`,{className:`absolute top-2 end-8 z-10`,children:t(ln,{className:`size-4 text-blue-600 dark:text-blue-400`})}),e&&t(`div`,{className:`absolute top-2 start-2 z-10 flex flex-col items-center gap-1`,children:t(`input`,{checked:e.isSelected(r.id),type:`checkbox`,onChange:b,onClick:e=>e.stopPropagation()})}),t(`div`,{className:`absolute top-1 end-1 z-10 flex flex-col items-center`,children:t(o,{variant:`ghost`,size:`sm`,title:`Preview Object`,onClick:e=>{e.stopPropagation(),u?.(r.id)},children:t(In,{className:`size-4 ${_===`ready`?`text-muted`:`text-white`}`})})}),p&&_===`ready`?t(`img`,{src:p,alt:h,className:`w-auto h-48 object-cover rounded-t-xl`}):t(`div`,{className:`h-48 bg-gray-700 rounded-t-xl flex items-center justify-center text-muted`,children:_}),t(Se,{className:`bg-gray-200 h-[2px]`}),n(c,{className:`p-2 flex flex-col`,children:[n(`div`,{className:`flex flex-col overflow-hidden`,children:[t(Be,{placement:`top`,description:y,children:t(`h3`,{className:`text-start font-medium leading-none truncate`,children:y})}),r?.type?.name?t(Be,{placement:`bottom`,size:`xs`,description:r?.type?.name,children:t(`p`,{className:`text-start text-xs text-muted truncate`,children:r?.type?.name})}):t(`p`,{className:`text-xs text-muted`,children:` `})]}),r.score&&n(`div`,{className:`text-xs text-muted w-full flex justify-end`,children:[`Score: `,r.score.toFixed(4)??`-`]})]})]})}function ib({objects:e,selection:r,isLoading:i,columns:a,onRowClick:o,highlightRow:s,selectedObject:c,toggleAll:l,onSelectionChange:u}){let{t:d}=Z();return n(Ne,{className:`w-full`,children:[t(je,{children:n(`tr`,{children:[r&&t(`th`,{children:t(`input`,{type:`checkbox`,onChange:l})}),a.map(e=>t(`th`,{children:e.name},e.name))]})}),n(Ae,{isLoading:i,columns:a.length+1,children:[e?.map(e=>{let i=s?.(e);return n(`tr`,{className:`group cursor-pointer hover:bg-muted ${c?.id===e.id?`bg-muted`:``} ${i?`bg-blue-50 dark:bg-blue-900/20`:``}`,onClick:()=>{o?.(e)},children:[r&&t(`td`,{onClick:e=>e.stopPropagation(),children:t(`input`,{checked:r.isSelected(e.id),type:`checkbox`,className:`${r.isSelected(e.id)?``:`hidden group-hover:block`}`,onChange:t=>u(e,t)})}),a.map((t,n)=>t.render(e,n)),t(`td`,{className:`w-8 text-center`,children:i&&t(ln,{className:`size-4 text-blue-600 dark:text-blue-400 inline-block`})})]},e.id)}),e.length===0&&t(`tr`,{children:t(`td`,{colSpan:a.length+ +!!r,className:`text-center`,children:d(`store.noObjectsDragAndDrop`)})})]})]})}function ab({objects:r,selection:i,isLoading:a,onSelectionChange:o,onRowClick:s,highlightRow:c,previewObject:l,selectedObject:u}){return n(e,{children:[t(nb,{isLoading:a}),t(`div`,{className:`w-full gap-2 grid xs:grid-cols-1 sm:grid-cols-2 md:grid-cols-4 lg:grid-cols-6 @xs:grid-cols-1 @sm:grid-cols-2 @md:grid-cols-3 @lg:grid-cols-4`,children:r.map(e=>t(rb,{document:e,selection:i,onSelectionChange:o,onRowClick:s,highlightRow:c,previewObject:l,selectedObject:u},e.id))})]})}var ob=class{client;limit;collectionId;facets=new Ce({});result=new Ce({objects:[],isLoading:!1});initialized=!1;facetSpecs=[];query={};constructor(e,t=100){this.client=e,this.limit=t}withFacets(e){return this.facetSpecs=e,this}get objects(){return this.result.value.objects}get error(){return this.result.value.error}get isRunning(){return this.result.value.isLoading}get hasMore(){return this.result.value.hasMore||!1}getFilterValue(e){return this.query[e]}setFilterValue(e,t){this.query[e]=t,this.search()}setDefaultKeys(e){}clearFilters(e=!0){let{parent:t,full_text:n,vector:r,weights:i,score_aggregation:a,dynamic_scaling:o,limit:s,all_revisions:c}=this.query;this.query={parent:t,...n!==void 0&&{full_text:n},...r!==void 0&&{vector:r},...i!==void 0&&{weights:i},...a!==void 0&&{score_aggregation:a},...o!==void 0&&{dynamic_scaling:o},...s!==void 0&&{limit:s},...c!==void 0&&{all_revisions:c}},e&&this.search()}getFacetBuckets(e){let t=this.facets.value[e];return Array.isArray(t)?t:[]}resetFacets(){this.query={}}reset(e=!1){this.initialized=!1,this.result.value={objects:[],isLoading:e,hasMore:!0}}_updateRunningState(e){let t=this.result.value;this.result.value={objects:t.objects,isLoading:e,error:t.error,hasMore:t.hasMore}}_searchRequest(e,t,n,r=!0){let i={limit:t,offset:n,query:e,facets:r?this.facetSpecs:void 0};return this.collectionId?this.client.collections.searchMembers(this.collectionId,i):this.client.objects.search(i)}_facetsRequest(){let e={facets:this.facetSpecs,query:this.query};return this.collectionId?this.client.collections.computeFacets(this.collectionId,e):this.client.objects.computeFacets(e)}computeFacets(e){this._facetsRequest().then(e=>{this.facets.value=e})}async _search(e=!1,t=!1){if(this.isRunning&&e)return!1;let n=this.result.value;e||(this.initialized=!0),this.result.value={isLoading:!0,objects:e?this.objects:[],hasMore:!e||this.result.value.hasMore};let r=this.limit,i=e?this.objects.length:0;try{let n=await this._searchRequest(this.query,r,i,!t),a=n.results||[],o=n.facets||{};return this.result.value={isLoading:!1,objects:e?this.objects.concat(a):a,hasMore:a.length===r},!t&&o&&Object.keys(o).length>0&&(this.facets.value=o),!0}catch(e){if(typeof e==`object`&&e&&`status`in e&&e.status===404)return this.result.value={isLoading:!1,objects:[],hasMore:!1},!1;let t=e instanceof Error?e:Error(String(e));return this.result.value={error:t,isLoading:!1,objects:n.objects,hasMore:!1},!1}}search(e=!1){return this.isRunning?Promise.resolve(!1):this._search(!1,e)}loadMore(e=!1){return this.isRunning||!this.hasMore||this.query.vector?Promise.resolve(!1):(this.objects.length>0&&(e=!0),this._search(!0,e))}};const sb=ot(void 0);function cb(){return lt(sb)}function lb(){return Ze(cb().facets)}function ub(){let e=cb();return{...Ze(e.result),search:e}}function db(){let e=cb();return Ze(e.facets).total}const fb=Vt.getFixedT(null,Bt);var pb;(function(e){e.CREATE=`create`,e.SKIP=`skip`,e.UPDATE=`update`})(pb||={});async function mb(e){try{let t=await e.arrayBuffer(),n=new xa;return n.appendByteArray(new Uint8Array(t)),n.end()?.toString()}catch(e){console.error(`Error calculating file hash:`,e);return}}async function hb(e,t){let n=[];for(let r=0;r<e.length;r+=5){let i=e.slice(r,r+5),a=await Promise.all(i.map(async e=>{let n=t||`/`;if(e.webkitRelativePath){let r=e.webkitRelativePath.split(`/`);if(r.length>1){let e=r.slice(0,-1).join(`/`);n=t?`${t}/${e}`:e}}return{file:e,hash:await mb(e),name:e.name,size:e.size,location:n}}));n.push(...a)}return n}function gb(){let{client:e}=Q(),t=Xe();return{checkDocumentProcessing:K(async(n,r,i)=>{try{console.log(`Preparing metadata for ${n.length} files...`);let t=await hb(n,r);return await(async()=>{let n=t.map(e=>e.hash).filter(Boolean);if(n.length===0)return;let r={"content.etag":{$in:n}},a;if(i){let t={query:{match:r},select:`id content.etag`};a=(await e.store.collections.searchMembers(i,t)).results.filter(e=>typeof e.id==`string`)}else{let t={query:r,select:`id content.etag`};a=(await e.store.objects.find(t)).flatMap(e=>typeof e.id==`string`?[{id:e.id,content:e.content}]:[])}for(let e of a){let n=t.find(t=>t.hash===e.content?.etag);n&&(n.existingId=e.id,n.action=pb.SKIP)}})(),await(async()=>{let n=t.filter(e=>e.action!==pb.SKIP),r=n.map(e=>e.location),a=Array.from(new Set(r)),o=[];for(let t of a){let r={"content.name":{$in:n.filter(e=>e.location===t).map(e=>e.name)},location:t||`/`};if(i){let t=e.store.collections.searchMembers(i,{query:{match:r},select:`id content.name location`}).then(e=>e.results);o.push(t)}else{let t=e.store.objects.find({query:r,select:`id content.name location`});o.push(t)}}let s=(await Promise.all(o)).flat();console.log(`Found ${s.length} document to update`,s);for(let e of s){let n=t.find(t=>t.name===e.content?.name&&(t.location?t.location===e.location:e.location===`/`));n&&(n.existingId=e.id,n.action=pb.UPDATE)}console.log(`Reconciled ${t.filter(e=>e.action===pb.UPDATE).length}`)})(),t.forEach(e=>{e.action||=pb.CREATE}),console.log(`Document processing check results:`,{totalFiles:n.length,toCreate:t.filter(e=>e.action===pb.CREATE).length,toUpdate:t.filter(e=>e.action===pb.UPDATE).length,toSkip:t.filter(e=>e.action===pb.SKIP).length}),t}catch(e){throw t({title:fb(`store.errorInUploadProcessingCheck`),status:`error`,description:Ve(e)}),console.log(`Error in file upload processing check`,e),Error(`Error in file upload processing check: ${Ve(e)}`,{cause:e})}},[e,t])}}function _b({isOpen:r,onClose:i,files:a,collectionId:s,selectedFolder:c,title:l,children:u,onUploadComplete:d,hideFileSelection:f=!1,showTypeSelectionOnly:p=!1,allowFolders:m=!0,initialTypeId:h,defaultProperties:g}){let{client:_}=Q(),{registry:v}=Tv(),y=Xe(),{t:b}=Z(),x=l??b(`upload.uploadFiles`),[S,C]=X([]),[w,T]=X([]),[E,D]=X(!1),[O,k]=X(null),[A,j]=X([]),[M,N]=X(!1),[P,F]=X(!1),[I,L]=X(0),[ee,R]=X(Date.now()),[te,z]=X(void 0),[ne,B]=X(null),[ce,V]=X(x),[le,ue]=X(``);q(()=>{s&&_.store.collections.retrieve(s).then(z)},[_.store.collections.retrieve,s]),q(()=>{M?(V(b(`upload.uploadingFiles`)),ue(`${Math.round(I)}% complete`)):P?(V(b(`upload.uploadComplete`)),ue(``)):E?(V(b(`upload.fileAnalysisResults`)),ue(`${S.length} file${S.length===1?``:`s`}`)):S.length>0?(V(x),ue(b(`upload.checkingForDuplicates`))):(V(x),ue(``))},[M,P,E,x,I,S.length,b]);let de=()=>!te&&!c?null:n(re,{className:`mb-4`,status:`default`,icon:t(qn,{className:`size-5`}),children:[t(`div`,{className:`flex items-center`,children:t(`span`,{className:`font-medium`,children:b(`upload.uploadLocation`)})}),n(`div`,{className:`text-sm mt-1`,children:[te&&n(`div`,{className:`flex items-center`,children:[t(`span`,{className:`me-1`,children:b(`upload.collectionLabel`)}),t(`span`,{className:`font-medium`,children:te.name})]}),c&&n(`div`,{className:`flex items-center mt-1`,children:[t(`span`,{className:`me-1`,children:b(`upload.folderLabel`)}),t(`span`,{className:`font-medium`,children:c})]})]})]}),[fe,pe]=X({toCreate:0,toUpdate:0,toSkip:0}),{checkDocumentProcessing:me}=gb(),he=J(()=>v?.types||[],[v?.types]),ge=K(async e=>{if(e.length)try{console.log(`Processing ${e.length} files to determine required actions...`);let t=await me(e,c,s);T(t);let n=t.filter(e=>e.action===pb.CREATE).length,r=t.filter(e=>e.action===pb.UPDATE).length,i=t.filter(e=>e.action===pb.SKIP).length;pe({toCreate:n,toUpdate:r,toSkip:i}),y({title:b(`upload.filesAnalyzed`),description:`${e.length} file(s): ${n} new, ${r} to update, ${i} to skip`,status:`info`,duration:4e3}),D(!0)}catch(e){console.error(`Error processing files:`,e),y({title:b(`agent.error`),description:b(`upload.errorAnalyzingFiles`),status:`error`,duration:5e3})}},[me,s,c,b,y]);q(()=>{r&&(T([]),D(!1),k(h?v?.getType(h)??null:null),j([]),N(!1),F(!1),L(0),pe({toCreate:0,toUpdate:0,toSkip:0}),B(null),V(x),ue(``),a&&a.length>0?(C(a),ge(a)):C([]),R(Date.now()))},[a,h,r,ge,x,v]);let _e=()=>{C([]),T([]),D(!1),k(null),j([]),N(!1),F(!1),L(0),pe({toCreate:0,toUpdate:0,toSkip:0}),B(null),V(x),ue(``),R(Date.now()),i()},ve=e=>{e&&e.length>0&&(C(e),ge(e))},ye=async()=>{if(!w.length)return;let e=O?.id||null,t=w.map(e=>({file:e.file,status:`pending`,progress:0,action:e.action===pb.CREATE?`create`:e.action===pb.UPDATE?`update`:`skip`}));j(t),N(!0),F(!1);let n=w.filter(e=>e.action===pb.SKIP),r=w.filter(e=>e.action===pb.UPDATE),i=w.filter(e=>e.action===pb.CREATE),a={success:!0,objectIds:[],uploadedFiles:[],skippedFiles:[],failedFiles:[]};for(let t of n)t.existingId&&(a.objectIds.push(t.existingId),a.skippedFiles.push({id:t.existingId,name:t.name,type:e,status:`skipped`,location:t.location}),j(e=>e.map(e=>e.file===t.file?{...e,status:`success`,progress:100,id:t.existingId}:e)));let o=async(t,n)=>{let r=[];for(let e=0;e<t.length;e+=50)r.push(t.slice(e,e+50));for(let i=0;i<r.length;i++){let o=r[i];if(console.log(`Processing ${n} batch ${i+1}/${r.length} (${o.length} files)`),t.length>50){let e=i*50;y({title:b(`upload.processingFilesAction`,{action:n}),description:b(`upload.processedCount`,{processed:e,total:t.length}),status:`info`,duration:2e3})}let c=0;await Promise.all(o.map(async t=>{try{if(j(e=>e.map(e=>e.file===t.file?{...e,status:`uploading`,progress:20}:e)),n===`update`&&t.existingId)await _.store.objects.update(t.existingId,{type:e||void 0,content:t.file,location:t.location,name:t.name},{createRevision:!0,revisionLabel:`upload on ${new Date().toISOString()}`}),j(e=>e.map(e=>e.file===t.file?{...e,status:`success`,progress:100,id:t.existingId}:e)),a.objectIds.push(t.existingId),a.uploadedFiles.push({id:t.existingId,name:t.name,type:e,status:`updated`,location:t.location});else{let n=await _.store.objects.create({type:e||void 0,content:t.file,location:t.location||t.file.webkitRelativePath||t.name,properties:g},{collection_id:s});j(e=>e.map(e=>e.file===t.file?{...e,status:`success`,progress:100,id:n.id}:e)),a.objectIds.push(n.id),a.uploadedFiles.push({id:n.id,name:t.name,type:e,status:`created`,location:t.location})}}catch(n){console.error(`Failed to process file ${t.name}:`,n),j(e=>e.map(e=>e.file===t.file?{...e,status:`error`,progress:100,message:Ve(n,`Unknown error`)}:e)),a.failedFiles.push({name:t.name,error:Ve(n,`Unknown error`),status:`failed`,location:t.location,type:e}),a.success=!1}c++,(c%5==0||c===o.length)&&j(e=>{let t=e.filter(e=>e.status===`success`||e.status===`error`).length,n=e.length,r=n>0?Math.round(t/n*100):0;return L(r),e})}))}};r.length>0&&await o(r,`update`),i.length>0&&await o(i,`create`),j(e=>{let t=e.filter(e=>e.status===`pending`).map(e=>({...e,status:`error`,progress:100,message:b(`upload.uploadProcessInterrupted`)}));return t.length>0?(t.forEach(e=>{a.failedFiles.push({name:e.file.name,error:b(`upload.uploadProcessInterrupted`),status:`failed`,type:O?.id||null})}),a.success=!1,e.map(e=>e.status===`pending`?{...e,status:`error`,progress:100,message:b(`upload.uploadProcessInterrupted`)}:e)):e}),N(!1),F(!0);let c=a.uploadedFiles.filter(e=>e.status===`created`).length,l=a.uploadedFiles.filter(e=>e.status===`updated`).length,u=a.skippedFiles.length,d=a.failedFiles.length,f=``;c>0&&(f+=`${c} file${c===1?``:`s`} uploaded`),l>0&&(f+=f?`, `:``,f+=`${l} file${l===1?``:`s`} updated`),u>0&&(f+=f?`, `:``,f+=`${u} file${u===1?``:`s`} skipped`),d>0&&(f+=f?`, `:``,f+=`${d} file${d===1?``:`s`} failed`),y({title:b(`upload.uploadComplete`),description:f,status:d>0?`warning`:`success`,duration:5e3}),B(a)},xe=()=>n(`div`,{className:`mb-4`,children:[n(`div`,{className:`block text-sm font-medium mb-2`,children:[b(`store.contentType`),` `,t(`span`,{className:`text-muted font-normal`,children:b(`store.optional`)}),t(Be,{description:b(`upload.contentTypeTooltip`),placement:`top`,size:`xs`,children:t(rr,{className:`size-3 ms-2`})})]}),t(be,{options:he,value:O,optionLabel:e=>e?e.name:b(`store.selectContentTypeLabel`),placeholder:b(`store.selectContentTypeAuto`),onChange:e=>k(e===void 0?null:e),filterBy:`name`,isClearable:!0}),!O&&t(`div`,{className:`p-2 rounded-md`,children:n(`div`,{className:`flex items-center text-attention`,children:[t(cn,{className:`size-4 me-1`}),b(`store.automaticTypeDetection`),t(Be,{description:b(`store.automaticTypeDetectionDescription`),placement:`top`,size:`xs`,children:t(rr,{className:`size-3 ms-2`})})]})})]});return n(ie,{isOpen:r,onClose:_e,className:`mx-auto`,disableCloseOnClickOutside:!0,children:[t(se,{description:le,children:ce}),p?n(ae,{children:[u,de(),xe()]}):S.length===0&&!f?n(ae,{className:`flex flex-col items-center justify-center p-8`,children:[de(),t(yt,{onDrop:ve,message:b(`upload.dragAndDrop`),buttonLabel:b(`upload.selectFiles`),className:`w-full h-64`,allowFolders:m}),u]}):!M&&!P?t(ae,{children:E?n(e,{children:[de(),t(`div`,{className:`mb-4`,children:t(`div`,{className:`p-4 rounded-md mb-4`,children:n(`div`,{className:`grid grid-cols-3 gap-4`,children:[n(`div`,{className:`flex flex-col items-center`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(si,{className:`size-5 text-primary`}),t(`span`,{className:`font-medium`,children:b(`upload.new`)})]}),t(`div`,{className:`text-2xl font-semibold`,children:fe.toCreate})]}),n(`div`,{className:`flex flex-col items-center`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(cn,{className:`size-5 text-success`}),t(`span`,{className:`font-medium`,children:b(`upload.update`)})]}),t(`div`,{className:`text-2xl font-semibold`,children:fe.toUpdate})]}),n(`div`,{className:`flex flex-col items-center`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(Gt,{className:`size-5 text-mixer-attention/40`}),t(`span`,{className:`font-medium`,children:b(`upload.skip`)})]}),t(`div`,{className:`text-2xl font-semibold`,children:fe.toSkip})]})]})})}),xe(),t(re,{className:`mb-4`,status:`info`,children:fe.toCreate+fe.toUpdate>0?n(`div`,{className:`space-y-1`,children:[t(`p`,{children:b(`upload.filesReadyToProcess`,{count:fe.toCreate+fe.toUpdate})}),t(`p`,{children:fe.toSkip>0&&b(`upload.filesToSkip`,{count:fe.toSkip})})]}):fe.toSkip>0?t(`span`,{children:b(`upload.allFilesExist`,{count:fe.toSkip})}):t(`span`,{children:b(`upload.noFilesToProcess`)})})]}):n(`div`,{className:`flex flex-col items-center justify-center py-4`,children:[t(De,{size:`lg`,className:`mb-4`}),t(`div`,{className:`text-lg font-medium`,children:b(`upload.analyzingFiles`)})]})}):M?n(ae,{children:[de(),t(`div`,{className:`mb-4`,children:t(`div`,{className:`h-2 bg-muted/20 rounded-full overflow-hidden`,children:t(`div`,{className:`h-full bg-primary rounded-full`,style:{width:`${I}%`}})})}),t(`div`,{className:`max-h-96 overflow-y-auto`,children:A.map((e,r)=>n(`div`,{className:`flex items-center py-2 border-b border-border last:border-b-0`,children:[n(`div`,{className:`me-3`,children:[e.status===`pending`&&t(Rn,{className:`size-5 text-muted`}),e.status===`uploading`&&t(De,{size:`sm`}),e.status===`success`&&t(cn,{className:`size-5 text-success`}),e.status===`error`&&t(gi,{className:`size-5 text-destructive`})]}),n(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`truncate font-medium`,children:e.file.name}),n(`div`,{className:`text-xs text-muted`,children:[e.status===`pending`&&b(`agent.waiting`),e.status===`uploading`&&b(`agent.uploading`),e.status===`success`&&(e.action===`create`?b(`store.created`):e.action===`update`?b(`store.updated`):b(`upload.skip`)),e.status===`error`&&e.message]})]})]},`${e.file.name}-${e.file.size}-${e.file.lastModified}`))})]}):t(ae,{children:n(`div`,{className:`mb-4`,children:[de(),t(Ot,{files:A.map(e=>{let t;return t=e.status===`success`?e.action===`create`?`success`:e.action===`update`?`updated`:`skipped`:`failed`,{name:e.file.name,status:t,error:e.status===`error`?e.message:void 0}}),location:c||void 0,collection:te?.name})]})}),(()=>{if(p)return n(oe,{children:[t(o,{variant:`ghost`,onClick:_e,children:b(`modal.cancel`)}),t(o,{onClick:()=>{let e={success:!0,objectIds:[],uploadedFiles:[{name:`type-selection`,type:O?.id||null,status:`created`}],skippedFiles:[],failedFiles:[]};d&&d(e),_e()},children:O?b(`upload.useTypeName`,{typeName:O.name}):b(`upload.useAutoDetection`)})]});if(S.length===0&&!f)return t(oe,{children:t(o,{variant:`ghost`,onClick:_e,children:b(`modal.cancel`)})});if(!M&&!P){let e=E;return n(oe,{children:[t(o,{variant:`ghost`,onClick:_e,children:b(`modal.cancel`)}),t(o,{disabled:!e,onClick:ye,children:fe.toCreate+fe.toUpdate>0?b(`agent.upload`):b(`upload.continue`)})]})}return M?t(oe,{children:t(o,{variant:`ghost`,disabled:!0,children:b(`agent.uploading`)})}):n(oe,{children:[t(o,{variant:`ghost`,onClick:()=>{C([]),T([]),D(!1),k(null),j([]),N(!1),F(!1),L(0),pe({toCreate:0,toUpdate:0,toSkip:0})},children:b(`upload.uploadMore`)}),t(o,{onClick:()=>{d&&ne&&d(ne),_e()},children:b(`agent.close`)})]})})()]},ee)}function vb(e){let t=typeof e==`function`?e:e.onUploadDone,{client:n,project:r,store:i}=Q(),a=cb(),o=Xe(),s=Vt.getFixedT(null,Bt),{checkDocumentProcessing:c}=gb();return async(e,l,u)=>{let d={success:!1,objectIds:[],uploadedFiles:[],skippedFiles:[],failedFiles:[]};if(!r)return o({status:`error`,title:s(`store.noProjectSelected`),duration:3e3}),d;if(!e||e.length===0)return o({status:`warning`,title:s(`store.noFilesSelected`),duration:3e3}),d;let f=Array.from(e).filter(e=>e.size>0);if(f.length===0)return o({status:`error`,title:s(`store.noValidFilesSelected`),description:s(`store.pleaseSelectValidFiles`),duration:5e3}),d;let p=[],m=[],h=[];console.log(`Processing ${f.length} files with smart file processing...`);let g=await c(f,null,u),_=g.filter(e=>e.action===pb.CREATE).length,v=g.filter(e=>e.action===pb.UPDATE).length,y=g.filter(e=>e.action===pb.SKIP).length;o({title:s(`store.filesAnalyzedTitle`),description:`${f.length} file(s): ${_} new, ${v} to update, ${y} to skip`,status:`info`,duration:4e3});for(let e of g.filter(e=>e.action===pb.SKIP&&e.existingId))p.push({id:e.existingId,name:e.name,type:l,status:`skipped`,location:e.location});let b=g.filter(e=>(e.action===pb.CREATE||e.action===pb.UPDATE)&&e.file);if(b.length>0){console.log(`Processing ${b.length} files (${b.filter(e=>e.action===pb.CREATE).length} create, ${b.filter(e=>e.action===pb.UPDATE).length} update)...`);let e=[];for(let t=0;t<b.length;t+=50)e.push(b.slice(t,t+50));for(let t=0;t<e.length;t++){let r=e[t],a=t*50;console.log(`Processing batch ${t+1}/${e.length} (${r.length} files)`),b.length>50&&o({title:s(`store.processingFiles`),description:`Processed ${a}/${b.length} files...`,status:`info`,duration:2e3});let c=await Promise.all(r.map(async e=>{try{if(e.action===pb.UPDATE&&e.existingId){let t=await n.store.objects.update(e.existingId,{type:l||void 0,content:e.file,location:e.location,name:e.name},{createRevision:!0,revisionLabel:`upload on ${new Date().toISOString()}`});return m.push({id:e.existingId,name:e.name,type:l,status:`updated`,location:e.location}),d.objectIds.push(e.existingId),{success:!0,id:t.id,name:e.name,action:`update`}}{let t=u?{collection_id:u}:void 0,n=await i.objects.create({type:l||void 0,content:e.file,location:e.location||e.file.webkitRelativePath||e.name},t);m.push({id:n.id,name:e.name,type:l,status:`created`,location:e.location})}}catch(t){console.error(`Failed to process file ${e.name}:`,t),h.push({name:e.name,error:Ve(t,`Unknown error`),status:`failed`,location:e.location,type:l}),o({status:`error`,title:s(`store.processingFailedFor`,{name:e.name}),description:Ve(t),duration:4e3})}})),f=m.filter(e=>e.status===`created`),p=m.filter(e=>e.status===`updated`),g=m.filter(e=>e.status===`failed`);console.log(`Batch ${t+1} results:`,{creates:f,updates:p,failures:g,total:c.length})}}let x=m.filter(e=>e.status===`created`).length,S=m.filter(e=>e.status===`updated`).length,C=m.filter(e=>e.status===`failed`).length,w=m.filter(e=>e.status===`skipped`).length;t&&(console.log(`Upload complete:`,{totalObjectIds:d.objectIds.length,uploadedFiles:x,updatedFiles:S,skippedFiles:w,failedFiles:C}),await t(d.objectIds));let T=``;return x>0&&(T+=`${x} file${x===1?``:`s`} uploaded`),S>0&&(T+=T?`, `:``,T+=`${S} file${S===1?``:`s`} updated`),w>0&&(T+=T?`, `:``,T+=`${w} file${w===1?``:`s`} skipped (already existed)`),C>0&&(T+=T?`, `:``,T+=`${C} file${C===1?``:`s`} failed`),T&&o({status:C>0?`warning`:`success`,title:T,duration:4e3}),a.search(),d}}const yb=[{name:`ID`,field:`id`,type:`objectId?slice=-7`},{name:`Name`,field:`.`,type:`objectName`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Updated At`,field:`updated_at`,type:`date`}];function bb({isGridView:e=!1,onUpload:n,collectionId:r,...i}){return n?t(xb,{...i,onUpload:n,isGridView:e,collectionId:r}):t(Sb,{...i,isGridView:e})}function xb({isGridView:e,onUpload:r,collectionId:i,skipTypeModal:a=!1,...o}){let[s,c]=X(!1),[l,u]=X([]),[d,f]=X(!1),[p,m]=X(null),[h,g]=X(!1),_=cb(),v=Xe(),{t:y}=Z(),{checkDocumentProcessing:b}=gb(),x=async(e,t)=>{console.log(`Files dropped on ObjectTable:`,e.length,t),c(!0);try{if(i){let t=await b(e,null,i);m(t);let n=t.filter(e=>e.action===`create`).length,r=t.filter(e=>e.action===`update`).length,a=t.filter(e=>e.action===`skip`).length;v({title:y(`store.filesReadyToProcess`),description:`${e.length} file(s): ${n} new, ${r} to update, ${a} to skip`,status:`info`,duration:4e3})}else m(null)}catch(e){console.error(`Error processing files:`,e),v({title:y(`store.errorProcessingFiles`),description:y(`store.errorCheckingDuplicates`),status:`error`,duration:4e3}),m(null)}finally{if(c(!1),u(e),f(!1),a){console.log(`Skipping type modal and calling onUpload directly`,{filesLength:e.length,processedFilesLength:p?.length});let t=r(e,null,i);t&&typeof t==`object`&&(t.processedFiles=p)}else console.log(`Setting typeSelectionOpen to true`,{filesLength:e.length}),g(!0)}},S=e=>{let t=[...l];u([]),m(null),g(!1),t.length>0&&e!==void 0&&(c(!0),console.log(`Starting upload with`,{typeId:e,filesCount:t.length,hasProcessingResults:!!p,collectionId:i}),r(t,e,i).finally(()=>{c(!1),_.search()}))},C=e=>{e.preventDefault(),e.stopPropagation(),f(!0)};return n(`div`,{className:`min-h-[400px] relative`,onDragOver:C,onDragEnter:C,onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),!e.currentTarget.contains(e.relatedTarget)&&f(!1)},onDrop:e=>{if(e.preventDefault(),e.stopPropagation(),f(!1),e.dataTransfer.items){let t=[];for(let n=0;n<e.dataTransfer.items.length;n++){let r=e.dataTransfer.items[n];if(r.kind===`file`){let e=r.getAsFile();e&&t.push(e)}}if(t.length>0){let e={count:t.length,message:`Preparing to upload ${t.length} file${t.length===1?``:`s`}...`};x(t,e)}}},children:[t(`div`,{className:Qe(`bg-white dark:bg-gray-800 opacity-40 absolute inset-0 z-50 flex justify-center items-center`,s?`block`:`hidden`),children:t(De,{size:`xl`})}),t(Sb,{...o,isGridView:e}),t(`div`,{className:Qe(`absolute inset-0 pointer-events-none`,d?`z-40`:`-z-10`),children:t(`div`,{className:`w-full h-full relative`,children:t(yt,{onDrop:x,message:`Drop files or folders here to upload`,className:Qe(`absolute inset-0 bg-white/90 dark:bg-gray-800/90 pointer-events-auto`,d?`flex`:`hidden`),buttonLabel:`Select Files or Folders`,allowFolders:!0})})}),t(_b,{isOpen:h&&l.length>0,onClose:()=>{u([]),m(null),g(!1),S(void 0)},files:l,collectionId:i,selectedFolder:null,title:`Upload Files`,onUploadComplete:e=>{if(e){if(e.failedFiles&&e.failedFiles.length>0&&v({title:y(`store.uploadIssues`),description:`${e.failedFiles.length} file(s) failed to upload`,status:`warning`,duration:5e3}),e.success){let t=e.uploadedFiles.filter(e=>e.status===`created`).length,n=e.uploadedFiles.filter(e=>e.status===`updated`).length,r=e.skippedFiles.length;(t>0||n>0)&&v({title:y(`store.uploadComplete`),description:`${t>0?`${t} created`:``}${t>0&&n>0?`, `:``}${n>0?`${n} updated`:``}${r>0?`, ${r} skipped`:``}`,status:`success`,duration:5e3})}_.search()}u([]),m(null),g(!1),e?.success&&e.objectIds.length>0?S(null):S(void 0)}})]})}function Sb({objects:e,layout:n=yb,isLoading:r,onRowClick:i,onSelectionChange:a,highlightRow:o,previewObject:s,selectedObject:c,isGridView:l}){let u=xy(),d=(t,n)=>{if(u){let r=n.nativeEvent instanceof MouseEvent&&n.nativeEvent.shiftKey;if(!n.target.checked)u.remove(t.id);else if(u.add(t),r){let n=e.findIndex(e=>e.id===t.id),r=Cb(e,n,u);if(r>-1&&r<n-1){let t=[];for(let i=r+1;i<n;i++)t.push(e[i]);u.addAll(t)}else{let t=wb(e,n,u);if(t>-1&&t>n+1){let r=[];for(let i=n+1;i<t;i++)r.push(e[i]);u.addAll(r)}}}a?.(u)}},f=t=>{u&&(t.target.checked?u.addAll(e):u.removeAll())},p=J(()=>{let e=n.length>0?n:yb;return console.log(`Using layout with columns:`,e.map(e=>e.name).join(`, `)),e.map(e=>new tb(e,s))},[n,s]);return t(l?ab:ib,{objects:e,isLoading:r,columns:p,onRowClick:i,highlightRow:o,previewObject:s,selectedObject:c,selection:u,toggleAll:f,onSelectionChange:d})}function Cb(e,t,n){for(let r=t-1;r>=0;r--)if(n.isSelected(e[r].id))return r;return-1}function wb(e,t,n){let r=e.length;for(let i=t+1;i<r;i++)if(n.isSelected(e[i].id))return i;return-1}function Tb({children:e,limit:n,parent:r,typeId:i,facets:a,name:o,collectionId:s}){let{store:c}=Q(),l=J(()=>{let e;a?e=a:(e=[{name:`status`,field:`status`},{name:`location`,field:`location`}],i||e.unshift({name:`type`,field:`type`}));let t=new ob(c,n).withFacets(e);return t.collectionId=s,t.query.type=i,t.query.parent=r,t.query.name=o,s&&(t.query.all_revisions=!0),t},[s,a,n,o,r,c,i]);return t(sb.Provider,{value:l,children:e})}const Eb=`vertesia.content_store.lastDisplayedView`;function Db({onUpdate:e}){let{t:n}=Z(),[r,i]=X(localStorage.getItem(Eb)===`grid`),a=()=>{r?c():s()},s=()=>{localStorage.setItem(Eb,`grid`),i(!0),e(!0)},c=()=>{localStorage.setItem(Eb,`table`),i(!1),e(!1)};return t(o,{variant:`outline`,onClick:a,title:n(r?`misc.tableView`:`misc.thumbnailView`),children:t(r?ri:or,{})})}Db.LAST_DISPLAYED_VIEW=Eb;const Ob=[{name:`Name`,field:`properties.title`,type:`string`,fallback:`name`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Created At`,field:`created_at`,type:`date`}];function kb({onChange:e,selectedIds:n}){return t(Tb,{children:t(Ab,{onRowClick:t=>{e(t||void 0)},selectedIds:n})})}function Ab({onRowClick:e,selectedIds:r}){let{t:i}=Z(),a=K(e=>!!r?.has(e.id),[r]),[s,c]=X(!1),[l,u]=X(localStorage.getItem(`vertesia.content_store.lastDisplayedView`)===`grid`),{search:d,isLoading:f,error:p,objects:m,hasMore:h}=ub(),g=Y(null);W(g,()=>{s&&h&&!f&&(c(!1),d.loadMore(!0).finally(()=>{c(!0)}))},{threshold:.1,deps:[s,h,f]}),q(()=>{d.search().finally(()=>{c(!0)})},[d]);let _=lb(),v=cb();return p?t(M,{title:i(`store.searchFailed`),children:p.message}):n(`div`,{className:`flex flex-col gap-2 h-full w-full`,children:[n(`div`,{className:`flex justify-between items-center flex-shrink-0`,children:[t(zv,{facets:_,search:v}),n(`div`,{className:`flex items-center gap-2`,children:[t(o,{variant:`outline`,onClick:()=>{c(!1),d.search().then(()=>c(!0))},"aria-label":`Refresh`,children:t(zr,{size:16})}),t(Db,{onUpdate:u})]})]}),n(`div`,{className:`@container relative flex-1 overflow-y-auto`,children:[t(bb,{objects:m||[],isLoading:!m.length&&f,layout:Ob,onRowClick:e,highlightRow:r?.size?a:void 0,isGridView:l}),t(`div`,{ref:g,className:`h-4 w-full`})]})]})}function jb(e){let t=Math.max(0,e)/1e3,n=+(t>0&&t<10&&!Number.isInteger(t));return`${new Intl.NumberFormat(void 0,{maximumFractionDigits:n}).format(t)}K`}function Mb({onSend:e,onStop:r,approvalModeSlot:i,mcpSlot:a,disabled:s=!1,isSending:c=!1,isStopping:l=!1,isStreaming:u=!1,isCompleted:d=!1,contextWindowUsage:f,onCompactContext:p,isCompactingContext:m=!1,activeTaskCount:h=0,activeWorkstreams:g=[],onSelectWorkstream:_,placeholder:v,onFilesSelected:y,uploadedFiles:b=[],onRemoveFile:x,onRemoveProcessingFile:S,acceptedFileTypes:C,maxFiles:T=5,processingFiles:E,artifactRunId:D,hasProcessingFiles:O=!1,renderDocumentSearch:k,selectedDocuments:A=[],onRemoveDocument:j,hideObjectLinking:M=!1,hideFileUpload:N=!1,disableDropZone:P=!1,className:F,inputClassName:I}){let{t:L}=Z(),ee=v??L(`agent.typeYourMessage`),R=Y(null),te=Y(null),[z,ne]=X(``),[re,oe]=X(!1),[ce,V]=X(!1),[le,ue]=X(!1),de=!!(y&&!N),fe=de&&!P,pe=!M||de||!!k,me=b.length>=T,he=S??x,ge=J(()=>g.filter(e=>e.status===`running`||e.status===`canceling`),[g]),_e=ge.length||h,ve=f?L(`agent.contextUsageCompactLabel`,{percent:f.usedPercent}):void 0,ye=f?L(`agent.contextTokenUsage`,{used:jb(f.usedTokens),limit:jb(f.checkpointTokens)}):void 0,be=J(()=>{let e=[];if(!N&&E)for(let t of E.values()){let n=t.preview_url,r=t.status===Di.UPLOADING?L(`agent.uploading`):t.status===Di.PROCESSING?L(`agent.processing`):t.status===Di.ERROR?L(`agent.error`):t.status===Di.READY?L(`agent.ready`):t.status;e.push({id:t.id,name:t.name,contentType:t.content_type,artifactPath:t.artifact_path,previewUrl:n,removable:!!he,statusLabel:r,statusTone:t.status===Di.ERROR?`destructive`:t.status===Di.READY?`success`:`attention`})}if(!N)for(let t of b)e.push({id:t.id,name:t.name,contentType:t.type,artifactPath:t.artifact_path,previewUrl:t.previewUrl,removable:!!x,statusLabel:L(`agent.ready`),statusTone:`success`});for(let t of A)e.push({id:t.id,name:t.name,href:`/store/objects/${t.id}`,removable:!!j,statusTone:`info`});return e},[he,N,j,x,E,A,L,b]);q(()=>{!s&&d&&R.current?.focus()},[s,d]);let xe=K(e=>{if(!de||!y)return;let t=Array.from(e),n=T-b.length,r=t.slice(0,n);r.length>0&&y(r)},[de,y,T,b.length]),Se=K(e=>{e.preventDefault(),e.stopPropagation(),fe&&ue(!0)},[fe]),Ce=K(e=>{e.preventDefault(),e.stopPropagation(),ue(!1)},[]),we=K(e=>{e.preventDefault(),e.stopPropagation(),ue(!1),fe&&e.dataTransfer?.files&&e.dataTransfer.files.length>0&&xe(e.dataTransfer.files)},[fe,xe]),Te=K(e=>{if(!de)return;let t=s_(e.clipboardData?.items);t.length>0&&xe(t)},[de,xe]),Ee=K(e=>{de&&e.target.files&&e.target.files.length>0&&(xe(e.target.files),e.target.value=``)},[de,xe]),Oe=K(()=>{te.current?.click()},[]),ke=K(()=>V(!1),[]),Ae=K(e=>V(!1),[]),je=()=>{let t=z.trim();!t||s||c||O||(e(t),ne(``))},Me=()=>{r&&!l&&r()},Ne=Y(0),Pe=e=>{if(e.key===`Enter`){if(!(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)){e.preventDefault(),z.trim().length>0&&je();return}e.shiftKey||(e.preventDefault(),He(e.currentTarget,ne));return}if(e.key===`Escape`&&u&&r){let e=Date.now();e-Ne.current<500?(Me(),Ne.current=0):Ne.current=e}},Fe=K(()=>{let e=R.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]);return q(()=>{Fe()},[z,Fe]),n(`div`,{className:H(`px-3 py-3 flex-shrink-0 transition-all fixed lg:sticky bottom-0 start-0 end-0 lg:start-auto lg:end-auto w-full bg-background/95 backdrop-blur z-10`,le&&fe&&`bg-info/10 border-info`,F),onDragOver:fe?Se:void 0,onDragLeave:fe?Ce:void 0,onDrop:fe?we:void 0,children:[le&&fe&&t(`div`,{className:`absolute inset-0 flex items-center justify-center bg-blue-100/80 dark:bg-blue-900/40 rounded-lg z-10 pointer-events-none`,children:n(`div`,{className:`text-blue-600 dark:text-blue-400 font-medium flex items-center gap-2`,children:[t(si,{className:`size-5`}),L(`agent.dropFilesToUpload`)]})}),de&&t(`input`,{ref:te,type:`file`,multiple:!0,accept:C,onChange:Ee,className:`hidden`}),t(O_,{activeWorkstreams:g,onSelectWorkstream:_}),n(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-2 rounded-2xl border border-border/70 bg-mixer-muted/15 p-2.5 shadow-lg shadow-black/5`,children:[be.length>0&&t(bd,{items:be,artifactRunId:D,variant:`composer`,onRemove:e=>{E?.has(e)?he?.(e):b.some(t=>t.id===e)?x?.(e):j?.(e)},className:`gap-1.5`}),t(`div`,{className:`flex min-w-0 flex-1`,children:t(ze,{ref:R,value:z,onKeyDown:Pe,onChange:e=>ne(e.target.value),onPaste:Te,disabled:s,"aria-label":ee,placeholder:ee,rows:1,style:{maxHeight:`160px`},className:H(`min-h-[44px] resize-none border-0 bg-transparent px-0 py-0 text-sm leading-6 shadow-none focus-visible:ring-0`,I)})}),n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[pe&&n(w,{align:`left`,trigger:t(o,{variant:`ghost`,size:`icon`,className:`size-8 rounded-full text-muted hover:bg-muted`,title:L(`agent.addAttachment`),children:t(Ir,{className:`size-4`})}),children:[!M&&n(B,{onClick:()=>oe(!0),isDisabled:!d,children:[t(Or,{className:`size-4`}),L(`agent.linkObject`)]}),de&&n(B,{onClick:Oe,isDisabled:me,children:[t(si,{className:`size-4`}),L(`agent.upload`)]}),k&&n(B,{onClick:()=>V(!0),children:[t(Un,{className:`size-4`}),t(`span`,{children:L(`agent.searchDocuments`)}),A.length>0&&t(`span`,{className:`ms-auto inline-flex items-center justify-center rounded-full bg-info/20 px-1.5 py-0.5 text-[10px] font-medium text-info`,children:A.length})]})]}),i,a,f&&t(Be,{asChild:!0,placement:`top`,size:`md`,className:`text-foreground shadow-lg`,description:n(`span`,{className:`block max-w-56 text-start text-sm leading-6`,children:[t(`span`,{className:`block`,children:L(`agent.contextRemainingUntilCompact`,{percent:f.remainingPercent})}),ye&&t(`span`,{className:`mt-1 block text-foreground/80`,children:ye})]}),children:t(o,{type:`button`,variant:`ghost`,size:`icon`,className:H(`size-8 rounded-lg text-info hover:bg-muted hover:text-info disabled:opacity-60`,`focus-visible:ring-2 focus-visible:ring-info/40`),"aria-label":ve,onClick:p,disabled:!p||m,children:m?t(De,{size:`sm`}):n(`svg`,{viewBox:`0 0 24 24`,className:H(`size-8 -rotate-90`,f.usedPercent>=90?`text-destructive`:f.usedPercent>=70?`text-attention`:`text-info`),"aria-hidden":`true`,children:[t(`circle`,{cx:`12`,cy:`12`,r:`9.75`,fill:`none`,strokeWidth:`4.5`,className:`stroke-current text-muted/50`}),t(`circle`,{cx:`12`,cy:`12`,r:`9.75`,fill:`none`,pathLength:100,strokeWidth:`4.5`,strokeLinecap:`round`,strokeDasharray:100,style:{strokeDashoffset:100-f.usedPercent},className:`stroke-current`})]})})}),ge.length===0&&_e>0&&t(`output`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,"aria-live":`polite`,children:n(`span`,{className:`inline-flex h-8 items-center gap-1 rounded-full px-2 text-xs text-muted`,children:[t(Ut,{className:`size-3 text-attention`}),L(`agent.activeWorkstreams`,{count:_e})]})})]}),u&&r&&!z.trim()?t(o,{onClick:Me,disabled:l,variant:`ghost`,size:`icon`,className:H(`size-9 rounded-full border border-border/60 bg-foreground text-background shadow-sm`,`hover:bg-foreground/90 hover:text-background`,`disabled:bg-mixer-muted/25 disabled:text-muted disabled:opacity-100`,`[&_svg]:text-destructive disabled:[&_svg]:text-muted`),title:L(`agent.stopTooltip`),children:l?t(De,{size:`sm`}):t($r,{className:`size-3 fill-current stroke-current`})}):t(o,{onClick:je,disabled:s||c||!z.trim()||O,variant:`ghost`,size:`icon`,className:H(`size-9 rounded-full border border-border/60 bg-foreground text-background shadow-sm`,`hover:bg-foreground/90 hover:text-background`,`disabled:bg-mixer-muted/25 disabled:text-muted disabled:opacity-100`),title:L(O?`agent.waitForFiles`:`agent.sendTooltip`),"aria-label":L(O?`agent.waitForFiles`:`agent.send`),children:c?t(De,{size:`sm`}):t(Yt,{className:`size-4`})})]})]}),n(ie,{isOpen:re,onClose:()=>oe(!1),className:`min-w-[60vw]`,children:[t(se,{children:L(`agent.linkObject`)}),t(ae,{className:`pb-6`,children:t(kb,{onChange:e=>{let t=`[${e.properties?.title||e.name||`Object`}](store:${e.id})`,n=z||``,r=R.current?.selectionStart||n.length,i=n.substring(0,r)+t+n.substring(r);ne(i),oe(!1),setTimeout(()=>{if(R.current){R.current.focus();let e=r+t.length;R.current.setSelectionRange(e,e)}},100)}})})]}),k?.({isOpen:ce,onClose:ke,onSelect:Ae})]})}function Nb({code:e}){let{onProposalSelect:n,onProposalSubmit:r}=Rt(),i=J(()=>Ft(e),[e]),a=J(()=>{if(i)return null;try{let t=e.trim(),i=JSON.parse(t);if(!i.options||!i.question&&!i.title)return null;let a={question:i.question||i.title||``,description:i.description,options:Array.isArray(i.options)?i.options.map(e=>({id:e.id||e.value||``,label:e.label||``,description:e.description})):void 0,allowFreeResponse:i.allowFreeResponse??i.multiple,variant:i.variant,onSelect:n,onSubmit:r};return!a.question||!a.options?.length?null:a}catch{return null}},[e,n,r,i]);return i?t(_t,{type:`proposal`,message:`Loading options...`}):a?t(gt,{type:`proposal`,fallbackCode:e,children:t(dl,{...a})}):t(_t,{type:`proposal`,error:`Invalid proposal specification`})}const Pb=ct(function({code:e}){let n=J(()=>{try{let t=JSON.parse(e);return t?.library===`vega-lite`&&t?.spec&&typeof t.spec==`object`?t:typeof t?.$schema==`string`&&t.$schema.includes(`vega`)?{library:`vega-lite`,spec:t}:null}catch{return null}},[e]);return n?t(po,{spec:n}):null}),Fb=ct(function({code:e}){let n=J(()=>{try{return{library:`vega-lite`,spec:JSON.parse(e)}}catch{return null}},[e]);return n?t(po,{spec:n}):null}),Ib={chart:Pb,"vega-lite":Fb,vegalite:Fb,"fusion-fragment":pa,proposal:Nb,askuser:Nb};function Lb({url:e,code:n}){let[r,i]=X(null);return q(()=>{import(e).then(e=>{i(()=>e.default)}).catch(t=>{console.error(`Failed to load remote widget component from `,e,t)})},[e]),r?t(r,{code:n}):null}async function Rb(e){let n=await e.apps.getInstalledApps(`tools`),r=new Set;for(let e of n){if(e.manifest.tool_collections&&e.manifest.tool_collections.length>0)for(let t of e.manifest.tool_collections||[]){let e=Wi(t).url;if(e.startsWith(`http://`)||e.startsWith(`https://`)){let t=e.indexOf(`/api/`);if(t>0){let n=e.substring(0,t);r.add(`${n}/api/widgets`)}}}e.manifest.endpoint&&e.manifest.capabilities?.includes(`tools`)&&r.add(new URL(`/api/widgets`,e.manifest.endpoint).toString())}let i=await Promise.all(Array.from(r).map(e=>fetch(e).then(e=>{if(!e.ok)throw Error(`Failed to fetch widgets: ${e.status} ${e.statusText}`);return e.json()}).then(e=>{let n=[],r=e.widgets;for(let[e,i]of Object.entries(r))n.push({name:e,component:e=>t(Lb,{url:i.url,code:e.code})});return n}).catch(()=>(console.error(`Failed to fetch skill widgets from `,e),null)))),a={};for(let e of i.flat())e&&(a[e.name]=e.component);return a}function zb({children:e}){let{client:n}=Q(),[r,i]=X(Ib);return q(()=>{Rb(n).then(e=>{i({...Ib,...e})})},[n]),t(vt,{components:r,children:e})}const Bb=new Map,Vb=[400,1200];async function Hb(e,t,n){for(let r=0;;r++)try{return await e.agents.sendSignal(t,`FileBatchClosed`,n),!0}catch(e){if(r>=Vb.length)return console.error(`Failed to close staged file batch:`,e),!1;await new Promise(e=>setTimeout(e,Vb[r]))}}function Ub(e){if(typeof e==`number`)return e;if(!e)return Date.now();let t=new Date(e).getTime();return Number.isFinite(t)?t:Date.now()}function Wb(e){return e===`running`||e===`canceling`}function Gb(e){return!Wb(e)}function Kb(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function qb(e){for(let t=e.length-1;t>=0;t--){let n=e[t].details;if(!n)continue;let r=n.token_usage,i=Kb(r?.prompt),a=i&&i>0?i:Kb(r?.total),o=Kb(n.checkpoint_threshold)??Kb(n.checkpoint_at);if(typeof a!=`number`||typeof o!=`number`||o<=0)continue;let s=Math.max(0,Math.min(100,Math.round(a/o*100)));return{usedTokens:a,checkpointTokens:o,usedPercent:s,remainingPercent:Math.max(0,100-s)}}}function Jb(e,t){return!Gb(e.status)||!Wb(t.status)?{...e,...t}:{...e,interaction:e.interaction??t.interaction,elapsed_ms:Math.max(e.elapsed_ms,t.elapsed_ms),deadline_ms:Math.max(e.deadline_ms,t.deadline_ms),remaining_ms:0,phase:e.phase??t.phase,child_workflow_id:e.child_workflow_id??t.child_workflow_id,child_workflow_run_id:e.child_workflow_run_id??t.child_workflow_run_id}}function Yb(e){let t=e.details,n=typeof t?.workstream_id==`string`&&t.workstream_id.trim()?t.workstream_id:Pl(e);return n===`main`||n===`all`?null:{workstreamId:n,launchId:typeof t?.launch_id==`string`?t.launch_id:void 0,interaction:typeof t?.interaction==`string`?t.interaction:void 0,childWorkflowId:typeof t?.child_workflow_id==`string`?t.child_workflow_id:void 0,childWorkflowRunId:typeof t?.child_workflow_run_id==`string`?t.child_workflow_run_id:void 0}}function Xb(e){if(e.type!==$.ERROR)return!1;let t=e.details;if(t?.event_class!==`activity`||t.workstream_event)return!1;let n=typeof e.workstream_id==`string`&&e.workstream_id.trim()?e.workstream_id.trim():typeof t.workstream_id==`string`?t.workstream_id.trim():``,r=n.toLowerCase();return!n||r===`main`||r===`all`?!1:!(t.tool||t.tool_status||t.tool_run_id||t.activity_group_id||t.tool_event)}function Zb(e,t,n,r,i,a){if(r){let a=t.get(n);if(a?.startsWith(`message-derived:`)){let t=e.get(a);t&&(e.delete(a),e.set(r,{...t,launch_id:r,updated_at:Math.max(t.updated_at,i)}))}t.set(n,r)}let o=r??t.get(n)??`message-derived:${n}`,s=e.get(o);if(s)return s;let c={workstream_id:n,launch_id:o,elapsed_ms:0,deadline_ms:0,remaining_ms:0,status:`running`,started_at:i,updated_at:i,order:a};return e.set(o,c),t.has(n)||t.set(n,o),c}function Qb(e){let t=new Map,n=new Map;return e.forEach((e,r)=>{let i=Ub(e.timestamp),a=Yb(e),o=Cl(e),s=o?.workstreamId??a?.workstreamId;if(!s)return;let c=o?.launchId??a?.launchId,l=bl(e);if(!o&&!c&&l&&!n.has(s))return;let u=Zb(t,n,s,c,i,r);o?(u.interaction=o.interaction??u.interaction,u.child_workflow_id=o.childWorkflowId??u.child_workflow_id,u.child_workflow_run_id=o.childWorkflowRunId??u.child_workflow_run_id,u.status=`running`):(u.interaction=a?.interaction??u.interaction,u.child_workflow_id=a?.childWorkflowId??u.child_workflow_id,u.child_workflow_run_id=a?.childWorkflowRunId??u.child_workflow_run_id);let d=Sl(e);d?u.status=d:l||(Xb(e)?u.status=`failed`:(e.type===$.COMPLETE||e.type===$.IDLE)&&(u.status=`completed`)),!l&&(u.updated_at=Math.max(u.updated_at,i),Wb(u.status)?u.elapsed_ms=Math.max(u.elapsed_ms,i-u.started_at):(u.elapsed_ms=Math.max(u.elapsed_ms,i-u.started_at),u.remaining_ms=0))}),Array.from(t.values()).sort((e,t)=>{let n=Number(!Wb(e.status))-Number(!Wb(t.status));return n===0?Wb(e.status)?e.order-t.order:t.updated_at-e.updated_at||e.order-t.order:n}).map(({started_at:e,updated_at:t,order:n,...r})=>r)}function $b(e){return{workstream_id:e.workstream_id,launch_id:e.launch_id,interaction:e.interaction,elapsed_ms:e.elapsed_ms,deadline_ms:e.deadline_ms,remaining_ms:Math.max(0,e.deadline_ms-e.elapsed_ms),status:e.status,phase:e.latest_progress?.phase,child_workflow_id:e.child_workflow_id,child_workflow_run_id:e.child_workflow_run_id}}function ex(e){return{workstream_id:e.workstream_id,launch_id:e.launch_id,interaction:e.interaction,elapsed_ms:e.duration_ms??0,deadline_ms:0,remaining_ms:0,status:e.status,phase:e.last_progress?.phase,child_workflow_id:e.child_workflow_id,child_workflow_run_id:e.child_workflow_run_id}}function tx(e,t){let n=e.findIndex(e=>e.launch_id===t.launch_id);if(n>=0){e[n]=Jb(e[n],t);return}let r=e.findIndex(e=>e.workstream_id===t.workstream_id&&e.launch_id.startsWith(`message-derived:`));if(r>=0&&!t.launch_id.startsWith(`message-derived:`)){e[r]=Jb(e[r],t);return}e.push(t)}function nx(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function rx(e,t=!0){let[n,r]=X(()=>Math.max(0,Math.floor((Date.now()-Ub(e))/1e3)));return q(()=>{if(!t)return;let n=()=>{r(Math.max(0,Math.floor((Date.now()-Ub(e))/1e3)))};n();let i=window.setInterval(n,1e3);return()=>window.clearInterval(i)},[t,e]),n}function ix(e=!0){let[t,n]=X(0);return q(()=>{if(!e)return;let t=window.setInterval(()=>{n(()=>Math.floor(Math.random()*nd.length))},4e3);return()=>window.clearInterval(t)},[e]),t}function ax({message:e,startedAt:r}){let{t:i}=Z(),a=rx(r),o=ix();return n(`div`,{className:`mx-auto flex min-h-full w-full max-w-3xl flex-col justify-end gap-6 px-1 py-8`,children:[t(`div`,{className:`flex w-full justify-end`,children:t(`div`,{className:H(`max-w-[min(44rem,82%)] rounded-[1.35rem] bg-mixer-muted/35 px-4 py-2.5`,`break-words text-sm font-normal leading-6 text-foreground/90 shadow-sm shadow-black/5`,`dark:bg-mixer-muted/15 dark:text-foreground/88 dark:shadow-none [overflow-wrap:anywhere]`),children:t(`div`,{className:`whitespace-pre-wrap`,children:e})})}),n(`div`,{className:`border-b border-border/70 pb-4 text-sm text-muted`,children:[n(`div`,{className:`flex items-center gap-3`,children:[t(Ru,{size:`sm`,color:`blue`}),n(`div`,{className:`min-w-0`,children:[n(`div`,{children:[t(`span`,{className:`font-medium`,children:i(`agent.preparing`)}),n(`span`,{className:`ms-2 text-muted/75`,children:[`for `,nx(a)]})]}),t(`div`,{className:`mt-1 truncate text-muted/80`,children:nd[o]})]})]}),t(`div`,{className:`mt-3 ps-6`,children:t(Lu,{color:`blue`})})]})]})}function ox(e,t){if(typeof window>`u`||typeof document>`u`)return!1;let n=document.createElement(`iframe`);n.style.position=`fixed`,n.style.right=`0`,n.style.bottom=`0`,n.style.width=`0`,n.style.height=`0`,n.style.border=`0`,n.style.visibility=`hidden`,document.body.appendChild(n);let r=n.contentWindow;if(!r)return n.parentNode?.removeChild(n),!1;let i=r.document;return i.open(),i.write(`<!doctype html><html><head><title></title></head><body></body></html>`),i.close(),i.title=t,document.querySelectorAll(`link[rel="stylesheet"], style`).forEach(e=>{i.head.appendChild(e.cloneNode(!0))}),i.body.innerHTML=e.innerHTML,r.focus(),r.print(),setTimeout(()=>{n.parentNode?.removeChild(n)},1e3),!0}function sx(e){let t=0,n=e.length;for(;t<n&&e[t]===`-`;)t++;for(;n>t&&e[n-1]===`-`;)n--;return e.slice(t,n)}function cx(e){return sx(e.trim().replace(/[^a-z0-9-_]+/gi,`-`)).slice(0,80)}function lx(e,t){let n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}function ux(e){let{agentRunId:n,startWorkflow:r,resourceResolver:i}=e;if(n){let r=t(zb,{children:t(px,{...e,agentRunId:n})});return i?t(mt,{value:i,children:r}):r}return r?t(fx,{...e}):t(dx,{})}function dx(){let{t:e}=Z();return n(re,{status:`info`,icon:t(Zt,{className:`size-16 text-muted mb-4`}),children:[t(`div`,{className:`text-base font-medium text-muted`,children:e(`agent.noAgentRunning`)}),t(`div`,{className:`mt-3 text-sm text-muted`,children:e(`agent.selectInteraction`)})]})}function fx({initialMessage:e,interactive:r=!0,startWorkflow:i,onClose:a,isModal:s=!1,fullWidth:c=!1,placeholder:l,startButtonText:u,title:d,getAttachedDocs:f,onAttachmentsSent:p,acceptedFileTypes:m,maxFiles:h=5,hideHeader:g=!1,hideFileUpload:_=!1,hideObjectLinking:v,headerVariant:y,startViewVariant:b=`default`,inputContainerClassName:x,inputClassName:S,className:C,allowWorkflowControl:w,initialToolApprovalMode:T,onAgentWorkingChange:E}){let{t:D}=Z(),O=b!=="default",k=b===`expanded-composer`,A=!_,j=l??D(`agent.typeYourMessage`),M=u??D(`agent.startAgent`),N=d??D(`agent.startNewConversation`),{client:P}=Q(),[F,I]=X(``),[L,ee]=X(!1),[R,te]=X(null),[z,ne]=X(null),[B,re]=X(null),[ie,ae]=X(()=>Ui(T,r)),oe=Xe(),se=Y(null),ce=Y(null),[V,le]=X([]),[ue,de]=X(!1),fe=ue?V:V.slice(0,3),pe=V.length-3;q(()=>{E?.(L)},[L,E]);let[me,he]=X(!1),ge=Y(0),_e=K(e=>{A&&(e.preventDefault(),e.stopPropagation(),ge.current++,e.dataTransfer?.types?.includes(`Files`)&&he(!0))},[A]),ve=K(e=>{A&&(e.preventDefault(),e.stopPropagation())},[A]),ye=K(e=>{A&&(e.preventDefault(),e.stopPropagation(),ge.current--,ge.current===0&&he(!1))},[A]),be=K(e=>{if(A&&(e.preventDefault(),e.stopPropagation(),ge.current=0,he(!1),e.dataTransfer?.files&&e.dataTransfer.files.length>0)){let t=Array.from(e.dataTransfer.files);le(e=>[...e,...t].slice(0,h))}},[h,A]),xe=K(e=>{if(!A)return;let t=s_(e.clipboardData?.items);t.length>0&&le(e=>[...e,...t].slice(0,h))},[A,h]),Se=K(e=>{if(e.target.files&&e.target.files.length>0){let t=Array.from(e.target.files);le(e=>[...e,...t].slice(0,h))}e.target.value=``},[h]),Ce=K(e=>{le(t=>t.filter((t,n)=>n!==e))},[]);q(()=>{V.length<=3&&de(!1)},[V.length]),q(()=>{se.current&&se.current.focus()},[]);let we=async()=>{if(!i)return;let e=F.trim();if(!(!e||L)){ee(!0);try{sessionStorage.removeItem(`plan-panel-shown`),oe({title:A&&V.length>0?D(`agent.startingAgentUploading`):D(`agent.startingAgent`),status:`info`,duration:3e3});let t=f?.()||[],n=e;if(t.length>0&&!/store:\S+/.test(e)&&(n=[e,``,`Attachments:`,...t.map(e=>`[${e.name}](/store/objects/${e.id})`)].join(`
|
|
441
439
|
`)),A&&V.length>0){let e=V.map(e=>e.name).join(`, `);n=[n,``,`[System: ${V.length} file(s) are being uploaded: ${e}. Please wait for the "Files Ready" notification before processing them.]`].join(`
|
|
442
|
-
`)}let r=await i(n,{tool_approval_mode:ie});if(!r){ne(null),re(null);return}ne(n),re(Date.now());let a=r.agent_run_id,o=[];if(A&&V.length>0){for(let e of V)try{let t=`files/${e.name}`;await P.agents.uploadArtifact(a,t,e),await P.agents.sendSignal(a,`FileUploaded`,{id:`file-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:e.name,content_type:e.type||`application/octet-stream`,reference:`artifact:${t}`,artifact_path:t}),o.push(e.name)}catch(t){console.error(`Failed to upload staged file ${e.name}:`,t)}if(o.length>0)try{await P.agents.sendSignal(a,`UserInput`,{message:`[Files Ready] All ${o.length} file(s) have been uploaded and are now available: ${o.join(`, `)}. You can now process them.`,metadata:{type:`files_ready`,files:o}})}catch(e){console.error(`Failed to send files ready signal:`,e)}le([])}p?.(),te(a),I(``),oe({title:D(`agent.agentStarted`),status:`success`,duration:3e3})}catch(e){ne(null),re(null),oe({title:D(`agent.errorStarting`),status:`error`,duration:3e3,description:e instanceof Error?e.message:D(`agent.unknownError`)})}finally{ee(!1)}}},Ee=e=>{if(e.key===`Enter`){if(!(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)){e.preventDefault(),we();return}e.shiftKey||(e.preventDefault(),Be(e.currentTarget,I))}},De=G(()=>{let e=se.current;if(e){if(k){e.style.height=`100%`;return}e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`}},[k]);return K(()=>{De()},[F,De]),R?t(Ib,{onClose:a,isModal:s,initialMessage:e,placeholder:l,fullWidth:c,hideHeader:g,headerVariant:y,hideFileUpload:_,hideObjectLinking:v,inputContainerClassName:x,inputClassName:S,className:C,allowWorkflowControl:w,onAgentWorkingChange:E,agentRunId:R,title:d,pendingStartMessage:z??void 0,pendingStartTimestamp:B??void 0,initialToolApprovalMode:ie}):t(`div`,{className:H(`flex flex-col items-center bg-background`,O&&!k?``:`h-full`,C),children:n(`div`,{className:H(`relative flex w-full flex-col overflow-hidden border-0`,O&&!k?``:`h-full`,c?``:`max-w-4xl`),onDragEnter:A?_e:void 0,onDragOver:A?ve:void 0,onDragLeave:A?ye:void 0,onDrop:A?be:void 0,children:[A&&me&&t(`div`,{className:`absolute inset-0 flex items-center justify-center bg-info-background z-50 pointer-events-none rounded-lg`,children:n(`div`,{className:`text-info font-medium flex items-center gap-2 text-lg`,children:[t(ti,{className:`size-6`}),`Drop files to stage for upload`]})}),A&&t(`input`,{ref:ce,type:`file`,multiple:!0,accept:m,onChange:Se,className:`hidden`}),!g&&n(`div`,{className:`flex items-center justify-between border-b border-border/60 bg-background px-3 py-2`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(`div`,{className:`p-1`,children:t(Cn,{className:`size-3.5 text-muted`})}),t(`span`,{className:`text-sm font-medium text-foreground`,children:N})]}),a&&!s&&t(o,{size:`xs`,variant:`ghost`,onClick:a,title:D(`agent.close`),className:`text-muted hover:text-foreground`,children:t(di,{className:`size-4`})})]}),t(`div`,{className:H(`flex flex-col items-center justify-end bg-background px-4`,O?`shrink-0 pt-3`:`flex-1 overflow-y-auto`),children:z&&B?t(Ob,{message:z,startedAt:B}):t(`div`,{className:H(`mx-auto flex w-full max-w-3xl flex-col justify-end`,O?``:`min-h-full py-8`),children:e&&t(`div`,{className:`text-[15px] leading-relaxed text-foreground/80`,children:e})})}),t(`div`,{className:H(`bg-background px-4 pb-safe-area-4 pt-2`,k?`flex min-h-0 flex-1 flex-col`:`shrink-0`),children:n(`div`,{className:H(`mx-auto flex max-w-3xl flex-col gap-3 rounded-2xl border border-border/70 bg-mixer-muted/15 p-3 shadow-lg shadow-black/5`,k&&`min-h-0 w-full flex-1`,x),children:[A&&V.length>0&&n(`div`,{className:`flex flex-wrap gap-2`,children:[fe.map((e,r)=>n(`div`,{className:`flex items-center gap-1.5 rounded-md bg-attention/10 px-2 py-1 text-sm text-attention`,title:D(`agent.fileStagedTooltip`),children:[t(Rn,{className:`size-3.5`}),t(`span`,{className:`max-w-[120px] truncate`,children:e.name}),t(`span`,{className:`text-xs opacity-70`,children:D(`agent.staged`)}),t(o,{variant:`unstyled`,"aria-label":`Remove staged file ${e.name}`,onClick:()=>Ce(r),className:`ms-1 rounded p-0.5 hover:bg-attention/20`,children:t(di,{className:`size-3`})})]},`${e.name}-${e.size}-${e.lastModified}`)),V.length>3&&n(o,{type:`button`,variant:`ghost`,size:`sm`,"aria-expanded":ue,onClick:()=>de(e=>!e),className:`h-8 shrink-0 gap-1 rounded-xl px-2.5 text-xs text-muted`,children:[!ue&&n(`span`,{children:[`+`,pe]}),D(ue?`agent.showLess`:`agent.showMore`),t(an,{className:H(`size-3.5 transition-transform`,ue&&`rotate-180`),"aria-hidden":`true`})]})]}),t(Le,{ref:se,value:F,onChange:e=>I(e.target.value),onKeyDown:Ee,onPaste:xe,placeholder:j,disabled:L,rows:2,className:H(`min-h-[72px] resize-none overflow-hidden border-0 bg-transparent px-0 py-0 text-sm leading-6 shadow-none focus-visible:ring-0`,k&&`min-h-0 flex-1`,S),style:k?{minHeight:`72px`,maxHeight:`none`}:{minHeight:`72px`,maxHeight:`200px`}}),n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex min-w-0 items-center gap-2`,children:[A&&t(o,{variant:`ghost`,size:`icon`,onClick:()=>ce.current?.click(),disabled:L||V.length>=h,"aria-label":D(`agent.upload`),className:`rounded-full text-muted`,title:D(`agent.upload`),children:t(ti,{className:`size-4`})}),r&&t(Ja,{mode:ie,onChange:ae,disabled:L})]}),t(o,{onClick:we,disabled:!F.trim()||L,variant:`ghost`,size:`icon`,className:H(`size-9 rounded-full border border-border/60 bg-foreground text-background shadow-sm`,`hover:bg-foreground/90 hover:text-background`,`disabled:bg-mixer-muted/25 disabled:text-muted disabled:opacity-100`),title:M,children:L?t(Te,{size:`sm`}):t(Wt,{className:`size-4`})})]})]})})]})})}function Ib({agentRunId:r,title:i,interactive:a=!0,onClose:s,isModal:c=!1,fullWidth:l=!1,placeholder:u,resetWorkflow:d,onRestart:f,onClone:p,onShowDetails:m,allowWorkflowControl:h=!0,uploadedFiles:g,onRemoveFile:_,acceptedFileTypes:v,maxFiles:y,renderDocumentSearch:b,selectedDocuments:x,onRemoveDocument:S,hideObjectLinking:C,hideHeader:w,headerVariant:T=`full`,hideMessageInput:E,failedAction:D,hidePlanPanel:O,hideWorkstreamTabs:k,showRightPanel:A=!0,hideFileUpload:j,showArtifacts:M=!1,hideDocumentPanel:N,hiddenMessageTypes:P,getAttachedDocs:F,onAttachmentsSent:I,isUploading:L=!1,getMessageContext:ee,className:R,inputContainerClassName:te,inputClassName:z,composerContext:ne,fusionData:B,fileUploadRef:ce,sendMessageRef:V,onMessage:le,onAgentWorkingChange:ue,onProcessingFilesChange:de,processingFiles:fe,onPlansChange:pe,onWorkstreamStatusChange:me,viewMode:he,onViewModeChange:ge,onShowInputChange:_e,stopRef:ve,onStoppingChange:ye,messageItemClassNames:be,messageStyleOverrides:xe,toolCallGroupClassNames:Se,hideToolCallsInViewMode:Ce,streamingMessageClassNames:we,batchProgressPanelClassNames:Te,workingIndicatorClassName:Ee,messageListClassName:De,StoreLinkComponent:Oe,CollectionLinkComponent:ke,prependFriendlyMessage:Ae,initialRequestData:je,initialRequestSchema:Me,initialRequestTitle:Ne,initialRequestTemplate:Pe,payloadContent:Fe,conversationContent:Ie,conversationTab:Le=!1,pendingStartMessage:Re,pendingStartTimestamp:ze,initialToolApprovalMode:Be,enablePlayback:Ve,showPlaybackToggle:He=!0,messageFilter:Ue}){let{t:We}=X(),{client:Ge}=Z(),Ke=Ye(),{messages:qe,streamingMessages:Je,isCompleted:Xe,initialHistoryStatus:Ze,debugChunkFlash:Qe,addOptimisticMessage:$e,updateOptimisticMessageStatus:et,reconnect:U,agentRunStatus:W,workflowRunId:tt,serverFileUpdates:nt}=a_(Ge,r,le),{plans:rt,activePlanIndex:it,setActivePlanIndex:at,workstreamStatusMap:ot,showInput:st,showSlidingPanel:ct,setShowSlidingPanel:lt}=Jg(qe,a,c),{openDocuments:ut,activeDocumentId:dt,isDocPanelOpen:ft,docRefreshKey:pt,closeDocPanel:mt,closeDocument:ht,selectDocument:gt,openDocInPanel:_t,updateDocumentTitle:vt}=l_(qe),{processingFiles:yt,hasProcessingFiles:bt,handleFileUpload:xt,removeProcessingFile:St,clearProcessingFiles:Ct}=p_(Ge,r,nt,Ke,q(()=>sf(qe),[qe])),wt=a&&!j,Tt=G(e=>{St(e)},[St]),Et=J(null),Dt=J(null),Ot=J(null),[At,jt]=Y(!1),[Mt,Nt]=Y(!1),[Pt,Ft]=Y(`sliding`),It=he??Pt,Lt=G(e=>{ge?ge(e):Ft(e)},[ge]),[Rt,zt]=Y(!1),[Bt,Vt]=Y(!1),[Ht,Ut]=Y(`all`),[Wt,Gt]=Y(`live`),[Kt,qt]=Y(!1),[Jt,Yt]=Y(0),[Xt,Zt]=Y([]),[Qt,$t]=Y([]),[tn,nn]=Y(!1),rn=q(()=>Be===void 0&&a?void 0:Li(Be,a),[Be,a]),[an,on]=Y(rn),sn=J(!1),cn=J(0),ln=J(!1),un=J(0),dn=J(null);K(()=>{on(rn)},[rn]);let fn=J(At);fn.current=At;let pn=J(bt);pn.current=bt;let mn=J(yt);mn.current=yt;let hn=q(()=>{let e=qe.filter(e=>(e.workstream_id||`main`)===`main`);return e[e.length-1]},[qe]),gn=q(()=>hn?.type===Q.TERMINATED?`TERMINATED`:hn?.type===Q.COMPLETE&&(!W||W===`RUNNING`)?`COMPLETED`:W,[hn,W]),_n=q(()=>{let e=gn?.toUpperCase();return e===`COMPLETED`||e===`FAILED`||e===`CANCELED`||e===`CANCELLED`||e===`TERMINATED`||e===`TIMED_OUT`},[gn]),vn=q(()=>_n&&gn?.toUpperCase()!==`FAILED`&&!!f,[_n,gn,f]),yn=!E||vn,bn=q(()=>gn?.toUpperCase()===`FAILED`||W?.toUpperCase()===`FAILED`,[gn,W]),xn=q(()=>{for(let e=qe.length-1;e>=0;e--){let t=qe[e];if(t.type!==Q.ERROR||_u(t)!==`main`)continue;let n=typeof t.message==`string`?t.message.trim():``;if(n)return n}},[qe]),Sn=J(_n);Sn.current=_n;let Cn=J(vn);Cn.current=vn;let wn=q(()=>{let e=rt[it]||{plan:{plan:[]},timestamp:0},t=ot.get(e.timestamp)||new Map;return{plan:e.plan,workstreamStatus:t}},[rt,it,ot]),Tn=q(()=>xb(qe),[qe]),En=q(()=>{let e=[...Tn];for(let t of Qt)wb(e,Cb(t));for(let t of Xt)wb(e,Sb(t));return e.map((e,t)=>({workstream:e,index:t})).sort((e,t)=>Number(!pb(e.workstream.status))-Number(!pb(t.workstream.status))||e.index-t.index).map(({workstream:e})=>e)},[Tn,Xt,Qt]),Dn=q(()=>En.filter(e=>pb(e.status)),[En]),On=q(()=>Dn.filter(e=>e.status===`running`).length,[Dn]),kn=q(()=>{if(Ht===`all`)return;let e=En.find(e=>e.workstream_id===Ht||e.launch_id===Ht);return e?Ql(e.workstream_id,e.interaction):Ql(Ht)},[Ht,En]),An=q(()=>{if(u)return u;if(kn)return We(`agent.messageMainAgentWhileViewingWorkstream`,{workstream:kn})},[kn,u,We]),jn=He&&Ve===void 0&&Eo(),Mn=Ve??(Do()||Kt),Nn=q(()=>qe.filter(e=>!pu(e)&&!(P?.includes(e.type)??!1)),[P,qe]),Pn=q(()=>bu(Nn,Ht),[Ht,Nn]),Fn=q(()=>wo(Pn,Wt,Mn),[Mn,Wt,Pn]),In=Fn.cursor,Ln=Fn.isLive,Rn=Mn&&!Ln&&Fn.cursorIndex===Pn.length-1,zn=Fn.displayedMessages,Bn=q(()=>Ue?zn.filter(e=>Ue(e)):zn,[zn,Ue]),Vn=q(()=>Ue?Nn.filter(e=>Ue(e)):Nn,[Ue,Nn]),Hn=Ln?Je:db,Un=q(()=>xb(zn),[zn]),Wn=q(()=>Un.filter(e=>pb(e.status)),[Un]),Gn=q(()=>Xe||!mu(qe),[Xe,qe]),Kn=Ln||Rn?Gn:!1,qn=!Gn&&!_n;K(()=>{ue?.(qn)},[qn,ue]);let Jn=q(()=>{let e=new Set;for(let t of zn)Yu(r,t)&&e.add(Gu(t));return gd(zn,`main`,e)},[r,zn]),Yn=!!Jn&&!bn&&(!_n||vn),Xn=Mn&&!Ln,Zn=yn&&!Xn,Qn=q(()=>gb(qe),[qe]),$n=h&&!_n&&Ln&&!!Qn;K(()=>{uu(`conversation render state`,{agentRunId:r,messageCount:qe.length,playbackMessageCount:Pn.length,displayedMessageCount:Bn.length,streamingCount:Je.size,displayedStreamingCount:Hn.size,initialHistoryStatus:Ze,isCompleted:Xe,effectiveIsCompleted:Gn,displayedIsCompleted:Kn,agentRunStatus:W,effectiveWorkflowStatus:gn,isWorkflowTerminal:_n,playbackCursor:In,isPlaybackEnabled:Mn,isPlaybackLive:Ln,isPlaybackAtLatest:Rn,activeWorkstream:Ht,showInitialRequest:Ze===`empty`&&qe.length===0,pendingStartVisible:qe.length===0&&!Gn&&!!Re})},[Ht,r,W,In,Kn,Bn.length,Hn.size,Gn,gn,Ze,Xe,Rn,Mn,Ln,_n,qe.length,Re,Pn.length,Je.size]);let er=G(()=>{qt(e=>!e)},[]),tr=G(e=>{let t=xo(In,Pn.length),n=xo(e,Pn.length);Mn&&(n>t||e===`live`&&In!==`live`)&&(ln.current=!0,Yt(e=>e+1)),Gt(e)},[In,Mn,Pn.length]);K(()=>{if(!Mn){Wt!==`live`&&Gt(`live`);return}In!==Wt&&Gt(In)},[In,Mn,Wt]),K(()=>{if(!Mn||!ln.current)return;ln.current=!1;let e=window.requestAnimationFrame(()=>{Et.current?.scrollIntoView({behavior:`smooth`,block:`end`})});return()=>window.cancelAnimationFrame(e)},[Mn,Jt]);let nr=G(e=>{at(e)},[at]),[rr,ir]=Y(Ie||Le?`conversation`:`plan`),[ar,or]=Y(null),[sr,cr]=Y(400),[lr,ur]=Y(!1),[dr,fr]=Y(!1),pr=A&&!dr&&(ct||ft||!k&&En.length>0||!!Ie||Le),mr=J(ft);K(()=>{ft&&!mr.current&&fr(!1),mr.current=ft},[ft]);let hr=G(()=>{pr?(fr(!0),lt(!1)):(fr(!1),lt(!0),sessionStorage.setItem(`plan-panel-shown`,`true`))},[pr,lt]);K(()=>{!pr&&lr&&ur(!1)},[pr,lr]),K(()=>{if(!lr)return;let e=e=>{let t=Ot.current;if(!t)return;let n=t.getBoundingClientRect(),r=Math.max(300,n.width-420),i=n.right-e.clientX;cr(Math.min(Math.max(i,300),r))},t=()=>{ur(!1)};return window.addEventListener(`mousemove`,e),window.addEventListener(`mouseup`,t),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,()=>{window.removeEventListener(`mousemove`,e),window.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[lr]);let gr=G(()=>{fr(!0),lt(!1),mt()},[lt,mt]),_r=G(e=>{/\.md$/i.test(e)&&(fr(!1),or(e),ir(`artifacts`),lt(!0))},[lt]),vr=J(null);K(()=>{let e,t;for(let n of qe){let r=n.details;r?.event_class===`display_artifact`&&typeof r.path==`string`&&(e=r.path,t=`${n.timestamp??``}:${r.path}`)}!e||!t||t===vr.current||(vr.current=t,fr(!1),or(e),ir(`artifacts`),lt(!0))},[qe,lt]);let yr=G(({href:e,documentId:n,children:r})=>t(`a`,{href:e,className:`text-info underline cursor-pointer hover:text-info/80`,onClick:e=>{e.preventDefault(),e.stopPropagation(),_t(n),ir(`documents`)},children:r}),[_t]),br=Oe??yr;K(()=>(ce&&(ce.current=wt?xt:null),()=>{ce&&(ce.current=null)}),[ce,xt,wt]),K(()=>{de?.(yt)},[yt,de]),K(()=>{pe?.(rt,it)},[rt,it,pe]),K(()=>{me?.(ot)},[ot,me]),K(()=>{or(null),sn.current=!1,nn(!1),Zt([]),$t([])},[r]),K(()=>{let e=Ze!==`loading`&&!Gn&&!_n&&!tn;if(uu(`active workstreams poll state`,{agentRunId:r,shouldPoll:e,initialHistoryStatus:Ze,effectiveIsCompleted:Gn,isWorkflowTerminal:_n,isWorkstreamQueryUnavailable:tn}),!e){Zt(e=>e.length===0?e:[]);return}let t=!1,n=!1,i=async()=>{if(n){uu(`active workstreams fetch skipped while previous request is pending`,{agentRunId:r});return}n=!0;try{uu(`active workstreams fetch start`,{agentRunId:r});let e=await Ge.agents.getActiveWorkstreams(r);if(t)return;if(uu(`active workstreams fetch success`,{agentRunId:r,runningCount:e.running?.length??0,completedCount:e.completed?.length??0,unavailable:e.unavailable===!0}),Zt(e.running??[]),$t(e.completed??[]),e.unavailable){nn(!0);return}sn.current=!1}catch(e){if(t)return;Zt(e=>e.length===0?e:[]),nn(!0),uu(`active workstreams fetch failed`,{agentRunId:r,error:e instanceof Error?e.message:String(e)}),sn.current||=(console.warn(`Failed to fetch active workstreams:`,e),!0)}finally{n=!1}};i();let a=window.setInterval(i,1e4);return()=>{t=!0,window.clearInterval(a)}},[Ge.agents,r,Gn,Ze,_n,tn]),K(()=>{if(qe.length!==0){if(vn){_e?.(!0);return}if(!st){_e?.(!1);return}if(gn&&gn!==`RUNNING`){_e?.(!1);return}gn!==null&&_e?.(!0)}},[st,gn,qe.length,_e,vn]);let xr=G(async()=>{let e=dn.current;e&&await e},[]),Sr=G((e,t)=>{let n=e.trim();if(!n||fn.current||Sn.current&&!Cn.current)return;if(pn.current){Ke({status:`warning`,title:We(`agent.filesProcessing`),description:We(`agent.waitForFilesProcessing`),duration:3e3});return}let i=td(t);jt(!0);let a=F?.()||[],o=ee?.()||{},s=n;a.length>0&&!/store:\S+/.test(n)&&(s=[n,``,`Attachments:`,...a.map(e=>`[${e.name}](/store/objects/${e.id})`)].join(`
|
|
443
|
-
`));let c=Array.from(
|
|
444
|
-
`));let l=`msg-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,u={timestamp:Date.now(),workflow_run_id:r,type:Q.QUESTION,message:s,workstream_id:`main`,details:{_optimistic:!0,_messageId:l,_deliveryStatus:`sending`,...t?.editing_action?{editing_action:t.editing_action}:{},...t?.request_input_response?{request_input_response:t.request_input_response}:{}}};$e(u);let d={...a.length>0?{attached_docs:a.map(e=>e.id)}:{},...o,...t,id:l,_messageId:l},f=()=>Ge.agents.sendSignal(r,`UserInput`,{message:s,client_message_id:l,metadata:d}),p=()=>{et(l,`received`),I?.(),Ct()};i&&qu(r,i),(async()=>{await xr(),Sn.current&&(await Ge.agents.restart(r),U()),await f(),p()})().catch(e=>{i&&Ju(r,i),et(l,`failed`),Ke({status:`error`,title:We(`agent.failedToSend`),description:e instanceof Error?e.message:We(`agent.unknownError`),duration:3e3})}).finally(()=>{jt(!1)})},[r,Ge,Ke,F,ee,I,Ct,U,$e,et,We,xr]);K(()=>(V&&(V.current=Sr),()=>{V?.current===Sr&&(V.current=null)}),[Sr,V]);let Cr=G(async(e,t)=>{try{await Ge.agents.sendSignal(r,`McpConfigChanged`,{})}catch(e){console.error(`Failed to signal MCP config change`,e)}Sr(We(`agent.mcpConnectedMessage`,{name:e.name}),t)},[Ge,r,Sr,We]),[wr,Tr]=Y(void 0);K(()=>{let e=!1,t=un.current;return Ge.agents.retrieve(r).then(n=>{e||(Tr(n.disabled_mcp_collections),un.current===t&&(n.tool_approval_mode!==void 0||n.interactive!==void 0)&&on(Li(n.tool_approval_mode,n.interactive)))}).catch(()=>{}),()=>{e=!0}},[Ge,r]);let Er=G(e=>{let t=e.length>0?e:void 0;Tr(t),Ge.agents.sendSignal(r,`McpConfigChanged`,{disabled_mcp_collections:e}).catch(e=>console.error(`Failed to signal MCP config change`,e))},[Ge,r]),Dr=G(()=>{Ge.agents.sendSignal(r,`McpConfigChanged`,{}).catch(e=>console.error(`Failed to signal MCP config change`,e))},[Ge,r]),Or=G(e=>{let t=Li(e,a),n=an;un.current+=1,on(t);let i=Ge.agents.sendSignal(r,`ToolApprovalModeChanged`,{mode:t}).then(()=>void 0).catch(e=>{on(e=>e===t?n:e),Ke({status:`error`,title:We(`agent.approvalMode.changeFailed`),description:e instanceof Error?e.message:We(`agent.unknownError`),duration:3e3})});dn.current=i,i.finally(()=>{dn.current===i&&(dn.current=null)})},[r,Ge,a,We,Ke,an]),kr=G(e=>{wt&&(e.preventDefault(),e.stopPropagation(),cn.current++,e.dataTransfer?.types?.includes(`Files`)&&Vt(!0))},[wt]),Ar=G(e=>{wt&&(e.preventDefault(),e.stopPropagation())},[wt]),jr=G(e=>{wt&&(e.preventDefault(),e.stopPropagation(),cn.current--,cn.current===0&&Vt(!1))},[wt]),Mr=G(e=>{if(wt&&(e.preventDefault(),e.stopPropagation(),cn.current=0,Vt(!1),e.dataTransfer?.files&&e.dataTransfer.files.length>0)){let t=Array.from(e.dataTransfer.files);xt(t)}},[xt,wt]),Nr=G(async()=>{if(Rt)return;let e=`stop-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,t={timestamp:Date.now(),workflow_run_id:r,type:Q.IDLE,message:`Stopped. Waiting for your command...`,workstream_id:`main`,details:{_optimistic:!0,_messageId:e,_deliveryStatus:`sending`,display_role:`user_stopped`,status_reason:`user_stopped`}};$e(t),zt(!0);try{await Ge.agents.sendSignal(r,`Stop`,{message:`User requested stop`,client_message_id:e,metadata:{id:e,_messageId:e}}),et(e,`received`)}catch(t){Ke({status:`error`,title:We(`agent.failedToInterrupt`),description:t instanceof Error?t.message:We(`agent.unknownError`),duration:3e3}),et(e,`failed`)}finally{zt(!1)}},[Rt,r,$e,Ge.agents,Ke,We,et]),Pr=G(async()=>{if(!(Mt||Gn||!Ln)){Nt(!0);try{await Ge.agents.sendSignal(r,`TriggerCheckpoint`,{reason:`manual user request`})}catch(e){Ke({status:`error`,title:We(`agent.failedToCompactContext`),description:e instanceof Error?e.message:We(`agent.unknownError`),duration:3e3})}finally{Nt(!1)}}},[r,Ge.agents,Gn,Mt,Ln,We,Ke]);K(()=>(ve&&(ve.current=h&&!Gn?Nr:null),()=>{ve&&(ve.current=null)}),[ve,Gn,Nr,h]),K(()=>{ye?.(Rt)},[Rt,ye]);let Fr=i||We(`agent.agentConversation`),Ir=async()=>{try{let e=await xu(Ge,r);e&&window.open(e,`_blank`)}catch(e){console.error(`Failed to download conversation`,e),Ke({status:`error`,title:We(`agent.failedToDownload`),duration:3e3})}},Lr=G(()=>{let e=new Date().toISOString(),t=Je.size>0?[{cursor:`live`,streamingMessages:Array.from(Je,([e,t])=>({id:e,...t}))}]:void 0,n={metadata:{title:Fr,agent_run_id:r,exported_at:e,message_count:qe.length},messages:qe,...t?{streamingFrames:t}:{}};Mb(`${jb(Fr)||`agent-chat`}-${jb(r)}.json`,n),Ke({status:`success`,title:We(`agent.rewind.fixtureExported`),duration:2e3})},[Fr,r,qe,Je,We,Ke]),[Rr,zr]=Y(!1),Br=()=>{if(!Dt.current){Ke({status:`error`,title:We(`agent.pdfExportFailed`),description:We(`agent.noConversationContent`),duration:3e3});return}zr(!0)},Vr=()=>{if(!Dt.current){Ke({status:`error`,title:We(`agent.pdfExportFailed`),description:We(`agent.noConversationContent`),duration:3e3});return}let e=`${Fr} - ${r}`;if(!kb(Dt.current,e)){Ke({status:`error`,title:We(`agent.pdfExportFailed`),description:We(`agent.unableToOpenPrint`),duration:4e3});return}Ke({status:`success`,title:We(`agent.pdfExportReady`),description:We(`agent.printDialogDescription`),duration:4e3}),zr(!1)},Hr=q(()=>qe.filter(e=>e.type===Q.COMPLETE||e.type===Q.THOUGHT&&e.details?.tool_status===`completed`).length,[qe]),Ur=q(()=>{if(!ar)return{key:Hr,details:void 0};let e=0,t;for(let n of qe){let r=n.details;kt(r,ar)&&(e++,t=r)}return{key:e,details:t}},[Hr,qe,ar]),Wr=a&&Ln&&gn?.toUpperCase()===`RUNNING`,Gr=q(()=>wn.plan.plan?.reduce((e,t)=>(t.id&&t.goal&&e.set(t.id.toString(),t.goal),e),new Map),[wn.plan]),Kr=e=>t(b_,{title:Fr,variant:e,isCompleted:Gn,isTerminal:_n,onClose:s,isModal:c,agentRunId:r,workflowRunId:tt||``,viewMode:It,onViewModeChange:Lt,showPlanPanel:pr,hasPlan:A&&rt.length>0,showPlanButton:A&&!Le,onTogglePlanPanel:hr,showPlaybackButton:jn,isPlaybackEnabled:Mn,onTogglePlayback:er,onDownload:Ir,onExportFixture:Lr,resetWorkflow:d,onClone:p,onShowDetails:m,allowWorkflowControl:h,onExportPdf:Br,isReceivingChunks:Qe}),qr=n(`div`,{ref:Dt,"data-agent-playback-enabled":Mn||void 0,"data-agent-playback-cursor":Mn?In:void 0,"data-agent-live-message-count":qe.length,"data-agent-rendered-message-count":Bn.length,className:H(`flex flex-col min-h-0 min-w-0 border-0`,Le?`flex-1 h-full`:pr?`w-full flex-1 min-h-[50vh]`:l?`flex-1 w-full`:`flex-1 mx-auto ${c?``:`max-w-4xl`}`),children:[!w&&T===`compact`&&t(`div`,{className:`flex flex-shrink-0 justify-end border-b border-border/60 px-2 py-1 lg:hidden`,children:Kr(`compact`)}),!w&&T!==`compact`&&t(`div`,{className:`flex-shrink-0`,children:Kr(T)}),Mn&&t(`div`,{className:`flex flex-shrink-0 justify-end px-2 py-1.5`,children:t(Ao,{cursor:In,messages:Pn,onChangeCursor:tr})}),qe.length===0&&!Gn&&Re&&ze?t(Ob,{message:Re,startedAt:ze}):t(Vh,{messages:Bn,workstreamSourceMessages:Vn,bottomRef:Et,isCompleted:Kn,plan:wn.plan,workstreamStatus:wn.workstreamStatus,showPlanPanel:A&&ct,onTogglePlanPanel:hr,plans:rt,activePlanIndex:it,onChangePlan:nr,taskLabels:Gr,streamingMessages:Hn,onSendMessage:Ln?Sr:void 0,onOpenArtifact:M?_r:void 0,messageItemClassNames:be,messageStyleOverrides:xe,toolCallGroupClassNames:Se,hideToolCallsInViewMode:Ce,streamingMessageClassNames:we,batchProgressPanelClassNames:Te,artifactRunId:r,viewMode:It,hideWorkstreamTabs:k,workingIndicatorClassName:Ee,messageListClassName:De,StoreLinkComponent:br,CollectionLinkComponent:ke,prependFriendlyMessage:Ae,initialRequestData:je,initialRequestSchema:Me,initialRequestTitle:Ne,initialRequestTemplate:Pe,showInitialRequest:Ze===`empty`&&qe.length===0,hiddenMessageTypes:P,disableAutoScroll:!Ln,renderRequestInputControls:!Yn,activeWorkstream:Ht,onActiveWorkstreamChange:Ut}),Yn?t(vd,{message:Jn,onSendMessage:Ln?Sr:void 0,onMcpConnected:Ln?Cr:void 0,disabled:L||!Ln,isLoading:At||L}):Xn&&Wn.length>0?t(`div`,{className:`flex-shrink-0 pb-safe-area`,children:t(m_,{activeWorkstreams:Wn,onSelectWorkstream:Ut})}):Zn&&t(`div`,{className:`flex-shrink-0 pb-safe-area`,children:bn?D??t(re,{status:`error`,title:We(`agent.failed`),className:`m-2`,children:xn??We(`agent.error`)}):gn&&gn!==`RUNNING`&&!vn?It===`sliding`&&gn===`COMPLETED`?t(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-3 text-sm text-muted`,children:n(`div`,{className:`flex items-center gap-2 border-t border-success/25 pt-3 text-success`,children:[t(en,{className:`size-4`}),t(`span`,{className:`font-medium`,children:`Workflow completed`})]})}):n(re,{status:gn===`COMPLETED`?`success`:`done`,icon:null,className:`m-2`,children:[`This Workflow is `,gn]}):(st||vn)&&n(e,{children:[ne,t(rb,{onSend:Sr,onStop:h?Nr:void 0,approvalModeSlot:a&&an?t(Ja,{mode:an,onChange:Or,disabled:!Ln||_n||!h}):void 0,mcpSlot:t(ig,{disabledCollections:wr,onChange:Er,onConnectionChange:Dr}),disabled:L||!Ln,isSending:At||L,isStopping:Rt,isStreaming:!Gn,isCompleted:Gn,contextWindowUsage:$n?Qn:void 0,onCompactContext:$n?Pr:void 0,isCompactingContext:Mt,activeTaskCount:On,activeWorkstreams:Dn,onSelectWorkstream:Ut,placeholder:An,onFilesSelected:wt?xt:void 0,uploadedFiles:g,onRemoveFile:_,onRemoveProcessingFile:Tt,acceptedFileTypes:v,maxFiles:y,processingFiles:yt,artifactRunId:r,hasProcessingFiles:bt,renderDocumentSearch:b,selectedDocuments:x,onRemoveDocument:S,hideObjectLinking:C,hideFileUpload:!wt,disableDropZone:wt,className:te,inputClassName:z})]})})]}),Jr=t(Xa,{children:t(Ud,{children:n(`div`,{ref:Ot,className:H(`flex flex-col lg:flex-row gap-2 w-full h-full relative overflow-hidden`,wt&&Bt&&`ring-2 ring-blue-400 ring-inset`,R),onDragEnter:wt?kr:void 0,onDragOver:wt?Ar:void 0,onDragLeave:wt?jr:void 0,onDrop:wt?Mr:void 0,children:[wt&&Bt&&t(`div`,{className:`absolute inset-0 flex items-center justify-center bg-blue-100/80 dark:bg-blue-900/40 z-50 pointer-events-none rounded-lg`,children:n(`div`,{className:`text-blue-600 dark:text-blue-400 font-medium flex items-center gap-2 text-lg`,children:[t(ti,{className:`size-6`}),`Drop files to upload`]})}),!Le&&qr,!Le&&T===`compact`&&!w&&t(`div`,{className:`hidden h-full w-12 shrink-0 items-start justify-center px-1 pt-2 lg:flex`,children:Kr(`compact`)}),pr&&n(e,{children:[!Le&&t(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize right panel`,"aria-valuenow":Math.round(sr),"aria-valuemin":300,"aria-valuetext":`${Math.round(sr)} pixels`,tabIndex:0,className:`hidden lg:block lg:w-1 lg:shrink-0 cursor-col-resize bg-border/70 hover:bg-border transition-colors`,onMouseDown:()=>ur(!0),onKeyDown:e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault();let t=e.shiftKey?32:16,n=e.key===`ArrowLeft`?t:-t,r=Ot.current,i=r?Math.max(300,r.getBoundingClientRect().width-420):900;cr(e=>Math.min(Math.max(e+n,300),i))}}),t(`div`,{className:Le?`w-full h-full overflow-auto`:`w-full lg:w-[var(--agent-right-panel-width)] lg:shrink-0 min-h-[50vh] lg:h-full border-t lg:border-t-0`,style:Le?void 0:{"--agent-right-panel-width":`${sr}px`},children:t(Kg,{plan:wn.plan,workstreamStatus:wn.workstreamStatus,plans:rt,activePlanIndex:it,onChangePlan:nr,showPlan:!O&&ct,activeWorkstreams:En,hideWorkstreams:k,openDocuments:ut,activeDocumentId:dt,onSelectDocument:gt,onCloseDocument:ht,onUpdateDocumentTitle:vt,docRefreshKey:pt,runId:r,processingFiles:fe??yt,showArtifacts:M,artifactRefreshKey:Ur.key,artifactRefreshDetails:Ur.details,selectedArtifactPath:ar,onSelectedArtifactPathChange:or,onSendMessage:Wr?Sr:void 0,messages:qe,payloadContent:Fe,conversationContent:Le?qr:Ie,onClose:gr,defaultTab:rr,activeTab:rr,onTabChange:ir})})]}),n(ie,{isOpen:Rr,onClose:()=>zr(!1),children:[t(se,{children:`Export conversation as PDF`}),n(ae,{children:[t(`p`,{className:`mb-2`,children:`This will open your browser's print dialog with the current conversation.`}),t(`p`,{className:`text-sm text-muted`,children:`To save a PDF, choose "Save as PDF" or a similar option in the print dialog.`})]}),n(oe,{align:`right`,children:[t(o,{variant:`ghost`,size:`sm`,onClick:()=>zr(!1),children:`Cancel`}),t(o,{size:`sm`,onClick:Vr,children:`Open print dialog`})]})]})]})})});return B?t(pa,{data:B,sendMessage:Sr,ChartComponent:ho,artifactRunId:r,children:Jr}):Jr}function Lb({messages:e}){return t(`div`,{className:`flex flex-col overflow-y-auto space-y-6 py-4`,children:W.useMemo(()=>[...e].sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),[e]).map(e=>t(Nf,{message:e,showPulsatingCircle:!1},`${e.workstream_id??`main`}-${e.timestamp}-${e.type}`))})}function Rb({messages:e,bottomRef:n,className:r,messagesClassName:i,emptyClassName:a}){let o=W.useRef(null);K(()=>{n.current&&n.current.scrollIntoView({behavior:`smooth`})},[e,n]);let s=W.useMemo(()=>[...e].sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),[e]);return t(`div`,{ref:o,className:`flex-1 min-h-0 h-full overflow-y-auto py-4 px-4 sm:px-6 lg:px-8 bg-white flex flex-col ${r||``}`,"data-testid":`messages-container`,children:s.length===0?t(`div`,{className:`flex items-center justify-center h-full text-center py-8 ${a||``}`,children:t(`div`,{className:`flex items-center px-4 py-3 text-gray-500`,children:`Waiting for agent response...`})}):t(`div`,{className:`flex-1 flex flex-col justify-start h-full min-h-0 ${i||``}`,children:t(Lb,{messages:s,isCompleted:!1})})})}Ea.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${Ea.version}/build/pdf.worker.min.mjs`;function zb({className:e,size:n=`md`}){return t(`div`,{className:`flex items-center justify-center ${e||``}`,children:t(sr,{className:`${{sm:`w-4 h-4`,md:`w-6 h-6`,lg:`w-8 h-8`}[n]} animate-spin text-muted-foreground`})})}function Bb({pdfUrl:e,pageNumber:r,width:i,className:a,renderTextLayer:o=!1,renderAnnotationLayer:s=!1,onLoadSuccess:c,onError:l}){let[u,d]=Y(!0),[f,p]=Y(null);return f?t(`div`,{className:`flex items-center justify-center text-destructive text-sm ${a||``}`,children:`Failed to load PDF`}):n(`div`,{className:a,children:[u&&t(zb,{className:`py-4`,size:`md`}),t(wa,{file:e,onLoadSuccess:({numPages:e})=>{d(!1),c?.(e)},onLoadError:e=>{d(!1),p(e),l?.(e)},loading:null,children:t(Ta,{pageNumber:r,width:i,renderTextLayer:o,renderAnnotationLayer:s,loading:t(zb,{className:`py-4`,size:`sm`})})})]})}const Vb=nt(null);function Hb({pdfUrl:e,urlLoading:n=!1,children:r,onLoadSuccess:i}){let[a,o]=Y(0),[s,c]=Y(!0),[l,u]=Y(null),[d,f]=Y(null),p=async e=>{o(e.numPages),i?.(e.numPages);try{let t=(await e.getPage(1)).getViewport({scale:1});f({width:t.width,height:t.height,aspectRatio:t.width/t.height})}catch(e){console.error(`Failed to get page dimensions:`,e)}c(!1)},m=e=>{c(!1),u(e)},h={pdfUrl:e,numPages:a,loading:n||!e||s,error:l,pageDimensions:d};return l?t(`div`,{className:`flex items-center justify-center text-destructive text-sm py-4`,children:`Failed to load PDF`}):t(Vb.Provider,{value:h,children:e?t(wa,{file:e,onLoadSuccess:p,onLoadError:m,loading:t(zb,{className:`py-4`,size:`md`}),children:r((e,n)=>t(Ta,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(zb,{className:`py-4`,size:`sm`})},e))}):t(zb,{className:`py-4`,size:`md`})})}function Ub(){return at(Vb)}const Wb=210/297;function Gb({pageNumber:e,width:n,className:r}){let i=Ub(),a=i?.pageDimensions?.aspectRatio??Wb,o=n?Math.round(n/a):200;return i?.loading?t(`div`,{className:`flex items-center justify-center bg-muted ${r||``}`,style:{height:o,width:n||`100%`},children:t(zb,{size:`md`})}):t(`div`,{className:r,children:t(Ta,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(zb,{className:`py-4`,size:`sm`})})})}function Kb({pageNumber:e,width:n,isSelected:r,onSelect:i,renderThumbnail:a,aspectRatio:o=Wb,rootMargin:s=`200px 0px`}){let c=J(null),[l,u]=Y(!1);K(()=>{let e=c.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0]?.isIntersecting&&u(!0)},{rootMargin:s,threshold:0});return t.observe(e),()=>t.disconnect()},[s]);let d=n?Math.round(n/o):200;return t(`div`,{ref:c,children:a({pageNumber:e,isSelected:r,pageElement:l?t(Ta,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(`div`,{className:`flex items-center justify-center bg-muted`,style:{height:d},children:t(zb,{size:`sm`})})}):t(`div`,{className:`flex items-center justify-center bg-muted`,style:{height:d,width:n||`100%`},children:t(`span`,{className:`text-muted-foreground text-xs`,children:e})}),onSelect:i})})}function qb(e){if(!e)return null;let t=e.parentElement;for(;t;){let e=window.getComputedStyle(t).overflowY;if(e===`auto`||e===`scroll`)return t;t=t.parentElement}return null}function Jb({pdfUrl:r,urlLoading:i=!1,pageCount:a,currentPage:o,thumbnailWidth:s,onPageSelect:c,renderThumbnail:l,scrollContainerRef:u,onAspectRatioChange:d,onItemHeightChange:f,calculateItemHeight:p,onPageCountChange:m}){let[h,g]=Y(null),[_,v]=Y({start:0,end:Math.min(15,a)}),[y,b]=Y(null),x=J(null),S=G(e=>{g(e)},[]),C=G(async e=>{m?.(e.numPages);try{let t=(await e.getPage(1)).getViewport({scale:1}),n=t.width/t.height;b(n),d?.(n)}catch(e){console.error(`Failed to get page dimensions:`,e),b(Wb),d?.(Wb)}},[d,m]),w=y??Wb,T=s?Math.round(s/w):200,E=p?p(T):T+16+24+8;if(K(()=>{E>0&&y!==null&&f?.(E)},[E,y,f]),K(()=>{let e=u?.current||qb(x.current);if(!e)return;let t=()=>{let t=e.scrollTop,n=e.clientHeight,r=Math.floor(t/E),i=Math.ceil((t+n)/E),o=Math.max(0,r-5),s=Math.min(a,i+5);v(e=>e.start!==o||e.end!==s?{start:o,end:s}:e)};return t(),e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[E,a,u]),h)return t(`div`,{className:`flex items-center justify-center text-destructive text-sm py-4`,children:`Failed to load PDF`});if(i||!r)return t(zb,{className:`py-4`,size:`md`});let D=_.start*E,O=(a-_.end)*E,k=y!==null;return t(`div`,{ref:x,children:t(wa,{file:r,onLoadSuccess:C,onLoadError:S,loading:t(zb,{className:`py-4`,size:`md`}),children:k?n(e,{children:[D>0&&t(`div`,{style:{height:D}}),Array.from({length:_.end-_.start},(e,n)=>{let r=_.start+n+1;return t(`div`,{"data-page-index":r-1,style:{height:E,overflow:`hidden`},children:t(Kb,{pageNumber:r,width:s,isSelected:r===o,onSelect:()=>c(r),renderThumbnail:l,aspectRatio:w})},r)}),O>0&&t(`div`,{style:{height:O}})]}):t(zb,{className:`py-4`,size:`md`})})})}function Yb({pdfUrl:e,pageNumber:r,width:i,height:a,className:o,renderTextLayer:s=!1,renderAnnotationLayer:c=!1,onPageChange:l}){let[u,d]=Y(0),[f,p]=Y(!0),[m,h]=Y(null);return K(()=>{u>0&&l?.(r,u)},[r,u,l]),m?t(`div`,{className:`flex items-center justify-center text-destructive ${o||``}`,children:n(`span`,{children:[`Failed to load PDF: `,m.message]})}):n(`div`,{className:o,children:[f&&t(zb,{className:`py-8`,size:`lg`}),t(wa,{file:e,onLoadSuccess:({numPages:e})=>{d(e),p(!1)},onLoadError:e=>{p(!1),h(e)},loading:null,children:t(Ta,{pageNumber:Math.min(r,u||1),width:i,height:a,renderTextLayer:s,renderAnnotationLayer:c,loading:t(zb,{className:`py-8`,size:`md`})})})]})}const Xb=[50,75,100,125,150,200,300];function Zb({pdfUrl:r,pdfUrlLoading:i=!1,pageCount:a,currentPage:s,onChange:c,onPageCountChange:l,className:u,compact:d=!1,headerExtra:f}){let{t:m}=X(),h=J(null),g=J(null),[_,v]=Y(void 0),[y,b]=Y(100),[x,S]=Y(.7070707070707071),[C,w]=Y(null),T=J(null),E=_?Math.round(_*y/100):void 0,D=G(()=>{let e=Xb.findIndex(e=>e>=y);e===-1&&(e=Xb.length-1);let t=Math.min(e+1,Xb.length-1);b(Xb[t])},[y]),O=G(()=>{let e=Xb.findIndex(e=>e>=y);e===-1&&(e=Xb.length-1);let t=Math.max(e-1,0);b(Xb[t])},[y]),k=G(()=>{b(100)},[]),A=G(e=>e+(d?28:48),[d]),j=G((e,t)=>{let n=e?Math.round(e/t):200;return A(n)},[A]);K(()=>{let e=g.current;if(!e)return;let t=null,n=()=>e.clientWidth-16-16-4,r=()=>{let t=n();if(t<=0)return;let r=T.current;if(r&&r>0){let n=e.scrollTop,i=Math.round(n/r),a=j(t,x),o=i*a;v(t),requestAnimationFrame(()=>{e.scrollTo({top:o,behavior:`instant`})}),T.current=a}else v(t),T.current=j(t,x)},i=n();i>0&&(v(i),T.current=j(i,x));let a=new ResizeObserver(()=>{t&&clearTimeout(t),t=setTimeout(r,150)});return a.observe(e),()=>{t&&clearTimeout(t),a.disconnect()}},[x,j]);let M=J(!1),N=J(null),P=J(y);K(()=>{P.current!==y&&(P.current=y,N.current={targetPage:s},M.current=!0)},[y,s]),K(()=>{let e=g.current,t=N.current;if(t&&e&&C){N.current=null;let n=(t.targetPage-1)*C;requestAnimationFrame(()=>{e.scrollTo({top:n,behavior:`instant`}),requestAnimationFrame(()=>{M.current=!1})})}},[C]);let F=J(!1);K(()=>{let e=g.current;if(!(!e||!C||F.current))if(s>1){F.current=!0,M.current=!0;let t=(s-1)*C;e.scrollTo({top:t,behavior:`instant`}),requestAnimationFrame(()=>{M.current=!1})}else F.current=!0},[C,s]);let I=J(s);return K(()=>{let e=g.current;if(!(!e||!C)&&I.current!==s){I.current=s,M.current=!0;let t=(s-1)*C;e.scrollTo({top:t,behavior:`instant`}),requestAnimationFrame(()=>{M.current=!1})}},[s,C]),K(()=>{let e=g.current;if(!e||!C)return;let t=null,n=()=>{M.current||(t&&clearTimeout(t),t=setTimeout(()=>{let t=e.scrollTop,n=Math.round(t/C)+1,r=Math.max(1,Math.min(n,a));r!==s&&(I.current=r,c(r))},50))};return e.addEventListener(`scroll`,n,{passive:!0}),()=>{t&&clearTimeout(t),e.removeEventListener(`scroll`,n)}},[C,a,s,c]),n(`div`,{ref:h,className:Ze(`flex flex-col items-stretch`,d?`gap-y-1`:`gap-y-2`,u),children:[n(`div`,{className:Ze(`relative flex items-center justify-center px-2`,d?`h-6`:`h-9`),children:[t(o,{variant:`ghost`,size:`xs`,onClick:()=>{s>1&&c(s-1)},title:m(`pdf.previousPage`),children:t(mn,{className:`size-4`})}),n(`div`,{className:`absolute start-2 flex items-center gap-x-1`,children:[t($b,{zoom:y,onZoomIn:D,onZoomOut:O,onFitToView:k,canZoomIn:y<Xb[Xb.length-1],canZoomOut:y>Xb[0]}),f&&n(e,{children:[t(`div`,{className:`w-px h-4 bg-border mx-1`}),f]})]}),t(`div`,{className:`absolute end-2`,children:t(Qb,{currentPage:s,totalPages:a,onChange:c})})]}),t(`div`,{ref:g,className:Ze(`flex flex-col items-center flex-1 overflow-y-auto px-2`,d?`gap-1`:`gap-2`),children:t(Jb,{pdfUrl:r,urlLoading:i,pageCount:a,currentPage:s,thumbnailWidth:E,onPageSelect:c,onPageCountChange:l,scrollContainerRef:g,onAspectRatioChange:S,onItemHeightChange:w,calculateItemHeight:A,renderThumbnail:({pageNumber:e,isSelected:r,pageElement:i,onSelect:a})=>n(`div`,{className:Ze(`hover:bg-muted rounded-md w-full`,d?`p-1`:`p-2`),children:[t(o,{variant:`unstyled`,size:`none`,"aria-pressed":r,"aria-label":`Page ${e}`,className:Ze(`relative border-[2px] cursor-pointer overflow-hidden`,r?`border-primary`:`border-border`),onClick:a,children:i}),t(p,{className:Ze(`text-muted-foreground font-semibold`,d?`text-xs pt-0.5`:`text-sm pt-1`),children:e})]},e)})}),t(`div`,{className:Ze(`flex items-center justify-center`,d?`h-6`:`h-9`),children:t(o,{variant:`ghost`,size:`xs`,onClick:()=>{s<a&&c(s+1)},title:m(`pdf.nextPage`),children:t(dn,{className:`size-4`})})})]})}function Qb({currentPage:e,totalPages:r,onChange:i}){let{t:a}=X(),o=J(null),[s,c]=Y(String(e));K(()=>{c(String(e))},[e]);let l=()=>{let t=parseInt(s,10);!Number.isNaN(t)&&t>=1&&t<=r?i(t):c(String(e))};return n(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[t(`span`,{children:a(`pdf.page`)}),t(`input`,{ref:o,type:`text`,value:s,onChange:e=>c(e.target.value),onKeyDown:t=>{t.key===`Enter`?(l(),o.current?.blur()):t.key===`Escape`&&(c(String(e)),o.current?.blur())},onBlur:()=>{l()},className:`w-8 h-5 text-center text-xs px-1 py-0 bg-background border border-border rounded focus:outline-none focus:border-primary`}),n(`span`,{children:[`/ `,r]})]})}function $b({zoom:e,onZoomIn:r,onZoomOut:i,onFitToView:a,canZoomIn:s,canZoomOut:c}){let{t:l}=X();return n(`div`,{className:`flex items-center gap-x-0.5`,children:[t(o,{variant:`ghost`,size:`xs`,onClick:i,isDisabled:!c,title:l(`pdf.zoomOut`),children:t(_r,{})}),n(`span`,{className:`text-xs text-muted-foreground min-w-[32px] text-center`,children:[e,`%`]}),t(o,{variant:`ghost`,size:`xs`,onClick:r,isDisabled:!s,title:l(`pdf.zoomIn`),children:t(kr,{})}),t(o,{variant:`ghost`,size:`xs`,onClick:a,title:l(`pdf.fitToWidth`),className:e===100?`text-muted-foreground/40`:void 0,children:t(dr,{})})]})}function ex({object:e,url:r,source:i,className:a}){let{t:s}=X(),{client:c}=Z(),[l,u]=Y(1),[d,f]=Y(r||``),[p,m]=Y(!r),[h,g]=Y(0),[_,v]=Y(!1);K(()=>{if(r){f(r),m(!1);return}let t=i||e?.content?.source;if(!t){m(!1);return}m(!0),c.files.getDownloadUrl(t).then(e=>{f(e.url)}).catch(e=>{console.error(`Failed to get PDF URL:`,e)}).finally(()=>{m(!1)})},[r,i,e?.content?.source,c]),K(()=>{let t=e?.metadata,n=t?.pages||t?.page_count||0;n>0&&g(n)},[e?.metadata]);let y=e=>{g(e)};return p?t(`div`,{className:`flex items-center justify-center h-full`,children:t(Te,{size:`lg`})}):d?_?n(`div`,{className:`fixed inset-0 bg-background z-50 flex flex-col overflow-hidden`,children:[t(`div`,{className:`flex h-9 items-center justify-end shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:t(o,{variant:`ghost`,size:`xs`,onClick:()=>v(!1),title:s(`pdf.closeFullscreen`),children:t(ci,{className:`size-4`})})}),t(Zb,{pdfUrl:d,pdfUrlLoading:p,pageCount:h||100,currentPage:l,onChange:u,onPageCountChange:y,className:`flex-1 min-h-0`})]}):t(`div`,{className:`relative h-full flex flex-col`,children:t(Zb,{pdfUrl:d,pdfUrlLoading:p,pageCount:h||100,currentPage:l,onChange:u,onPageCountChange:y,className:a,compact:!0,headerExtra:t(o,{title:s(`pdf.fullscreen`),tooltipPlacement:`bottom`,variant:`unstyled`,className:`p-1 rounded cursor-pointer transition-colors text-muted-foreground hover:text-foreground hover:bg-muted`,onClick:()=>v(!0),children:t(fr,{className:`size-4`})})})}):t(`div`,{className:`flex items-center justify-center h-full text-muted`,children:s(`pdf.noPdfAvailable`)})}var tx=Na({UniversalDocumentViewer:()=>Ex});function nx(e){return e.fileName||e.title||e.artifact?.path.split(`/`).pop()||e.sourcePath?.split(`/`).pop()||`Document`}function rx(e){let t=e.split(`?`)[0]||e;return t.includes(`.`)&&t.split(`.`).pop()?.toLowerCase()||``}function ix(e){return e.contentType===`application/pdf`||e.extension===`pdf`}function ax(e){return[`md`,`markdown`].includes(e.extension)||[`text/markdown`,`text/x-markdown`].includes(e.contentType||``)}function ox(e){return e.contentType?.startsWith(`image/`)||[`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`].includes(e.extension)}function sx(e){return e.contentType===`text/html`||[`html`,`htm`].includes(e.extension)}function cx(e){return[`application/xml`,`text/xml`].includes(e.contentType||``)||e.extension===`xml`}function lx(e){return e.contentType?.startsWith(`text/`)||[`css`,`csv`,`json`,`txt`,`tsx`,`ts`,`jsx`,`js`,`xml`,`yaml`,`yml`].includes(e.extension)}function ux(e){return[`tsx`,`jsx`].includes(e.extension)}function dx(e){return[`doc`,`docx`,`ppt`,`pptx`].includes(e.extension)||[`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-powerpoint`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`].includes(e.contentType||``)}function fx({content:e,extension:n}){return t(`pre`,{className:`h-full overflow-auto rounded-md bg-muted/10 p-3 text-xs leading-5`,children:t(`code`,{className:n?`language-${n}`:void 0,children:e||``})})}function px({message:e}){return n(`div`,{className:`flex h-full min-h-64 flex-col items-center justify-center gap-2 text-muted`,children:[t(Nn,{className:`size-8`}),t(`span`,{className:`text-sm`,children:e})]})}function mx(e,n){if(e.Component){let r=e.Component;return t(r,{context:n})}return e.render?.(n)??null}function hx(e,t){return e.includes(`.`)?e.replace(/\.[^/.]+$/,t):`${e}${t}`}function gx(e){return e.split(`/`).pop()||e}function _x(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function vx(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function yx(e){if(e!==void 0)return e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(+(e<1e4))} s`}function bx(e){return Array.isArray(e)?e.length:0}function xx(e){try{let t=_x(JSON.parse(e));if(!t)return;let n=_x(t.viewport);return{ok:typeof t.ok==`boolean`?t.ok:void 0,source_artifact:typeof t.source_artifact==`string`?t.source_artifact:void 0,screenshot_artifact:typeof t.screenshot_artifact==`string`?t.screenshot_artifact:void 0,rendered_at:typeof t.rendered_at==`string`?t.rendered_at:void 0,viewport:n?{width:vx(n.width),height:vx(n.height)}:void 0,dependencies_reused:typeof t.dependencies_reused==`boolean`?t.dependencies_reused:void 0,status:vx(t.status),title:typeof t.title==`string`?t.title:void 0,console_errors:Array.isArray(t.console_errors)?t.console_errors:void 0,page_errors:Array.isArray(t.page_errors)?t.page_errors:void 0,failed_requests:Array.isArray(t.failed_requests)?t.failed_requests:void 0,bad_responses:Array.isArray(t.bad_responses)?t.bad_responses:void 0,timings_ms:_x(t.timings_ms),error:t.error}}catch{return}}async function Sx(e,t){let n=await fetch(e);if(!n.ok)throw Error(`Failed to load ${t}: ${n.statusText}`);return n.text()}function Cx({metadata:e,sourcePath:t,fallbackPath:n,artifactMode:r}){let i=e?.screenshot_artifact?.replace(/^\/+/,``);if(!i)return n;if(r)return i;let a=e?.source_artifact?.replace(/^\/+/,``),o=t.replace(/^\/+/,``);if(a&&o.endsWith(a)){let e=o.slice(0,-a.length).replace(/\/+$/,``);return e?`${e}/${i}`:i}let s=o.includes(`/`)?o.slice(0,o.lastIndexOf(`/`)+1):``;return s?`${s}${gx(i)}`:n}function wx({metadata:e}){if(!e)return null;let r=vx(e.timings_ms?.total_before_cleanup),a=bx(e.console_errors)+bx(e.page_errors)+bx(e.failed_requests)+bx(e.bad_responses);return n(`div`,{className:`grid gap-2 border-b p-3 text-xs`,children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.ok!==void 0&&t(i,{variant:e.ok?`success`:`destructive`,children:e.ok?`render ok`:`render failed`}),e.dependencies_reused!==void 0&&n(i,{variant:e.dependencies_reused?`info`:`secondary`,children:[`deps `,e.dependencies_reused?`reused`:`installed`]}),e.status&&n(i,{variant:`secondary`,children:[`HTTP `,e.status]}),a>0&&n(i,{variant:`attention`,children:[a,` browser issue(s)`]})]}),n(`div`,{className:`grid gap-1 text-muted sm:grid-cols-2`,children:[e.viewport?.width&&e.viewport.height&&n(`div`,{children:[`Viewport `,e.viewport.width,` x `,e.viewport.height]}),yx(r)&&n(`div`,{children:[`Total `,yx(r)]}),e.rendered_at&&n(`div`,{children:[`Rendered `,new Date(e.rendered_at).toLocaleString()]}),e.title&&n(`div`,{className:`truncate`,children:[`Title `,e.title]})]}),typeof e.error==`string`&&t(`div`,{className:`text-destructive`,children:e.error})]})}function Tx({context:e}){let{client:r}=Z(),a=e.source.artifact,o=a?.path||e.source.sourcePath,s=!!a,c=e.content||``,[l,u]=Y({isLoading:!1}),d=G(async(e,t)=>a?(await r.files.getArtifactDownloadUrl(a.runId,e,t)).url:(await r.files.getDownloadUrl(e,gx(e),t)).url,[a,r]);return K(()=>{if(!o){u({isLoading:!1,previewError:`No source path is available for this TSX artifact.`});return}let e=o,t=!1,n=hx(e,`.png`),r=hx(e,`.render.json`);async function i(){u({isLoading:!0});let i,a,o=n;try{i=xx(await Sx(await d(r,`inline`),gx(r))),o=Cx({metadata:i,sourcePath:e,fallbackPath:n,artifactMode:s})}catch(e){a=e instanceof Error?e.message:`Render metadata is not available`}let c,l;try{c=await d(o,`inline`)}catch(e){l=e instanceof Error?e.message:`Sandbox render image is not available`}t||u({isLoading:!1,imageUrl:c,metadata:i,metadataError:a,previewError:l})}return i(),()=>{t=!0}},[s,d,o]),n(`div`,{className:`flex h-full min-h-0 flex-col`,children:[n(`div`,{className:`flex min-h-10 flex-wrap items-center gap-2 border-b px-3 py-2 text-sm`,children:[t(Zn,{className:`size-4 text-info`}),t(`span`,{className:`font-medium`,children:`Sandbox render`}),l.isLoading?t(i,{variant:`secondary`,children:`loading`}):l.imageUrl?t(i,{variant:`success`,children:`PNG preview`}):t(i,{variant:`attention`,children:`source only`}),l.metadata?.rendered_at&&t(`span`,{className:`text-xs text-muted`,children:new Date(l.metadata.rendered_at).toLocaleString()})]}),l.isLoading?n(`div`,{className:`flex h-full min-h-64 items-center justify-center gap-2 text-muted`,children:[t(cr,{className:`size-5 animate-spin`}),t(`span`,{className:`text-sm`,children:`Loading sandbox render...`})]}):l.imageUrl?n(`div`,{className:`grid min-h-0 flex-1 xl:grid-cols-[minmax(0,1fr)_minmax(24rem,0.7fr)]`,children:[t(`div`,{className:`flex min-h-0 items-center justify-center overflow-auto bg-muted/10 p-3`,children:t(`img`,{src:l.imageUrl,alt:`${e.fileName} sandbox render`,className:`max-h-full max-w-full rounded-md object-contain`})}),n(`div`,{className:`min-h-0 overflow-auto border-t xl:border-s xl:border-t-0`,children:[t(wx,{metadata:l.metadata}),t(`div`,{className:`p-3`,children:t(fx,{content:c,extension:e.extension})})]})]}):n(`div`,{className:`grid min-h-0 flex-1 grid-rows-[auto_minmax(0,1fr)]`,children:[n(`div`,{className:`border-b px-3 py-2 text-xs text-muted`,children:[`No sandbox-rendered PNG was found for this TSX artifact. Showing the source without executing it in Studio.`,l.previewError&&n(`span`,{className:`ms-1`,children:[`Preview lookup: `,l.previewError]}),!l.previewError&&l.metadataError&&n(`span`,{className:`ms-1`,children:[`Metadata lookup: `,l.metadataError]})]}),n(`div`,{className:`min-h-0 overflow-auto p-3`,children:[t(wx,{metadata:l.metadata}),t(fx,{content:c,extension:e.extension})]})]})]})}function Ex({source:e,className:r,bodyClassName:i,renderers:a=[],converters:s=[],resolveUrl:c,loadText:l,createRendition:u,markdownComponents:d,showHeader:f=!0,onDownload:p}){let{client:m}=Z(),h=q(()=>nx(e),[e]),g=q(()=>rx(h),[h]),[_,v]=Y(e.url),[y,b]=Y(e.content),[x,S]=Y(null),[C,w]=Y(!1),[T,E]=Y(null),[D,O]=Y(0),k=[e.id,e.title,e.fileName,e.contentType,e.url,e.sourcePath,e.content,e.artifact?.runId,e.artifact?.path].join(`\0`),A=G(async(e,t)=>e.url?e.url:e.artifact?(await m.files.getArtifactDownloadUrl(e.artifact.runId,e.artifact.path,t)).url:e.sourcePath?(await m.files.getDownloadUrl(e.sourcePath,e.fileName,t)).url:``,[m]),j=c||A,M=G(async e=>{if(e.content!==void 0)return e.content;let t=await j(e,`inline`);if(!t)return``;let n=await fetch(t);if(!n.ok)throw Error(`Failed to load ${nx(e)}: ${n.statusText}`);return n.text()},[j]),N=l||M,P={source:e,fileName:h,extension:g,contentType:e.contentType||x?.contentType,url:x?.url||_,content:x?.content||y,isLoading:C,error:T,reload:()=>O(e=>e+1)},F=a.find(e=>e.canRender(P)),I=!F&&(ax(P)||sx(P)||cx(P)||lx(P)),L=!F&&(ix(P)||ox(P)),ee={source:e,fileName:h,extension:g,contentType:e.contentType,target:`pdf`},R=!F&&!P.url?s.find(e=>e.target===`pdf`&&e.canConvert(ee)):void 0,te=!F&&!P.url&&(dx(P)||!!R)&&(!!R||!!u);K(()=>{let t=!1,n=e;E(null),v(n.url),b(n.content),S(null);async function r(){if(!(!I&&!L&&!te)){w(!0);try{if(te){let e=R?await R.convert({source:n,fileName:h,extension:g,contentType:n.contentType,target:`pdf`}):await u?.(n,`pdf`);t||S(e??null);return}if(I){let e=await N(n);t||b(e);return}if(L){let e=await j(n,`inline`);t||v(e)}}catch(e){t||E(e instanceof Error?e.message:`Failed to load document`)}finally{t||w(!1)}}}return r(),()=>{t=!0}},[u,g,h,N,te,I,L,D,j,R,e,k]);let z={...P,url:x?.url||_,content:x?.content||y,contentType:x?.contentType||e.contentType,isLoading:C,error:T},ne;return ne=C?n(`div`,{className:`flex h-full min-h-64 items-center justify-center gap-2 text-muted`,children:[t(cr,{className:`size-5 animate-spin`}),t(`span`,{className:`text-sm`,children:`Loading preview...`})]}):T?n(`div`,{className:`flex h-full min-h-64 flex-col items-center justify-center gap-2 text-destructive`,children:[t(Bt,{className:`size-7`}),t(`span`,{className:`max-w-xl text-center text-sm`,children:T}),t(o,{variant:`outline`,size:`sm`,onClick:z.reload,children:`Retry`})]}):F?mx(F,z):(ix(z)||x?.contentType===`application/pdf`)&&z.url?t(ex,{url:z.url,className:`h-full`}):ox(z)&&z.url?t(`div`,{className:`flex h-full min-h-0 items-center justify-center overflow-auto bg-muted/10 p-3`,children:t(`img`,{src:z.url,alt:h,className:`max-h-full max-w-full rounded-md object-contain`})}):ax(z)?t(`div`,{className:`prose prose-sm dark:prose-invert max-w-none px-5 py-4`,children:t(bt,{artifactRunId:e.artifact?.runId,components:d,children:z.content||``})}):sx(z)?t(`iframe`,{title:h,className:`h-full min-h-96 w-full bg-white`,sandbox:``,srcDoc:z.content||``}):cx(z)?t(`div`,{className:`px-4 py-2`,children:t(Tt,{xml:z.content||``,collapsible:!0})}):ux(z)?t(Tx,{context:z}):lx(z)?t(fx,{content:z.content,extension:g}):dx(z)&&!R&&!u?t(px,{message:`This file needs a PDF rendition before it can be previewed.`}):t(px,{message:`Preview is not available for this file type.`}),n(`div`,{className:H(`flex h-full min-h-0 flex-col overflow-hidden`,r),children:[f&&n(`div`,{className:`flex min-h-10 items-center justify-between gap-3 border-b py-2 ps-3 pe-16`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`truncate text-sm font-medium`,title:h,children:h}),z.contentType&&t(`div`,{className:`truncate text-xs text-muted`,children:z.contentType})]}),p&&t(o,{variant:`outline`,size:`sm`,onClick:()=>p(e),children:`Download`})]}),t(`div`,{className:H(`min-h-0 flex-1 overflow-auto`,i),children:ne})]})}function Dx(e){return e.name}function Ox({isClearable:e=!1,onChange:n,ignoreVirtuals:r=!1,selectedEnvId:i,disabled:a=!1}){let{t:o}=X(),{client:s}=Z(),[c,l]=Y(),{data:u,isLoading:d}=We(()=>s.environments.list().then(e=>(r?e.filter(e=>!e.provider.startsWith(`virtual_`)):e).slice().sort((e,t)=>e.name.localeCompare(t.name))));return K(()=>{l(u?.find(e=>e.id===i))},[u,i]),t(ve,{isClearable:e,optionLabel:Dx,options:u??[],value:c,onChange:e=>{l(e),n(e)},placeholder:o(`intakePolicy.placeholder.environment`),filterBy:`name`,disabled:a,isLoading:d})}function kx(e){return e.name}function Ax(e){return e?.length?n=>t(`span`,{className:e.some(e=>e.id===n.id)?`opacity-50`:``,children:n.name}):kx}function jx({envId:e,isClearable:n,onChange:r,selectedModelId:i,disabled:a=!1,greyedModels:o,onModelsLoaded:s}){let{t:c}=X(),{client:l}=Z(),[u,d]=Y(),{data:f,isLoading:p}=Ue(async()=>{if(!e)return[];try{return[...(await l.environments.retrieve(e)).enabled_models??[]].sort((e,t)=>e.name.localeCompare(t.name))}catch{return[]}},[e]);return K(()=>{if(!i){d(void 0);return}let e=f?.find(e=>e.id===i);d(e??{id:i,name:i,provider:`unknown`})},[f,i]),K(()=>{f&&s?.(f)},[f,s]),t(ve,{isClearable:n,by:`id`,optionLabel:Ax(o),options:f??[],value:u,onChange:e=>{d(e),r(e)},placeholder:c(`intakePolicy.placeholder.model`),disabled:a,isLoading:p})}function Mx({env:e,isClearable:n,onChange:r}){let{t:i}=X(),{client:a}=Z(),[o,s]=Y(),{data:c,isLoading:l}=Ue(async()=>{if(!e)return[];try{return a.environments.listTrainableModels(e.id)}catch{return[]}},[e?.id]);return t(ve,{isClearable:n,by:`id`,optionLabel:kx,options:c??[],value:o,onChange:e=>{s(e),r(e)},placeholder:i(`intakePolicy.placeholder.model`),disabled:!e,isLoading:l})}function Nx({children:e,fallback:n}){return Px?t(Px,{fallback:n,children:e}):t(Da,{FallbackComponent:n,children:e})}let Px=null;function Fx(e){Px=e}function Ix({children:e}){return t(Nx,{fallback:Lx,children:e})}function Lx({error:e}){let{t:r}=X(),i=e instanceof Error?e.message:void 0;return n(re,{status:`error`,title:r(`errors.somethingWentWrong`),children:[n(`div`,{className:`mb-4`,children:[r(`errors.teamNotifiedLine1`),` `,r(`errors.teamNotifiedLine2`),`\xA0`,t(`a`,{className:`text-info`,href:`mailto:support@vertesiahq.com`,children:`support@vertesiahq.com`}),`.`]}),i&&t(`code`,{className:`w-full mt-4 text-sm text-muted break-words`,children:i})]})}function Rx({children:e}){return t(Nx,{fallback:zx,children:e})}function zx({error:e}){let r=e instanceof Error?e.message:void 0;return t(`tr`,{children:n(`td`,{colSpan:100,children:[t(`span`,{className:`text-xs`,children:` Cannot display row`}),t(`br`,{}),t(`span`,{className:`bg-gray-400`,children:r})]})})}function Bx({children:e}){return t(Nx,{fallback:Vx,children:e})}function Vx({error:e}){let r=e instanceof Error?e.message:void 0;return console.log(`WidgetError`,e),n(`div`,{className:`text-sm`,children:[`Sorry, this area cannot be loaded or rendered.`,r&&t(`pre`,{children:r})]})}const Hx=/^[a-f0-9]{24}$|^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$|^(?=.*\d)(?=.*[a-zA-Z])[a-zA-Z0-9_-]{8,}$/i;function Ux(e){return Hx.test(e)}function Wx({className:e,children:r,title:i,description:o,actions:s,breadcrumbs:c,useDynamicBreadcrumbs:l=!0}){let u=_a();function d(e){return e.replace(/[-_]/g,` `).split(` `).map(e=>Ji(e)).join(` `)}let f=e=>{if(e?.title)return e.title;let t=e?.href||``;if(!t)return`Page`;let n=t.split(`#`)[0].split(`?`)[0].split(`/`).filter(e=>e.length>0);return n.length>=1?d(n[n.length-1]):`Page`},p=(()=>{let e=[];if(l&&typeof window<`u`){let t=window.history.state?.historyChain;if(Array.isArray(t))t.forEach((n,r)=>{let i=t.length-r;e.push({label:f(n),href:n.href,onClick:()=>u(n.href,{stepsBack:i})})});else{let t=window.location.pathname.split(`/`).filter(e=>e.length>0);for(let n=0;n<t.length;n++)if(Ux(t[n])){let r=`/${t.slice(0,n).join(`/`)}`;e.push({label:d(t[n-1]||r),href:r,onClick:()=>u(r,{isBasePathNested:!1})})}}}return c&&c.length>0&&c.forEach(t=>{let n=t.props?.children||t,r=t.props?.href;e.push(r?{href:r,label:n,onClick:()=>u(r,{replace:t.props.clearBreadcrumbs})}:{label:n})}),e})();return n(`div`,{className:Ze(`pb-0 ps-4 pe-2 py-2 flex flex-col`,e),children:[n(`div`,{className:`flex items-start gap-4`,children:[n(`div`,{className:`w-full flex place-content-between h-auto min-h-8 flex-col items-start justify-center`,children:[n(`nav`,{className:`flex-1 flex justify-start text-sm`,children:[p.length>0&&t(a,{path:p,separator:t(cn,{className:`size-3.5 cn-rtl-flip`}),maxItems:4}),o&&t(Re,{description:o,children:t(Qn,{className:`size-4 text-muted ms-4`})})]}),i&&t(`div`,{className:`flex gap-2 items-center`,children:t(`h1`,{className:`text-xl font-semibold break-all`,children:i})})]}),t(`div`,{className:`flex gap-x-2 shrink-0 items-center`,children:s})]}),r&&t(`div`,{className:`w-full flex items-center`,children:r})]})}function Gx(){let{t:e}=X();return n(`div`,{className:`text-center pt-32`,children:[t(`h1`,{className:`text-3xl font-bold text-red-500`,children:`404`}),t(`p`,{className:`text-2xl`,children:e(`layout.pageNotFound`)})]})}function Kx({objectId:e,onExtractionChanged:r,selectedField:i,onClose:a}){let{t:o}=X(),{client:s}=Z(),[c,l]=Y(void 0),u=J(r);u.current=r;let d=J(i);d.current=i;let f=G(async t=>{let n=d.current,r=n&&t?`Regarding the field "${n}": ${t}`:t,i=await s.store.objects.analyze(e).startGroundedAssistant(r?{user_prompt:r}:{});return l(i.agent_run_id),{agent_run_id:i.agent_run_id}},[s,e]),p=G(e=>{e&&u.current?.()},[]);return n(`div`,{className:`flex h-full flex-col`,children:[i&&!c&&n(`div`,{className:`shrink-0 border-b border-border bg-muted/40 px-3 py-1.5 text-xs text-muted-foreground`,children:[o(`grounded.assistantField`),` `,t(`span`,{className:`font-mono text-foreground`,children:i})]}),t(Nb,{agentRunId:c,startWorkflow:f,interactive:!0,fullWidth:!0,hideObjectLinking:!0,onShowInputChange:p,onClose:a})]})}const qx=`magic-pdf`;function Jx(e){return e.replace(/^\$\.?/,``).replace(/^data\./,``)}function Yx(e){let{client:t}=Z(),[n,r]=Y(!1);return K(()=>{let n=!1;return r(!1),t.files.getDownloadUrl(`${qx}/${e}/grounded-extraction.json`).then(e=>fetch(e.url,{method:`HEAD`})).then(e=>{n||r(e.ok)}).catch(()=>{}),()=>{n=!0}},[t,e]),n}function Xx(e){let{client:t}=Z(),[n,r]=Y(null);return K(()=>{let n=!1;return r(null),t.files.getDownloadUrl(`${qx}/${e}/grounded-extraction.json`).then(e=>fetch(e.url)).then(e=>e.ok?e.json():null).then(e=>{n||!e?.citations||r({confidence:e.confidence,verified:e.citations.filter(e=>e.verified).length,total:e.citations.length,verdict:e.verdict,verdict_reason:e.verdict_reason})}).catch(()=>{}),()=>{n=!0}},[t,e]),n}function Zx({objectId:e,onClose:r}){let{t:i}=X(),{client:a}=Z(),{data:s,error:c,isLoading:l,refetch:u}=Ue(async()=>{let t=await a.files.getDownloadUrl(`${qx}/${e}/grounded-extraction.json`),n=await fetch(t.url);if(!n.ok)throw Error(i(`grounded.notFound`));return n.json()},[e]);return c?t(`div`,{className:`flex h-full items-center justify-center`,children:n(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md`,children:[t(M,{title:i(`grounded.failedToLoad`),children:ze(c)}),r&&t(o,{variant:`outline`,onClick:r,children:i(`pdf.close`)})]})}):l||!s?t(`div`,{className:`flex h-full items-center justify-center`,children:t(Te,{size:`lg`})}):t(`div`,{className:`relative h-full`,children:t($x,{extraction:s,objectId:e,onClose:r,onExtractionChanged:u})})}function Qx({objectId:e,onClose:n}){return t(`div`,{className:`fixed inset-0 bg-background z-50`,children:t(Zx,{objectId:e,onClose:n})})}function $x({extraction:r,objectId:a,onClose:s,onExtractionChanged:c}){let{t:l}=X(),{client:u}=Z(),d=q(()=>Object.keys(r.pages).map(e=>parseInt(e,10)).sort((e,t)=>e-t),[r.pages]),f=e=>{u.files.getDownloadUrl(`${qx}/${a}/${e}`).then(e=>window.open(e.url,`_blank`)).catch(()=>{})},[p,m]=Y(d[0]??1),[h,g]=Y(void 0),[_,v]=Y(!1),[y,b]=Y(!1),[x,S]=Y(`original`),[C,w]=Y(!1),T=q(()=>{let e={digital:0,ocr:0,reviewerConfirmed:0,snapped:0,imageRead:0},t=[];for(let n of r.citations)n.verified?n.snapped?e.snapped++:(n.confidence??0)>=1?e.digital++:e.ocr++:n.reviewed?e.reviewerConfirmed++:(e.imageRead++,t.push(n));let n=e.digital+e.ocr+e.snapped,i=e.reviewerConfirmed;return{groups:e,unverified:t,digitallyVerified:n,modelVerified:i,totalVerified:n+i}},[r.citations]),E=q(()=>{let e=new Map;for(let t of r.citations){let n=Jx(t.path),r=e.get(n)??[];r.push(t),e.set(n,r)}return e},[r.citations]),D=r.citations.length,O=e=>{g(e);let t=E.get(Jx(e))?.[0];t&&m(t.page)},k=d.indexOf(p),A=h?E.get(Jx(h))?.find(e=>e.page===p):void 0,j=A?.cells?A.cells.start===A.cells.end?A.cells.start:`${A.cells.start}:${A.cells.end}`:void 0;return n(_e,{direction:`horizontal`,className:`absolute inset-0`,children:[n(ge,{defaultSize:55,minSize:25,className:`flex flex-col bg-muted`,children:[n(`div`,{className:`relative flex h-9 shrink-0 items-center justify-center bg-sidebar px-2 border-b border-sidebar-border`,children:[j&&t(i,{variant:`secondary`,className:`absolute start-2 max-w-32 truncate font-mono text-[11px]`,title:j,children:j}),n(`div`,{className:`flex items-center gap-2`,children:[t(o,{variant:`ghost`,size:`xs`,"aria-label":l(`grounded.previousPage`),disabled:k<=0,onClick:()=>m(d[k-1]),children:t(sn,{className:`size-4`})}),t(`span`,{className:`text-xs text-muted-foreground`,children:l(`pdf.pageOf`,{pageNumber:p,totalPages:d.length})}),t(o,{variant:`ghost`,size:`xs`,"aria-label":l(`grounded.nextPage`),disabled:k>=d.length-1,onClick:()=>m(d[k+1]),children:t(cn,{className:`size-4`})})]}),n(`fieldset`,{className:`absolute end-2 flex items-center gap-0.5 rounded border-0 bg-muted p-0.5`,children:[t(`legend`,{className:`sr-only`,children:l(`grounded.checkerboard`)}),t(Re,{description:l(`pdf.originalImages`),placement:`bottom`,size:`xs`,asChild:!0,children:n(o,{variant:x===`original`?`outline`:`ghost`,size:`xs`,"aria-label":l(`pdf.originalImages`),"aria-pressed":x===`original`,className:`h-6 gap-1 px-1.5`,onClick:()=>S(`original`),children:[t(Xn,{className:`size-3.5`}),t(`span`,{className:`hidden sm:inline`,children:l(`pdf.page`)})]})}),t(Re,{description:l(`grounded.checkerboard`),placement:`bottom`,size:`xs`,asChild:!0,children:n(o,{variant:x===`grid`?`outline`:`ghost`,size:`xs`,"aria-label":l(`grounded.checkerboard`),"aria-pressed":x===`grid`,className:`h-6 gap-1 px-1.5`,onClick:()=>S(`grid`),children:[t(qn,{className:`size-3.5`}),t(`span`,{className:`hidden sm:inline`,children:l(`grounded.checkerboard`)})]})})]})]}),t(`div`,{className:`flex-1 overflow-auto p-2`,children:t(eS,{objectId:a,page:p,dims:r.pages[String(p)],citations:r.citations.filter(e=>e.page===p),selectedPath:h,onSelectPath:g,imageMode:x})})]}),t(he,{className:`w-[4px] bg-border cursor-ew-resize`}),n(ge,{defaultSize:45,minSize:20,className:`flex flex-col`,children:[n(`div`,{className:`flex h-9 items-center justify-between shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:[t(`span`,{className:`text-sm font-medium`,children:l(`grounded.title`)}),n(`div`,{className:`flex items-center gap-2`,children:[t(Re,{description:l(`grounded.assistantTooltip`),placement:`bottom`,size:`xs`,asChild:!0,children:t(o,{variant:C?`primary`:`ghost`,size:`xs`,"aria-label":l(`grounded.assistant`),onClick:()=>w(e=>!e),children:t(Kr,{className:`size-4`})})}),r.verdict&&t(`button`,{type:`button`,className:`cursor-pointer`,onClick:()=>b(e=>!e),"aria-expanded":y,"aria-label":l(`grounded.verdictDetails`),children:t(i,{variant:r.verdict===`good_to_go`?`success`:`attention`,children:r.verdict===`good_to_go`?l(`grounded.verdictGoodToGo`):l(`grounded.verdictNeedsReview`)})}),typeof r.hardness?.score==`number`&&n(i,{variant:r.hardness.score>=.5?`attention`:r.hardness.score>=.2?`info`:`secondary`,title:l(`grounded.hardnessHint`),children:[l(`grounded.hardness`,{percent:Math.round(r.hardness.score*100)}),r.hardness.escalated?` ↑`:``]}),r.citations.length>0&&(()=>{let e=Math.round(100*T.totalVerified/r.citations.length);return t(i,{variant:e>=95?`success`:e>=50?`attention`:`destructive`,title:l(`grounded.confidenceHint`),children:l(`grounded.confidence`,{percent:e})})})(),n(`button`,{type:`button`,className:`flex cursor-pointer items-center gap-1`,onClick:()=>v(e=>!e),"aria-expanded":_,"aria-label":l(`grounded.breakdownTitle`),children:[T.digitallyVerified>0&&t(i,{variant:`success`,title:l(`grounded.digitalVerifiedHint`),children:l(`grounded.digitalVerifiedOf`,{count:T.digitallyVerified,total:D})}),T.modelVerified>0&&t(i,{variant:`success`,title:l(`grounded.modelVerifiedHint`),children:l(`grounded.modelVerifiedOf`,{count:T.modelVerified,total:D})}),T.groups.imageRead>0&&t(i,{variant:`attention`,title:l(`grounded.unverifiedHint`),children:l(`grounded.unverifiedCount`,{count:T.groups.imageRead})})]}),t(o,{variant:`ghost`,size:`xs`,"aria-label":l(`grounded.downloadCitations`),title:l(`grounded.downloadCitations`),onClick:()=>f(`grounded-extraction.json`),children:t(Pn,{className:`size-4`})}),t(o,{variant:`ghost`,size:`xs`,"aria-label":l(`grounded.downloadBlocks`),title:l(`grounded.downloadBlocks`),onClick:()=>f(`pages/page-${p}.json`),children:t(Ln,{className:`size-4`})}),t(o,{variant:`ghost`,size:`xs`,"aria-label":l(`grounded.downloadAnnotated`),title:l(`grounded.downloadAnnotated`),onClick:()=>f(`grounded-annotated.pdf`),children:t(Mn,{className:`size-4`})}),!!s&&t(o,{variant:`ghost`,size:`xs`,onClick:s,"aria-label":l(`pdf.close`),children:t(ci,{className:`size-4`})})]})]}),y&&r.verdict&&n(`div`,{className:`shrink-0 border-b border-border bg-background px-3 py-2 text-sm`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(`span`,{className:H(`font-medium`,r.verdict===`good_to_go`?`text-success`:`text-attention`),children:r.verdict===`good_to_go`?l(`grounded.verdictGoodToGo`):l(`grounded.verdictNeedsReview`)}),t(`span`,{className:`text-xs text-muted-foreground`,children:r.review?l(`grounded.verdictByReviewer`):l(`grounded.verdictByConfidence`)})]}),(r.verdict_reason??r.review?.verdict_reason)&&t(`p`,{className:`mt-1 text-xs`,children:r.verdict_reason??r.review?.verdict_reason}),r.review?.summary&&n(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[n(`span`,{className:`font-medium text-foreground`,children:[l(`grounded.reviewSummary`),`: `]}),r.review.summary]}),typeof r.review?.corrections_applied==`number`&&r.review.corrections_applied>0&&t(`p`,{className:`mt-1 text-xs text-info`,children:l(`grounded.reviewCorrections`,{count:r.review.corrections_applied})})]}),_&&n(`div`,{className:`shrink-0 border-b border-border bg-background px-3 py-2 text-sm max-h-72 overflow-auto`,children:[t(`div`,{className:`font-medium mb-1`,children:l(`grounded.breakdownTitle`)}),n(`div`,{className:`grid grid-cols-2 gap-x-4 text-xs`,children:[t(`span`,{className:`col-span-2 mt-1 font-medium text-success`,children:l(`grounded.digitalVerifiedOf`,{count:T.digitallyVerified,total:D})}),t(`span`,{className:`ps-2 text-muted-foreground`,children:l(`grounded.breakdownDigital`)}),t(`span`,{className:`text-end text-success`,children:T.groups.digital}),t(`span`,{className:`ps-2 text-muted-foreground`,children:l(`grounded.breakdownOcr`)}),t(`span`,{className:`text-end text-success`,children:T.groups.ocr}),t(`span`,{className:`ps-2 text-muted-foreground`,children:l(`grounded.breakdownSnapped`)}),t(`span`,{className:`text-end text-success`,children:T.groups.snapped}),t(`span`,{className:`col-span-2 mt-2 font-medium text-success`,children:l(`grounded.modelVerifiedOf`,{count:T.modelVerified,total:D})}),t(`span`,{className:`ps-2 text-muted-foreground`,children:l(`grounded.breakdownReviewer`)}),t(`span`,{className:`text-end text-success`,children:T.groups.reviewerConfirmed}),T.groups.imageRead>0&&n(e,{children:[t(`span`,{className:`col-span-2 mt-2 font-medium text-attention`,children:l(`grounded.unverifiedCount`,{count:T.groups.imageRead})}),t(`span`,{className:`ps-2 text-muted-foreground`,children:l(`grounded.breakdownImageRead`)}),t(`span`,{className:`text-end text-attention`,children:T.groups.imageRead})]})]}),t(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:l(`grounded.breakdownVerificationHelp`)}),T.unverified.length>0&&n(`div`,{className:`mt-2`,children:[t(`div`,{className:`text-xs font-medium text-muted-foreground mb-1`,children:l(`grounded.breakdownUnverifiedList`)}),t(`ul`,{className:`space-y-0.5`,children:T.unverified.map(e=>t(`li`,{children:n(`button`,{type:`button`,className:`w-full text-start text-xs rounded px-1 py-0.5 hover:bg-muted cursor-pointer`,onClick:()=>{O(e.path),v(!1)},children:[t(`span`,{className:`text-muted-foreground`,children:e.path}),` `,t(`span`,{children:String(e.value??``)})]})},e.path))})]})]}),n(`div`,{className:`flex-1 overflow-auto p-3`,children:[t(tS,{value:r.data,path:``,citationsByPath:E,selectedPath:h,onSelect:O}),r.conflicts&&r.conflicts.length>0&&t(`div`,{className:`mt-4 text-xs text-attention`,children:l(`grounded.conflicts`,{count:r.conflicts.length})})]})]}),C&&n(e,{children:[t(he,{className:`w-[4px] bg-border cursor-ew-resize`}),t(ge,{defaultSize:30,minSize:20,className:`flex flex-col border-s border-border`,children:t(Kx,{objectId:a,onExtractionChanged:c,selectedField:h,onClose:()=>w(!1)})})]})]})}function eS({objectId:e,page:r,dims:i,citations:a,selectedPath:o,onSelectPath:s,imageMode:c}){let{t:l}=X(),{client:u}=Z(),[d,f]=Y(void 0);if(K(()=>{let t=!1;return f(void 0),u.files.getDownloadUrl(`${qx}/${e}/pages/page-${r}.${c}.jpg`).then(e=>{t||f(e.url)}).catch(e=>console.warn(`Failed to load page image`,e)),()=>{t=!0}},[u,c,e,r]),!d||!i)return t(`div`,{className:`flex items-center justify-center h-64`,children:t(Te,{})});let p=a.flatMap(e=>e.boxes.map((n,r)=>{let a=o!==void 0&&Jx(o)===Jx(e.path),c=e.cells?e.cells.start===e.cells.end?e.cells.start:`${e.cells.start}:${e.cells.end}`:void 0;return t(`button`,{type:`button`,"aria-label":e.path,title:`${e.path}${c?`\n${c}`:``}${e.source_text?`\n${e.source_text}`:``}`,onClick:()=>s(Jx(e.path)),className:H(`absolute cursor-pointer border rounded-[1px] transition-colors`,e.misaligned&&`border-dashed`,a?`border-2 border-destructive bg-destructive/20 z-10`:o?`border-info/30 hover:border-info`:e.verified?`border-success/70 hover:bg-success/20`:e.reviewed?`border-info/70 hover:bg-info/20`:`border-attention/80 hover:bg-attention/20`),style:{position:`absolute`,left:`${n.x/i.width*100}%`,top:`${n.y/i.height*100}%`,width:`${n.w/i.width*100}%`,height:`${n.h/i.height*100}%`}},`${e.path}-${r}`)})),m=((i.rotation??0)%360+360)%360;if(m!==0){let e=m===90||m===270;return n(`div`,{className:`relative w-full`,style:{aspectRatio:`${i.width} / ${i.height}`},children:[t(`img`,{src:d,alt:l(`grounded.pageAlt`,{page:r}),className:`absolute select-none`,style:{left:`50%`,top:`50%`,width:`${(e?i.height/i.width:1)*100}%`,height:`${(e?i.width/i.height:1)*100}%`,maxWidth:`none`,transform:`translate(-50%, -50%) rotate(${m}deg)`,transformOrigin:`center center`}}),p]})}return n(`div`,{className:`relative w-full`,children:[t(`img`,{src:d,alt:l(`grounded.pageAlt`,{page:r}),className:`w-full select-none`}),p]})}function tS({value:e,path:r,citationsByPath:i,selectedPath:a,onSelect:o}){return Array.isArray(e)?e.length>0&&e.every(e=>typeof e==`object`&&!!e)?t(nS,{items:e,path:r,citationsByPath:i,selectedPath:a,onSelect:o}):t(`div`,{className:`space-y-1`,children:e.map((e,n)=>t(tS,{value:e,path:`${r}[${n}]`,citationsByPath:i,selectedPath:a,onSelect:o},`${r}[${n}]`))}):typeof e==`object`&&e?t(`div`,{className:r?`ps-3 border-s border-border space-y-0.5`:`space-y-0.5`,children:Object.entries(e).map(([e,s])=>{let c=r?`${r}.${e}`:e;return typeof s!=`object`||!s?t(rS,{label:e,value:s,path:c,citationsByPath:i,selectedPath:a,onSelect:o},c):n(`div`,{className:`pt-1`,children:[!(Array.isArray(s)&&s.length>0&&s.every(e=>typeof e==`object`&&!!e))&&t(`div`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:e}),t(tS,{value:s,path:c,citationsByPath:i,selectedPath:a,onSelect:o})]},c)})}):null}function nS({items:e,path:r,citationsByPath:i,selectedPath:a,onSelect:o}){let{t:s}=X(),c=q(()=>{let t=new Set;for(let n of e)for(let e of Object.keys(n))t.add(e);return Array.from(t)},[e]);return n(`div`,{className:`pt-1`,children:[n(`div`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:[r.split(`.`).pop(),` (`,e.length,`)`]}),t(`div`,{className:`overflow-x-auto`,children:n(`table`,{className:`w-full text-xs`,children:[t(`thead`,{children:t(`tr`,{className:`text-start text-muted-foreground`,children:c.map(e=>t(`th`,{scope:`col`,className:`py-1 pe-2 font-medium`,children:e},e))})}),t(`tbody`,{children:e.map((e,l)=>t(`tr`,{className:`border-t border-border/50`,children:c.map(c=>{let u=`${r}[${l}].${c}`,d=i.get(u)?.[0];return t(`td`,{className:`py-0.5 pe-2`,children:n(`button`,{type:`button`,onClick:()=>o(u),className:H(`text-start rounded px-1 w-full`,a===u?`bg-destructive/15 ring-1 ring-destructive`:d?`hover:bg-muted cursor-pointer`:`text-muted-foreground cursor-default`),children:[oS(e[c]),d&&typeof d.confidence==`number`&&t(`span`,{className:H(`ms-1 text-[10px]`,aS(d.confidence)),title:s(`grounded.confidenceHint`),children:iS(d.confidence)})]})},c)})},`${r}[${l}]`))})]})})]})}function rS({label:e,value:r,path:i,citationsByPath:a,selectedPath:o,onSelect:s}){let{t:c}=X(),l=a.get(i)?.[0];return n(`button`,{type:`button`,onClick:()=>l&&s(i),className:H(`flex items-center gap-2 w-full text-start text-sm rounded px-1.5 py-0.5`,o===i?`bg-destructive/15 ring-1 ring-destructive`:l?`hover:bg-muted`:``,!l&&`cursor-default`),children:[t(`span`,{className:`text-muted-foreground min-w-28 shrink-0`,children:e}),t(`span`,{className:`flex-1 wrap-break-word`,children:oS(r)}),l&&typeof l.confidence==`number`&&t(`span`,{className:H(`text-xs shrink-0`,aS(l.confidence)),title:c(`grounded.confidenceHint`),children:iS(l.confidence)}),l&&(l.verified?t(tn,{"aria-label":c(`grounded.verified`),className:`size-3.5 shrink-0 text-success`}):l.reviewed?t(Kr,{"aria-label":c(`grounded.aiVerified`),className:`size-3.5 shrink-0 text-info`}):t(jn,{"aria-label":c(`grounded.readFromImage`),className:`size-3.5 shrink-0 text-attention`}))]})}function iS(e){let t=e*100;return Number.isInteger(t)?`${t}%`:`${(Math.floor(t*100)/100).toFixed(2)}%`}function aS(e){return e>=.95?`text-success`:e>=.7?`text-attention`:`text-destructive`}function oS(e){return e==null||e===``?`—`:typeof e==`boolean`?e?`true`:`false`:typeof e==`object`?JSON.stringify(e):String(e)}const sS=`magic-pdf`;var cS;(function(e){e.original=`original`,e.instrumented=`instrumented`})(cS||={});var lS=class{client;objectId;totalPages;cache=new Map;pending=new Map;constructor(e,t,n){this.client=e,this.objectId=t,this.totalPages=n}getCacheKey(e,t){return`${t}-${e}`}async getPageImageUrl(e,t){let n=this.getCacheKey(e,t),r=this.cache.get(n);if(r)return r;let i=this.pending.get(n);if(i)return i;let a=this.fetchImageUrl(e,t);this.pending.set(n,a);try{let e=await a;return this.cache.set(n,e),e}finally{this.pending.delete(n)}}async fetchImageUrl(e,t){let n=this.getImagePath(e,t);return(await this.client.files.getDownloadUrl(n)).url}getImagePath(e,t){let n=`${sS}/${this.objectId}/pages`;switch(t){case cS.original:return`${n}/page-${e}.original.jpg`;case cS.instrumented:return`${n}/page-${e}.instrumented.jpg`}}},uS=class{client;objectId;totalPages;cache=new Map;pending=new Map;constructor(e,t,n){this.client=e,this.objectId=t,this.totalPages=n}async getPageLayout(e){let t=this.cache.get(e);if(t!==void 0)return t;let n=this.pending.get(e);if(n)return n;let r=this.fetchPageLayout(e);this.pending.set(e,r);try{let t=await r;return this.cache.set(e,t),t}finally{this.pending.delete(e)}}async fetchPageLayout(e){let t=`${sS}/${this.objectId}/pages/page-${e}.layout.json`,n=await this.client.files.getDownloadUrl(t),r=await fetch(n.url,{method:`GET`});if(!r.ok)throw Error(`Failed to fetch json layout: ${r.statusText}`);return r.text()}},dS=class{totalPages;pages=[];constructor(e){this.totalPages=e}initFromContent(e){this.pages=fS(e,this.totalPages)}async loadUrls(e,t){}async getPageMarkdown(e){let t=e-1;return t<0||t>=this.pages.length?``:this.pages[t]}};function fS(e,t){let n=Array(t).fill(``),r=/<!--\s*\{\s*"page"\s*:\s*(\d+)\s*\}\s*-->/g,i=[];for(let t of e.matchAll(r))i.push({page:parseInt(t[1],10),index:t.index+t[0].length});for(let r=0;r<i.length;r++){let a=i[r],o=a.page-1;if(o<0||o>=t)continue;let s=a.index,c=e.slice(s).match(/<!--\s*\{\s*"page"\s*:\s*\d+\s*\}\s*-->/),l=c&&c.index!==void 0?s+c.index:e.length,u=e.slice(s,l).trim();u=u.replace(/\n---\s*$/,``).trim(),n[o]=u}return n}const pS=nt(void 0);function mS({children:e,object:n}){let{client:r}=Z(),i=n.metadata.page_count||10,[a,o]=Y(()=>{let e=new dS(i);return n.text&&e.initFromContent(n.text),{count:i,layoutProvider:new uS(r,n.id,i),markdownProvider:e,imageProvider:new lS(r,n.id,i),pdfUrl:``,pdfUrlLoading:!0}});return K(()=>{let e=n.metadata?.renditions?.find(e=>e.name===Ei),t=n.content?.type===`application/pdf`,i=e?.content?.source||(t?n.content?.source:void 0);i?r.store.objects.getDownloadUrl(i,void 0,`inline`).then(e=>{o(t=>({...t,pdfUrl:e.url,pdfUrlLoading:!1}))}).catch(e=>{console.warn(`Failed to get PDF URL:`,e),o(e=>({...e,pdfUrlLoading:!1}))}):o(e=>({...e,pdfUrlLoading:!1}))},[r,n.metadata,n.content?.type,n.content?.source]),t(pS.Provider,{value:a,children:e})}function hS(e,t,n){return e.files.getDownloadUrl(`${sS}/${t}/${n}`).then(e=>e.url)}function gS(){let e=W.useContext(pS);if(!e)throw Error(`useMagicPdfContext must be used within a MagicPdfProvider`);return e}function _S({object:e}){let{t:n}=X(),{client:r}=Z(),i=t=>{hS(r,e.id,t).then(e=>window.open(e,`_blank`))};return t(o,{variant:`ghost`,size:`xs`,onClick:()=>i(`document.md`),title:n(`pdf.download`),children:t(Tn,{className:`size-4`})})}function vS({className:e}){return t(`div`,{className:`flex items-center justify-center ${e||``}`,children:t(sr,{className:`w-6 h-6 animate-spin text-gray-400`})})}function yS({viewType:e,pageNumber:n}){switch(e){case`json`:return t(bS,{pageNumber:n});case`markdown`:return t(xS,{pageNumber:n});default:return t(xS,{pageNumber:n})}}function bS({pageNumber:e}){let[n,r]=Y(null),[i,a]=Y(!0),[o,s]=Y(null),{layoutProvider:c}=gS();return K(()=>{a(!0),s(null),c.getPageLayout(e).then(e=>{r(e?JSON.parse(e):null),a(!1)}).catch(e=>{console.error(e),s(e.message||`Failed to load layout`),a(!1)})},[e,c]),i?t(`div`,{className:`px-4 py-8`,children:t(vS,{})}):o?t(`div`,{className:`px-4 py-2 text-red-500 text-sm`,children:o}):n?t(_t,{className:`w-full`,data:n}):null}function xS({pageNumber:e}){let[r,i]=Y(null),[a,o]=Y(!0),[s,c]=Y(null),{markdownProvider:l}=gS();return K(()=>{o(!0),c(null),l.getPageMarkdown(e).then(e=>{i(e),o(!1)}).catch(e=>{console.error(e),c(e.message||`Failed to load markdown`),o(!1)})},[e,l]),a?n(`div`,{className:`h-full flex flex-col items-center justify-center gap-2`,children:[t(vS,{}),t(`span`,{className:`text-sm text-muted-foreground`,children:`Loading...`})]}):s?t(`div`,{className:`px-4 py-2 text-red-500 text-sm`,children:s}):t(`div`,{className:`px-4 py-2 prose prose-sm max-w-none dark:prose-invert`,children:r?t(bt,{children:r}):t(`div`,{children:`No markdown content available`})})}var SS=class extends tt{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`PDF View error:`,e,t)}render(){return this.state.hasError?t(`div`,{className:`fixed inset-0 bg-background z-50 flex items-center justify-center`,children:n(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md`,children:[t(M,{title:It.t(`pdf.failedToLoadViewer`,{ns:Ft}),children:this.state.error?.message||`An unexpected error occurred`}),this.props.onClose&&t(o,{variant:`outline`,onClick:this.props.onClose,children:`Close`})]})}):this.props.children}};function CS({objectId:e,onClose:r}){let{t:i}=X(),{client:a}=Z(),{data:s,error:c}=Ue(()=>a.store.objects.retrieve(e,`+text`),[e]);return c?t(`div`,{className:`fixed inset-0 bg-background z-50 flex items-center justify-center`,children:n(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md`,children:[t(M,{title:i(`pdf.fetchingDocumentFailed`),children:ze(c)}),r&&t(o,{variant:`outline`,onClick:r,children:`Close`})]})}):s?t(SS,{onClose:r,children:t(`div`,{className:`fixed inset-0 bg-background z-50 flex items-center justify-center`,children:t(mS,{object:s,children:t(wS,{object:s,onClose:r})})})}):n(`div`,{className:`fixed inset-0 bg-background z-50 flex flex-col`,children:[t(`div`,{className:`flex h-9 items-center justify-end shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:r&&t(o,{variant:`ghost`,size:`xs`,onClick:r,title:i(`pdf.close`),children:t(ci,{className:`size-4`})})}),t(`div`,{className:`flex-1 flex items-center justify-center`,children:t(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary`})})]})}function wS({object:e,onClose:r}){let{t:i}=X(),{count:a,pdfUrl:s,pdfUrlLoading:c}=gS(),[l,u]=Y(1);return n(_e,{direction:`horizontal`,className:`absolute inset-0`,children:[t(ge,{defaultSize:50,minSize:20,maxSize:80,className:`bg-muted`,children:t(Zb,{pdfUrl:s,pdfUrlLoading:c,pageCount:a,className:`h-full`,currentPage:l,onChange:u})}),t(he,{className:`w-[4px] bg-border cursor-ew-resize`}),n(ge,{defaultSize:50,minSize:20,className:`flex flex-col`,children:[n(`div`,{className:`flex h-9 items-center justify-between shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:[t(`div`,{className:`flex items-center gap-x-2`,children:t(_S,{object:e})}),t(`span`,{className:`text-xs text-muted-foreground`,children:i(`pdf.pageOf`,{pageNumber:l,totalPages:a})}),t(`div`,{className:`flex items-center gap-x-2`,children:!!r&&t(o,{variant:`ghost`,size:`xs`,onClick:r,title:i(`pdf.close`),children:t(ci,{className:`size-4`})})})]}),t(`div`,{className:`flex-1 overflow-auto px-2`,children:t(yS,{pageNumber:l,viewType:`markdown`})})]})]})}const TS=[`image/jpeg`,`image/jpg`,`image/png`,`image/gif`,`image/webp`,`image/svg+xml`],ES=[`video/mp4`,`video/webm`],DS=[`audio/mp4`,`audio/m4a`,`audio/x-m4a`,`audio/mpeg`,`audio/ogg`,`audio/wav`,`audio/webm`];function OS(e){let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=Math.floor(e%60);return t>0?`${t}:${n.toString().padStart(2,`0`)}:${r.toString().padStart(2,`0`)}`:`${n}:${r.toString().padStart(2,`0`)}`}function kS({url:e,source:r,object:i,className:a}){let{t:o}=X(),{client:s}=Z(),[c,l]=Y(e),[u,d]=Y(!e&&(!!r||!!i)),f=i?.metadata,p=(f?.renditions||[]).find(e=>e.name===_i),m=i?.content?.type&&DS.includes(i.content.type),h=!!i&&i.metadata?.type===yi.Audio&&!p&&!m;return K(()=>{if(e){l(e),d(!1);return}l(void 0),r||i?(d(!0),(async()=>{try{if(r){let e=await s.files.getDownloadUrl(r);l(e.url);return}if(!i||i.metadata?.type!==yi.Audio)return;let e;p?.content?.source?e=await s.files.getDownloadUrl(p.content.source):m&&i.content?.source&&(e=await s.files.getDownloadUrl(i.content.source)),e&&l(e.url)}catch(e){console.error(`Failed to get audio URL`,e)}finally{d(!1)}})()):d(!1)},[e,r,i,p,m,s]),h?t(`div`,{className:`flex justify-center items-center h-[200px] text-muted ${a??``}`.trim(),children:n(`div`,{className:`text-center`,children:[t(`p`,{children:o(`store.noAudioRendition`)}),t(`p`,{className:`text-sm mt-2`,children:o(`store.audioFormatRequired`)})]})}):u?t(`div`,{className:`flex justify-center items-center h-[200px] ${a??``}`.trim(),children:t(Te,{size:`md`})}):c?n(`div`,{className:`flex flex-col items-center gap-4 ${a??``}`.trim(),children:[t(`audio`,{src:c,controls:!0,className:`w-full max-w-2xl`,children:`Your browser does not support the audio tag.`}),f?.duration&&n(`div`,{className:`text-sm text-muted`,children:[`Duration: `,OS(f.duration)]})]}):t(`div`,{className:`flex justify-center items-center h-[200px] text-muted ${a??``}`.trim(),children:`Failed to load audio`})}function AS({url:e,source:n,object:r,className:i}){let{client:a}=Z(),[o,s]=Y(e),[c,l]=Y(!e&&(!!n||!!r));return K(()=>{if(e){s(e),l(!1);return}s(void 0),n||r?(l(!0),(async()=>{try{if(n){let e=await a.files.getDownloadUrl(n);s(e.url);return}if(!r||r.metadata?.type!==yi.Image)return;let e=r.content?.type&&TS.includes(r.content.type);try{let e=await a.objects.getRendition(r.id,{format:Ci.jpeg,generate_if_missing:!1,sign_url:!0});if(e.status===`found`&&e.renditions?.length){s(e.renditions[0]);return}}catch{}if(e&&r.content?.source){let e=await a.files.getDownloadUrl(r.content.source);s(e.url)}}finally{l(!1)}})()):l(!1)},[e,n,r,a]),c?t(`div`,{className:i,children:t(Te,{size:`md`})}):o?t(`img`,{src:o,alt:r?.name,className:`w-full object-contain ${i??``}`.trim()}):null}function jS({url:e,source:r,object:i,className:a}){let{t:o}=X(),{client:s}=Z(),[c,l]=Y(e),[u,d]=Y(),[f,p]=Y(!e&&(!!r||!!i)),m=i?.metadata?.renditions||[],h=m.find(e=>e.content.type===`video/mp4`)||m.find(e=>e.content.type===`video/webm`),g=i?.content?.type&&ES.includes(i.content.type),_=m.find(e=>e.name===Di),v=!!i&&i.metadata?.type===yi.Video&&!h&&!g;return K(()=>{if(e){l(e),p(!1);return}l(void 0),d(void 0),r||i?(p(!0),(async()=>{try{if(r){let e=await s.files.getDownloadUrl(r);l(e.url);return}if(!i||i.metadata?.type!==yi.Video)return;let e;h?.content?.source?e=await s.files.getDownloadUrl(h.content.source):g&&i.content?.source&&(e=await s.files.getDownloadUrl(i.content.source)),e&&l(e.url)}catch(e){console.error(`Failed to get video URL`,e)}finally{p(!1)}})()):p(!1)},[e,r,i,h,g,s]),K(()=>{_?.content?.source&&s.files.getDownloadUrl(_.content.source).then(e=>d(e.url)).catch(e=>console.error(`Failed to load poster image`,e))},[_,s]),v?t(`div`,{className:`flex justify-center items-center h-[400px] text-muted ${a??``}`.trim(),children:n(`div`,{className:`text-center`,children:[t(`p`,{children:o(`store.noVideoRendition`)}),t(`p`,{className:`text-sm mt-2`,children:o(`store.videoFormatRequired`)})]})}):f?t(`div`,{className:`flex justify-center items-center h-[400px] ${a??``}`.trim(),children:t(Te,{size:`md`})}):c?t(`video`,{src:c,poster:u,controls:!0,className:`w-full h-full object-contain ${a??``}`.trim(),children:`Your browser does not support the video tag.`}):t(`div`,{className:`flex justify-center items-center h-[400px] text-muted ${a??``}`.trim(),children:`Failed to load video`})}function MS({oauthProviderId:r,onAuthChange:i}){let{client:a}=Z(),{t:o}=X(),[s,c]=Y(null),[l,u]=Y(!0),[d,f]=Y(!1),[p,m]=Y(!1),h=G(async()=>{try{u(!0);let e=await a.oauthProviders.getStatus(r);c(e)}catch(e){console.error(`Failed to load OAuth provider status:`,e)}finally{u(!1)}},[a,r]);K(()=>{h()},[h]);let{openOAuthPopup:g}=lc({onComplete:()=>{f(!1),h(),i?.()},onError:e=>{console.error(`OAuth provider auth failed:`,e),f(!1)}});return l?t(sc,{className:`size-4`}):s?.authenticated?n(`div`,{className:`flex items-center gap-2`,children:[n(`div`,{className:`flex items-center gap-1 text-success text-sm`,children:[t(tn,{className:`size-4`}),t(`span`,{children:o(`oauthProvider.connected`)})]}),t(Wo,{variant:`outline`,size:`sm`,onClick:async()=>{if(!p)try{m(!0),await a.oauthProviders.disconnect(r),await h(),i?.()}catch(e){console.error(`Failed to disconnect OAuth provider:`,e)}finally{m(!1)}},disabled:p,children:p?t(sc,{className:`size-3`}):o(`oauthProvider.disconnect`)})]}):t(Wo,{variant:`outline`,size:`sm`,onClick:async()=>{if(!d)try{f(!0);let e=await a.oauthProviders.authorize(r);e.authorization_url&&g(e.authorization_url)}catch(e){console.error(`Failed to authorize OAuth provider:`,e),f(!1)}},disabled:d,children:d?n(e,{children:[t(sc,{className:`size-4`}),t(`span`,{children:o(`oauthProvider.authenticating`)})]}):n(e,{children:[t(kn,{className:`size-4 me-1`}),t(`span`,{children:o(`oauthProvider.authenticate`)})]})})}function NS(...e){let t=Array.from(e);return t.__AnyOf__=!0,t}function PS(...e){return Array.from(e)}function FS(e){return e.__AnyOf__===!0}var IS=class{system_roles;roles;permissions;constructor(e,t=[]){this.system_roles=t;let n=[...e.account_roles||[],...e.project_roles||[]],r=new Set(n);this.roles=r;let i=e.permissions??LS(n,t),a=e.type===ki.OAuthAccess?new Set(e.permissions??[]):void 0;this.permissions=new Set(a?i.filter(e=>a.has(e)):i)}hasPermission(e){if(typeof e==`string`)return this.permissions.has(e);if(FS(e))return e.some(e=>this.permissions.has(e));for(let t of e)if(!this.permissions.has(t))return!1;return!0}};function LS(e,t){let n=new Map(t.map(e=>[e.name,e.permissions])),r=new Set;for(let t of e)for(let e of n.get(t)??[])r.add(e);return Array.from(r)}const RS=nt(void 0);function zS(){let e=at(RS);if(!e)throw Error(`UserPermissionContext cannot be used outside UserPermissionProvider`);return e}function BS({children:e}){let{t:n}=X(),r=Z(),i=r.authToken,a=!!(i&&!i.permissions),{data:o,error:s,isLoading:c}=Ue(()=>a?r.client.iam.roles.listSystem():Promise.resolve(void 0),[r.client,i,a]),l=q(()=>{if(i){if(i.permissions||!a)return new IS(i);if(o&&!c)return new IS(i,o)}else return},[i,o,c,a]);return s?t(M,{title:n(`store.failedToFetchRoleMappings`),children:ze(s)}):l&&t(RS.Provider,{value:l,children:e})}function VS({permission:e,isDisabled:n,title:r,children:i,...a}){return zS().hasPermission(e)?t(o,{isDisabled:n,title:r,...a,children:i}):null}function HS({permission:e,...n}){return zS().hasPermission(e)?t(ka,{...n}):null}const US=new WeakMap;function WS(e,t){let n=US.get(e);n||(n=new Map,US.set(e,n));let r=n.get(t);return r||(r=e.types.catalog.resolve(t).then(e=>e??void 0,()=>{US.get(e)?.delete(t)}),n.set(t,r)),r}function GS(e,t){let n=US.get(e);n&&(t?n.delete(t):n.clear())}function KS(e){let t=e.configuration?.defaults?.system?.agent??e.configuration?.defaults?.base;return{environment:t?.environment,model:t?.model}}function qS(e){return e.name}function JS(e){return e.name}function YS(e){return e.split(`/`).filter(Boolean).pop()||e}function XS({value:e,onChange:r,disabled:i=!1,isLoading:a=!1}){let{client:s}=Z(),{t:c}=X(),[l,u]=Y([]),[d,f]=Y([]),[p,m]=Y(!0),[h,g]=Y(!1),_=J(void 0);K(()=>{let e=!1;return m(!0),s.environments.list().then(t=>{e||u(t.slice().sort((e,t)=>e.name.localeCompare(t.name)))}).catch(t=>{console.warn(`Failed to list document editing environments`,t),e||u([])}).finally(()=>{e||m(!1)}),()=>{e=!0}},[s]),K(()=>{if(!e.environment){f([]),g(!1);return}let t=!1,n=e.environment;return g(!0),s.environments.retrieve(n).then(e=>{t||f((e.enabled_models??[]).map(e=>({id:e.id,name:e.name||e.id})).sort((e,t)=>e.name.localeCompare(t.name)))}).catch(e=>{console.warn(`Failed to load document editing models`,e),t||f([])}).finally(()=>{t||g(!1)}),()=>{t=!0}},[s,e.environment]);let v=l.find(t=>t.id===e.environment),y=q(()=>{if(e.model)return d.find(t=>t.id===e.model)??{id:e.model,name:YS(e.model)}},[d,e.model]),b=e=>{_.current=e.id,r({environment:e.id}),s.environments.retrieve(e.id).then(t=>{if(_.current!==e.id)return;let n=t.default_model??t.enabled_models?.[0]?.id;r({environment:e.id,model:n})}).catch(e=>{console.warn(`Failed to select a default document editing model`,e)})},x=t=>{_.current=void 0,r({environment:e.environment,model:t.id})},S=y?.name||c(`agent.documentEditingSelectModel`);return n(le,{children:[t(de,{asChild:!0,children:n(o,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 max-w-[15rem] gap-1.5 px-2 text-xs`,"aria-label":c(`agent.documentEditingConfiguration`),title:c(`agent.documentEditingConfiguration`),children:[a?t(Te,{size:`sm`}):t(Gr,{className:`size-3.5 shrink-0`}),t(`span`,{className:`min-w-0 truncate`,children:S}),t(an,{className:`size-3.5 shrink-0 opacity-70`})]})}),n(ue,{align:`end`,className:`z-[1000000] w-80 space-y-3 p-3`,children:[n(`div`,{children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:c(`agent.documentEditingConfiguration`)}),t(`div`,{className:`mt-0.5 text-xs leading-4 text-muted`,children:c(i?`agent.documentEditingConfigurationLocked`:`agent.documentEditingConfigurationDescription`)})]}),n(`div`,{className:`space-y-1`,children:[t(`label`,{className:`text-xs font-medium text-foreground`,htmlFor:`document-editing-environment`,children:c(`agent.environment`)}),t(ve,{id:`document-editing-environment`,by:`id`,options:l,value:v,optionLabel:qS,filterBy:`name`,placeholder:c(`agent.documentEditingSelectEnvironment`),onChange:b,disabled:i,isLoading:p})]}),n(`div`,{className:`space-y-1`,children:[t(`label`,{className:`text-xs font-medium text-foreground`,htmlFor:`document-editing-model`,children:c(`agent.model`)}),t(ve,{id:`document-editing-model`,by:`id`,options:d,value:y,optionLabel:JS,filterBy:`name`,placeholder:c(`agent.documentEditingSelectModel`),onChange:x,disabled:i||!e.environment,isLoading:h,warnOnMissingValue:!1})]})]})]})}function ZS({isLocked:e,onToggleLock:r}){let{t:i}=X(),a=i(e?`agent.editingLockedTitle`:`agent.editingManuallyUnlockedTitle`),s=i(e?`agent.editingLockedDescription`:`agent.editingManuallyUnlockedDescription`),c=i(e?`agent.unlockEditing`:`agent.lockEditing`);return n(`div`,{className:`flex h-8 max-w-64 shrink-0 items-center gap-1 rounded-md border border-mixer-attention/30 bg-mixer-attention/10 ps-2 pe-1 text-attention`,role:e?`status`:`alert`,"aria-live":`polite`,children:[e?t(lr,{className:`size-3.5 shrink-0 animate-pulse`}):t(ur,{className:`size-3.5 shrink-0`}),t(Re,{description:s,asChild:!0,children:t(`span`,{className:`min-w-0 truncate text-xs font-medium text-foreground`,children:a})}),t(`span`,{className:`sr-only`,children:s}),t(Re,{description:c,asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,className:`size-6 shrink-0 rounded p-0 text-attention hover:bg-mixer-attention/15`,onClick:r,"aria-label":c,children:t(e?ur:lr,{className:`size-3.5`})})})]})}const QS=/artifact:(?!agents\/)(?!documents\/)([^\s)\]"]+)/g;function $S(e){let t=new Set;for(let n of e.matchAll(QS))t.add(n[1].replace(/^\/+/,``));return[...t]}async function eC(e,t,n,r){let i=$S(t);if(i.length===0)return{content:t,persisted:[],failed:[]};let a=new Map,o=[],s=[];for(let t of i){let i=`documents/${r}/${t}`;try{await e.copyFile(`agents/${n}/${t}`,i),a.set(t,i),o.push({from:t,to:i})}catch(e){console.warn(`Failed to persist a referenced artifact; keeping a run-scoped link`,{artifact_path:t,error:e instanceof Error?e.message:String(e)}),a.set(t,`agents/${n}/${t}`),s.push(t)}}return{content:t.replace(QS,(e,t)=>{let n=a.get(t.replace(/^\/+/,``));return n?`artifact:${n}`:e}),persisted:o,failed:s}}const tC=[`ask_user`,`think`,`plan`,`update_plan`,`end_conversation`,`learn_artifact_operations`,`learn_code_execution`,`learn_content_authoring`,`learn_document_management`,`learn_document_search`,`learn_image_analysis`,`execute_shell`,`fetch_document`],nC=[`artifact_operations`,`code_execution`],rC=[`update_document`,`update_document_properties`,`create_document`,`set_document_type`,`merge_documents`,`import_file`,`create_or_update_object_type`,`disable_type`,`batch_execute`];function iC(e,t){return[`Direct edits are already saved to '${e}'. Use this compact unified diff as context only;`,`do not re-apply it. The artifact remains the current source of truth.`,"```diff",`--- a/${e}`,`+++ b/${e}`,t,"```"].join(`
|
|
445
|
-
`)}const
|
|
446
|
-
`)}function
|
|
447
|
-
`)}function
|
|
448
|
-
`)}function NC(e){if(!(!e||typeof e!=`object`||!(`status`in e)))return typeof e.status==`number`?e.status:void 0}function PC({original:e,workingCopy:r}){let i=q(()=>Dt(e,r),[e,r]),a=q(()=>({added:i.reduce((e,t)=>e+(t.type===`added`?t.text.length:0),0),removed:i.reduce((e,t)=>e+(t.type===`removed`?t.text.length:0),0)}),[i]);return n(`div`,{className:`flex h-full min-h-0 flex-col bg-muted/10`,children:[n(`div`,{className:`flex shrink-0 items-center justify-end gap-3 border-b border-mixer-muted/20 px-5 py-2 text-xs`,children:[n(`span`,{className:`text-destructive`,children:[`−`,a.removed]}),n(`span`,{className:`text-success`,children:[`+`,a.added]})]}),t(`div`,{className:`min-h-0 flex-1 overflow-auto p-5`,children:t(`pre`,{className:`mx-auto max-w-5xl whitespace-pre-wrap break-words rounded-lg border border-mixer-muted/25 bg-background p-5 font-mono text-xs leading-6 shadow-sm`,children:i.map((e,n)=>e.type===`removed`?t(`del`,{className:`bg-mixer-destructive/15 text-destructive line-through decoration-destructive/50`,children:e.text},n):e.type===`added`?t(`ins`,{className:`bg-mixer-success/15 text-success no-underline`,children:e.text},n):t(`span`,{children:e.text},n))})})]})}function FC({object:r,initialContent:i=``,onDocumentUpdated:a,onClose:s,sendMessageRef:c,model:l,startImmediately:u=!1}){let{client:d,project:f,store:m,user:h}=Z(),{t:g}=X(),_=Ye(),v=J(null),y=c??v,[x,S]=Y(),[C,w]=Y(!1),[T,E]=Y(!1),[D,O]=Y(!0),[k,A]=Y(!0),[j,M]=Y(!1),[N,P]=Y(0),[F,I]=Y(!1),L=JSON.stringify(l?{environment:l.env,model:l.model,model_options:l.options}:{}),ee=l!==void 0,R=q(()=>JSON.parse(L),[L]),[te,z]=Y(!ee),[ne,B]=Y(!1),[re,ie]=Y(!1),[ae,oe]=Y(!1),[se,ce]=Y(!1),[V,le]=Y(!1),[ue,de]=Y(!1),[fe,pe]=Y({key:0}),[me,ve]=Y(i),[ye,be]=Y(!1),[xe,Se]=Y(i),[Ce,we]=Y(i),[Ee,De]=Y(`document`),[Oe,ke]=Y(),[Ae,je]=Y(r.id),[Me,Ne]=Y(r.content?.etag),[Pe,Fe]=Y(),[Ie,Le]=Y(R),H=J(ee?`host`:`none`),Be=J(void 0),Ve=J(new Set),He=J(void 0),Ue=J(!1),We=J(null),Ge=r.revision?.root||r.id,Ke=q(()=>kC(Ge),[Ge]),qe=h?.sub?`user:${h.sub}`:void 0,Je=`${f?.id??`no-project`}:${Ge}`,Xe=`${Je}:${r.type?.id??`no-type`}`,Ze=Pe?.key===Xe?Pe.interaction:void 0,Qe=J(Je),$e=J({editingScopeKey:Je,id:r.id}),et=J({documentId:r.id,documentRootId:Ge}),U=ye&&me!==Ce,W=se&&!V;et.current.documentRootId!==Ge&&(et.current={documentId:r.id,documentRootId:Ge}),$e.current.editingScopeKey!==Je&&($e.current={editingScopeKey:Je,id:r.id}),K(()=>{Qe.current!==Je&&(Qe.current=Je,H.current=ee?`host`:`none`,Le(R),z(!ee),Ve.current.clear(),ve(i),Se(i),we(i),be(!1),de(!1),ce(!1),le(!1),Ue.current=!1,De(`document`),je(r.id),Ne(r.content?.etag))},[Je,ee,i,r.content?.etag,r.id,R]),K(()=>{let e=!1,t=Je,n=$e.current.id;return A(!0),M(!1),TC(m.objects,n).then(n=>{e||$e.current.editingScopeKey!==t||($e.current={editingScopeKey:t,id:n.id},et.current={documentId:n.id,documentRootId:Ge},je(n.id),Ne(n.etag),Se(n.content),we(n.content))}).catch(n=>{console.warn(`Failed to resolve the document editing target`,{error:n,attempt:N}),!e&&$e.current.editingScopeKey===t&&M(!0)}).finally(()=>{!e&&$e.current.editingScopeKey===t&&A(!1)}),()=>{e=!0}},[Ge,Je,m.objects,N]),K(()=>{let e=!1,t=r.type?.id;if(!t){Fe({key:Xe,interaction:oC});return}return WS(d,t).then(t=>{e||Fe({key:Xe,interaction:t?.editing?.interaction?.trim()||`sys:GeneralAgent`})}),()=>{e=!0}},[d,Xe,r.type?.id]),K(()=>{x||H.current===`run`||(ee?(H.current=`host`,Le(R),z(!1)):H.current===`host`&&(H.current=`none`,Le({})))},[x,ee,R]),K(()=>{if(ee){z(!1);return}if(!f){z(!1);return}let e=!1,t=Je;return z(!0),d.projects.retrieve(f.id).then(n=>{e||Qe.current!==t||H.current!==`none`||(H.current=`project`,Le(KS(n)))}).catch(e=>{console.warn(`Failed to load the default document editing model`,e)}).finally(()=>{e||z(!1)}),()=>{e=!0}},[d,Je,ee,f]),K(()=>{if(S(void 0),!qe||!Ze){O(!1);return}let e=!1;return O(!0),CC(d.agents,et.current.documentId,Ge,qe,Ze).then(t=>{e||!t||(S(t.id),t.config?.environment&&t.config.model&&(H.current=`run`,Le({environment:t.config.environment,model:t.config.model,model_options:t.config.model_options})))}).catch(e=>{console.warn(`Failed to look up an existing document editing run`,e)}).finally(()=>{e||O(!1)}),()=>{e=!0}},[d,Ge,Ze,qe]);let tt=G(e=>{H.current=`user`,Le(e)},[]),nt=G(()=>{x&&navigator.clipboard.writeText(x).then(()=>_({status:`success`,title:g(`agent.runIdCopied`),duration:2e3})).catch(e=>console.warn(`Failed to copy the agent run id`,e))},[x,g,_]),rt=G(async()=>{if(!(!x||T)){E(!0);try{await d.agents.terminate(x,`cancel`),_({status:`success`,title:g(`agent.workflowCancelled`),duration:2e3})}catch(e){console.warn(`Failed to terminate the document editing run`,e)}finally{E(!1)}Ve.current.clear(),S(void 0),be(!1),ve(Ce),de(!1),Ue.current=!1,ce(!1),le(!1)}},[x,d.agents,T,Ce,g,_]),it=G(async(e,t)=>{if(!(!f||!Ze||D||k||j||C||te)){w(!0);try{if(!Ie.environment||!Ie.model){_({status:`error`,title:g(`agent.documentEditingDefaultsRequired`),duration:5e3});return}let n=AC(r,Ae,Me,Ke,e?.trim()||g(`agent.documentEditingInitialRequest`)),i=gC(Ae,Ge),a={interaction:Ze,interactive:!0,tool_approval_mode:t?.tool_approval_mode,tool_names:tC,excluded_tools:rC,initial_skills:nC,initial_tool_calls:[{id:`hydrate-working-copy`,tool:`fetch_document`,input:{id:Ae,mode:`content`,output_artifact:{path:Ke}}},{id:`read-working-copy`,tool:`read_artifact`,input:{path:Ke}}],data:{user_prompt:n},config:{environment:Ie.environment,model:Ie.model,model_options:Ie.model_options},started_by:qe,tags:i.tags,properties:i.properties},o=await d.agents.start(a);return S(o.id),{agent_run_id:o.id}}catch(e){console.error(`Failed to start document editing agent`,e),_({status:`error`,title:g(`agent.documentEditingStartFailed`),description:e instanceof Error?e.message:void 0,duration:5e3});return}finally{w(!1)}}},[d.agents,Ge,Ke,Ie,Ze,te,D,k,C,r,f,qe,g,Ae,Me,j,_]),at=G((e,t)=>{He.current=t,ve(e),be(!0)},[]);K(()=>{if(!u||x||!f||!Ze||D||k||j||C||te||!Ie.environment||!Ie.model)return;let e=JSON.stringify({scope:Je,interaction:Ze,document:Ae,configuration:Ie});Be.current!==e&&(Be.current=e,it(g(`agent.documentEditingStartRequest`),{tool_approval_mode:`full_control`}))},[x,Ze,Je,Ie,te,D,k,C,f,u,it,g,Ae,j]);let ot=G(e=>{let t=Ue.current;Ue.current=e,ce(e),e||(le(!1),t&&pe(e=>({key:e.key+1})))},[]),st=G((e,t)=>{let n=y.current;if(!n){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}n(e,t)},[y,g,_]),ct=G(e=>{let t=e.anchor.block_type.replaceAll(`_`,` `),n=e.comment?.trim()||g(`agent.editedSelectionMessage`,{blockType:t});st(n,{editing_action:e})},[st,g]),lt=G(async(e,t)=>{if(!(!ye||!Me||!U||W||ne||k||j)){B(!0);try{let n=me;x&&(n=(await eC(d.files,n,x,crypto.randomUUID())).content);let i=r.content?.type||`text/markdown`,o=r.content?.name||`content.md`,s=new File([new Blob([n],{type:i})],o,{type:i}),c=await m.objects.update(Ae,{content:s},{createRevision:e,revisionLabel:t,ifMatch:Me});if(je(c.id),Ne(c.content?.etag),we(n),ke(void 0),ie(!1),a?.(c.id,e),_({status:`success`,title:g(`store.textSaved`),duration:2500}),x&&n!==me&&He.current)try{await d.agents.updateArtifactContent(x,Ke,{content:n,generation:He.current}),pe(e=>({key:e.key+1}))}catch(e){console.warn(`Failed to sync persisted artifact links into the working copy`,e)}}catch(e){let t=NC(e),n=t===412;if(t===412||t===400)try{let e=await TC(m.objects,Ae);(e.id!==Ae||t===412)&&(n=!0,je(e.id),Ne(e.etag),ke({headId:e.id}))}catch(e){console.warn(`Failed to resolve the new head after a save conflict`,e)}_({status:`error`,title:g(`store.errorSavingText`),description:n?g(`store.textConflict`):ze(e,g(`store.errorSavingTextDefault`)),duration:5e3})}finally{B(!1)}}},[x,me,ye,d.agents,d.files,Ke,U,W,k,ne,r.content?.name,r.content?.type,a,m.objects,g,Ae,Me,j,_]),ut=G(()=>{let e=y.current;if(!e||!Oe){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}e(jC(Ge,Oe.headId,Ke)),ke(void 0),De(`document`)},[Ge,Ke,y,Oe,g,_]),ft=G(()=>{let e=y.current;if(!e){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}e(MC(Ge,$e.current.id,Ke))},[Ge,Ke,y,g,_]),pt=G(async()=>Ee!==`editor`||!ue||!!await We.current?.(),[ue,Ee]),mt=G(async e=>{e!==Ee&&await pt()&&De(e)},[pt,Ee]),ht=G(async()=>{await pt()&&s?.()},[pt,s]),gt=G(async()=>{let e=y.current;if(!e||!x||W||ae){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}oe(!0);try{let t=await We.current?.();if(!t)return;let n=Et(t.previous,t.current,{context:1});n&&e(iC(Ke,n)),de(!1),_({status:`success`,title:g(`agent.changesSentToAgent`),duration:2e3})}finally{oe(!1)}},[x,Ke,W,ae,y,g,_]);return n(`div`,{className:`flex h-full min-h-0 flex-col`,children:[n(`div`,{className:`flex h-14 shrink-0 items-center justify-between gap-3 border-b border-mixer-muted/20 px-4`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`truncate font-semibold`,children:r.name||r.content?.name}),n(`div`,{className:`flex items-center gap-2 text-xs text-muted`,children:[n(`span`,{className:`flex shrink-0 items-center gap-1.5`,children:[U?t(`span`,{"aria-hidden":!0,className:`size-1.5 rounded-full bg-attention`}):ye?t(Qt,{className:`size-3 text-success`}):null,g(U?`store.unsavedChanges`:`store.textSaved`)]}),t(`span`,{"aria-hidden":!0,className:`text-mixer-muted/60`,children:`·`}),t(Re,{description:`${g(`agent.workingCopy`)}: ${Ke}`,asChild:!0,children:n(`span`,{className:`min-w-0 truncate font-mono`,children:[`drafts/`,OC(Ge),`.md`]})}),t(`span`,{"aria-hidden":!0,className:`text-mixer-muted/60`,children:`·`}),t(Re,{description:`${g(`agent.originalDocument`)}: ${$e.current.id}`,asChild:!0,children:n(`span`,{className:`shrink-0 font-mono`,children:[g(`agent.originalDocument`).toLowerCase(),` `,OC($e.current.id)]})})]})]}),n(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[n(`div`,{className:`flex items-center rounded-md border border-mixer-muted/25 bg-muted/10 p-0.5`,children:[n(o,{variant:Ee===`document`?`secondary`:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:()=>void mt(`document`),children:[t(Ln,{className:`size-3.5`}),g(`agent.document`)]}),n(o,{variant:Ee===`editor`?`secondary`:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:()=>void mt(`editor`),children:[t(Fn,{className:`size-3.5`}),g(`agent.fullEditor`)]}),n(o,{variant:Ee===`diff`?`secondary`:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:()=>void mt(`diff`),disabled:!ye||me===xe,children:[t(Gn,{className:`size-3.5`}),g(`agent.reviewChanges`)]})]}),Ee===`diff`?n(o,{variant:`ghost`,size:`sm`,className:`h-8 gap-1.5`,onClick:ft,disabled:!ye||me===xe,children:[t(or,{className:`size-3.5`}),g(`agent.summarizeChanges`)]}):null,t(Re,{description:g(`agent.refresh`),asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,onClick:()=>pe(e=>({key:e.key+1})),disabled:!x,"aria-label":g(`agent.refresh`),children:t(Nr,{className:`size-4`})})}),t(`div`,{"aria-hidden":!0,className:`mx-1 h-6 w-px bg-mixer-muted/25`}),t(XS,{value:Ie,onChange:tt,disabled:!!x||C||D,isLoading:te}),x?null:n(o,{variant:`primary`,size:`sm`,className:`h-8 gap-1.5`,onClick:()=>void it(g(`agent.documentEditingStartRequest`)),disabled:C||D||k||te||j||!f||!Ze||!Ie.environment||!Ie.model,children:[C?t(Te,{size:`sm`}):t(Kr,{className:`size-4`}),g(C?`agent.startingAgent`:`agent.documentEditingStart`)]}),x?n(e,{children:[t(Re,{description:x,asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,className:`font-mono text-[11px] text-muted`,onClick:nt,"aria-label":g(`agent.copyRunId`),children:OC(x)})}),t(Re,{description:g(`agent.startNewConversation`),asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,onClick:()=>{U?I(!0):rt()},disabled:T,"aria-label":g(`agent.startNewConversation`),children:t(Fr,{className:`size-4`})})})]}):null,t(`div`,{"aria-hidden":!0,className:`mx-1 h-6 w-px bg-mixer-muted/25`}),n(o,{variant:`primary`,className:`min-w-36 gap-2`,onClick:()=>ie(!0),disabled:!U||!Me||W||ne||k||j,children:[ne?t(Te,{size:`sm`}):t(Rr,{className:`size-4`}),g(`agent.saveToDocument`)]}),s?t(o,{variant:`ghost`,size:`sm`,onClick:()=>void ht(),"aria-label":g(`agent.close`),children:t(ci,{className:`size-4`})}):null]})]}),Oe?n(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-b border-mixer-attention/30 bg-mixer-attention/10 px-4 py-2 text-sm`,children:[t(`span`,{className:`min-w-0 truncate text-attention`,children:g(`agent.saveConflictNotice`)}),n(`div`,{className:`flex shrink-0 items-center gap-2`,children:[t(o,{variant:`outline`,size:`sm`,onClick:ut,children:g(`agent.askAgentToReconcile`)}),t(o,{variant:`ghost`,size:`sm`,onClick:()=>ke(void 0),"aria-label":g(`agent.close`),children:t(ci,{className:`size-4`})})]})]}):null,n(_e,{direction:`horizontal`,className:`min-h-0 flex-1`,children:[t(ge,{defaultSize:65,minSize:35,className:`min-w-0 bg-background`,children:t(`div`,{className:`flex h-full min-h-0 flex-col`,children:t(`div`,{className:`min-h-0 flex-1`,children:Ee===`diff`?t(PC,{original:xe,workingCopy:me}):t(dt,{runId:x,path:Ke,viewMode:Ee===`editor`?`document`:`components`,baselineContent:xe,initialContent:Ce,refreshKey:fe.key,refreshDetails:fe.details,readOnly:W,allowComments:!!x,onContentChange:at,onAction:ct,onSendMessage:st,onSendChangesToAgent:gt,hasUnsentChanges:U&&ue,isSendingChanges:ae,sendChangesDisabled:!x||W,toolbarStatus:se?t(ZS,{isLocked:W,onToggleLock:()=>le(e=>!e)}):void 0,onDocumentEdit:()=>de(!0),flushChangesRef:We})})})}),t(he,{withHandle:!0}),t(ge,{defaultSize:35,minSize:25,className:`min-w-[320px]`,children:D||k?t(p,{className:`h-full`,children:t(Te,{size:`lg`})}):j?n(p,{className:`h-full flex-col gap-3 px-6 text-center`,children:[t(`div`,{className:`text-sm text-muted`,children:g(`agent.failedToLoadDocument`)}),t(o,{variant:`outline`,size:`sm`,onClick:()=>P(e=>e+1),children:g(`agent.retry`)})]}):t(Nb,{agentRunId:x,startWorkflow:it,resetWorkflow:()=>S(void 0),onRestart:e=>S(e.id),sendMessageRef:y,onMessage:e=>{let t=e.details;if(!kt(t,Ke))return;let n=`${e.timestamp}:${t?.path}:${t?.generation??``}`;Ve.current.has(n)||(Ve.current.add(n),pe(e=>({key:e.key+1,details:t})))},onAgentWorkingChange:ot,title:g(`agent.documentEditing`),initialMessage:g(`agent.documentEditingWelcome`),startButtonText:g(C?`agent.startingAgent`:`agent.startAgent`),placeholder:g(`agent.documentEditingPlaceholder`),initialToolApprovalMode:`full_control`,hideObjectLinking:!0,hideHeader:!0,showRightPanel:!1,fullWidth:!0,interactive:!0})})]}),t(b,{isOpen:F,title:g(`agent.newSessionDiscardTitle`),content:g(`agent.newSessionDiscardDescription`),onConfirm:()=>{I(!1),rt()},onCancel:()=>I(!1)}),t(DC,{isOpen:re,onClose:()=>ie(!1),onConfirm:lt,isLoading:ne})]})}function IC({object:e,initialContent:n,onClose:r,onDocumentUpdated:i,sendMessageRef:a,model:o,startImmediately:s}){let{t:c}=X();return t(ie,{isOpen:!0,onClose:r,size:`full`,noCloseButton:!0,disableCloseOnClickOutside:!0,className:`gap-0 overflow-hidden p-0`,description:c(`agent.documentEditingWelcome`),children:t(FC,{object:e,initialContent:n,onClose:r,onDocumentUpdated:i,sendMessageRef:a,model:o,startImmediately:s})})}function LC({isOpen:r,onClose:i,object:a,refetch:s}){let{client:c,store:l}=Z(),u=Ye(),{t:d}=X(),{theme:f}=Je(),p=_a(),[m,h]=Y(!1),[g,_]=Y(``),[v,y]=Y(!1),[b,x]=Y(null),S=J(void 0),[C,w]=Y(null),[T,E]=Y(null),D=G(async e=>{try{let t=await l.types.retrieve(e);t.object_schema&&w(t.object_schema)}catch(e){console.error(`Failed to fetch JSON schema:`,e)}},[l.types]);K(()=>{r&&(_(JSON.stringify(a.properties||{},null,2)),a.type?.id&&D(a.type.id))},[r,a,D]);let O=e=>{C&&e.json.jsonDefaults.setDiagnosticsOptions({validate:!0,schemas:[{uri:`http://myserver/object-schema.json`,fileMatch:[`*`],schema:C}]})};function k(){if(!S.current)return;let e=S.current.getValue();try{let t=JSON.parse(e);x(t),y(!0)}catch{u({status:`error`,title:d(`store.invalidJson`),description:d(`store.pleaseFixJsonSyntax`),duration:5e3})}}let A=e=>{_(e)};async function j(e,t){try{h(!0);let n=b||JSON.parse(g);if(e){let e=await c.objects.update(a.id,{properties:n},{createRevision:!0,revisionLabel:t});e.id!==a.id&&E(e.id),u({status:`success`,title:d(`store.newVersionCreated`),description:d(`store.newVersionCreatedDesc`),duration:2e3}),y(!1),i(),e.id!==a.id&&setTimeout(()=>{p(`/objects/${e.id}`),u({status:`info`,title:d(`store.viewingNewVersion`),description:t?d(`store.viewingVersionLabel`,{label:t}):d(`store.viewingNewVersionDefault`),duration:3e3})},100)}else await l.objects.update(a.id,{properties:n}),u({status:`success`,title:d(`store.propertiesUpdated`),description:d(`store.propertiesUpdatedDesc`),duration:2e3}),s&&await s(),y(!1),i()}catch(e){u({status:`error`,title:d(`store.errorUpdatingProperties`),description:ze(e,d(`store.errorUpdatingPropertiesDefault`)),duration:5e3}),h(!1)}}function M(){y(!1)}return n(e,{children:[n(ie,{isOpen:r,onClose:i,className:`sm:max-w-[90%] md:max-w-[80%] lg:max-w-[75%] xl:max-w-[70%]`,children:[t(se,{children:d(`store.editProperties`)}),n(ae,{children:[n(`div`,{className:`mb-2 text-sm text-gray-500`,children:[a.type?.name?n(`span`,{children:[`Editing properties for object type: `,t(`strong`,{children:a.type.name})]}):t(`span`,{children:d(`store.editingGenericDocument`)}),C!==null&&t(`span`,{className:`ms-2 text-green-600`,children:`(JSON schema validation enabled)`})]}),t(`div`,{className:`h-[75vh] border rounded-md overflow-hidden`,children:t(xt,{value:g,language:`json`,editorRef:S,onChange:e=>A(e.state.doc.toString()),beforeMount:O,theme:f===`dark`?`vs-dark`:`vs`})})]}),n(oe,{children:[t(o,{variant:`secondary`,onClick:i,children:`Cancel`}),t(o,{variant:`primary`,onClick:k,children:`Save Changes`})]})]}),t(DC,{isOpen:v,onClose:M,onConfirm:j,isLoading:m})]})}function RC(e){switch(e){case`text/markdown`:case`text/x-markdown`:return`markdown`;case`application/json`:return`json`;case`application/xml`:case`text/xml`:return`xml`;default:return`plaintext`}}function zC({object:r,text:i,onClose:a,onSaved:s}){let{store:c}=Z(),l=Ye(),{t:u}=X(),{theme:d}=Je(),f=_a(),p=J(void 0),[m,h]=Y(i),[g,_]=Y(!1),[v,y]=Y(!1),[b,x]=Y(!1),S=RC(r.content?.type),C=yC(r.content?.type);K(()=>{h(i),_(!1)},[i]);let w=G(()=>{g||_(!0)},[g]),T=G(e=>{h(e),_(e!==i)},[i]);function E(){!C&&!p.current||x(!0)}async function D(e,t){if(!C&&!p.current)return;let n=C?m:p.current?.getValue();if(n===void 0)return;let i=r.content?.type||`text/plain`,o=r.content?.name||`content.txt`;try{y(!0);let d=new Blob([n],{type:i}),p=new File([d],o,{type:i}),m=await c.objects.update(r.id,{content:p},{createRevision:e,revisionLabel:t,ifMatch:r.content?.etag});l({status:`success`,title:u(`store.textSaved`),duration:2e3}),x(!1),e&&m.id!==r.id?(a(),setTimeout(()=>{f(`/objects/${m.id}`)},100)):s()}catch(e){let t=ze(e,u(`store.errorSavingTextDefault`)),n=(typeof e==`object`&&e&&`status`in e?e.status:void 0)===412||t.includes(`412`);l({status:`error`,title:u(`store.errorSavingText`),description:n?u(`store.textConflict`):t,duration:5e3})}finally{y(!1)}}return n(e,{children:[n(`div`,{className:`flex items-center gap-2 px-2 py-1 shrink-0`,children:[g&&t(`span`,{className:`text-xs text-attention`,children:u(`store.unsavedChanges`)}),t(`div`,{className:`flex-1`}),t(o,{variant:`ghost`,size:`sm`,onClick:a,disabled:v,children:u(`store.cancelEdit`)}),t(o,{variant:`secondary`,size:`sm`,onClick:E,disabled:!g,isLoading:v,children:u(`store.saveText`)})]}),t(`div`,{className:`flex-1 min-h-0 border rounded-md overflow-hidden mx-2 mb-2`,children:C?t(Aa,{value:m,onChange:T}):t(xt,{value:i,language:S,editorRef:p,onChange:w,theme:d===`dark`?`vs-dark`:`vs`,options:{wordWrap:`on`,minimap:{enabled:!1},lineNumbers:`on`,scrollBeyondLastLine:!1}})}),t(DC,{isOpen:b,onClose:()=>x(!1),onConfirm:D,isLoading:v})]})}const BC=128*1024;function VC(e,t,n=!1,r=e){let{store:i}=Z(),[a,o]=Y(t),[s,c]=Y(()=>t&&t.length>BC?t.substring(0,BC):t),[l,u]=Y(!1),[d,f]=Y(()=>!!t&&t.length>BC),[p,m]=Y(),h=J(t),g=J(e),_=J(r),v=J(!1),y=G((e,t=!0)=>{let n=h.current;t&&n&&e&&n!==e?m(e=>({previousText:n,version:(e?.version??0)+1})):t||m(void 0),h.current=e,o(e),e&&e.length>BC?(c(e.substring(0,BC)),f(!0)):(c(e),f(!1))},[]),b=G(()=>{let t=e,n=r;u(!0),i.objects.getObjectText(e).then(e=>{if(g.current!==t)return;let r=_.current===n&&!v.current;y(e.text,r),v.current=!1}).catch(e=>{console.error(`Failed to load text`,e)}).finally(()=>{g.current===t&&u(!1)})},[y,r,e,i]);return st(()=>{let i=g.current!==e,a=_.current!==r;g.current=e,_.current=r,a&&(v.current=!0),t!==void 0&&(y(t,!a),v.current=!1),n&&t===void 0&&(i||h.current===void 0)&&b()},[y,r,t,n,b,e]),{fullText:a,displayText:s,isLoading:l,isCropped:d,changeHighlight:p,loadText:b}}function HC(e,t){let{client:n}=Z(),[r,i]=Y({isComplete:!1});return K(()=>{if(!t)return;let r=!1,a,o=(e,t,n)=>{i(r=>{let i=JSON.stringify(r.progress??null),a=JSON.stringify(e??null);return r.status===t&&r.isComplete===n&&i===a?r:{progress:e,status:t,isComplete:n}})};function s(){r||n.objects.analyze(e).getStatus().then(e=>{e.status===Ni.RUNNING?(o(e.progress,e.status,!1),r||(a=setTimeout(s,2e3))):o(e.progress,e.status,!0)}).catch(()=>{r||(a=setTimeout(s,1e4))})}return s(),()=>{r=!0,a&&clearTimeout(a)}},[t,e,n]),{progress:r.progress,status:r.status,isComplete:r.isComplete}}function UC(e,t){let{client:n}=Z(),r=It.getFixedT(null,Ft),[i,a]=Y(),[o,s]=Y(!1),[c,l]=Y();return{pdfUrl:i,isConverting:o,error:c,triggerConversion:G(async()=>{if(!t||o)return;s(!0),l(void 0);let i=async t=>{try{let o=await n.objects.getRendition(e,{format:Ti.pdf,generate_if_missing:t,sign_url:!0,block_on_generation:!1});o.status===`generating`?setTimeout(()=>i(!1),5e3):o.status===`found`&&o.renditions?.length?(a(o.renditions[0]),s(!1)):o.status===`failed`&&(l(r(`store.pdfConversionFailed`)),s(!1))}catch(e){console.error(`Failed to convert Office document to PDF:`,e),l(r(`store.failedToConvertToPdf`)),s(!1)}};await i(!0)},[e,t,o,n,r])}}const WC=()=>({a:({node:e,...n})=>{let r=n.href||``;return r.includes(`/store/objects/`)?t(ga,{topLevelNav:!0,href:r,className:`text-info`,children:n.children}):t(`a`,{...n,target:`_blank`,rel:`noopener noreferrer`})},p:({node:e,...n})=>t(`p`,{...n,className:`my-0`}),pre:({node:e,...n})=>t(`pre`,{...n,className:`my-2 p-2 rounded`}),code:({node:e,className:n,children:r,...i})=>{let a=!/language-(\w+)/.exec(n||``);return t(`code`,{...i,className:a?`px-1.5 py-0.5 rounded`:`text-muted`,children:r})},h1:({node:e,...n})=>t(`h1`,{...n,className:`font-bold text-2xl my-2`}),h2:({node:e,...n})=>t(`h2`,{...n,className:`font-bold text-xl my-2`}),h3:({node:e,...n})=>t(`h3`,{...n,className:`font-bold text-lg my-2`}),li:({node:e,...n})=>t(`li`,{...n})});function GC(e){return e===bi.created||e===bi.processing}function KC(e){return e.metadata?.content_processor?.type}function qC(e){return e?e.includes(`
|
|
440
|
+
`)}let r=await i(n,{tool_approval_mode:ie});if(!r){ne(null),re(null);return}ne(n),re(Date.now());let a=r.agent_run_id,o=!0;if(A&&V.length>0){let e=`batch-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,t=[],n=[];for(let e of V)try{let n=`files/${e.name}`;await P.agents.uploadArtifact(a,n,e);let r=`file-${Date.now()}-${Math.random().toString(36).substr(2,9)}`;await P.agents.sendSignal(a,`FileUploaded`,{id:r,name:e.name,content_type:e.type||`application/octet-stream`,reference:`artifact:${n}`,artifact_path:n}),t.push(r)}catch(t){console.error(`Failed to upload staged file ${e.name}:`,t),n.push({name:e.name,error:t instanceof Error?t.message:String(t)})}o=await Hb(P,a,{batch_id:e,file_ids:t,failed_uploads:n.length>0?n:void 0}),o&&le([]),n.length>0&&oe({title:D(`agent.stagedFilesUploadFailed`),status:`warning`,duration:6e3,description:n.map(e=>e.name).join(`, `)})}p?.(),te(a),I(``),oe(o?{title:D(`agent.agentStarted`),status:`success`,duration:3e3}:{title:D(`agent.stagedFilesNotDelivered`),status:`error`,duration:8e3,description:D(`agent.stagedFilesNotDeliveredDescription`)})}catch(e){ne(null),re(null),oe({title:D(`agent.errorStarting`),status:`error`,duration:3e3,description:e instanceof Error?e.message:D(`agent.unknownError`)})}finally{ee(!1)}}},Te=e=>{if(e.key===`Enter`){if(!(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)){e.preventDefault(),we();return}e.shiftKey||(e.preventDefault(),He(e.currentTarget,I))}},Ee=K(()=>{let e=se.current;if(e){if(k){e.style.height=`100%`;return}e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`}},[k]);return q(()=>{Ee()},[F,Ee]),R?t(px,{onClose:a,isModal:s,initialMessage:e,placeholder:l,fullWidth:c,hideHeader:g,headerVariant:y,hideFileUpload:_,hideObjectLinking:v,inputContainerClassName:x,inputClassName:S,className:C,allowWorkflowControl:w,onAgentWorkingChange:E,agentRunId:R,title:d,pendingStartMessage:z??void 0,pendingStartTimestamp:B??void 0,initialToolApprovalMode:ie}):t(`div`,{className:H(`flex flex-col items-center bg-background`,O&&!k?``:`h-full`,C),children:n(`div`,{className:H(`relative flex w-full flex-col overflow-hidden border-0`,O&&!k?``:`h-full`,c?``:`max-w-4xl`),onDragEnter:A?_e:void 0,onDragOver:A?ve:void 0,onDragLeave:A?ye:void 0,onDrop:A?be:void 0,children:[A&&me&&t(`div`,{className:`absolute inset-0 flex items-center justify-center bg-info-background z-50 pointer-events-none rounded-lg`,children:n(`div`,{className:`text-info font-medium flex items-center gap-2 text-lg`,children:[t(si,{className:`size-6`}),`Drop files to stage for upload`]})}),A&&t(`input`,{ref:ce,type:`file`,multiple:!0,accept:m,onChange:Se,className:`hidden`}),!g&&n(`div`,{className:`flex items-center justify-between border-b border-border/60 bg-background px-3 py-2`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(`div`,{className:`p-1`,children:t(On,{className:`size-3.5 text-muted`})}),t(`span`,{className:`text-sm font-medium text-foreground`,children:N})]}),a&&!s&&t(o,{size:`xs`,variant:`ghost`,onClick:a,title:D(`agent.close`),className:`text-muted hover:text-foreground`,children:t(_i,{className:`size-4`})})]}),t(`div`,{className:H(`flex flex-col items-center justify-end bg-background px-4`,O?`shrink-0 pt-3`:`flex-1 overflow-y-auto`),children:z&&B?t(ax,{message:z,startedAt:B}):t(`div`,{className:H(`mx-auto flex w-full max-w-3xl flex-col justify-end`,O?``:`min-h-full py-8`),children:e&&t(`div`,{className:`text-[15px] leading-relaxed text-foreground/80`,children:e})})}),t(`div`,{className:H(`bg-background px-4 pb-safe-area-4 pt-2`,k?`flex min-h-0 flex-1 flex-col`:`shrink-0`),children:n(`div`,{className:H(`mx-auto flex max-w-3xl flex-col gap-3 rounded-2xl border border-border/70 bg-mixer-muted/15 p-3 shadow-lg shadow-black/5`,k&&`min-h-0 w-full flex-1`,x),children:[A&&V.length>0&&n(`div`,{className:`flex flex-wrap gap-2`,children:[fe.map((e,r)=>n(`div`,{className:`flex items-center gap-1.5 rounded-md bg-attention/10 px-2 py-1 text-sm text-attention`,title:D(`agent.fileStagedTooltip`),children:[t(Un,{className:`size-3.5`}),t(`span`,{className:`max-w-[120px] truncate`,children:e.name}),t(`span`,{className:`text-xs opacity-70`,children:D(`agent.staged`)}),t(o,{variant:`unstyled`,"aria-label":`Remove staged file ${e.name}`,onClick:()=>Ce(r),className:`ms-1 rounded p-0.5 hover:bg-attention/20`,children:t(_i,{className:`size-3`})})]},`${e.name}-${e.size}-${e.lastModified}`)),V.length>3&&n(o,{type:`button`,variant:`ghost`,size:`sm`,"aria-expanded":ue,onClick:()=>de(e=>!e),className:`h-8 shrink-0 gap-1 rounded-xl px-2.5 text-xs text-muted`,children:[!ue&&n(`span`,{children:[`+`,pe]}),D(ue?`agent.showLess`:`agent.showMore`),t(un,{className:H(`size-3.5 transition-transform`,ue&&`rotate-180`),"aria-hidden":`true`})]})]}),t(ze,{ref:se,value:F,onChange:e=>I(e.target.value),onKeyDown:Te,onPaste:xe,placeholder:j,disabled:L,rows:2,className:H(`min-h-[72px] resize-none border-0 bg-transparent px-0 py-0 text-sm leading-6 shadow-none focus-visible:ring-0`,k?`min-h-0 flex-1 overflow-y-auto`:`overflow-hidden`,S),style:k?{minHeight:`72px`,maxHeight:`none`}:{minHeight:`72px`,maxHeight:`200px`}}),n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex min-w-0 items-center gap-2`,children:[A&&t(o,{variant:`ghost`,size:`icon`,onClick:()=>ce.current?.click(),disabled:L||V.length>=h,"aria-label":D(`agent.upload`),className:`rounded-full text-muted`,title:D(`agent.upload`),children:t(si,{className:`size-4`})}),r&&t(Ua,{mode:ie,onChange:ae,disabled:L})]}),t(o,{onClick:we,disabled:!F.trim()||L,variant:`ghost`,size:`icon`,className:H(`size-9 rounded-full border border-border/60 bg-foreground text-background shadow-sm`,`hover:bg-foreground/90 hover:text-background`,`disabled:bg-mixer-muted/25 disabled:text-muted disabled:opacity-100`),title:M,children:L?t(De,{size:`sm`}):t(Yt,{className:`size-4`})})]})]})})]})})}function px({agentRunId:r,title:i,interactive:a=!0,onClose:s,isModal:c=!1,fullWidth:l=!1,placeholder:u,resetWorkflow:d,onRestart:f,onClone:p,onShowDetails:m,allowWorkflowControl:h=!0,uploadedFiles:g,onRemoveFile:_,acceptedFileTypes:v,maxFiles:y,renderDocumentSearch:b,selectedDocuments:x,onRemoveDocument:S,hideObjectLinking:C,hideHeader:w,headerVariant:T=`full`,hideMessageInput:E,failedAction:D,hidePlanPanel:O,hideWorkstreamTabs:k,showRightPanel:A=!0,hideFileUpload:j,showArtifacts:M=!1,hideDocumentPanel:N,hiddenMessageTypes:P,getAttachedDocs:F,onAttachmentsSent:I,isUploading:L=!1,getMessageContext:ee,className:R,inputContainerClassName:te,inputClassName:z,composerContext:ne,fusionData:B,fileUploadRef:ce,sendMessageRef:V,onMessage:le,onAgentWorkingChange:ue,onProcessingFilesChange:de,processingFiles:fe,onPlansChange:pe,onWorkstreamStatusChange:me,viewMode:he,onViewModeChange:ge,onShowInputChange:_e,stopRef:ve,onStoppingChange:ye,messageItemClassNames:be,messageStyleOverrides:xe,toolCallGroupClassNames:Se,hideToolCallsInViewMode:Ce,streamingMessageClassNames:we,batchProgressPanelClassNames:Te,workingIndicatorClassName:Ee,messageListClassName:De,StoreLinkComponent:Oe,CollectionLinkComponent:ke,prependFriendlyMessage:Ae,initialRequestData:je,initialRequestSchema:Me,initialRequestTitle:Ne,initialRequestTemplate:Pe,payloadContent:Fe,conversationContent:Ie,conversationTab:Le=!1,pendingStartMessage:Re,pendingStartTimestamp:ze,initialToolApprovalMode:Be,enablePlayback:Ve,showPlaybackToggle:He=!0,messageFilter:Ue,initialWorkstream:We}){let{t:U}=Z(),{client:Ge}=Q(),Ke=Xe(),{messages:W,streamingMessages:qe,isCompleted:Je,initialHistoryStatus:Ye,debugChunkFlash:Ze,addOptimisticMessage:Qe,updateOptimisticMessageStatus:$e,reconnect:et,agentRunStatus:tt,workflowRunId:nt,serverFileUpdates:G}=y_(Ge,r,le),{plans:rt,activePlanIndex:it,setActivePlanIndex:at,workstreamStatusMap:ot,showInput:st,showSlidingPanel:ct,setShowSlidingPanel:lt}=c_(W,a,c),{openDocuments:ut,activeDocumentId:dt,isDocPanelOpen:ft,docRefreshKey:pt,closeDocPanel:mt,closeDocument:ht,selectDocument:gt,openDocInPanel:_t,updateDocumentTitle:vt}=C_(W),{processingFiles:yt,hasProcessingFiles:bt,handleFileUpload:xt,removeProcessingFile:St,clearProcessingFiles:Ct}=D_(Ge,r,G,Ke,J(()=>Ed(W),[W])),wt=a&&!j,Tt=K(e=>{St(e)},[St]),Et=Y(null),Dt=Y(null),Ot=Y(null),[kt,At]=X(!1),[jt,Mt]=X(!1),[Nt,Ft]=X(`sliding`),It=he??Nt,Lt=K(e=>{ge?ge(e):Ft(e)},[ge]),[Rt,zt]=X(!1),[Bt,Vt]=X(!1),[Ht,Ut]=X(We||`all`),Wt=Y(We);q(()=>{We&&We!==Wt.current&&(Wt.current=We,Ut(We))},[We]);let[Gt,Kt]=X(`live`),[qt,Jt]=X(!1),[Yt,Xt]=X(0),[Zt,Qt]=X([]),[$t,en]=X([]),[tn,nn]=X(!1),rn=J(()=>Be===void 0&&a?void 0:Ui(Be,a),[Be,a]),[an,sn]=X(rn),cn=Y(!1),ln=Y(0),un=Y(!1),dn=Y(0),fn=Y(null);q(()=>{sn(rn)},[rn]);let pn=Y(kt);pn.current=kt;let mn=Y(bt);mn.current=bt;let hn=Y(yt);hn.current=yt;let gn=J(()=>{let e=W.filter(e=>(e.workstream_id||`main`)===`main`);return e[e.length-1]},[W]),_n=J(()=>gn?.type===$.TERMINATED?`TERMINATED`:gn?.type===$.COMPLETE&&(!tt||tt===`RUNNING`)?`COMPLETED`:tt,[gn,tt]),vn=J(()=>{let e=_n?.toUpperCase();return e===`COMPLETED`||e===`FAILED`||e===`CANCELED`||e===`CANCELLED`||e===`TERMINATED`||e===`TIMED_OUT`},[_n]),yn=J(()=>vn&&_n?.toUpperCase()!==`FAILED`&&!!f,[vn,_n,f]),bn=!E||yn,xn=J(()=>_n?.toUpperCase()===`FAILED`||tt?.toUpperCase()===`FAILED`,[_n,tt]),Sn=J(()=>{for(let e=W.length-1;e>=0;e--){let t=W[e];if(t.type!==$.ERROR||Pl(t)!==`main`)continue;let n=typeof t.message==`string`?t.message.trim():``;if(n)return n}},[W]),Cn=Y(vn);Cn.current=vn;let wn=Y(yn);wn.current=yn;let Tn=J(()=>{let e=rt[it]||{plan:{plan:[]},timestamp:0},t=ot.get(e.timestamp)||new Map;return{plan:e.plan,workstreamStatus:t}},[rt,it,ot]),En=J(()=>Qb(W),[W]),Dn=J(()=>{let e=[...En];for(let t of $t)tx(e,ex(t));for(let t of Zt)tx(e,$b(t));return e.map((e,t)=>({workstream:e,index:t})).sort((e,t)=>Number(!Wb(e.workstream.status))-Number(!Wb(t.workstream.status))||e.index-t.index).map(({workstream:e})=>e)},[En,Zt,$t]),On=J(()=>Dn.filter(e=>Wb(e.status)),[Dn]),kn=J(()=>On.filter(e=>e.status===`running`).length,[On]),An=J(()=>{if(Ht===`all`)return;let e=Dn.find(e=>e.workstream_id===Ht||e.launch_id===Ht);return e?hl(e.workstream_id,e.interaction):hl(Ht)},[Ht,Dn]),jn=J(()=>{if(u)return u;if(An)return U(`agent.messageMainAgentWhileViewingWorkstream`,{workstream:An})},[An,u,U]),Mn=He&&Ve===void 0&&wo(),Nn=Ve??(To()||qt),Pn=J(()=>W.filter(e=>!Al(e)&&!(P?.includes(e.type)??!1)),[P,W]),Fn=J(()=>Ll(Pn,Ht),[Ht,Pn]),In=J(()=>So(Fn,Gt,Nn),[Nn,Gt,Fn]),Ln=In.cursor,Rn=In.isLive,zn=Nn&&!Rn&&In.cursorIndex===Fn.length-1,Bn=In.displayedMessages,Vn=J(()=>Ue?Bn.filter(e=>Ue(e)):Bn,[Bn,Ue]),Hn=J(()=>Ue?Pn.filter(e=>Ue(e)):Pn,[Ue,Pn]),Un=Rn?qe:Bb,Wn=J(()=>Qb(Bn),[Bn]),Gn=J(()=>Wn.filter(e=>Wb(e.status)),[Wn]),Kn=J(()=>Je||!jl(W),[Je,W]),qn=Rn||zn?Kn:!1,Jn=!Kn&&!vn;q(()=>{ue?.(Jn)},[Jn,ue]);let Yn=J(()=>{let e=new Set;for(let t of Bn)pu(r,t)&&e.add(lu(t));return Pu(Bn,`main`,e)},[r,Bn]),Xn=!!Yn&&!xn&&(!vn||yn),Zn=Nn&&!Rn,Qn=bn&&!Zn,$n=J(()=>qb(W),[W]),er=h&&!vn&&Rn&&!!$n;q(()=>{Dl(`conversation render state`,{agentRunId:r,messageCount:W.length,playbackMessageCount:Fn.length,displayedMessageCount:Vn.length,streamingCount:qe.size,displayedStreamingCount:Un.size,initialHistoryStatus:Ye,isCompleted:Je,effectiveIsCompleted:Kn,displayedIsCompleted:qn,agentRunStatus:tt,effectiveWorkflowStatus:_n,isWorkflowTerminal:vn,playbackCursor:Ln,isPlaybackEnabled:Nn,isPlaybackLive:Rn,isPlaybackAtLatest:zn,activeWorkstream:Ht,showInitialRequest:Ye===`empty`&&W.length===0,pendingStartVisible:W.length===0&&!Kn&&!!Re})},[Ht,r,tt,Ln,qn,Vn.length,Un.size,Kn,_n,Ye,Je,zn,Nn,Rn,vn,W.length,Re,Fn.length,qe.size]);let tr=K(()=>{Jt(e=>!e)},[]),nr=K(e=>{let t=yo(Ln,Fn.length),n=yo(e,Fn.length);Nn&&(n>t||e===`live`&&Ln!==`live`)&&(un.current=!0,Xt(e=>e+1)),Kt(e)},[Ln,Nn,Fn.length]);q(()=>{if(!Nn){Gt!==`live`&&Kt(`live`);return}Ln!==Gt&&Kt(Ln)},[Ln,Nn,Gt]),q(()=>{if(!Nn||!un.current)return;un.current=!1;let e=window.requestAnimationFrame(()=>{Et.current?.scrollIntoView({behavior:`smooth`,block:`end`})});return()=>window.cancelAnimationFrame(e)},[Nn,Yt]);let rr=K(e=>{at(e)},[at]),[ir,ar]=X(Ie||Le?`conversation`:`plan`),[or,sr]=X(null),[cr,lr]=X(400),[ur,dr]=X(!1),[fr,pr]=X(!1),mr=A&&!fr&&(ct||ft||!k&&Dn.length>0||!!Ie||Le),hr=Y(ft);q(()=>{ft&&!hr.current&&pr(!1),hr.current=ft},[ft]);let gr=K(()=>{mr?(pr(!0),lt(!1)):(pr(!1),lt(!0),sessionStorage.setItem(`plan-panel-shown`,`true`))},[mr,lt]);q(()=>{!mr&&ur&&dr(!1)},[mr,ur]),q(()=>{if(!ur)return;let e=e=>{let t=Ot.current;if(!t)return;let n=t.getBoundingClientRect(),r=Math.max(300,n.width-420),i=n.right-e.clientX;lr(Math.min(Math.max(i,300),r))},t=()=>{dr(!1)};return window.addEventListener(`mousemove`,e),window.addEventListener(`mouseup`,t),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,()=>{window.removeEventListener(`mousemove`,e),window.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[ur]);let _r=K(()=>{pr(!0),lt(!1),mt()},[lt,mt]),vr=K(e=>{/\.md$/i.test(e)&&(pr(!1),sr(e),ar(`artifacts`),lt(!0))},[lt]),yr=Y(null);q(()=>{let e,t;for(let n of W){let r=n.details;r?.event_class===`display_artifact`&&typeof r.path==`string`&&(e=r.path,t=`${n.timestamp??``}:${r.path}`)}!e||!t||t===yr.current||(yr.current=t,pr(!1),sr(e),ar(`artifacts`),lt(!0))},[W,lt]);let br=K(({href:e,documentId:n,children:r})=>t(`a`,{href:e,className:`text-info underline cursor-pointer hover:text-info/80`,onClick:e=>{e.preventDefault(),e.stopPropagation(),_t(n),ar(`documents`)},children:r}),[_t]),xr=Oe??br;q(()=>(ce&&(ce.current=wt?xt:null),()=>{ce&&(ce.current=null)}),[ce,xt,wt]),q(()=>{de?.(yt)},[yt,de]),q(()=>{pe?.(rt,it)},[rt,it,pe]),q(()=>{me?.(ot)},[ot,me]),q(()=>{sr(null),cn.current=!1,nn(!1),Qt([]),en([])},[r]),q(()=>{let e=Ye!==`loading`&&!Kn&&!vn&&!tn;if(Dl(`active workstreams poll state`,{agentRunId:r,shouldPoll:e,initialHistoryStatus:Ye,effectiveIsCompleted:Kn,isWorkflowTerminal:vn,isWorkstreamQueryUnavailable:tn}),!e){Qt(e=>e.length===0?e:[]);return}let t=!1,n=!1,i=async()=>{if(n){Dl(`active workstreams fetch skipped while previous request is pending`,{agentRunId:r});return}n=!0;try{Dl(`active workstreams fetch start`,{agentRunId:r});let e=await Ge.agents.getActiveWorkstreams(r);if(t)return;if(Dl(`active workstreams fetch success`,{agentRunId:r,runningCount:e.running?.length??0,completedCount:e.completed?.length??0,unavailable:e.unavailable===!0}),Qt(e.running??[]),en(e.completed??[]),e.unavailable){nn(!0);return}cn.current=!1}catch(e){if(t)return;Qt(e=>e.length===0?e:[]),nn(!0),Dl(`active workstreams fetch failed`,{agentRunId:r,error:e instanceof Error?e.message:String(e)}),cn.current||=(console.warn(`Failed to fetch active workstreams:`,e),!0)}finally{n=!1}};i();let a=window.setInterval(i,1e4);return()=>{t=!0,window.clearInterval(a)}},[Ge.agents,r,Kn,Ye,vn,tn]),q(()=>{if(W.length!==0){if(yn){_e?.(!0);return}if(!st){_e?.(!1);return}if(_n&&_n!==`RUNNING`){_e?.(!1);return}_n!==null&&_e?.(!0)}},[st,_n,W.length,_e,yn]);let Sr=K(async()=>{let e=fn.current;e&&await e},[]),Cr=K((e,t)=>{let n=e.trim();if(!n||pn.current||Cn.current&&!wn.current)return;if(mn.current){Ke({status:`warning`,title:U(`agent.filesProcessing`),description:U(`agent.waitForFilesProcessing`),duration:3e3});return}let i=yu(t);At(!0);let a=F?.()||[],o=ee?.()||{},s=n;a.length>0&&!/store:\S+/.test(n)&&(s=[n,``,`Attachments:`,...a.map(e=>`[${e.name}](/store/objects/${e.id})`)].join(`
|
|
441
|
+
`));let c=Array.from(hn.current.values()).filter(e=>e.status===Di.READY).map(e=>{let t=e.reference?.startsWith(`artifact:`)?e.reference:e.artifact_path?`artifact:${e.artifact_path}`:void 0;return t?`[${e.name}](${t})`:void 0}).filter(e=>!!e);c.length>0&&(s=[s,``,`Uploaded artifacts:`,...c].join(`
|
|
442
|
+
`));let l=`msg-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,u={timestamp:Date.now(),workflow_run_id:r,type:$.QUESTION,message:s,workstream_id:`main`,details:{_optimistic:!0,_messageId:l,_deliveryStatus:`sending`,...t?.editing_action?{editing_action:t.editing_action}:{},...t?.request_input_response?{request_input_response:t.request_input_response}:{}}};Qe(u);let d={...a.length>0?{attached_docs:a.map(e=>e.id)}:{},...o,...t,id:l,_messageId:l},f=()=>Ge.agents.sendSignal(r,`UserInput`,{message:s,client_message_id:l,metadata:d}),p=()=>{$e(l,`received`),I?.(),Ct()};i&&du(r,i),(async()=>{await Sr(),Cn.current&&(await Ge.agents.restart(r),et()),await f(),p()})().catch(e=>{i&&fu(r,i),$e(l,`failed`),Ke({status:`error`,title:U(`agent.failedToSend`),description:e instanceof Error?e.message:U(`agent.unknownError`),duration:3e3})}).finally(()=>{At(!1)})},[r,Ge,Ke,F,ee,I,Ct,et,Qe,$e,U,Sr]);q(()=>(V&&(V.current=Cr),()=>{V?.current===Cr&&(V.current=null)}),[Cr,V]);let wr=K(async(e,t)=>{try{await Ge.agents.sendSignal(r,`McpConfigChanged`,{})}catch(e){console.error(`Failed to signal MCP config change`,e)}Cr(U(`agent.mcpConnectedMessage`,{name:e.name}),t)},[Ge,r,Cr,U]),[Tr,Er]=X(void 0);q(()=>{let e=!1,t=dn.current;return Ge.agents.retrieve(r).then(n=>{e||(Er(n.disabled_mcp_collections),dn.current===t&&(n.tool_approval_mode!==void 0||n.interactive!==void 0)&&sn(Ui(n.tool_approval_mode,n.interactive)))}).catch(()=>{}),()=>{e=!0}},[Ge,r]);let Dr=K(e=>{let t=e.length>0?e:void 0;Er(t),Ge.agents.sendSignal(r,`McpConfigChanged`,{disabled_mcp_collections:e}).catch(e=>console.error(`Failed to signal MCP config change`,e))},[Ge,r]),Or=K(()=>{Ge.agents.sendSignal(r,`McpConfigChanged`,{}).catch(e=>console.error(`Failed to signal MCP config change`,e))},[Ge,r]),kr=K(e=>{let t=Ui(e,a),n=an;dn.current+=1,sn(t);let i=Ge.agents.sendSignal(r,`ToolApprovalModeChanged`,{mode:t}).then(()=>void 0).catch(e=>{sn(e=>e===t?n:e),Ke({status:`error`,title:U(`agent.approvalMode.changeFailed`),description:e instanceof Error?e.message:U(`agent.unknownError`),duration:3e3})});fn.current=i,i.finally(()=>{fn.current===i&&(fn.current=null)})},[r,Ge,a,U,Ke,an]),Ar=K(e=>{wt&&(e.preventDefault(),e.stopPropagation(),ln.current++,e.dataTransfer?.types?.includes(`Files`)&&Vt(!0))},[wt]),jr=K(e=>{wt&&(e.preventDefault(),e.stopPropagation())},[wt]),Mr=K(e=>{wt&&(e.preventDefault(),e.stopPropagation(),ln.current--,ln.current===0&&Vt(!1))},[wt]),Nr=K(e=>{if(wt&&(e.preventDefault(),e.stopPropagation(),ln.current=0,Vt(!1),e.dataTransfer?.files&&e.dataTransfer.files.length>0)){let t=Array.from(e.dataTransfer.files);xt(t)}},[xt,wt]),Pr=K(async()=>{if(Rt)return;let e=`stop-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,t={timestamp:Date.now(),workflow_run_id:r,type:$.IDLE,message:`Stopped. Waiting for your command...`,workstream_id:`main`,details:{_optimistic:!0,_messageId:e,_deliveryStatus:`sending`,display_role:`user_stopped`,status_reason:`user_stopped`}};Qe(t),zt(!0);try{await Ge.agents.sendSignal(r,`Stop`,{message:`User requested stop`,client_message_id:e,metadata:{id:e,_messageId:e}}),$e(e,`received`)}catch(t){Ke({status:`error`,title:U(`agent.failedToInterrupt`),description:t instanceof Error?t.message:U(`agent.unknownError`),duration:3e3}),$e(e,`failed`)}finally{zt(!1)}},[Rt,r,Qe,Ge.agents,Ke,U,$e]),Fr=K(async()=>{if(!(jt||Kn||!Rn)){Mt(!0);try{await Ge.agents.sendSignal(r,`TriggerCheckpoint`,{reason:`manual user request`})}catch(e){Ke({status:`error`,title:U(`agent.failedToCompactContext`),description:e instanceof Error?e.message:U(`agent.unknownError`),duration:3e3})}finally{Mt(!1)}}},[r,Ge.agents,Kn,jt,Rn,U,Ke]);q(()=>(ve&&(ve.current=h&&!Kn?Pr:null),()=>{ve&&(ve.current=null)}),[ve,Kn,Pr,h]),q(()=>{ye?.(Rt)},[Rt,ye]);let Ir=i||U(`agent.agentConversation`),Lr=async()=>{try{let e=await Rl(Ge,r);e&&window.open(e,`_blank`)}catch(e){console.error(`Failed to download conversation`,e),Ke({status:`error`,title:U(`agent.failedToDownload`),duration:3e3})}},Rr=K(()=>{let e=new Date().toISOString(),t=qe.size>0?[{cursor:`live`,streamingMessages:Array.from(qe,([e,t])=>({id:e,...t}))}]:void 0,n={metadata:{title:Ir,agent_run_id:r,exported_at:e,message_count:W.length},messages:W,...t?{streamingFrames:t}:{}};lx(`${cx(Ir)||`agent-chat`}-${cx(r)}.json`,n),Ke({status:`success`,title:U(`agent.rewind.fixtureExported`),duration:2e3})},[Ir,r,W,qe,U,Ke]),[zr,Br]=X(!1),Vr=()=>{if(!Dt.current){Ke({status:`error`,title:U(`agent.pdfExportFailed`),description:U(`agent.noConversationContent`),duration:3e3});return}Br(!0)},Hr=()=>{if(!Dt.current){Ke({status:`error`,title:U(`agent.pdfExportFailed`),description:U(`agent.noConversationContent`),duration:3e3});return}let e=`${Ir} - ${r}`;if(!ox(Dt.current,e)){Ke({status:`error`,title:U(`agent.pdfExportFailed`),description:U(`agent.unableToOpenPrint`),duration:4e3});return}Ke({status:`success`,title:U(`agent.pdfExportReady`),description:U(`agent.printDialogDescription`),duration:4e3}),Br(!1)},Ur=J(()=>W.filter(e=>e.type===$.COMPLETE||e.type===$.THOUGHT&&e.details?.tool_status===`completed`).length,[W]),Wr=J(()=>{if(!or)return{key:Ur,details:void 0};let e=0,t;for(let n of W){let r=n.details;Pt(r,or)&&(e++,t=r)}return{key:e,details:t}},[Ur,W,or]),Gr=a&&Rn&&_n?.toUpperCase()===`RUNNING`,Kr=J(()=>Tn.plan.plan?.reduce((e,t)=>(t.id&&t.goal&&e.set(t.id.toString(),t.goal),e),new Map),[Tn.plan]),qr=e=>t(I_,{title:Ir,variant:e,isCompleted:Kn,isTerminal:vn,onClose:s,isModal:c,agentRunId:r,workflowRunId:nt||``,viewMode:It,onViewModeChange:Lt,showPlanPanel:mr,hasPlan:A&&rt.length>0,showPlanButton:A&&!Le,onTogglePlanPanel:gr,showPlaybackButton:Mn,isPlaybackEnabled:Nn,onTogglePlayback:tr,onDownload:Lr,onExportFixture:Rr,resetWorkflow:d,onClone:p,onShowDetails:m,allowWorkflowControl:h,onExportPdf:Vr,isReceivingChunks:Ze}),Jr=n(`div`,{ref:Dt,"data-agent-playback-enabled":Nn||void 0,"data-agent-playback-cursor":Nn?Ln:void 0,"data-agent-live-message-count":W.length,"data-agent-rendered-message-count":Vn.length,className:H(`flex flex-col min-h-0 min-w-0 border-0`,Le?`flex-1 h-full`:mr?`w-full flex-1 min-h-[50vh]`:l?`flex-1 w-full`:`flex-1 mx-auto ${c?``:`max-w-4xl`}`),children:[!w&&T===`compact`&&t(`div`,{className:`flex flex-shrink-0 justify-end border-b border-border/60 px-2 py-1 lg:hidden`,children:qr(`compact`)}),!w&&T!==`compact`&&t(`div`,{className:`flex-shrink-0`,children:qr(T)}),Nn&&t(`div`,{className:`flex flex-shrink-0 justify-end px-2 py-1.5`,children:t(Oo,{cursor:Ln,messages:Fn,onChangeCursor:nr})}),W.length===0&&!Kn&&Re&&ze?t(ax,{message:Re,startedAt:ze}):t(sh,{messages:Vn,workstreamSourceMessages:Hn,bottomRef:Et,isCompleted:qn,plan:Tn.plan,workstreamStatus:Tn.workstreamStatus,showPlanPanel:A&&ct,onTogglePlanPanel:gr,plans:rt,activePlanIndex:it,onChangePlan:rr,taskLabels:Kr,streamingMessages:Un,onSendMessage:Rn?Cr:void 0,onOpenArtifact:M?vr:void 0,messageItemClassNames:be,messageStyleOverrides:xe,toolCallGroupClassNames:Se,hideToolCallsInViewMode:Ce,streamingMessageClassNames:we,batchProgressPanelClassNames:Te,artifactRunId:r,viewMode:It,hideWorkstreamTabs:k,workingIndicatorClassName:Ee,messageListClassName:De,StoreLinkComponent:xr,CollectionLinkComponent:ke,prependFriendlyMessage:Ae,initialRequestData:je,initialRequestSchema:Me,initialRequestTitle:Ne,initialRequestTemplate:Pe,showInitialRequest:Ye===`empty`&&W.length===0,hiddenMessageTypes:P,disableAutoScroll:!Rn,renderRequestInputControls:!Xn,activeWorkstream:Ht,onActiveWorkstreamChange:Ut}),Xn?t(Iu,{message:Yn,onSendMessage:Rn?Cr:void 0,onMcpConnected:Rn?wr:void 0,disabled:L||!Rn,isLoading:kt||L}):Zn&&Gn.length>0?t(`div`,{className:`flex-shrink-0 pb-safe-area`,children:t(O_,{activeWorkstreams:Gn,onSelectWorkstream:Ut})}):Qn&&t(`div`,{className:`flex-shrink-0 pb-safe-area`,children:xn?D??t(re,{status:`error`,title:U(`agent.failed`),className:`m-2`,children:Sn??U(`agent.error`)}):_n&&_n!==`RUNNING`&&!yn?It===`sliding`&&_n===`COMPLETED`?t(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-3 text-sm text-muted`,children:n(`div`,{className:`flex items-center gap-2 border-t border-success/25 pt-3 text-success`,children:[t(on,{className:`size-4`}),t(`span`,{className:`font-medium`,children:`Workflow completed`})]})}):n(re,{status:_n===`COMPLETED`?`success`:`done`,icon:null,className:`m-2`,children:[`This Workflow is `,_n]}):(st||yn)&&n(e,{children:[ne,t(Mb,{onSend:Cr,onStop:h?Pr:void 0,approvalModeSlot:a&&an?t(Ua,{mode:an,onChange:kr,disabled:!Rn||vn||!h}):void 0,mcpSlot:t(wh,{disabledCollections:Tr,onChange:Dr,onConnectionChange:Or}),disabled:L||!Rn,isSending:kt||L,isStopping:Rt,isStreaming:!Kn,isCompleted:Kn,contextWindowUsage:er?$n:void 0,onCompactContext:er?Fr:void 0,isCompactingContext:jt,activeTaskCount:kn,activeWorkstreams:On,onSelectWorkstream:Ut,placeholder:jn,onFilesSelected:wt?xt:void 0,uploadedFiles:g,onRemoveFile:_,onRemoveProcessingFile:Tt,acceptedFileTypes:v,maxFiles:y,processingFiles:yt,artifactRunId:r,hasProcessingFiles:bt,renderDocumentSearch:b,selectedDocuments:x,onRemoveDocument:S,hideObjectLinking:C,hideFileUpload:!wt,disableDropZone:wt,className:te,inputClassName:z})]})})]}),Yr=t(Ka,{children:t(sd,{children:n(`div`,{ref:Ot,className:H(`flex flex-col lg:flex-row gap-2 w-full h-full relative overflow-hidden`,wt&&Bt&&`ring-2 ring-blue-400 ring-inset`,R),onDragEnter:wt?Ar:void 0,onDragOver:wt?jr:void 0,onDragLeave:wt?Mr:void 0,onDrop:wt?Nr:void 0,children:[wt&&Bt&&t(`div`,{className:`absolute inset-0 flex items-center justify-center bg-blue-100/80 dark:bg-blue-900/40 z-50 pointer-events-none rounded-lg`,children:n(`div`,{className:`text-blue-600 dark:text-blue-400 font-medium flex items-center gap-2 text-lg`,children:[t(si,{className:`size-6`}),`Drop files to upload`]})}),!Le&&Jr,!Le&&T===`compact`&&!w&&t(`div`,{className:`hidden h-full w-12 shrink-0 items-start justify-center px-1 pt-2 lg:flex`,children:qr(`compact`)}),mr&&n(e,{children:[!Le&&t(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize right panel`,"aria-valuenow":Math.round(cr),"aria-valuemin":300,"aria-valuetext":`${Math.round(cr)} pixels`,tabIndex:0,className:`hidden lg:block lg:w-1 lg:shrink-0 cursor-col-resize bg-border/70 hover:bg-border transition-colors`,onMouseDown:()=>dr(!0),onKeyDown:e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault();let t=e.shiftKey?32:16,n=e.key===`ArrowLeft`?t:-t,r=Ot.current,i=r?Math.max(300,r.getBoundingClientRect().width-420):900;lr(e=>Math.min(Math.max(e+n,300),i))}}),t(`div`,{className:Le?`w-full h-full overflow-auto`:`w-full lg:w-[var(--agent-right-panel-width)] lg:shrink-0 min-h-[50vh] lg:h-full border-t lg:border-t-0`,style:Le?void 0:{"--agent-right-panel-width":`${cr}px`},children:t(o_,{plan:Tn.plan,workstreamStatus:Tn.workstreamStatus,plans:rt,activePlanIndex:it,onChangePlan:rr,showPlan:!O&&ct,activeWorkstreams:Dn,hideWorkstreams:k,openDocuments:ut,activeDocumentId:dt,onSelectDocument:gt,onCloseDocument:ht,onUpdateDocumentTitle:vt,docRefreshKey:pt,runId:r,processingFiles:fe??yt,showArtifacts:M,artifactRefreshKey:Wr.key,artifactRefreshDetails:Wr.details,selectedArtifactPath:or,onSelectedArtifactPathChange:sr,onSendMessage:Gr?Cr:void 0,messages:W,payloadContent:Fe,conversationContent:Le?Jr:Ie,onClose:_r,defaultTab:ir,activeTab:ir,onTabChange:ar})})]}),n(ie,{isOpen:zr,onClose:()=>Br(!1),children:[t(se,{children:`Export conversation as PDF`}),n(ae,{children:[t(`p`,{className:`mb-2`,children:`This will open your browser's print dialog with the current conversation.`}),t(`p`,{className:`text-sm text-muted`,children:`To save a PDF, choose "Save as PDF" or a similar option in the print dialog.`})]}),n(oe,{align:`right`,children:[t(o,{variant:`ghost`,size:`sm`,onClick:()=>Br(!1),children:`Cancel`}),t(o,{size:`sm`,onClick:Hr,children:`Open print dialog`})]})]})]})})});return B?t(ma,{data:B,sendMessage:Cr,ChartComponent:po,artifactRunId:r,children:Yr}):Yr}function mx({messages:e}){let n=G.useMemo(()=>[...e].sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),[e]);return t(`div`,{className:`flex flex-col overflow-y-auto space-y-6 py-4`,children:n.map(e=>t(Qd,{message:e,showPulsatingCircle:!1},`${e.workstream_id??`main`}-${e.timestamp}-${e.type}`))})}function hx({messages:e,bottomRef:n,className:r,messagesClassName:i,emptyClassName:a}){let o=G.useRef(null);q(()=>{n.current&&n.current.scrollIntoView({behavior:`smooth`})},[e,n]);let s=G.useMemo(()=>[...e].sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),[e]);return t(`div`,{ref:o,className:`flex-1 min-h-0 h-full overflow-y-auto py-4 px-4 sm:px-6 lg:px-8 bg-white flex flex-col ${r||``}`,"data-testid":`messages-container`,children:s.length===0?t(`div`,{className:`flex items-center justify-center h-full text-center py-8 ${a||``}`,children:t(`div`,{className:`flex items-center px-4 py-3 text-gray-500`,children:`Waiting for agent response...`})}):t(`div`,{className:`flex-1 flex flex-col justify-start h-full min-h-0 ${i||``}`,children:t(mx,{messages:s,isCompleted:!1})})})}function gx(e){return e.name}function _x({isClearable:e=!1,onChange:n,ignoreVirtuals:r=!1,selectedEnvId:i,disabled:a=!1}){let{t:o}=Z(),{client:s}=Q(),[c,l]=X(),{data:u,isLoading:d}=Ge(()=>s.environments.list().then(e=>(r?e.filter(e=>!e.provider.startsWith(`virtual_`)):e).slice().sort((e,t)=>e.name.localeCompare(t.name))));return q(()=>{l(u?.find(e=>e.id===i))},[u,i]),t(be,{isClearable:e,optionLabel:gx,options:u??[],value:c,onChange:e=>{l(e),n(e)},placeholder:o(`intakePolicy.placeholder.environment`),filterBy:`name`,disabled:a,isLoading:d})}function vx(e){return e.name}function yx(e){return e?.length?n=>{let r=e.some(e=>e.id===n.id);return t(`span`,{className:r?`opacity-50`:``,children:n.name})}:vx}function bx({envId:e,isClearable:n,onChange:r,selectedModelId:i,disabled:a=!1,greyedModels:o,onModelsLoaded:s}){let{t:c}=Z(),{client:l}=Q(),[u,d]=X(),{data:f,isLoading:p}=U(async()=>{if(!e)return[];try{return[...(await l.environments.retrieve(e)).enabled_models??[]].sort((e,t)=>e.name.localeCompare(t.name))}catch{return[]}},[e]);return q(()=>{if(!i){d(void 0);return}let e=f?.find(e=>e.id===i);d(e??{id:i,name:i,provider:`unknown`})},[f,i]),q(()=>{f&&s?.(f)},[f,s]),t(be,{isClearable:n,by:`id`,optionLabel:yx(o),options:f??[],value:u,onChange:e=>{d(e),r(e)},placeholder:c(`intakePolicy.placeholder.model`),disabled:a,isLoading:p})}function xx({env:e,isClearable:n,onChange:r}){let{t:i}=Z(),{client:a}=Q(),[o,s]=X(),{data:c,isLoading:l}=U(async()=>{if(!e)return[];try{return a.environments.listTrainableModels(e.id)}catch{return[]}},[e?.id]);return t(be,{isClearable:n,by:`id`,optionLabel:vx,options:c??[],value:o,onChange:e=>{s(e),r(e)},placeholder:i(`intakePolicy.placeholder.model`),disabled:!e,isLoading:l})}function Sx({children:e,fallback:n}){return Cx?t(Cx,{fallback:n,children:e}):t(Sa,{FallbackComponent:n,children:e})}let Cx=null;function wx(e){Cx=e}function Tx({children:e}){return t(Sx,{fallback:Ex,children:e})}function Ex({error:e}){let{t:r}=Z(),i=e instanceof Error?e.message:void 0;return n(re,{status:`error`,title:r(`errors.somethingWentWrong`),children:[n(`div`,{className:`mb-4`,children:[r(`errors.teamNotifiedLine1`),` `,r(`errors.teamNotifiedLine2`),`\xA0`,t(`a`,{className:`text-info`,href:`mailto:support@vertesiahq.com`,children:`support@vertesiahq.com`}),`.`]}),i&&t(`code`,{className:`w-full mt-4 text-sm text-muted break-words`,children:i})]})}function Dx({children:e}){return t(Sx,{fallback:Ox,children:e})}function Ox({error:e}){let r=e instanceof Error?e.message:void 0;return t(`tr`,{children:n(`td`,{colSpan:100,children:[t(`span`,{className:`text-xs`,children:` Cannot display row`}),t(`br`,{}),t(`span`,{className:`bg-gray-400`,children:r})]})})}function kx({children:e}){return t(Sx,{fallback:Ax,children:e})}function Ax({error:e}){let r=e instanceof Error?e.message:void 0;return console.log(`WidgetError`,e),n(`div`,{className:`text-sm`,children:[`Sorry, this area cannot be loaded or rendered.`,r&&t(`pre`,{children:r})]})}const jx=/^[a-f0-9]{24}$|^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$|^(?=.*\d)(?=.*[a-zA-Z])[a-zA-Z0-9_-]{8,}$/i;function Mx(e){return jx.test(e)}function Nx({className:e,children:r,title:i,description:o,actions:s,breadcrumbs:c,useDynamicBreadcrumbs:l=!0,parentPath:u,parentLabel:d}){let f=_a();function p(e){return e.replace(/[-_]/g,` `).split(` `).map(e=>ea(e)).join(` `)}let m=e=>{if(e?.title)return e.title;let t=e?.href||``;if(!t)return`Page`;let n=t.split(`#`)[0].split(`?`)[0].split(`/`).filter(e=>e.length>0);return n.length>=1?p(n[n.length-1]):`Page`},h=(()=>{let e=[];if(l&&typeof window<`u`){let t=window.history.state?.historyChain;if(Array.isArray(t))t.forEach((n,r)=>{let i=t.length-r;e.push({label:m(n),href:n.href,onClick:()=>f(n.href,{stepsBack:i})})});else if(u)e.push({label:d??m({href:u}),href:u,onClick:()=>f(u,{isBasePathNested:!1,replace:!0})});else{let t=window.location.pathname.split(`/`).filter(e=>e.length>0);for(let n=0;n<t.length;n++)if(Mx(t[n])){let r=`/${t.slice(0,n).join(`/`)}`;e.push({label:p(t[n-1]||r),href:r,onClick:()=>f(r,{isBasePathNested:!1})})}}}return c&&c.length>0&&c.forEach(t=>{let n=t.props?.children||t,r=t.props?.href;e.push(r?{href:r,label:n,onClick:()=>f(r,{replace:t.props.clearBreadcrumbs})}:{label:n})}),e})();return n(`div`,{className:Qe(`pb-0 ps-4 pe-2 py-2 flex flex-col`,e),children:[n(`div`,{className:`flex items-start gap-4`,children:[n(`div`,{className:`w-full flex place-content-between h-auto min-h-8 flex-col items-start justify-center`,children:[n(`nav`,{className:`flex-1 flex justify-start text-sm`,children:[h.length>0&&t(a,{path:h,separator:t(pn,{className:`size-3.5 cn-rtl-flip`}),maxItems:4}),o&&t(Be,{description:o,children:t(rr,{className:`size-4 text-muted ms-4`})})]}),i&&t(`div`,{className:`flex gap-2 items-center`,children:t(`h1`,{className:`text-xl font-semibold break-all`,children:i})})]}),t(`div`,{className:`flex gap-x-2 shrink-0 items-center`,children:s})]}),r&&t(`div`,{className:`w-full flex items-center`,children:r})]})}function Px(){let{t:e}=Z();return n(`div`,{className:`text-center pt-32`,children:[t(`h1`,{className:`text-3xl font-bold text-red-500`,children:`404`}),t(`p`,{className:`text-2xl`,children:e(`layout.pageNotFound`)})]})}const Fx=`magic-pdf`;function Ix(e){return e.replace(/^\$\.?/,``).replace(/^data\./,``)}function Lx(e){let{client:t}=Q(),[n,r]=X(!1);return q(()=>{let n=!1;return r(!1),t.files.getDownloadUrl(`${Fx}/${e}/grounded-extraction.json`).then(e=>fetch(e.url,{method:`HEAD`})).then(e=>{n||r(e.ok)}).catch(()=>{}),()=>{n=!0}},[t,e]),n}function Rx(e){let{client:t}=Q(),[n,r]=X(null);return q(()=>{let n=!1;return r(null),t.files.getDownloadUrl(`${Fx}/${e}/grounded-extraction.json`).then(e=>fetch(e.url)).then(e=>e.ok?e.json():null).then(e=>{n||!e?.citations||r({confidence:e.confidence,verified:e.citations.filter(e=>e.verified).length,total:e.citations.length,verdict:e.verdict,verdict_reason:e.verdict_reason})}).catch(()=>{}),()=>{n=!0}},[t,e]),n}function zx({objectId:e,onClose:r}){let{t:i}=Z(),{client:a}=Q(),{data:s,error:c,isLoading:l}=U(async()=>{let t=await a.files.getDownloadUrl(`${Fx}/${e}/grounded-extraction.json`),n=await fetch(t.url);if(!n.ok)throw Error(i(`grounded.notFound`));return n.json()},[e]);return c?t(`div`,{className:`flex h-full items-center justify-center`,children:n(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md`,children:[t(M,{title:i(`grounded.failedToLoad`),children:Ve(c)}),r&&t(o,{variant:`outline`,onClick:r,children:i(`pdf.close`)})]})}):l||!s?t(`div`,{className:`flex h-full items-center justify-center`,children:t(De,{size:`lg`})}):t(`div`,{className:`relative h-full`,children:t(Vx,{extraction:s,objectId:e,onClose:r})})}function Bx({objectId:e,onClose:n}){return t(`div`,{className:`fixed inset-0 bg-background z-50`,children:t(zx,{objectId:e,onClose:n})})}function Vx({extraction:r,objectId:a,onClose:s}){let{t:c}=Z(),{client:l}=Q(),u=J(()=>Object.keys(r.pages).map(e=>parseInt(e,10)).sort((e,t)=>e-t),[r.pages]),d=e=>{l.files.getDownloadUrl(`${Fx}/${a}/${e}`).then(e=>window.open(e.url,`_blank`)).catch(()=>{})},[f,p]=X(u[0]??1),[m,h]=X(void 0),[g,_]=X(!1),[v,y]=X(`original`),b=J(()=>{let e={digital:0,ocr:0,reviewerConfirmed:0,snapped:0,imageRead:0},t=[];for(let n of r.citations)n.verified?n.snapped?e.snapped++:(n.confidence??0)>=1?e.digital++:e.ocr++:n.reviewed?e.reviewerConfirmed++:(e.imageRead++,t.push(n));let n=e.digital+e.ocr+e.snapped,i=e.reviewerConfirmed;return{groups:e,unverified:t,digitallyVerified:n,modelVerified:i,totalVerified:n+i}},[r.citations]),x=J(()=>{let e=new Map;for(let t of r.citations){let n=Ix(t.path),r=e.get(n)??[];r.push(t),e.set(n,r)}return e},[r.citations]),S=r.citations.length,C=b.totalVerified===S,T=e=>{h(e);let t=x.get(Ix(e))?.[0];t&&p(t.page)},E=u.indexOf(f),D=m?x.get(Ix(m))?.find(e=>e.page===f):void 0,O=D?.cells?D.cells.start===D.cells.end?D.cells.start:`${D.cells.start}:${D.cells.end}`:void 0;return n(ye,{direction:`horizontal`,className:`absolute inset-0`,children:[n(ve,{defaultSize:55,minSize:25,className:`flex flex-col bg-muted`,children:[n(`div`,{className:`relative flex h-9 shrink-0 items-center justify-center bg-sidebar px-2 border-b border-sidebar-border`,children:[O&&t(i,{variant:`secondary`,className:`absolute start-2 max-w-32 truncate font-mono text-[11px]`,title:O,children:O}),n(`div`,{className:`flex items-center gap-2`,children:[t(o,{variant:`ghost`,size:`xs`,"aria-label":c(`grounded.previousPage`),disabled:E<=0,onClick:()=>p(u[E-1]),children:t(fn,{className:`size-4`})}),t(`span`,{className:`text-xs text-muted`,children:c(`pdf.pageOf`,{pageNumber:f,totalPages:u.length})}),t(o,{variant:`ghost`,size:`xs`,"aria-label":c(`grounded.nextPage`),disabled:E>=u.length-1,onClick:()=>p(u[E+1]),children:t(pn,{className:`size-4`})})]}),n(`fieldset`,{className:`absolute end-2 flex items-center gap-0.5 rounded border-0 bg-muted p-0.5`,children:[t(`legend`,{className:`sr-only`,children:c(`grounded.checkerboard`)}),t(Be,{description:c(`pdf.originalImages`),placement:`bottom`,size:`xs`,asChild:!0,children:n(o,{variant:v===`original`?`outline`:`ghost`,size:`xs`,"aria-label":c(`pdf.originalImages`),"aria-pressed":v===`original`,className:`h-6 gap-1 px-1.5`,onClick:()=>y(`original`),children:[t(tr,{className:`size-3.5`}),t(`span`,{className:`hidden sm:inline`,children:c(`pdf.page`)})]})}),t(Be,{description:c(`grounded.checkerboard`),placement:`bottom`,size:`xs`,asChild:!0,children:n(o,{variant:v===`grid`?`outline`:`ghost`,size:`xs`,"aria-label":c(`grounded.checkerboard`),"aria-pressed":v===`grid`,className:`h-6 gap-1 px-1.5`,onClick:()=>y(`grid`),children:[t(Qn,{className:`size-3.5`}),t(`span`,{className:`hidden sm:inline`,children:c(`grounded.checkerboard`)})]})})]})]}),t(`div`,{className:`flex-1 overflow-auto p-2`,children:t(Hx,{objectId:a,page:f,dims:r.pages[String(f)],citations:r.citations.filter(e=>e.page===f),selectedPath:m,onSelectPath:h,imageMode:v})})]}),t(_e,{className:`w-[4px] bg-border cursor-ew-resize`}),n(ve,{defaultSize:45,minSize:20,className:`flex flex-col`,children:[n(`div`,{className:`flex h-9 items-center justify-between shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:[t(`span`,{className:`text-sm font-medium`,children:c(`grounded.title`)}),n(`div`,{className:`flex items-center gap-2`,children:[S>0&&t(Be,{description:c(`grounded.confidenceHint`),placement:`bottom`,size:`xs`,asChild:!0,children:n(i,{variant:C?`success`:`attention`,className:`gap-1 text-nowrap cursor-pointer`,onClick:()=>_(e=>!e),"aria-expanded":g,children:[t(C?sn:In,{className:`size-3.5`}),c(`grounded.verifiedOf`,{verified:b.totalVerified,total:S})]})}),n(w,{align:`right`,trigger:t(o,{variant:`ghost`,size:`xs`,"aria-label":c(`pdf.download`),title:c(`pdf.download`),children:t(An,{className:`size-4`})}),children:[n(B,{className:`text-xs`,onClick:()=>d(`grounded-extraction.json`),children:[t(zn,{className:`size-4`}),c(`grounded.downloadCitations`)]}),n(B,{className:`text-xs`,onClick:()=>d(`pages/page-${f}.json`),children:[t(Hn,{className:`size-4`}),c(`grounded.downloadBlocks`)]}),n(B,{className:`text-xs`,onClick:()=>d(`grounded-annotated.pdf`),children:[t(Ln,{className:`size-4`}),c(`grounded.downloadAnnotated`)]})]}),!!s&&t(o,{variant:`ghost`,size:`xs`,onClick:s,"aria-label":c(`pdf.close`),children:t(mi,{className:`size-4`})})]})]}),g&&n(`div`,{className:`shrink-0 border-b border-border bg-background px-3 py-2 text-sm max-h-72 overflow-auto`,children:[n(`div`,{className:`mb-1 flex items-center gap-1`,children:[t(`span`,{className:`font-medium`,children:c(`grounded.breakdownTitle`)}),t(Be,{description:c(`grounded.breakdownVerificationHelp`),size:`xs`,children:t(rr,{className:`size-3 text-muted`})})]}),n(`div`,{className:`grid grid-cols-2 gap-x-4 text-xs`,children:[t(`span`,{className:`col-span-2 mt-1 font-medium text-success`,children:c(`grounded.digitalVerifiedOf`,{count:b.digitallyVerified,total:S})}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownDigital`)}),t(`span`,{className:`text-end text-success`,children:b.groups.digital}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownOcr`)}),t(`span`,{className:`text-end text-success`,children:b.groups.ocr}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownSnapped`)}),t(`span`,{className:`text-end text-success`,children:b.groups.snapped}),t(`span`,{className:`col-span-2 mt-2 font-medium text-success`,children:c(`grounded.modelVerifiedOf`,{count:b.modelVerified,total:S})}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownReviewer`)}),t(`span`,{className:`text-end text-success`,children:b.groups.reviewerConfirmed}),b.groups.imageRead>0&&n(e,{children:[t(`span`,{className:`col-span-2 mt-2 font-medium text-attention`,children:c(`grounded.unverifiedCount`,{count:b.groups.imageRead})}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownImageRead`)}),t(`span`,{className:`text-end text-attention`,children:b.groups.imageRead})]})]}),typeof r.hardness?.score==`number`&&n(`p`,{className:`mt-2 text-xs text-muted`,title:c(`grounded.hardnessHint`),children:[c(`grounded.hardness`,{percent:Math.round(r.hardness.score*100)}),r.hardness.escalated?` ↑`:``]}),(r.verdict_reason??r.review?.verdict_reason)&&t(`p`,{className:`mt-2 text-xs`,children:r.verdict_reason??r.review?.verdict_reason}),r.review?.summary&&n(`p`,{className:`mt-2 text-xs text-muted`,children:[n(`span`,{className:`font-medium text-foreground`,children:[c(`grounded.reviewSummary`),`: `]}),r.review.summary]}),typeof r.review?.corrections_applied==`number`&&r.review.corrections_applied>0&&t(`p`,{className:`mt-1 text-xs text-info`,children:c(`grounded.reviewCorrections`,{count:r.review.corrections_applied})}),b.unverified.length>0&&n(`div`,{className:`mt-2`,children:[t(`div`,{className:`text-xs font-medium text-muted mb-1`,children:c(`grounded.breakdownUnverifiedList`)}),t(`ul`,{className:`space-y-0.5`,children:b.unverified.map(e=>t(`li`,{children:n(`button`,{type:`button`,className:`w-full text-start text-xs rounded px-1 py-0.5 hover:bg-muted cursor-pointer`,onClick:()=>{T(e.path),_(!1)},children:[t(`span`,{className:`text-muted`,children:e.path}),` `,t(`span`,{children:String(e.value??``)})]})},e.path))})]})]}),n(`div`,{className:`flex-1 overflow-auto p-3`,children:[t(Ux,{value:r.data,path:``,citationsByPath:x,selectedPath:m,onSelect:T}),r.conflicts&&r.conflicts.length>0&&t(`div`,{className:`mt-4 text-xs text-attention`,children:c(`grounded.conflicts`,{count:r.conflicts.length})})]})]})]})}function Hx({objectId:e,page:r,dims:i,citations:a,selectedPath:o,onSelectPath:s,imageMode:c}){let{t:l}=Z(),{client:u}=Q(),[d,f]=X(void 0);if(q(()=>{let t=!1;return f(void 0),u.files.getDownloadUrl(`${Fx}/${e}/pages/page-${r}.${c}.jpg`).then(e=>{t||f(e.url)}).catch(e=>console.warn(`Failed to load page image`,e)),()=>{t=!0}},[u,c,e,r]),!d||!i)return t(`div`,{className:`flex items-center justify-center h-64`,children:t(De,{})});let p=a.flatMap(e=>e.boxes.map((r,a)=>{let c=o!==void 0&&Ix(o)===Ix(e.path),l=e.cells?e.cells.start===e.cells.end?e.cells.start:`${e.cells.start}:${e.cells.end}`:void 0;return t(Be,{description:n(`span`,{className:`flex flex-col gap-0.5`,children:[t(`span`,{className:`flex items-center gap-1 font-medium`,children:Kx(e.path).map((e,r)=>n(it,{children:[r>0&&t(pn,{className:`size-3 shrink-0 cn-rtl-flip`}),e]},`${r}:${e}`))}),l&&t(`span`,{className:`font-mono`,children:l}),e.source_text&&t(`span`,{children:e.source_text})]}),size:`xs`,asChild:!0,children:t(`button`,{type:`button`,"aria-label":e.path,onClick:()=>s(Ix(e.path)),className:H(`absolute cursor-pointer border rounded-[1px] transition-colors`,e.misaligned&&`border-dashed`,c?`border-2 border-primary bg-primary/20 z-10`:e.verified?`border-success/70 hover:bg-success/20`:e.reviewed?`border-info/70 hover:bg-info/20`:`border-attention/80 hover:bg-attention/20`),style:{position:`absolute`,left:`${r.x/i.width*100}%`,top:`${r.y/i.height*100}%`,width:`${r.w/i.width*100}%`,height:`${r.h/i.height*100}%`}})},`${e.path}-${a}`)})),m=((i.rotation??0)%360+360)%360;if(m!==0){let e=m===90||m===270;return n(`div`,{className:`relative w-full`,style:{aspectRatio:`${i.width} / ${i.height}`},children:[t(`img`,{src:d,alt:l(`grounded.pageAlt`,{page:r}),className:`absolute select-none`,style:{left:`50%`,top:`50%`,width:`${(e?i.height/i.width:1)*100}%`,height:`${(e?i.width/i.height:1)*100}%`,maxWidth:`none`,transform:`translate(-50%, -50%) rotate(${m}deg)`,transformOrigin:`center center`}}),p]})}return n(`div`,{className:`relative w-full`,children:[t(`img`,{src:d,alt:l(`grounded.pageAlt`,{page:r}),className:`w-full select-none`}),p]})}function Ux({value:e,path:r,citationsByPath:i,selectedPath:a,onSelect:o}){return Array.isArray(e)?e.length>0&&e.every(e=>typeof e==`object`&&!!e)?t(Wx,{items:e,path:r,citationsByPath:i,selectedPath:a,onSelect:o}):t(`div`,{className:`space-y-1`,children:e.map((e,n)=>t(Ux,{value:e,path:`${r}[${n}]`,citationsByPath:i,selectedPath:a,onSelect:o},`${r}[${n}]`))}):typeof e==`object`&&e?t(`div`,{className:r?`ps-3 border-s border-border space-y-0.5`:`space-y-0.5`,children:Object.entries(e).map(([e,s])=>{let c=r?`${r}.${e}`:e;if(typeof s!=`object`||!s)return t(Gx,{label:e,value:s,path:c,citationsByPath:i,selectedPath:a,onSelect:o},c);let l=Array.isArray(s)&&s.length>0&&s.every(e=>typeof e==`object`&&!!e);return n(`div`,{className:`pt-1`,children:[!l&&t(`div`,{className:`text-sm font-semibold`,children:qx(e)}),t(Ux,{value:s,path:c,citationsByPath:i,selectedPath:a,onSelect:o})]},c)})}):null}function Wx({items:e,path:r,citationsByPath:i,selectedPath:a,onSelect:o}){let{t:s}=Z(),c=J(()=>{let t=new Set;for(let n of e)for(let e of Object.keys(n))t.add(e);return Array.from(t)},[e]);return n(`div`,{className:`pt-1`,children:[n(`div`,{className:`text-sm font-semibold`,children:[qx(r.split(`.`).pop()),` (`,e.length,`)`]}),t(`div`,{className:`overflow-x-auto`,children:n(`table`,{className:`w-full text-xs`,children:[t(`thead`,{children:t(`tr`,{className:`text-start text-muted`,children:c.map(e=>t(`th`,{scope:`col`,className:`py-1 pe-2 font-medium`,children:qx(e)},e))})}),t(`tbody`,{children:e.map((e,l)=>t(`tr`,{className:`border-t border-border/50`,children:c.map(c=>{let u=`${r}[${l}].${c}`,d=i.get(u)?.[0];return t(`td`,{className:`py-0.5 pe-2`,children:n(`button`,{type:`button`,onClick:()=>o(u),className:H(`text-start rounded px-1 w-full`,a===u?`bg-primary/15 ring-1 ring-primary`:d?`hover:bg-muted cursor-pointer`:`text-muted cursor-default`),children:[Xx(e[c]),d&&typeof d.confidence==`number`&&t(`span`,{className:H(`ms-1 text-[10px]`,Yx(d.confidence)),title:s(`grounded.scoreHint`),children:Jx(d.confidence)})]})},c)})},`${r}[${l}]`))})]})})]})}function Gx({label:e,value:r,path:i,citationsByPath:a,selectedPath:o,onSelect:s}){let{t:c}=Z(),l=a.get(i)?.[0];return n(`button`,{type:`button`,onClick:()=>l&&s(i),className:H(`flex items-center gap-2 w-full text-start text-sm rounded px-1.5 py-0.5`,o===i?`bg-primary/15 ring-1 ring-primary`:l?`hover:bg-muted`:``,!l&&`cursor-default`),children:[n(`span`,{className:`min-w-28 shrink-0 font-semibold`,children:[qx(e),`:`]}),t(`span`,{className:`flex-1 wrap-break-word`,children:Xx(r)}),l&&typeof l.confidence==`number`&&t(`span`,{className:H(`text-xs shrink-0`,Yx(l.confidence)),title:c(`grounded.scoreHint`),children:Jx(l.confidence)}),l&&(l.verified?t(sn,{"aria-label":c(`grounded.verified`),className:`size-3.5 shrink-0 text-success`}):l.reviewed?t(Qr,{"aria-label":c(`grounded.aiVerified`),className:`size-3.5 shrink-0 text-info`}):t(In,{"aria-label":c(`grounded.readFromImage`),className:`size-3.5 shrink-0 text-attention`}))]})}function Kx(e){return Ix(e).split(`.`).map(e=>qx(e.replace(/\[\d+\]/g,``))).filter(Boolean)}function qx(e){return e?At(e):``}function Jx(e){let t=e*100;return Number.isInteger(t)?`${t}%`:`${(Math.floor(t*100)/100).toFixed(2)}%`}function Yx(e){return e>=.95?`text-success`:e>=.7?`text-attention`:`text-destructive`}function Xx(e){return e==null||e===``?`—`:typeof e==`boolean`?e?`true`:`false`:typeof e==`object`?JSON.stringify(e):String(e)}const Zx=`magic-pdf`;var Qx;(function(e){e.original=`original`,e.instrumented=`instrumented`})(Qx||={});var $x=class{client;objectId;totalPages;cache=new Map;pending=new Map;constructor(e,t,n){this.client=e,this.objectId=t,this.totalPages=n}getCacheKey(e,t){return`${t}-${e}`}async getPageImageUrl(e,t){let n=this.getCacheKey(e,t),r=this.cache.get(n);if(r)return r;let i=this.pending.get(n);if(i)return i;let a=this.fetchImageUrl(e,t);this.pending.set(n,a);try{let e=await a;return this.cache.set(n,e),e}finally{this.pending.delete(n)}}async fetchImageUrl(e,t){let n=this.getImagePath(e,t);return(await this.client.files.getDownloadUrl(n)).url}getImagePath(e,t){let n=`${Zx}/${this.objectId}/pages`;switch(t){case Qx.original:return`${n}/page-${e}.original.jpg`;case Qx.instrumented:return`${n}/page-${e}.instrumented.jpg`}}},eS=class{client;objectId;totalPages;cache=new Map;pending=new Map;constructor(e,t,n){this.client=e,this.objectId=t,this.totalPages=n}async getPageLayout(e){let t=this.cache.get(e);if(t!==void 0)return t;let n=this.pending.get(e);if(n)return n;let r=this.fetchPageLayout(e);this.pending.set(e,r);try{let t=await r;return this.cache.set(e,t),t}finally{this.pending.delete(e)}}async fetchPageLayout(e){let t=`${Zx}/${this.objectId}/pages/page-${e}.layout.json`,n=await this.client.files.getDownloadUrl(t),r=await fetch(n.url,{method:`GET`});if(!r.ok)throw Error(`Failed to fetch json layout: ${r.statusText}`);return r.text()}},tS=class{totalPages;pages=[];constructor(e){this.totalPages=e}initFromContent(e){this.pages=nS(e,this.totalPages)}async loadUrls(e,t){}async getPageMarkdown(e){let t=e-1;return t<0||t>=this.pages.length?``:this.pages[t]}};function nS(e,t){let n=Array(t).fill(``),r=/<!--\s*\{\s*"page"\s*:\s*(\d+)\s*\}\s*-->/g,i=[];for(let t of e.matchAll(r))i.push({page:parseInt(t[1],10),index:t.index+t[0].length});for(let r=0;r<i.length;r++){let a=i[r],o=a.page-1;if(o<0||o>=t)continue;let s=a.index,c=e.slice(s).match(/<!--\s*\{\s*"page"\s*:\s*\d+\s*\}\s*-->/),l=c&&c.index!==void 0?s+c.index:e.length,u=e.slice(s,l).trim();u=u.replace(/\n---\s*$/,``).trim(),n[o]=u}return n}const rS=ot(void 0);function iS({children:e,object:n}){let{client:r}=Q(),i=n.metadata.page_count||10,[a,o]=X(()=>{let e=new tS(i);return n.text&&e.initFromContent(n.text),{count:i,layoutProvider:new eS(r,n.id,i),markdownProvider:e,imageProvider:new $x(r,n.id,i),pdfUrl:``,pdfUrlLoading:!0}});return q(()=>{let e=n.metadata?.renditions?.find(e=>e.name===ji),t=n.content?.type===`application/pdf`,i=e?.content?.source||(t?n.content?.source:void 0);i?r.store.objects.getDownloadUrl(i,void 0,`inline`).then(e=>{o(t=>({...t,pdfUrl:e.url,pdfUrlLoading:!1}))}).catch(e=>{console.warn(`Failed to get PDF URL:`,e),o(e=>({...e,pdfUrlLoading:!1}))}):o(e=>({...e,pdfUrlLoading:!1}))},[r,n.metadata,n.content?.type,n.content?.source]),t(rS.Provider,{value:a,children:e})}function aS(e,t,n){return e.files.getDownloadUrl(`${Zx}/${t}/${n}`).then(e=>e.url)}function oS(){let e=G.useContext(rS);if(!e)throw Error(`useMagicPdfContext must be used within a MagicPdfProvider`);return e}function sS({object:e}){let{t:n}=Z(),{client:r}=Q(),i=t=>{aS(r,e.id,t).then(e=>window.open(e,`_blank`))};return t(o,{variant:`ghost`,size:`xs`,onClick:()=>i(`document.md`),title:n(`pdf.download`),children:t(An,{className:`size-4`})})}function cS({className:e}){return t(`div`,{className:`flex items-center justify-center ${e||``}`,children:t(fr,{className:`w-6 h-6 animate-spin text-gray-400`})})}function lS({viewType:e,pageNumber:n}){switch(e){case`json`:return t(uS,{pageNumber:n});case`markdown`:return t(dS,{pageNumber:n});default:return t(dS,{pageNumber:n})}}function uS({pageNumber:e}){let[n,r]=X(null),[i,a]=X(!0),[o,s]=X(null),{layoutProvider:c}=oS();return q(()=>{a(!0),s(null),c.getPageLayout(e).then(e=>{r(e?JSON.parse(e):null),a(!1)}).catch(e=>{console.error(e),s(e.message||`Failed to load layout`),a(!1)})},[e,c]),i?t(`div`,{className:`px-4 py-8`,children:t(cS,{})}):o?t(`div`,{className:`px-4 py-2 text-red-500 text-sm`,children:o}):n?t(xt,{className:`w-full`,data:n}):null}function dS({pageNumber:e}){let[r,i]=X(null),[a,o]=X(!0),[s,c]=X(null),{markdownProvider:l}=oS();return q(()=>{o(!0),c(null),l.getPageMarkdown(e).then(e=>{i(e),o(!1)}).catch(e=>{console.error(e),c(e.message||`Failed to load markdown`),o(!1)})},[e,l]),a?n(`div`,{className:`h-full flex flex-col items-center justify-center gap-2`,children:[t(cS,{}),t(`span`,{className:`text-sm text-muted-foreground`,children:`Loading...`})]}):s?t(`div`,{className:`px-4 py-2 text-red-500 text-sm`,children:s}):t(`div`,{className:`px-4 py-2 prose prose-sm max-w-none dark:prose-invert`,children:r?t(wt,{children:r}):t(`div`,{children:`No markdown content available`})})}tg();var fS=class extends rt{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`PDF View error:`,e,t)}render(){return this.state.hasError?t(`div`,{className:`fixed inset-0 bg-background z-50 flex items-center justify-center`,children:n(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md`,children:[t(M,{title:Vt.t(`pdf.failedToLoadViewer`,{ns:Bt}),children:this.state.error?.message||`An unexpected error occurred`}),this.props.onClose&&t(o,{variant:`outline`,onClick:this.props.onClose,children:`Close`})]})}):this.props.children}};function pS({objectId:e,onClose:r}){let{t:i}=Z(),{client:a}=Q(),{data:s,error:c}=U(()=>a.store.objects.retrieve(e,`+text`),[e]);return c?t(`div`,{className:`fixed inset-0 bg-background z-50 flex items-center justify-center`,children:n(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md`,children:[t(M,{title:i(`pdf.fetchingDocumentFailed`),children:Ve(c)}),r&&t(o,{variant:`outline`,onClick:r,children:`Close`})]})}):s?t(fS,{onClose:r,children:t(`div`,{className:`fixed inset-0 bg-background z-50 flex items-center justify-center`,children:t(iS,{object:s,children:t(mS,{object:s,onClose:r})})})}):n(`div`,{className:`fixed inset-0 bg-background z-50 flex flex-col`,children:[t(`div`,{className:`flex h-9 items-center justify-end shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:r&&t(o,{variant:`ghost`,size:`xs`,onClick:r,title:i(`pdf.close`),children:t(mi,{className:`size-4`})})}),t(`div`,{className:`flex-1 flex items-center justify-center`,children:t(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary`})})]})}function mS({object:e,onClose:r}){let{t:i}=Z(),{count:a,pdfUrl:s,pdfUrlLoading:c}=oS(),[l,u]=X(1);return n(ye,{direction:`horizontal`,className:`absolute inset-0`,children:[t(ve,{defaultSize:50,minSize:20,maxSize:80,className:`bg-muted`,children:t(Yh,{pdfUrl:s,pdfUrlLoading:c,pageCount:a,className:`h-full`,currentPage:l,onChange:u})}),t(_e,{className:`w-[4px] bg-border cursor-ew-resize`}),n(ve,{defaultSize:50,minSize:20,className:`flex flex-col`,children:[n(`div`,{className:`flex h-9 items-center justify-between shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:[t(`div`,{className:`flex items-center gap-x-2`,children:t(sS,{object:e})}),t(`span`,{className:`text-xs text-muted-foreground`,children:i(`pdf.pageOf`,{pageNumber:l,totalPages:a})}),t(`div`,{className:`flex items-center gap-x-2`,children:!!r&&t(o,{variant:`ghost`,size:`xs`,onClick:r,title:i(`pdf.close`),children:t(mi,{className:`size-4`})})})]}),t(`div`,{className:`flex-1 overflow-auto px-2`,children:t(lS,{pageNumber:l,viewType:`markdown`})})]})]})}const hS=[`image/jpeg`,`image/jpg`,`image/png`,`image/gif`,`image/webp`,`image/svg+xml`],gS=[`video/mp4`,`video/webm`],_S=[`audio/mp4`,`audio/m4a`,`audio/x-m4a`,`audio/mpeg`,`audio/ogg`,`audio/wav`,`audio/webm`];function vS(e){let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=Math.floor(e%60);return t>0?`${t}:${n.toString().padStart(2,`0`)}:${r.toString().padStart(2,`0`)}`:`${n}:${r.toString().padStart(2,`0`)}`}function yS({url:e,source:r,object:i,className:a}){let{t:o}=Z(),{client:s}=Q(),[c,l]=X(e),[u,d]=X(!e&&(!!r||!!i)),f=i?.metadata,p=(f?.renditions||[]).find(e=>e.name===Si),m=i?.content?.type&&_S.includes(i.content.type),h=!!i&&i.metadata?.type===wi.Audio&&!p&&!m;return q(()=>{if(e){l(e),d(!1);return}l(void 0),r||i?(d(!0),(async()=>{try{if(r){let e=await s.files.getDownloadUrl(r);l(e.url);return}if(!i||i.metadata?.type!==wi.Audio)return;let e;p?.content?.source?e=await s.files.getDownloadUrl(p.content.source):m&&i.content?.source&&(e=await s.files.getDownloadUrl(i.content.source)),e&&l(e.url)}catch(e){console.error(`Failed to get audio URL`,e)}finally{d(!1)}})()):d(!1)},[e,r,i,p,m,s]),h?t(`div`,{className:`flex justify-center items-center h-[200px] text-muted ${a??``}`.trim(),children:n(`div`,{className:`text-center`,children:[t(`p`,{children:o(`store.noAudioRendition`)}),t(`p`,{className:`text-sm mt-2`,children:o(`store.audioFormatRequired`)})]})}):u?t(`div`,{className:`flex justify-center items-center h-[200px] ${a??``}`.trim(),children:t(De,{size:`md`})}):c?n(`div`,{className:`flex flex-col items-center gap-4 ${a??``}`.trim(),children:[t(`audio`,{src:c,controls:!0,className:`w-full max-w-2xl`,children:`Your browser does not support the audio tag.`}),f?.duration&&n(`div`,{className:`text-sm text-muted`,children:[`Duration: `,vS(f.duration)]})]}):t(`div`,{className:`flex justify-center items-center h-[200px] text-muted ${a??``}`.trim(),children:`Failed to load audio`})}function bS({url:e,source:n,object:r,className:i}){let{client:a}=Q(),[o,s]=X(e),[c,l]=X(!e&&(!!n||!!r));return q(()=>{if(e){s(e),l(!1);return}s(void 0),n||r?(l(!0),(async()=>{try{if(n){let e=await a.files.getDownloadUrl(n);s(e.url);return}if(!r||r.metadata?.type!==wi.Image)return;let e=r.content?.type&&hS.includes(r.content.type);try{let e=await a.objects.getRendition(r.id,{format:Oi.jpeg,generate_if_missing:!1,sign_url:!0});if(e.status===`found`&&e.renditions?.length){s(e.renditions[0]);return}}catch{}if(e&&r.content?.source){let e=await a.files.getDownloadUrl(r.content.source);s(e.url)}}finally{l(!1)}})()):l(!1)},[e,n,r,a]),c?t(`div`,{className:i,children:t(De,{size:`md`})}):o?t(`img`,{src:o,alt:r?.name,className:`w-full object-contain ${i??``}`.trim()}):null}function xS({url:e,source:r,object:i,className:a}){let{t:o}=Z(),{client:s}=Q(),[c,l]=X(e),[u,d]=X(),[f,p]=X(!e&&(!!r||!!i)),m=i?.metadata?.renditions||[],h=m.find(e=>e.content.type===`video/mp4`)||m.find(e=>e.content.type===`video/webm`),g=i?.content?.type&&gS.includes(i.content.type),_=m.find(e=>e.name===Mi),v=!!i&&i.metadata?.type===wi.Video&&!h&&!g;return q(()=>{if(e){l(e),p(!1);return}l(void 0),d(void 0),r||i?(p(!0),(async()=>{try{if(r){let e=await s.files.getDownloadUrl(r);l(e.url);return}if(!i||i.metadata?.type!==wi.Video)return;let e;h?.content?.source?e=await s.files.getDownloadUrl(h.content.source):g&&i.content?.source&&(e=await s.files.getDownloadUrl(i.content.source)),e&&l(e.url)}catch(e){console.error(`Failed to get video URL`,e)}finally{p(!1)}})()):p(!1)},[e,r,i,h,g,s]),q(()=>{_?.content?.source&&s.files.getDownloadUrl(_.content.source).then(e=>d(e.url)).catch(e=>console.error(`Failed to load poster image`,e))},[_,s]),v?t(`div`,{className:`flex justify-center items-center h-[400px] text-muted ${a??``}`.trim(),children:n(`div`,{className:`text-center`,children:[t(`p`,{children:o(`store.noVideoRendition`)}),t(`p`,{className:`text-sm mt-2`,children:o(`store.videoFormatRequired`)})]})}):f?t(`div`,{className:`flex justify-center items-center h-[400px] ${a??``}`.trim(),children:t(De,{size:`md`})}):c?t(`video`,{src:c,poster:u,controls:!0,className:`w-full h-full object-contain ${a??``}`.trim(),children:`Your browser does not support the video tag.`}):t(`div`,{className:`flex justify-center items-center h-[400px] text-muted ${a??``}`.trim(),children:`Failed to load video`})}function SS({oauthProviderId:r,onAuthChange:i}){let{client:a}=Q(),{t:o}=Z(),[s,c]=X(null),[l,u]=X(!0),[d,f]=X(!1),[p,m]=X(!1),h=K(async()=>{try{u(!0);let e=await a.oauthProviders.getStatus(r);c(e)}catch(e){console.error(`Failed to load OAuth provider status:`,e)}finally{u(!1)}},[a,r]);q(()=>{h()},[h]);let{openOAuthPopup:g}=vs({onComplete:()=>{f(!1),h(),i?.()},onError:e=>{console.error(`OAuth provider auth failed:`,e),f(!1)}});return l?t(gs,{className:`size-4`}):s?.authenticated?n(`div`,{className:`flex items-center gap-2`,children:[n(`div`,{className:`flex items-center gap-1 text-success text-sm`,children:[t(sn,{className:`size-4`}),t(`span`,{children:o(`oauthProvider.connected`)})]}),t(Bo,{variant:`outline`,size:`sm`,onClick:async()=>{if(!p)try{m(!0),await a.oauthProviders.disconnect(r),await h(),i?.()}catch(e){console.error(`Failed to disconnect OAuth provider:`,e)}finally{m(!1)}},disabled:p,children:p?t(gs,{className:`size-3`}):o(`oauthProvider.disconnect`)})]}):t(Bo,{variant:`outline`,size:`sm`,onClick:async()=>{if(!d)try{f(!0);let e=await a.oauthProviders.authorize(r);e.authorization_url&&g(e.authorization_url)}catch(e){console.error(`Failed to authorize OAuth provider:`,e),f(!1)}},disabled:d,children:d?n(e,{children:[t(gs,{className:`size-4`}),t(`span`,{children:o(`oauthProvider.authenticating`)})]}):n(e,{children:[t(Pn,{className:`size-4 me-1`}),t(`span`,{children:o(`oauthProvider.authenticate`)})]})})}function CS(...e){let t=Array.from(e);return t.__AnyOf__=!0,t}function wS(...e){return Array.from(e)}function TS(e){return e.__AnyOf__===!0}var ES=class{system_roles;roles;permissions;constructor(e,t=[]){this.system_roles=t;let n=[...e.account_roles||[],...e.project_roles||[]],r=new Set(n);this.roles=r;let i=e.permissions??DS(n,t),a=e.type===Pi.OAuthAccess?new Set(e.permissions??[]):void 0;this.permissions=new Set(a?i.filter(e=>a.has(e)):i)}hasPermission(e){if(typeof e==`string`)return this.permissions.has(e);if(TS(e))return e.some(e=>this.permissions.has(e));for(let t of e)if(!this.permissions.has(t))return!1;return!0}};function DS(e,t){let n=new Map(t.map(e=>[e.name,e.permissions])),r=new Set;for(let t of e)for(let e of n.get(t)??[])r.add(e);return Array.from(r)}const OS=ot(void 0);function kS(){let e=lt(OS);if(!e)throw Error(`UserPermissionContext cannot be used outside UserPermissionProvider`);return e}function AS({children:e}){let{t:n}=Z(),r=Q(),i=r.authToken,a=!!(i&&!i.permissions),{data:o,error:s,isLoading:c}=U(()=>a?r.client.iam.roles.listSystem():Promise.resolve(void 0),[r.client,i,a]),l=J(()=>{if(i){if(i.permissions||!a)return new ES(i);if(o&&!c)return new ES(i,o)}else return},[i,o,c,a]);return s?t(M,{title:n(`store.failedToFetchRoleMappings`),children:Ve(s)}):l&&t(OS.Provider,{value:l,children:e})}function jS({permission:e,isDisabled:n,title:r,children:i,...a}){return kS().hasPermission(e)?t(o,{isDisabled:n,title:r,...a,children:i}):null}function MS({permission:e,...n}){return kS().hasPermission(e)?t(wa,{...n}):null}const NS=new WeakMap;function PS(e,t){let n=NS.get(e);n||(n=new Map,NS.set(e,n));let r=n.get(t);return r||(r=e.types.catalog.resolve(t).then(e=>e??void 0,()=>{NS.get(e)?.delete(t)}),n.set(t,r)),r}function FS(e,t){let n=NS.get(e);n&&(t?n.delete(t):n.clear())}function IS(e){let t=e.configuration?.defaults?.system?.agent??e.configuration?.defaults?.base;return{environment:t?.environment,model:t?.model}}function LS(e){return e.name}function RS(e){return e.name}function zS(e){return e.split(`/`).filter(Boolean).pop()||e}function BS({value:e,onChange:r,disabled:i=!1,isLoading:a=!1}){let{client:s}=Q(),{t:c}=Z(),[l,u]=X([]),[d,f]=X([]),[p,m]=X(!0),[h,g]=X(!1),_=Y(void 0);q(()=>{let e=!1;return m(!0),s.environments.list().then(t=>{e||u(t.slice().sort((e,t)=>e.name.localeCompare(t.name)))}).catch(t=>{console.warn(`Failed to list document editing environments`,t),e||u([])}).finally(()=>{e||m(!1)}),()=>{e=!0}},[s]),q(()=>{if(!e.environment){f([]),g(!1);return}let t=!1,n=e.environment;return g(!0),s.environments.retrieve(n).then(e=>{t||f((e.enabled_models??[]).map(e=>({id:e.id,name:e.name||e.id})).sort((e,t)=>e.name.localeCompare(t.name)))}).catch(e=>{console.warn(`Failed to load document editing models`,e),t||f([])}).finally(()=>{t||g(!1)}),()=>{t=!0}},[s,e.environment]);let v=l.find(t=>t.id===e.environment),y=J(()=>{if(e.model)return d.find(t=>t.id===e.model)??{id:e.model,name:zS(e.model)}},[d,e.model]),b=e=>{_.current=e.id,r({environment:e.id}),s.environments.retrieve(e.id).then(t=>{if(_.current!==e.id)return;let n=t.default_model??t.enabled_models?.[0]?.id;r({environment:e.id,model:n})}).catch(e=>{console.warn(`Failed to select a default document editing model`,e)})},x=t=>{_.current=void 0,r({environment:e.environment,model:t.id})},S=y?.name||c(`agent.documentEditingSelectModel`);return n(de,{children:[t(pe,{asChild:!0,children:n(o,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 max-w-[15rem] gap-1.5 px-2 text-xs`,"aria-label":c(`agent.documentEditingConfiguration`),title:c(`agent.documentEditingConfiguration`),children:[a?t(De,{size:`sm`}):t(Zr,{className:`size-3.5 shrink-0`}),t(`span`,{className:`min-w-0 truncate`,children:S}),t(un,{className:`size-3.5 shrink-0 opacity-70`})]})}),n(fe,{align:`end`,className:`z-[1000000] w-80 space-y-3 p-3`,children:[n(`div`,{children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:c(`agent.documentEditingConfiguration`)}),t(`div`,{className:`mt-0.5 text-xs leading-4 text-muted`,children:c(i?`agent.documentEditingConfigurationLocked`:`agent.documentEditingConfigurationDescription`)})]}),n(`div`,{className:`space-y-1`,children:[t(`label`,{className:`text-xs font-medium text-foreground`,htmlFor:`document-editing-environment`,children:c(`agent.environment`)}),t(be,{id:`document-editing-environment`,by:`id`,options:l,value:v,optionLabel:LS,filterBy:`name`,placeholder:c(`agent.documentEditingSelectEnvironment`),onChange:b,disabled:i,isLoading:p})]}),n(`div`,{className:`space-y-1`,children:[t(`label`,{className:`text-xs font-medium text-foreground`,htmlFor:`document-editing-model`,children:c(`agent.model`)}),t(be,{id:`document-editing-model`,by:`id`,options:d,value:y,optionLabel:RS,filterBy:`name`,placeholder:c(`agent.documentEditingSelectModel`),onChange:x,disabled:i||!e.environment,isLoading:h,warnOnMissingValue:!1})]})]})]})}function VS({isLocked:e,onToggleLock:r}){let{t:i}=Z(),a=i(e?`agent.editingLockedTitle`:`agent.editingManuallyUnlockedTitle`),s=i(e?`agent.editingLockedDescription`:`agent.editingManuallyUnlockedDescription`),c=i(e?`agent.unlockEditing`:`agent.lockEditing`);return n(`div`,{className:`flex h-8 max-w-64 shrink-0 items-center gap-1 rounded-md border border-mixer-attention/30 bg-mixer-attention/10 ps-2 pe-1 text-attention`,role:e?`status`:`alert`,"aria-live":`polite`,children:[e?t(mr,{className:`size-3.5 shrink-0 animate-pulse`}):t(hr,{className:`size-3.5 shrink-0`}),t(Be,{description:s,asChild:!0,children:t(`span`,{className:`min-w-0 truncate text-xs font-medium text-foreground`,children:a})}),t(`span`,{className:`sr-only`,children:s}),t(Be,{description:c,asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,className:`size-6 shrink-0 rounded p-0 text-attention hover:bg-mixer-attention/15`,onClick:r,"aria-label":c,children:t(e?hr:mr,{className:`size-3.5`})})})]})}const HS=/artifact:(?!agents\/)(?!documents\/)([^\s)\]"]+)/g;function US(e){let t=new Set;for(let n of e.matchAll(HS))t.add(n[1].replace(/^\/+/,``));return[...t]}async function WS(e,t,n,r){let i=US(t);if(i.length===0)return{content:t,persisted:[],failed:[]};let a=new Map,o=[],s=[];for(let t of i){let i=`documents/${r}/${t}`;try{await e.copyFile(`agents/${n}/${t}`,i),a.set(t,i),o.push({from:t,to:i})}catch(e){console.warn(`Failed to persist a referenced artifact; keeping a run-scoped link`,{artifact_path:t,error:e instanceof Error?e.message:String(e)}),a.set(t,`agents/${n}/${t}`),s.push(t)}}return{content:t.replace(HS,(e,t)=>{let n=a.get(t.replace(/^\/+/,``));return n?`artifact:${n}`:e}),persisted:o,failed:s}}const GS=[`ask_user`,`think`,`plan`,`update_plan`,`end_conversation`,`learn_artifact_operations`,`learn_code_execution`,`learn_content_authoring`,`learn_document_management`,`learn_document_search`,`learn_image_analysis`,`execute_shell`,`fetch_document`],KS=[`artifact_operations`,`code_execution`],qS=[`update_document`,`update_document_properties`,`create_document`,`set_document_type`,`merge_documents`,`import_file`,`create_or_update_object_type`,`disable_type`,`batch_execute`];function JS(e,t){return[`Direct edits are already saved to '${e}'. Use this compact unified diff as context only;`,`do not re-apply it. The artifact remains the current source of truth.`,"```diff",`--- a/${e}`,`+++ b/${e}`,t,"```"].join(`
|
|
443
|
+
`)}const YS=`document-editing`,XS=`sys:GeneralAgent`,ZS=new Set,QS=new Set([`text/markdown`,`text/x-markdown`]),$S=new Set([...QS,`text/plain`]);function eC(e,t){return`${e}:${t}`}function tC(e){return ZS.has(e)}function nC(e,t){t?ZS.add(e):ZS.delete(e)}function rC(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:void 0}function iC(e){return`document-root:${e}`}function aC(e){return`document:${e}`}function oC(e,t){return{tags:[YS,iC(t),aC(e)],properties:{resource_kind:`store_document`,document_id:e,document_root_id:t}}}function sC(e,t){return{canEdit:e,canCollaborate:t}}function cC(e){return e?.split(`;`,1)[0]?.trim().toLowerCase()||void 0}function lC(e){let t=cC(e);return t!==void 0&&QS.has(t)}function uC(e){let t=cC(e);return t!==void 0&&$S.has(t)}function dC(e,t,n,r,i=XS){if(e.interaction!==i||e.started_by!==r||e.status===`cancelled`)return!1;let a=e.tags??[];if(!a.includes(YS))return!1;let o=rC(e.properties);return a.includes(iC(n))?o?.resource_kind===`store_document`&&o.document_root_id===n:a.includes(aC(n))||a.includes(aC(t))}async function fC(e,t,n,r,i,a){for(let o of t)try{let t=await e.retrieve(o);if(dC(t,n,r,i,a))return t}catch{}}async function pC(e,t,n,r,i=XS){let a=[iC(n),aC(n),aC(t)],o=new Set;for(let s of new Set(a))try{let a=(await e.search({interaction:i,started_by:r,tags:[s],limit:20,sort:[`updated_at:desc`]})).hits.map(e=>e.id).filter(e=>!o.has(e));for(let e of a)o.add(e);let c=await fC(e,a,t,n,r,i);if(c)return c}catch{break}return(await e.list({interaction:i,started_by:r,limit:100,sort:`updated_at`,order:`desc`})).items.find(e=>e.run_kind===`agent`&&dC(e,t,n,r,i))}var mC=class extends Error{constructor(e,t){super(e,t===void 0?void 0:{cause:t}),this.name=`DocumentEditingTargetError`}};async function hC(e,t){let n=await e.retrieve(t),r=n;if(n.revision&&!n.revision.head){let i=(await e.getRevisions(n.id)).filter(e=>e.revision?.head===!0);if(i.length!==1)throw new mC(`Expected one head revision for document ${t}, found ${i.length}`);if(r=await e.retrieve(i[0].id),r.revision?.head!==!0)throw new mC(`Resolved document ${r.id} is no longer the current head`)}let i=r.content?.etag;if(!i)throw new mC(`Document ${r.id} has no content ETag`);let a=await e.getObjectText(r.id);if(typeof a.text!=`string`)throw new mC(`Document ${r.id} has no text content`);return{id:r.id,etag:i,content:a.text}}var gC=class extends ge{idOf(e){return e.id}labelOf(e){return e.label}descriptionOf(e){return e.description}selectedClassName(e){return`border-3 border-primary`}};function _C({isOpen:e,onClose:r,onConfirm:i,isLoading:a,uploadedFileName:s}){let{t:c}=Z(),l=J(()=>[{id:`update`,label:c(`modal.saveVersion.updateCurrent`),description:c(s?`modal.saveVersion.updateWithFileDescription`:`modal.saveVersion.updateDescription`)},{id:`new-version`,label:c(`modal.saveVersion.createNew`),description:c(s?`modal.saveVersion.createWithFileDescription`:`modal.saveVersion.createDescription`)}],[c,s]),u=s?l[1]:l[0],[d,f]=X(u),[p,m]=X(``),h=new gC;q(()=>{e&&(f(u),m(``))},[u,e]);let g=d?.id===`new-version`;return n(ie,{isOpen:e,onClose:r,className:`sm:max-w-md`,children:[t(se,{children:c(`modal.saveChanges`)}),t(ae,{children:n(`div`,{className:`space-y-4`,children:[s&&t(`div`,{className:`mb-4 p-3 bg-blue-50 dark:bg-blue-900/20 rounded-md`,children:n(`p`,{className:`text-sm text-blue-700 dark:text-blue-300 font-medium`,children:[c(`modal.saveVersion.replaceFile`),` `,t(`span`,{className:`font-bold`,children:s})]})}),t(`p`,{className:`text-sm text-mixer-muted/5`,children:c(`modal.saveVersion.howToSave`)}),t(he,{adapter:h,options:l,selected:d,onSelect:e=>{f(e)}}),g&&t(L,{label:c(`modal.saveVersion.versionLabel`),description:c(`modal.saveVersion.versionLabelDescription`),className:`mt-3 ps-8`,children:t(R,{value:p,onChange:m,placeholder:c(`modal.saveVersion.versionLabelPlaceholder`),className:`w-full`})})]})}),n(oe,{children:[t(o,{variant:`secondary`,onClick:r,disabled:a,children:c(`modal.cancel`)}),t(o,{variant:`primary`,onClick:async()=>{await i(g,g?p:void 0)},isLoading:a,children:c(`modal.save`)})]})]})}function vC(e){return e.length>12?`${e.slice(0,4)}…${e.slice(-4)}`:e}function yC(e){return`drafts/${e}.md`}function bC(e,t,n,r,i){return[`You are collaborating with the user on one specific Markdown document in Vertesia.`,`Canonical document: [${e.name||e.content?.name||`Document`}](store:${t})`,`Canonical base revision ID: ${t}`,`Canonical base ETag: ${n??`unavailable`}`,`Working copy artifact: ${r}`,``,`The working copy was hydrated and read before your first turn. It is the source of truth for this editing`,`session. Apply requested changes only to that artifact using edit_artifact. Preserve all unrelated content`,`exactly. User block edits may already be applied to the artifact; acknowledge them and continue from the`,`current artifact generation. Attachments may contain review comments to apply in bulk.`,``,`Do not call update_document, create_document, or write_artifact for this working copy. The user publishes`,`the artifact back to the canonical document with the Save to document button, which enforces the base ETag.`,``,`You may use execute_shell to regenerate charts, diagrams, and other derived assets. Write generated files`,`under '/home/daytona/out/' so they sync back to the run, then reference them from Markdown with a run-local`,`link such as 'artifact:out/chart.png'. Saving the document persists and rewrites those links automatically.`,``,`Images: never inline image data as base64 data URIs — it bloats the document and cannot be reliably edited.`,`Keep existing image references (e.g. 'artifact:documents/…' URLs) exactly as they are: they point to durable`,`storage that outlives this session. Files already in this run's artifact space may be referenced with`,`run-local links like 'artifact:files/photo.png' — publishing copies them into durable storage and rewrites`,`the links automatically.`,``,`User request: ${i}`].join(`
|
|
444
|
+
`)}function xC(e,t,n){return[`The canonical document was updated outside this session, so publishing the working copy was rejected.`,`1) Fetch the latest canonical revision ${t} with fetch_document into 'drafts/${e}.theirs.md'.`,`2) Compare it with the working copy '${n}' and merge the external changes into the working copy with edit_artifact, preserving this session's edits.`,`3) Reply with a short list of what was merged, plus any conflicting passages and how you resolved them, so I can review before saving again.`].join(`
|
|
445
|
+
`)}function SC(e,t,n){return[`Summarize the changes in the working copy '${n}' relative to the original document revision ${t}.`,`If you no longer have the original content, fetch it with fetch_document into 'drafts/${e}.base.md'.`,`Do not modify the working copy.`,`Reply with a concise changelog: grouped bullets, most important first, suitable for a revision note.`].join(`
|
|
446
|
+
`)}function CC(e){if(!(!e||typeof e!=`object`||!(`status`in e)))return typeof e.status==`number`?e.status:void 0}function wC({original:e,workingCopy:r}){let i=J(()=>Mt(e,r),[e,r]),a=J(()=>({added:i.reduce((e,t)=>e+(t.type===`added`?t.text.length:0),0),removed:i.reduce((e,t)=>e+(t.type===`removed`?t.text.length:0),0)}),[i]);return n(`div`,{className:`flex h-full min-h-0 flex-col bg-muted/10`,children:[n(`div`,{className:`flex shrink-0 items-center justify-end gap-3 border-b border-mixer-muted/20 px-5 py-2 text-xs`,children:[n(`span`,{className:`text-destructive`,children:[`−`,a.removed]}),n(`span`,{className:`text-success`,children:[`+`,a.added]})]}),t(`div`,{className:`min-h-0 flex-1 overflow-auto p-5`,children:t(`pre`,{className:`mx-auto max-w-5xl whitespace-pre-wrap break-words rounded-lg border border-mixer-muted/25 bg-background p-5 font-mono text-xs leading-6 shadow-sm`,children:i.map((e,n)=>e.type===`removed`?t(`del`,{className:`bg-mixer-destructive/15 text-destructive line-through decoration-destructive/50`,children:e.text},n):e.type===`added`?t(`ins`,{className:`bg-mixer-success/15 text-success no-underline`,children:e.text},n):t(`span`,{children:e.text},n))})})]})}function TC({object:r,initialContent:i=``,onDocumentUpdated:a,onClose:s,sendMessageRef:c,model:l,startImmediately:u=!1}){let{client:d,project:f,store:m,user:h}=Q(),{t:g}=Z(),_=Xe(),v=Y(null),y=c??v,[x,S]=X(),[C,w]=X(!1),[T,E]=X(!1),[D,O]=X(!0),[k,A]=X(!0),[j,M]=X(!1),[N,P]=X(0),[F,I]=X(!1),L=JSON.stringify(l?{environment:l.env,model:l.model,model_options:l.options}:{}),ee=l!==void 0,R=J(()=>JSON.parse(L),[L]),[te,z]=X(!ee),[ne,B]=X(!1),[re,ie]=X(!1),[ae,oe]=X(!1),[se,ce]=X(!1),[V,le]=X(!1),[ue,de]=X(!1),[fe,pe]=X({key:0}),[me,he]=X(i),[ge,be]=X(!1),[xe,Se]=X(i),[Ce,we]=X(i),[Te,Ee]=X(`document`),[Oe,ke]=X(),[Ae,je]=X(r.id),[Me,Ne]=X(r.content?.etag),[Pe,Fe]=X(),[Ie,Le]=X(R),Re=Y(ee?`host`:`none`),ze=Y(void 0),H=Y(new Set),He=Y(void 0),Ue=Y(!1),We=Y(null),U=r.revision?.root||r.id,Ge=J(()=>yC(U),[U]),Ke=h?.sub?`user:${h.sub}`:void 0,W=`${f?.id??`no-project`}:${U}`,qe=`${W}:${r.type?.id??`no-type`}`,Je=Pe?.key===qe?Pe.interaction:void 0,Ye=Y(W),Ze=Y({editingScopeKey:W,id:r.id}),Qe=Y({documentId:r.id,documentRootId:U}),$e=ge&&me!==Ce,et=se&&!V;Qe.current.documentRootId!==U&&(Qe.current={documentId:r.id,documentRootId:U}),Ze.current.editingScopeKey!==W&&(Ze.current={editingScopeKey:W,id:r.id}),q(()=>{Ye.current!==W&&(Ye.current=W,Re.current=ee?`host`:`none`,Le(R),z(!ee),H.current.clear(),he(i),Se(i),we(i),be(!1),de(!1),ce(!1),le(!1),Ue.current=!1,Ee(`document`),je(r.id),Ne(r.content?.etag))},[W,ee,i,r.content?.etag,r.id,R]),q(()=>{let e=!1,t=W,n=Ze.current.id;return A(!0),M(!1),hC(m.objects,n).then(n=>{e||Ze.current.editingScopeKey!==t||(Ze.current={editingScopeKey:t,id:n.id},Qe.current={documentId:n.id,documentRootId:U},je(n.id),Ne(n.etag),Se(n.content),we(n.content))}).catch(n=>{console.warn(`Failed to resolve the document editing target`,{error:n,attempt:N}),!e&&Ze.current.editingScopeKey===t&&M(!0)}).finally(()=>{!e&&Ze.current.editingScopeKey===t&&A(!1)}),()=>{e=!0}},[U,W,m.objects,N]),q(()=>{let e=!1,t=r.type?.id;if(!t){Fe({key:qe,interaction:XS});return}return PS(d,t).then(t=>{e||Fe({key:qe,interaction:t?.editing?.interaction?.trim()||`sys:GeneralAgent`})}),()=>{e=!0}},[d,qe,r.type?.id]),q(()=>{x||Re.current===`run`||(ee?(Re.current=`host`,Le(R),z(!1)):Re.current===`host`&&(Re.current=`none`,Le({})))},[x,ee,R]),q(()=>{if(ee){z(!1);return}if(!f){z(!1);return}let e=!1,t=W;return z(!0),d.projects.retrieve(f.id).then(n=>{e||Ye.current!==t||Re.current!==`none`||(Re.current=`project`,Le(IS(n)))}).catch(e=>{console.warn(`Failed to load the default document editing model`,e)}).finally(()=>{e||z(!1)}),()=>{e=!0}},[d,W,ee,f]),q(()=>{if(S(void 0),!Ke||!Je){O(!1);return}let e=!1;return O(!0),pC(d.agents,Qe.current.documentId,U,Ke,Je).then(t=>{e||!t||(S(t.id),t.config?.environment&&t.config.model&&(Re.current=`run`,Le({environment:t.config.environment,model:t.config.model,model_options:t.config.model_options})))}).catch(e=>{console.warn(`Failed to look up an existing document editing run`,e)}).finally(()=>{e||O(!1)}),()=>{e=!0}},[d,U,Je,Ke]);let tt=K(e=>{Re.current=`user`,Le(e)},[]),nt=K(()=>{x&&navigator.clipboard.writeText(x).then(()=>_({status:`success`,title:g(`agent.runIdCopied`),duration:2e3})).catch(e=>console.warn(`Failed to copy the agent run id`,e))},[x,g,_]),G=K(async()=>{if(!(!x||T)){E(!0);try{await d.agents.terminate(x,`cancel`),_({status:`success`,title:g(`agent.workflowCancelled`),duration:2e3})}catch(e){console.warn(`Failed to terminate the document editing run`,e)}finally{E(!1)}H.current.clear(),S(void 0),be(!1),he(Ce),de(!1),Ue.current=!1,ce(!1),le(!1)}},[x,d.agents,T,Ce,g,_]),rt=K(async(e,t)=>{if(!(!f||!Je||D||k||j||C||te)){w(!0);try{if(!Ie.environment||!Ie.model){_({status:`error`,title:g(`agent.documentEditingDefaultsRequired`),duration:5e3});return}let n=bC(r,Ae,Me,Ge,e?.trim()||g(`agent.documentEditingInitialRequest`)),i=oC(Ae,U),a={interaction:Je,interactive:!0,tool_approval_mode:t?.tool_approval_mode,tool_names:GS,excluded_tools:qS,initial_skills:KS,initial_tool_calls:[{id:`hydrate-working-copy`,tool:`fetch_document`,input:{id:Ae,mode:`content`,output_artifact:{path:Ge}}},{id:`read-working-copy`,tool:`read_artifact`,input:{path:Ge}}],data:{user_prompt:n},config:{environment:Ie.environment,model:Ie.model,model_options:Ie.model_options},started_by:Ke,tags:i.tags,properties:i.properties},o=await d.agents.start(a);return S(o.id),{agent_run_id:o.id}}catch(e){console.error(`Failed to start document editing agent`,e),_({status:`error`,title:g(`agent.documentEditingStartFailed`),description:e instanceof Error?e.message:void 0,duration:5e3});return}finally{w(!1)}}},[d.agents,U,Ge,Ie,Je,te,D,k,C,r,f,Ke,g,Ae,Me,j,_]),it=K((e,t)=>{He.current=t,he(e),be(!0)},[]);q(()=>{if(!u||x||!f||!Je||D||k||j||C||te||!Ie.environment||!Ie.model)return;let e=JSON.stringify({scope:W,interaction:Je,document:Ae,configuration:Ie});ze.current!==e&&(ze.current=e,rt(g(`agent.documentEditingStartRequest`),{tool_approval_mode:`full_control`}))},[x,Je,W,Ie,te,D,k,C,f,u,rt,g,Ae,j]);let at=K(e=>{let t=Ue.current;Ue.current=e,ce(e),e||(le(!1),t&&pe(e=>({key:e.key+1})))},[]),ot=K((e,t)=>{let n=y.current;if(!n){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}n(e,t)},[y,g,_]),st=K(e=>{let t=e.anchor.block_type.replaceAll(`_`,` `),n=e.comment?.trim()||g(`agent.editedSelectionMessage`,{blockType:t});ot(n,{editing_action:e})},[ot,g]),ct=K(async(e,t)=>{if(!(!ge||!Me||!$e||et||ne||k||j)){B(!0);try{let n=me;x&&(n=(await WS(d.files,n,x,crypto.randomUUID())).content);let i=r.content?.type||`text/markdown`,o=r.content?.name||`content.md`,s=new File([new Blob([n],{type:i})],o,{type:i}),c=await m.objects.update(Ae,{content:s},{createRevision:e,revisionLabel:t,ifMatch:Me});if(je(c.id),Ne(c.content?.etag),we(n),ke(void 0),ie(!1),a?.(c.id,e),_({status:`success`,title:g(`store.textSaved`),duration:2500}),x&&n!==me&&He.current)try{await d.agents.updateArtifactContent(x,Ge,{content:n,generation:He.current}),pe(e=>({key:e.key+1}))}catch(e){console.warn(`Failed to sync persisted artifact links into the working copy`,e)}}catch(e){let t=CC(e),n=t===412;if(t===412||t===400)try{let e=await hC(m.objects,Ae);(e.id!==Ae||t===412)&&(n=!0,je(e.id),Ne(e.etag),ke({headId:e.id}))}catch(e){console.warn(`Failed to resolve the new head after a save conflict`,e)}_({status:`error`,title:g(`store.errorSavingText`),description:n?g(`store.textConflict`):Ve(e,g(`store.errorSavingTextDefault`)),duration:5e3})}finally{B(!1)}}},[x,me,ge,d.agents,d.files,Ge,$e,et,k,ne,r.content?.name,r.content?.type,a,m.objects,g,Ae,Me,j,_]),lt=K(()=>{let e=y.current;if(!e||!Oe){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}e(xC(U,Oe.headId,Ge)),ke(void 0),Ee(`document`)},[U,Ge,y,Oe,g,_]),ut=K(()=>{let e=y.current;if(!e){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}e(SC(U,Ze.current.id,Ge))},[U,Ge,y,g,_]),dt=K(async()=>Te!==`editor`||!ue||!!await We.current?.(),[ue,Te]),ft=K(async e=>{e!==Te&&await dt()&&Ee(e)},[dt,Te]),pt=K(async()=>{await dt()&&s?.()},[dt,s]),mt=K(async()=>{let e=y.current;if(!e||!x||et||ae){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}oe(!0);try{let t=await We.current?.();if(!t)return;let n=jt(t.previous,t.current,{context:1});n&&e(JS(Ge,n)),de(!1),_({status:`success`,title:g(`agent.changesSentToAgent`),duration:2e3})}finally{oe(!1)}},[x,Ge,et,ae,y,g,_]);return n(`div`,{className:`flex h-full min-h-0 flex-col`,children:[n(`div`,{className:`flex h-14 shrink-0 items-center justify-between gap-3 border-b border-mixer-muted/20 px-4`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`truncate font-semibold`,children:r.name||r.content?.name}),n(`div`,{className:`flex items-center gap-2 text-xs text-muted`,children:[n(`span`,{className:`flex shrink-0 items-center gap-1.5`,children:[$e?t(`span`,{"aria-hidden":!0,className:`size-1.5 rounded-full bg-attention`}):ge?t(rn,{className:`size-3 text-success`}):null,g($e?`store.unsavedChanges`:`store.textSaved`)]}),t(`span`,{"aria-hidden":!0,className:`text-mixer-muted/60`,children:`·`}),t(Be,{description:`${g(`agent.workingCopy`)}: ${Ge}`,asChild:!0,children:n(`span`,{className:`min-w-0 truncate font-mono`,children:[`drafts/`,vC(U),`.md`]})}),t(`span`,{"aria-hidden":!0,className:`text-mixer-muted/60`,children:`·`}),t(Be,{description:`${g(`agent.originalDocument`)}: ${Ze.current.id}`,asChild:!0,children:n(`span`,{className:`shrink-0 font-mono`,children:[g(`agent.originalDocument`).toLowerCase(),` `,vC(Ze.current.id)]})})]})]}),n(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[n(`div`,{className:`flex items-center rounded-md border border-mixer-muted/25 bg-muted/10 p-0.5`,children:[n(o,{variant:Te===`document`?`secondary`:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:()=>void ft(`document`),children:[t(Hn,{className:`size-3.5`}),g(`agent.document`)]}),n(o,{variant:Te===`editor`?`secondary`:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:()=>void ft(`editor`),children:[t(Bn,{className:`size-3.5`}),g(`agent.fullEditor`)]}),n(o,{variant:Te===`diff`?`secondary`:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:()=>void ft(`diff`),disabled:!ge||me===xe,children:[t(Xn,{className:`size-3.5`}),g(`agent.reviewChanges`)]})]}),Te===`diff`?n(o,{variant:`ghost`,size:`sm`,className:`h-8 gap-1.5`,onClick:ut,disabled:!ge||me===xe,children:[t(dr,{className:`size-3.5`}),g(`agent.summarizeChanges`)]}):null,t(Be,{description:g(`agent.refresh`),asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,onClick:()=>pe(e=>({key:e.key+1})),disabled:!x,"aria-label":g(`agent.refresh`),children:t(zr,{className:`size-4`})})}),t(`div`,{"aria-hidden":!0,className:`mx-1 h-6 w-px bg-mixer-muted/25`}),t(BS,{value:Ie,onChange:tt,disabled:!!x||C||D,isLoading:te}),x?null:n(o,{variant:`primary`,size:`sm`,className:`h-8 gap-1.5`,onClick:()=>void rt(g(`agent.documentEditingStartRequest`)),disabled:C||D||k||te||j||!f||!Je||!Ie.environment||!Ie.model,children:[C?t(De,{size:`sm`}):t(Qr,{className:`size-4`}),g(C?`agent.startingAgent`:`agent.documentEditingStart`)]}),x?n(e,{children:[t(Be,{description:x,asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,className:`font-mono text-[11px] text-muted`,onClick:nt,"aria-label":g(`agent.copyRunId`),children:vC(x)})}),t(Be,{description:g(`agent.startNewConversation`),asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,onClick:()=>{$e?I(!0):G()},disabled:T,"aria-label":g(`agent.startNewConversation`),children:t(Vr,{className:`size-4`})})})]}):null,t(`div`,{"aria-hidden":!0,className:`mx-1 h-6 w-px bg-mixer-muted/25`}),n(o,{variant:`primary`,className:`min-w-36 gap-2`,onClick:()=>ie(!0),disabled:!$e||!Me||et||ne||k||j,children:[ne?t(De,{size:`sm`}):t(Wr,{className:`size-4`}),g(`agent.saveToDocument`)]}),s?t(o,{variant:`ghost`,size:`sm`,onClick:()=>void pt(),"aria-label":g(`agent.close`),children:t(mi,{className:`size-4`})}):null]})]}),Oe?n(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-b border-mixer-attention/30 bg-mixer-attention/10 px-4 py-2 text-sm`,children:[t(`span`,{className:`min-w-0 truncate text-attention`,children:g(`agent.saveConflictNotice`)}),n(`div`,{className:`flex shrink-0 items-center gap-2`,children:[t(o,{variant:`outline`,size:`sm`,onClick:lt,children:g(`agent.askAgentToReconcile`)}),t(o,{variant:`ghost`,size:`sm`,onClick:()=>ke(void 0),"aria-label":g(`agent.close`),children:t(mi,{className:`size-4`})})]})]}):null,n(ye,{direction:`horizontal`,className:`min-h-0 flex-1`,children:[t(ve,{defaultSize:65,minSize:35,className:`min-w-0 bg-background`,children:t(`div`,{className:`flex h-full min-h-0 flex-col`,children:t(`div`,{className:`min-h-0 flex-1`,children:Te===`diff`?t(wC,{original:xe,workingCopy:me}):t(ht,{runId:x,path:Ge,viewMode:Te===`editor`?`document`:`components`,baselineContent:xe,initialContent:Ce,refreshKey:fe.key,refreshDetails:fe.details,readOnly:et,allowComments:!!x,onContentChange:it,onAction:st,onSendMessage:ot,onSendChangesToAgent:mt,hasUnsentChanges:$e&&ue,isSendingChanges:ae,sendChangesDisabled:!x||et,toolbarStatus:se?t(VS,{isLocked:et,onToggleLock:()=>le(e=>!e)}):void 0,onDocumentEdit:()=>de(!0),flushChangesRef:We})})})}),t(_e,{withHandle:!0}),t(ve,{defaultSize:35,minSize:25,className:`min-w-[320px]`,children:D||k?t(p,{className:`h-full`,children:t(De,{size:`lg`})}):j?n(p,{className:`h-full flex-col gap-3 px-6 text-center`,children:[t(`div`,{className:`text-sm text-muted`,children:g(`agent.failedToLoadDocument`)}),t(o,{variant:`outline`,size:`sm`,onClick:()=>P(e=>e+1),children:g(`agent.retry`)})]}):t(ux,{agentRunId:x,startWorkflow:rt,resetWorkflow:()=>S(void 0),onRestart:e=>S(e.id),sendMessageRef:y,onMessage:e=>{let t=e.details;if(!Pt(t,Ge))return;let n=`${e.timestamp}:${t?.path}:${t?.generation??``}`;H.current.has(n)||(H.current.add(n),pe(e=>({key:e.key+1,details:t})))},onAgentWorkingChange:at,title:g(`agent.documentEditing`),initialMessage:g(`agent.documentEditingWelcome`),startButtonText:g(C?`agent.startingAgent`:`agent.startAgent`),placeholder:g(`agent.documentEditingPlaceholder`),initialToolApprovalMode:`full_control`,hideObjectLinking:!0,hideHeader:!0,showRightPanel:!1,fullWidth:!0,interactive:!0})})]}),t(b,{isOpen:F,title:g(`agent.newSessionDiscardTitle`),content:g(`agent.newSessionDiscardDescription`),onConfirm:()=>{I(!1),G()},onCancel:()=>I(!1)}),t(_C,{isOpen:re,onClose:()=>ie(!1),onConfirm:ct,isLoading:ne})]})}function EC({object:e,initialContent:n,onClose:r,onDocumentUpdated:i,sendMessageRef:a,model:o,startImmediately:s}){let{t:c}=Z();return t(ie,{isOpen:!0,onClose:r,size:`full`,noCloseButton:!0,disableCloseOnClickOutside:!0,className:`gap-0 overflow-hidden p-0`,description:c(`agent.documentEditingWelcome`),children:t(TC,{object:e,initialContent:n,onClose:r,onDocumentUpdated:i,sendMessageRef:a,model:o,startImmediately:s})})}function DC({isOpen:r,onClose:i,object:a,refetch:s}){let{client:c,store:l}=Q(),u=Xe(),{t:d}=Z(),{theme:f}=Ye(),p=_a(),[m,h]=X(!1),[g,_]=X(``),[v,y]=X(!1),[b,x]=X(null),S=Y(void 0),[C,w]=X(null),[T,E]=X(null),D=K(async e=>{try{let t=await l.types.retrieve(e);t.object_schema&&w(t.object_schema)}catch(e){console.error(`Failed to fetch JSON schema:`,e)}},[l.types]);q(()=>{r&&(_(JSON.stringify(a.properties||{},null,2)),a.type?.id&&D(a.type.id))},[r,a,D]);let O=e=>{C&&e.json.jsonDefaults.setDiagnosticsOptions({validate:!0,schemas:[{uri:`http://myserver/object-schema.json`,fileMatch:[`*`],schema:C}]})};function k(){if(!S.current)return;let e=S.current.getValue();try{let t=JSON.parse(e);x(t),y(!0)}catch{u({status:`error`,title:d(`store.invalidJson`),description:d(`store.pleaseFixJsonSyntax`),duration:5e3})}}let A=e=>{_(e)};async function j(e,t){try{h(!0);let n=b||JSON.parse(g);if(e){let e=await c.objects.update(a.id,{properties:n},{createRevision:!0,revisionLabel:t});e.id!==a.id&&E(e.id),u({status:`success`,title:d(`store.newVersionCreated`),description:d(`store.newVersionCreatedDesc`),duration:2e3}),y(!1),i(),e.id!==a.id&&setTimeout(()=>{p(`/objects/${e.id}`),u({status:`info`,title:d(`store.viewingNewVersion`),description:t?d(`store.viewingVersionLabel`,{label:t}):d(`store.viewingNewVersionDefault`),duration:3e3})},100)}else await l.objects.update(a.id,{properties:n}),u({status:`success`,title:d(`store.propertiesUpdated`),description:d(`store.propertiesUpdatedDesc`),duration:2e3}),s&&await s(),y(!1),i()}catch(e){u({status:`error`,title:d(`store.errorUpdatingProperties`),description:Ve(e,d(`store.errorUpdatingPropertiesDefault`)),duration:5e3}),h(!1)}}function M(){y(!1)}return n(e,{children:[n(ie,{isOpen:r,onClose:i,className:`sm:max-w-[90%] md:max-w-[80%] lg:max-w-[75%] xl:max-w-[70%]`,children:[t(se,{children:d(`store.editProperties`)}),n(ae,{children:[n(`div`,{className:`mb-2 text-sm text-gray-500`,children:[a.type?.name?n(`span`,{children:[`Editing properties for object type: `,t(`strong`,{children:a.type.name})]}):t(`span`,{children:d(`store.editingGenericDocument`)}),C!==null&&t(`span`,{className:`ms-2 text-green-600`,children:`(JSON schema validation enabled)`})]}),t(`div`,{className:`h-[75vh] border rounded-md overflow-hidden`,children:t(Tt,{value:g,language:`json`,editorRef:S,onChange:e=>A(e.state.doc.toString()),beforeMount:O,theme:f===`dark`?`vs-dark`:`vs`})})]}),n(oe,{children:[t(o,{variant:`secondary`,onClick:i,children:`Cancel`}),t(o,{variant:`primary`,onClick:k,children:`Save Changes`})]})]}),t(_C,{isOpen:v,onClose:M,onConfirm:j,isLoading:m})]})}const OC=st(()=>import(`@vertesia/ui/rich-text`).then(e=>({default:e.VertesiaMarkdownDocumentEditor})));function kC(e){switch(e){case`text/markdown`:case`text/x-markdown`:return`markdown`;case`application/json`:return`json`;case`application/xml`:case`text/xml`:return`xml`;default:return`plaintext`}}function AC({object:r,text:i,onClose:a,onSaved:s}){let{store:c}=Q(),l=Xe(),{t:u}=Z(),{theme:d}=Ye(),f=_a(),p=Y(void 0),[m,h]=X(i),[g,_]=X(!1),[v,y]=X(!1),[b,x]=X(!1),S=kC(r.content?.type),C=lC(r.content?.type);q(()=>{h(i),_(!1)},[i]);let w=K(()=>{g||_(!0)},[g]),T=K(e=>{h(e),_(e!==i)},[i]);function E(){!C&&!p.current||x(!0)}async function D(e,t){if(!C&&!p.current)return;let n=C?m:p.current?.getValue();if(n===void 0)return;let i=r.content?.type||`text/plain`,o=r.content?.name||`content.txt`;try{y(!0);let d=new Blob([n],{type:i}),p=new File([d],o,{type:i}),m=await c.objects.update(r.id,{content:p},{createRevision:e,revisionLabel:t,ifMatch:r.content?.etag});l({status:`success`,title:u(`store.textSaved`),duration:2e3}),x(!1),e&&m.id!==r.id?(a(),setTimeout(()=>{f(`/objects/${m.id}`)},100)):s()}catch(e){let t=Ve(e,u(`store.errorSavingTextDefault`)),n=(typeof e==`object`&&e&&`status`in e?e.status:void 0)===412||t.includes(`412`);l({status:`error`,title:u(`store.errorSavingText`),description:n?u(`store.textConflict`):t,duration:5e3})}finally{y(!1)}}return n(e,{children:[n(`div`,{className:`flex items-center gap-2 px-2 py-1 shrink-0`,children:[g&&t(`span`,{className:`text-xs text-attention`,children:u(`store.unsavedChanges`)}),t(`div`,{className:`flex-1`}),t(o,{variant:`ghost`,size:`sm`,onClick:a,disabled:v,children:u(`store.cancelEdit`)}),t(o,{variant:`secondary`,size:`sm`,onClick:E,disabled:!g,isLoading:v,children:u(`store.saveText`)})]}),t(`div`,{className:`flex-1 min-h-0 border rounded-md overflow-hidden mx-2 mb-2`,children:C?t(at,{fallback:t(`div`,{className:`h-full w-full`}),children:t(OC,{value:m,onChange:T})}):t(Tt,{value:i,language:S,editorRef:p,onChange:w,theme:d===`dark`?`vs-dark`:`vs`,options:{wordWrap:`on`,minimap:{enabled:!1},lineNumbers:`on`,scrollBeyondLastLine:!1}})}),t(_C,{isOpen:b,onClose:()=>x(!1),onConfirm:D,isLoading:v})]})}const jC=131072;function MC(e,t,n=!1,r=e){let{store:i}=Q(),[a,o]=X(t),[s,c]=X(()=>t&&t.length>jC?t.substring(0,jC):t),[l,u]=X(!1),[d,f]=X(()=>!!t&&t.length>jC),[p,m]=X(),h=Y(t),g=Y(e),_=Y(r),v=Y(!1),y=K((e,t=!0)=>{let n=h.current;t&&n&&e&&n!==e?m(e=>({previousText:n,version:(e?.version??0)+1})):t||m(void 0),h.current=e,o(e),e&&e.length>jC?(c(e.substring(0,jC)),f(!0)):(c(e),f(!1))},[]),b=K(()=>{let t=e,n=r;u(!0),i.objects.getObjectText(e).then(e=>{if(g.current!==t)return;let r=_.current===n&&!v.current;y(e.text,r),v.current=!1}).catch(e=>{console.error(`Failed to load text`,e)}).finally(()=>{g.current===t&&u(!1)})},[y,r,e,i]);return dt(()=>{let i=g.current!==e,a=_.current!==r;g.current=e,_.current=r,a&&(v.current=!0),t!==void 0&&(y(t,!a),v.current=!1),n&&t===void 0&&(i||h.current===void 0)&&b()},[y,r,t,n,b,e]),{fullText:a,displayText:s,isLoading:l,isCropped:d,changeHighlight:p,loadText:b}}function NC(e,t){let{client:n}=Q(),[r,i]=X({isComplete:!1});return q(()=>{if(!t)return;let r=!1,a,o=(e,t,n)=>{i(r=>{let i=JSON.stringify(r.progress??null),a=JSON.stringify(e??null);return r.status===t&&r.isComplete===n&&i===a?r:{progress:e,status:t,isComplete:n}})};function s(){r||n.objects.analyze(e).getStatus().then(e=>{e.status===zi.RUNNING?(o(e.progress,e.status,!1),r||(a=setTimeout(s,2e3))):o(e.progress,e.status,!0)}).catch(()=>{r||(a=setTimeout(s,1e4))})}return s(),()=>{r=!0,a&&clearTimeout(a)}},[t,e,n]),{progress:r.progress,status:r.status,isComplete:r.isComplete}}function PC(e,t){let{client:n}=Q(),r=Vt.getFixedT(null,Bt),[i,a]=X(),[o,s]=X(!1),[c,l]=X();return{pdfUrl:i,isConverting:o,error:c,triggerConversion:K(async()=>{if(!t||o)return;s(!0),l(void 0);let i=async t=>{try{let o=await n.objects.getRendition(e,{format:Ai.pdf,generate_if_missing:t,sign_url:!0,block_on_generation:!1});o.status===`generating`?setTimeout(()=>i(!1),5e3):o.status===`found`&&o.renditions?.length?(a(o.renditions[0]),s(!1)):o.status===`failed`&&(l(r(`store.pdfConversionFailed`)),s(!1))}catch(e){console.error(`Failed to convert Office document to PDF:`,e),l(r(`store.failedToConvertToPdf`)),s(!1)}};await i(!0)},[e,t,o,n,r])}}Ag();const FC=()=>({a:({node:e,...n})=>{let r=n.href||``;return r.includes(`/store/objects/`)?t(ga,{topLevelNav:!0,href:r,className:`text-info`,children:n.children}):t(`a`,{...n,target:`_blank`,rel:`noopener noreferrer`})},p:({node:e,...n})=>t(`p`,{...n,className:`my-0`}),pre:({node:e,...n})=>t(`pre`,{...n,className:`my-2 p-2 rounded`}),code:({node:e,className:n,children:r,...i})=>{let a=!/language-(\w+)/.exec(n||``);return t(`code`,{...i,className:a?`px-1.5 py-0.5 rounded`:`text-muted`,children:r})},h1:({node:e,...n})=>t(`h1`,{...n,className:`font-bold text-2xl my-2`}),h2:({node:e,...n})=>t(`h2`,{...n,className:`font-bold text-xl my-2`}),h3:({node:e,...n})=>t(`h3`,{...n,className:`font-bold text-lg my-2`}),li:({node:e,...n})=>t(`li`,{...n})});function IC(e){return e===Ti.created||e===Ti.processing}function LC(e){return e.metadata?.content_processor?.type}function RC(e){return e?e.includes(`
|
|
449
447
|
# `)||e.includes(`
|
|
450
448
|
## `)||e.includes(`
|
|
451
449
|
### `)||e.includes(`
|
|
452
450
|
* `)||e.includes(`
|
|
453
451
|
- `)||e.includes(`
|
|
454
|
-
+ `)||e.includes(`:!1}function JC(e){return e?`h-full overflow-auto`:`hidden`}var YC;(function(e){e.Text=`text`,e.Image=`image`,e.Video=`video`,e.Audio=`audio`,e.Pdf=`pdf`,e.Transcript=`transcript`})(YC||={});function XC({object:r,loadText:i,refetch:a,canEditProperties:o=!0,canCollaborate:s=!1}){let c=Ye(),{t:l}=X(),{project:u,store:d}=Z(),f=_a(),p=r.revision?.root||r.id,m=u?.id?uC(u.id,p):void 0,[h,g]=Y(r),[_,v]=Y(()=>m?dC(m):!1),y=J(null),b=J(r.id),x=J(r.id),S=J(m);K(()=>{S.current!==m&&(S.current=m,v(m?dC(m):!1))},[m]);let C=G(()=>{v(e=>{let t=!e;return m&&fC(m,t),t})},[m]),w=G(()=>{m&&fC(m,!1),v(!1)},[m]);K(()=>{let e=x.current!==r.id;x.current=r.id,g(t=>!e&&t.id!==r.id?t:(b.current=r.id,t.id===r.id&&t.text&&!r.text?{...r,text:t.text}:r))},[r]);let T=G(async(e,t)=>{b.current=e;try{let[t,n]=await Promise.all([d.objects.retrieve(e),d.objects.getObjectText(e)]);b.current===e&&g({...t,text:n.text})}catch(e){console.error(`Failed to load the updated document revision`,e),c({status:`error`,title:l(`agent.failedToLoadDocument`),description:e instanceof Error?e.message:void 0,duration:5e3})}finally{t&&f(`/objects/${e}`)}},[f,d.objects,l,c]),E=async(e,t)=>{try{await navigator.clipboard.writeText(e),c({status:`success`,title:l(`store.contentCopied`,{type:l(t===`text`?`store.contentType`:`store.properties`)}),description:l(`store.successfullyCopied`,{type:t}),duration:2e3})}catch(e){console.error(`Failed to copy ${t}:`,e),c({status:`error`,title:l(`store.copyFailed`),description:l(`store.failedToCopy`,{type:t}),duration:5e3})}};return n(e,{children:[n(_e,{direction:`horizontal`,className:`h-full`,children:[t(ge,{defaultSize:67,className:`min-w-[100px]`,children:t(QC,{object:h,loadText:i??!1,handleCopyContent:E,refetch:a,canCollaborate:s,isCollaborating:_,onToggleCollaborate:C})}),t(he,{withHandle:!0}),t(ge,{defaultSize:33,className:`min-w-[100px]`,children:t(ZC,{object:h,refetch:a??(()=>Promise.resolve()),handleCopyContent:E,canEditProperties:o})})]}),_?t(IC,{object:h,initialContent:h.text??``,onClose:w,onDocumentUpdated:(e,t)=>void T(e,t),sendMessageRef:y}):null]})}function ZC({object:r,refetch:a,handleCopyContent:s,canEditProperties:c}){let{t:l}=X(),[u,d]=Y(!1),[f,p]=Y(!1),m=Xx(r.id);return n(e,{children:[n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`flex justify-between items-center px-2`,children:[n(`div`,{className:`flex items-center gap-1 bg-muted mb-2 p-1 rounded`,children:[t(o,{variant:`${u?`ghost`:`primary`}`,size:`sm`,title:l(`store.previewProperties`),onClick:()=>d(!u),children:`Properties`}),t(o,{variant:`${u?`primary`:`ghost`}`,size:`sm`,title:l(`store.viewInJsonFormat`),onClick:()=>d(!u),children:`JSON`})]}),n(`div`,{className:`flex items-center gap-2`,children:[r.properties&&t(o,{variant:`ghost`,size:`sm`,title:`Copy properties`,onClick:()=>s(JSON.stringify(r.properties,null,2),`properties`),children:t(xn,{className:`size-4`})}),c&&t(VS,{permission:Oi.content_write,variant:`ghost`,size:`sm`,onClick:()=>{p(!0)},title:`Edit properties`,className:`flex items-center gap-2`,children:t(Jr,{className:`size-4`})})]})]}),m&&r.properties&&n(`div`,{className:`flex items-center gap-2 px-2 pb-2`,children:[typeof m.confidence==`number`&&t(i,{variant:m.confidence>=.95?`success`:`attention`,title:l(`grounded.confidenceHint`),children:l(`grounded.confidence`,{percent:Math.floor(m.confidence*100)})}),t(i,{variant:m.verified===m.total?`success`:`attention`,children:l(`grounded.verifiedOf`,{verified:m.verified,total:m.total})})]}),r.properties?t(`div`,{className:`flex-1 min-h-0 px-2`,children:t(vt,{value:r.properties,viewCode:u})}):t(`div`,{className:`flex-1 min-h-0 px-2`,children:t(`div`,{children:l(`store.noPropertiesDefined`)})})]}),t(LC,{isOpen:f,onClose:()=>{p(!1)},object:r,refetch:a})]})}function QC(e){let{client:n}=Z(),r=e.object.type,i=r?.id,a=r?.default_view,{data:o}=Ue(async()=>!i||a?null:(await WS(n,i))?.intake?.default_view??null,[i,a]),s=a??o;return i&&!a&&o===void 0?t(`div`,{className:`flex h-full items-center justify-center`,children:t(Te,{size:`lg`})}):t($C,{...e,defaultView:s??void 0})}function $C({object:e,loadText:r,handleCopyContent:i,refetch:a,defaultView:s,canCollaborate:c,isCollaborating:l,onToggleCollaborate:u}){let{client:d}=Z(),{t:f}=X(),p=e?.metadata?.type===yi.Image,m=e?.metadata?.type===yi.Video,h=e?.metadata?.type===yi.Audio,g=e?.content?.type===`application/pdf`,_=e?.content?.type?cy(e.content.type):!1,v=GC(e?.status),y=!!(e.transcript&&(m||h)),b=e.metadata?.renditions?.find(e=>e.name===Ei),x=()=>{switch(s){case`text`:return YC.Text;case`pdf`:if(g||_||b)return YC.Pdf;break;case`image`:if(p)return YC.Image;break;case`properties`:return YC.Text;default:break}return m?YC.Video:h?YC.Audio:p?YC.Image:YC.Text},S=Yx(e.id),[C,w]=Y(x()),[T,E]=Y(C===YC.Pdf);K(()=>{C===YC.Pdf&&E(!0)},[C]);let[D,O]=Y(!1),k=_C(!!(e.content?.type&&!e.is_locked&&e.user_permissions?.can_write!==!1&&(e.content.type.startsWith(`text/`)||e.content.type===`application/json`||e.content.type===`application/xml`)),c),{fullText:A,displayText:j,isLoading:M,isCropped:N,loadText:P}=VC(e.id,e.text,r,e.revision?.root||e.id),F=(g||_)&&v&&(C===YC.Text||C===YC.Pdf),{progress:I,status:L,isComplete:ee}=HC(e.id,F),{pdfUrl:R,isConverting:te,error:z,triggerConversion:ne}=UC(e.id,_),B=q(()=>[{id:`office-pdf-rendition`,target:`pdf`,canConvert:({contentType:e,extension:t})=>_||(e?cy(e):!1)||[`doc`,`docx`,`ppt`,`pptx`].includes(t),convert:async()=>{let t=await d.objects.getRendition(e.id,{format:Ti.pdf,generate_if_missing:!0,sign_url:!0,block_on_generation:!0});return t.status===`found`&&t.renditions?.length?{url:t.renditions[0],contentType:`application/pdf`,fileName:`${e.name||`document`}.pdf`}:null}}],[d,_,e.id,e.name]);K(()=>{ee&&L===Ni.COMPLETED&&P()},[ee,L,P]);let re=(g||_)&&v&&!ee&&L===Ni.RUNNING,ie=C===YC.Pdf&&!re,ae=re&&(C===YC.Text||C===YC.Pdf),oe=T&&!re,se=J(null);return n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`flex justify-between items-center px-2 shrink-0`,children:[n(`div`,{className:`flex items-center gap-2 mb-2`,children:[n(`div`,{className:`flex items-center gap-1 bg-muted p-1 rounded`,children:[p&&t(o,{variant:C===YC.Image?`primary`:`ghost`,size:`sm`,title:f(`store.viewImage`),onClick:()=>w(YC.Image),children:`Image`}),m&&t(o,{variant:C===YC.Video?`primary`:`ghost`,size:`sm`,title:f(`store.viewVideo`),onClick:()=>w(YC.Video),children:`Video`}),h&&t(o,{variant:C===YC.Audio?`primary`:`ghost`,size:`sm`,title:f(`store.viewAudio`),onClick:()=>w(YC.Audio),children:`Audio`}),y&&t(o,{variant:C===YC.Transcript?`primary`:`ghost`,size:`sm`,title:f(`store.viewTranscript`),onClick:()=>w(YC.Transcript),children:`Transcript`}),t(o,{variant:C===YC.Text?`primary`:`ghost`,size:`sm`,title:f(`store.viewText`),onClick:()=>w(YC.Text),children:`Text`}),g&&t(o,{variant:C===YC.Pdf?`primary`:`ghost`,size:`sm`,title:f(`store.viewPdf`),onClick:()=>w(YC.Pdf),children:`PDF`}),_&&t(o,{variant:C===YC.Pdf?`primary`:`ghost`,size:`sm`,title:f(`store.viewAsPdf`),onClick:()=>{w(YC.Pdf),!b&&!R&&!te&&ne()},disabled:te,children:te?t(Te,{size:`sm`}):`PDF`})]}),n(`div`,{className:`flex items-center gap-1`,children:[t(rw,{object:e}),t(iw,{objectId:e.id,available:S})]})]}),C===YC.Text&&!re&&!D&&t(ew,{object:e,text:j,fullText:A,handleCopyContent:i,textContainerRef:se,isEditing:D,onToggleEdit:()=>O(!0),canEdit:k.canEdit,isCollaborating:l,onToggleCollaborate:u,canCollaborate:k.canCollaborate}),C===YC.Pdf&&_&&(b||R)&&t(aw,{object:e,pdfRendition:b,officePdfUrl:R})]}),C===YC.Image&&t(`div`,{className:JC(!0),children:t(AS,{object:e})}),C===YC.Video&&t(`div`,{className:JC(!0),children:t(jS,{object:e})}),C===YC.Audio&&t(`div`,{className:JC(!0),children:t(kS,{object:e})}),y&&C===YC.Transcript&&t(`div`,{className:JC(!0),children:t(nw,{object:e,handleCopyContent:i})}),g&&oe&&t(`div`,{className:JC(ie),children:t(ow,{object:e})}),_&&oe&&t(`div`,{className:JC(ie),children:t(sw,{object:e,pdfRendition:b,officePdfUrl:R,converters:B,officePdfConverting:te,officePdfError:z})}),ae&&t(`div`,{className:JC(!0),children:t(cw,{progress:I,status:L})}),C===YC.Text&&!re&&!D&&M&&!j&&t(`div`,{className:JC(!0),children:t(`div`,{className:`flex justify-center items-center flex-1`,children:t(Te,{size:`lg`})})}),C===YC.Text&&!re&&!D&&(!M||j)&&t(`div`,{className:JC(!0),children:t(tw,{object:e,text:j,isTextCropped:N,textContainerRef:se})}),D&&C===YC.Text&&A!=null&&t(zC,{object:e,text:A,onClose:()=>O(!1),onSaved:()=>{O(!1),P(),a?.()}})]})}function ew({object:r,text:i,fullText:a,handleCopyContent:s,onToggleEdit:c,canEdit:l,isCollaborating:u,onToggleCollaborate:d,canCollaborate:f}){let{client:p,project:m}=Z(),h=Ye(),{t:g}=X(),_=r.content,{renderDocument:v,isDownloading:y}=gf({client:p,toast:h}),{data:b}=Ue(()=>m?p.projects.retrieve(m.id):Promise.resolve(void 0),[m?.id]),x=b?.configuration?.pdf_template_object_id??void 0,S=yC(_?.type),C=bC(_?.type),T=async(e,t)=>{if(y)return;h({status:`info`,title:`Preparing ${e.toUpperCase()}`,description:g(`store.renderingDocument`),duration:2e3});let n=t===!1?void 0:x;await v(r.id,{format:e,title:r.name||`document`,useDefaultTemplate:t,templateObjectId:n})};return t(`div`,{className:`h-[41px] text-lg font-semibold flex justify-between items-center px-2`,children:n(`div`,{className:`flex items-center gap-2`,children:[a&&t(o,{variant:`ghost`,size:`sm`,title:`Copy text`,onClick:()=>s(a,`text`),children:t(xn,{className:`size-4`})}),y?t(o,{variant:`ghost`,size:`sm`,disabled:!0,className:`h-8 w-8 p-0`,title:g(`agent.download`),"aria-label":g(`agent.download`),children:t(Te,{size:`sm`})}):n(w,{trigger:t(o,{variant:`ghost`,size:`sm`,disabled:!i,className:`h-8 w-8 p-0`,title:g(`agent.download`),"aria-label":g(`agent.download`),children:t(Tn,{className:`size-4`})}),children:[a&&t(B,{onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!a)return;let t=`txt`,n=`text/plain`;_?.type===`application/xml`||_?.type===`text/xml`?(t=`xml`,n=`text/xml`):S&&(t=`md`,n=`text/markdown`);let i=new Blob([a],{type:n}),o=URL.createObjectURL(i),s=`${r.name||`document`}.${t}`,c=document.createElement(`a`);c.href=o,c.download=s,c.style.display=`none`,setTimeout(()=>{c.click(),URL.revokeObjectURL(o)},0)},children:n(`div`,{className:`flex items-center gap-2`,children:[t(Tn,{className:`size-4`}),`Download Text`]})}),S&&i&&n(e,{children:[t(B,{onClick:()=>T(Ti.docx),children:n(`div`,{className:`flex items-center gap-2`,children:[t(Tn,{className:`size-4`}),`Export as DOCX`]})}),t(B,{onClick:()=>T(Ti.pdf,!1),children:n(`div`,{className:`flex items-center gap-2`,children:[t(Tn,{className:`size-4`}),`Export as PDF`]})}),t(B,{onClick:()=>T(Ti.pdf),children:n(`div`,{className:`flex items-center gap-2`,children:[t(Tn,{className:`size-4`}),`Export as Branded PDF`]})})]})]}),a&&n(e,{children:[l&&c&&t(VS,{permission:Oi.content_write,variant:`ghost`,size:`sm`,onClick:c,title:g(`store.editText`),"aria-label":g(`store.editText`),className:`h-8 w-8 p-0`,children:t(Jr,{className:`size-4`})}),f&&d&&C&&t(o,{variant:u?`primary`:`ghost`,size:`sm`,onClick:d,title:g(`agent.editWithAI`),"aria-label":g(`agent.editWithAI`),className:`h-8 w-8 p-0`,children:t(Kr,{className:`size-4`})})]})]})})}const tw=it(({object:r,text:i,isTextCropped:a,textContainerRef:o})=>{let{t:s}=X(),c=GC(r?.status),l=r.content,u=KC(r)===`xml`||l?.type===`application/xml`||l?.type===`text/xml`,d=bC(l?.type),f=!u&&(d||qC(i)),p={id:r.id,title:r.name,fileName:r.content?.name||r.name,contentType:u?`text/xml`:f?`text/markdown`:r.content?.type,content:i,sourcePath:r.content?.source};return i?n(e,{children:[a&&t(`div`,{className:`px-2 py-2 bg-attention/10 border-s-4 border-attention mx-2 mb-2 rounded`,children:n(`div`,{className:`flex items-center gap-2 text-attention`,children:[t(Vt,{className:`size-4`}),t(`span`,{className:`text-sm font-semibold`,children:s(`store.showingFirst128K`)})]})}),t(`div`,{className:`max-w-7xl px-2 h-full overflow-auto`,ref:o,children:t(Ex,{source:p,className:`h-full`,bodyClassName:`overflow-auto`,markdownComponents:WC()})})]}):t(`div`,{className:`px-2`,children:t(`div`,{children:c?`Extracting content...`:`No content`})})});function nw({object:e,handleCopyContent:r}){let{t:i}=X(),a=e.transcript,s=a?.text,c=a?.segments,l=s||(c?c.map(e=>e.text).join(` `):``),u=e=>{let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=Math.floor(e%60);return t>0?`${t}:${n.toString().padStart(2,`0`)}:${r.toString().padStart(2,`0`)}`:`${n}:${r.toString().padStart(2,`0`)}`};return n(`div`,{className:`flex flex-col h-full`,children:[t(`div`,{className:`flex justify-end items-center px-2 mb-2`,children:l&&t(o,{variant:`ghost`,size:`sm`,title:`Copy transcript`,onClick:()=>r(l,`text`),children:t(xn,{className:`size-4`})})}),t(`div`,{className:`h-full} overflow-auto px-2`,children:c&&c.length>0?t(`div`,{className:`space-y-2`,children:c.map((e,r)=>n(`div`,{className:`flex gap-3 text-sm`,children:[n(`span`,{className:`text-muted font-mono text-xs shrink-0 pt-0.5`,children:[u(e.start),e.end&&` - ${u(e.end)}`]}),t(`span`,{className:`flex-1`,children:e.text})]},`segment-${r}`))}):s?t(`pre`,{className:`text-wrap bg-muted text-muted p-2 whitespace-pre-wrap`,children:s}):t(`div`,{className:`text-muted`,children:i(`store.noTranscriptAvailable`)})})]})}function rw({object:r}){let[i,a]=Y(!1);return KC(r)===`markdown`?n(e,{children:[t(o,{variant:`ghost`,size:`sm`,onClick:()=>a(!0),title:`Side by side view`,children:t(In,{className:`size-4`})}),i&&t(fe,{children:t(CS,{objectId:r.id,onClose:()=>a(!1)})})]}):null}function iw({objectId:r,available:i}){let{t:a}=X(),[s,c]=Y(!1);return i?n(e,{children:[t(o,{variant:`ghost`,size:`sm`,onClick:()=>c(!0),title:a(`grounded.title`),"aria-label":a(`grounded.title`),children:t(zr,{className:`size-4`})}),s&&t(fe,{children:t(Qx,{objectId:r,onClose:()=>c(!1)})})]}):null}function aw({object:e,pdfRendition:n,officePdfUrl:r}){let{client:i}=Z(),a=Ye(),{t:s}=X(),[c,l]=Y(!1);return t(`div`,{className:`flex items-center gap-2`,children:t(o,{variant:`ghost`,size:`sm`,onClick:async()=>{l(!0);try{let t=r;!t&&n?.content?.source&&(t=(await i.files.getDownloadUrl(n.content.source,`${e.name||`document`}.pdf`,`attachment`)).url),t&&window.open(t,`_blank`)}catch(e){console.error(`Failed to download PDF:`,e),a({status:`error`,title:s(`store.downloadFailed`),description:s(`store.failedToDownloadPdf`),duration:5e3})}finally{l(!1)}},disabled:c,title:`Download PDF`,children:c?t(Te,{size:`sm`}):t(Tn,{className:`size-4`})})})}function ow({object:e}){return t(`div`,{className:`h-full`,children:t(Ex,{source:{id:e.id,title:e.name,fileName:e.content?.name||e.name,contentType:e.content?.type,sourcePath:e.content?.source},className:`h-full`})})}function sw({object:e,pdfRendition:r,officePdfUrl:i,converters:a,officePdfConverting:o,officePdfError:s}){let{t:c}=X();return o?n(`div`,{className:`flex flex-col justify-center items-center flex-1 gap-2`,children:[t(Te,{size:`lg`}),t(`span`,{className:`text-muted`,children:c(`store.convertingToPdf`)})]}):s?n(`div`,{className:`flex flex-col justify-center items-center flex-1 gap-2 text-destructive`,children:[t(Vt,{className:`size-8`}),t(`span`,{children:s})]}):r?.content?.source?t(`div`,{className:`h-full`,children:t(Ex,{source:{id:e.id,title:e.name,fileName:`${e.name||`document`}.pdf`,contentType:`application/pdf`,sourcePath:r.content.source},className:`h-full`})}):i?t(`div`,{className:`h-full`,children:t(Ex,{source:{id:e.id,title:e.name,fileName:`${e.name||`document`}.pdf`,contentType:`application/pdf`,url:i},className:`h-full`})}):t(`div`,{className:`h-full`,children:t(Ex,{source:{id:e.id,title:e.name,fileName:e.content?.name||e.name,contentType:e.content?.type,sourcePath:e.content?.source},converters:a,className:`h-full`})})}function cw({progress:r,status:i}){let{t:a}=X(),o=hy(i),s=gy(i),c=r?.phase===`grounded_extraction`,l=r?.percent!=null&&!Number.isNaN(r.percent)?r.percent:0;return n(`div`,{className:`px-4 py-4`,children:[r&&n(`div`,{className:`space-y-2`,children:[n(`div`,{className:`flex flex-col gap-1`,children:[t(lw,{name:c?`Prepare Evidence`:`Analyze Page`,progress:r.pages}),c&&n(e,{children:[t(lw,{name:`Run OCR`,progress:r.images}),t(lw,{name:`Extract Grounded Data`,progress:r.tables}),t(lw,{name:`Review and Annotate`,progress:r.visuals})]})]}),n(`div`,{className:`pt-2 text-sm text-muted`,children:[`Progress: `,l,`%`,t(`span`,{className:`px-2`,children:`•`}),t(`span`,{className:o,children:s}),r.started_at&&n(e,{children:[t(`span`,{className:`px-2`,children:`•`}),n(`span`,{children:[((Date.now()-r.started_at)/1e3).toFixed(0),` sec. elapsed`]})]})]}),t(St,{percent:l})]}),!r&&n(`div`,{className:`flex items-center gap-2 text-muted`,children:[t(Te,{size:`sm`}),t(`span`,{children:a(`store.loadingProcessingStatus`)})]})]})}function lw({name:e,progress:t}){return n(`div`,{className:`flex gap-2 text-sm`,children:[n(`span`,{className:`text-muted min-w-36`,children:[e,`:`]}),n(`span`,{children:[t.processed,` of `,t.total]})]})}const uw=Object.values(Ai),dw=Object.values(Mi);function fw({onChange:e,isLoading:r,refresh:i,searchTypes:a}){let{client:s,project:c}=Z(),{t:l}=X(),u=Ye(),[d,f]=Y(void 0),[p,h]=Y(void 0),g=!!c&&(!!p?.embeddings.text||!!p?.embeddings.image),[_,v]=Y(void 0),y=J(i),b=J(void 0),[x,S]=Y(!1),[C,w]=Y(a||uw),[T,E]=Y(100);K(()=>{a&&w(a)},[a]);let D={},O=!1,k=!1;C.forEach(e=>{e===Ai.full_text?O=!0:k=!0,dw.includes(e)&&(D[e]=!0)}),K(()=>{y.current!==i&&(y.current=i,f(void 0),v(void 0))}),K(()=>{c&&s.projects.retrieve(c.id).then(e=>{h(e.configuration)})},[s.projects.retrieve,c]),K(()=>{_&&u({title:_,status:`success`,duration:2e3})},[_,u]),K(()=>{let t=b.current;b.current=d,t&&(!d||d.length===0)&&e(void 0)},[e,d]);let A=()=>{!g||!d||(e({vector:k?{text:d,config:D}:void 0,full_text:O?d:void 0,limit:T}),v(`Searching...`))},j=e=>{e.key===`Enter`&&A()},M=e=>t=>{w(t?t=>Array.from(new Set([...t,e])):t=>t.filter(t=>t!==e))};return n(`div`,{className:`flex gap-1 items-center`,children:[t(R,{placeholder:l(`store.searchPlaceholder`),value:d,onChange:f,onKeyDown:j,className:`min-w-[200px]`}),t(o,{variant:`ghost`,onClick:()=>S(!0),title:l(`store.semanticSearchSettings`),className:`ms-1`,children:t(Hr,{size:18})}),n(ie,{isOpen:x,onClose:()=>S(!1),children:[t(se,{children:l(`store.searchTypes`)}),t(ae,{children:n(`div`,{className:`flex flex-col gap-2`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(m,{id:`search-type-full_text`,checked:C.includes(Ai.full_text),onCheckedChange:M(Ai.full_text)}),t(z,{htmlFor:`search-type-full_text`,children:l(`store.fullText`)})]}),t(`div`,{className:`font-semibold mt-2 mb-1`,children:l(`store.embeddings`)}),dw.map(e=>n(`div`,{className:`flex items-center gap-2`,children:[t(m,{id:`search-type-${e}`,checked:C.includes(e),onCheckedChange:M(e)}),t(z,{htmlFor:`search-type-${e}`,children:e.charAt(0).toUpperCase()+e.slice(1)})]},e)),n(`div`,{className:`mt-3`,children:[t(`span`,{className:`me-2`,children:l(`store.limit`)}),t(ce,{type:`number`,min:1,value:T,onChange:e=>E(Number(e??100)),style:{width:80}})]})]})}),t(oe,{children:t(o,{variant:`outline`,onClick:()=>S(!1),children:l(`store.close`)})})]}),t(o,{variant:`secondary`,isLoading:r,onClick:A,isDisabled:!g,title:l(`store.semanticSearch`),children:l(`store.search`)})]})}const pw=[{name:`ID`,field:`id`,type:`objectId?slice=-7`},{name:`Name`,field:`.`,type:`objectName`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Updated At`,field:`updated_at`,type:`date`}];function mw(e,t){return(t?e.getTypeLayout(t):pw)??pw}function hw({onUploadDone:e=async()=>{},layout:n,toolbarActions:r}){let i=Ny(),a=Ye(),{t:o}=X(),s=Uy(G(async t=>{await e(t),setTimeout(()=>{console.log(`Delayed refresh after upload to ensure backend consistency`),i.search().then(e=>{e&&a({title:o(`store.documentListRefreshed`),description:o(`store.documentListRefreshedDesc`),status:`info`,duration:3e3})}).catch(e=>{console.error(`Failed to refresh search results:`,e)})},1e3)},[e,i,o,a]));return t(gw,{layout:n,onUpload:G((e,t)=>{let n=i.collectionId;return s(e,t,n)},[i,s]),toolbarActions:r})}function gw({layout:e,onUpload:r,allowFilter:i=!0,allowSearch:a=!0,toolbarActions:o}){let{t:s}=X(),c=Ny(),[l,u]=Y(!1),[d,f]=Y(null),{registry:p}=sv(),{search:m,isLoading:h,error:g,objects:_,hasMore:v}=Fy(),[y,b]=Y(p?e||mw(p,m.query.type):pw);K(()=>{e&&b(e)},[e]);let[x,S]=Y(0),[C,w]=Y(0),[T,E]=Y(localStorage.getItem(Qy.LAST_DISPLAYED_VIEW)===`grid`),[D,O]=Y([]),k=J(null),A=J(null),j=G((e,t)=>{u(!1),e.catch(e=>{console.error(t,e)}).finally(()=>{u(!0)})},[]);K(()=>{let e=!1;return m.initialized?(u(!0),()=>{e=!0}):(u(!1),w(0),m.search().catch(t=>{e||console.error(`Initial search failed:`,t)}).finally(()=>{e||u(!0)}),()=>{e=!0})},[m]),K(()=>{_.length<C&&w(_.length)},[_.length,C]),Ke(k,()=>{l&&_.length>0&&_.length!==C&&(u(!1),m.loadMore().catch(e=>{console.error(`Failed to load more search results:`,e)}).finally(()=>{w(_.length),u(!0)}))},{deps:[l,_.length]});let N=e=>{if(e?.vector){if(m.query.vector=e.vector,m.query.full_text=e.full_text,m.query.weights=e.weights,m.query.score_aggregation=e.score_aggregation,m.query.dynamic_scaling=e.dynamic_scaling,e.limit!==void 0&&(m.limit=e.limit,m.query.limit=e.limit),!y.find(e=>e.name===`Search Score`)){let e=[...y,{name:`Search Score`,field:`score`,render:e=>typeof e.score==`number`?e.score.toFixed(4):`0.0000`}];b(e)}j(m.search(),`Vector search failed:`)}else e?.full_text?(m.query.full_text=e.full_text,e.limit!==void 0&&(m.limit=e.limit,m.query.limit=e.limit),j(m.search(),`Text search failed:`)):e===void 0&&l&&(delete m.query.vector,delete m.query.full_text,j(m.search(),`Search reset failed:`))},P=Py(),F=Ny(),I=()=>{j(m.search(),`Search refresh failed:`)},L=pv(P),ee=mv(F),R=e=>{let t=typeof e==`function`?e(D):e;O(t),ee(t)},te=(e,t)=>{let n=L.find(t=>t.name===e),r={name:e,type:n?.type,placeholder:n?.placeholder,multiple:n?.multiple};R(i=>{let a=i.filter(t=>t.name!==e);if(n?.type===`stringList`||Array.isArray(t)){let n=Array.isArray(t)?t:[t],o=i.find(t=>t.name===e)?.value??[];return[...a,{...r,value:Array.from(new Set([...o,...n]))}]}return[...a,{...r,value:[{value:t,label:t}]}]})},z=new URL(window.location.href),ne=z.searchParams.get(`filters`);if(ne)try{let e=ne.split(`;`),t=e.filter(e=>{let[t]=e.split(`:`),n=decodeURIComponent(t);return n!==`start`&&n!==`end`});if(t.length!==e.length){let e=t.length>0?t.join(`;`):``;e?z.searchParams.set(`filters`,e):z.searchParams.delete(`filters`),window.history.replaceState(window.history.state||{},``,z.toString())}}catch(e){console.error(`Failed to clean start/end filters from URL:`,e)}let B=_a();return n(`div`,{className:`flex flex-col gap-y-2 flex-1 min-h-0 `,children:[t(vw,{object:d,onClose:()=>f(null)}),g&&t(M,{title:s(`store.error`),children:g.message}),t(_w,{isLoading:h,refreshTrigger:x,allowFilter:i,allowSearch:a,filterGroups:L,filters:D,handleFilterChange:R,handleVectorSearch:N,handleRefetch:I,setIsGridView:E,toolbarActions:o}),t(`div`,{className:`flex flex-col w-full flex-1 min-h-0 border rounded-md mb-2`,children:n(`div`,{ref:A,className:`flex-1 min-h-0 overflow-y-auto`,children:[t(Yv,{onFilter:te,children:t(Gy,{objects:_,isLoading:!_.length&&h,layout:y,onRowClick:e=>{B(`/objects/${e.id}`)},previewObject:e=>{let t=_.find(t=>t.id===e)||null;f(t)},selectedObject:d,onUpload:r,isGridView:T,collectionId:c.collectionId})}),v?t(`div`,{ref:k,className:`w-full flex justify-center`,children:t(Te,{size:`xl`})}):t(`div`,{className:`text-muted text-center text-sm py-1`,children:`All ${_.length} objects loaded.`})]})})]})}function _w(e){let{t:r}=X(),{isLoading:i,refreshTrigger:a,allowFilter:s,allowSearch:c,filterGroups:l,filters:u,handleFilterChange:d,handleVectorSearch:f,handleRefetch:p,setIsGridView:m,toolbarActions:h}=e;return n(`div`,{className:`sticky top-0 z-10 bg-background py-2 flex justify-between items-center`,children:[s?t(I,{filterGroups:l,filters:u,setFilters:d,children:n(`div`,{children:[t(`div`,{className:`flex flex-row gap-4 items-center justify-between w-full`,children:n(`div`,{className:`flex gap-2 items-center w-2/3`,children:[c&&t(fw,{onChange:f,isLoading:i,refresh:a,className:`w-full`}),t(P,{})]})}),n(`div`,{className:`flex gap-2 items-center pt-2`,children:[t(N,{}),t(F,{})]})]})}):t(`div`,{className:`flex flex-row gap-4 items-center justify-between w-full`,children:t(`div`,{className:`flex gap-2 items-center w-2/3`,children:c&&t(fw,{onChange:f,isLoading:i,refresh:a})})}),n(`div`,{className:`flex gap-1 items-center`,children:[h,t(o,{variant:`outline`,onClick:p,title:r(`store.refresh`),children:t(Nr,{size:16})}),t(Qy,{onUpdate:m})]})]})}function vw({object:e,onClose:r}){let{store:i}=Z(),a=Ye(),s=_a(),{downloadFromContentSource:c}=gf({client:i,toast:a}),l=e?.content?.source,u=typeof e?.properties?.title==`string`?e.properties.title:e?.name;return e?n(Se,{title:u,isOpen:!0,onClose:r,children:[n(`div`,{className:`flex items-center gap-x-2`,children:[t(o,{variant:`ghost`,size:`sm`,title:`Open Object`,onClick:()=>s(`/objects/${e.id}`),children:t(kn,{className:`size-4`})}),l&&t(o,{variant:`ghost`,size:`sm`,title:`Download`,onClick:()=>c(l,hf(e)),children:t(Tn,{className:`size-4`})})]}),t(C,{className:`my-2`}),t(`div`,{className:`pt-2`,children:t(XC,{object:e,loadText:!0},e.id)})]}):null}const yw=[{name:`ID`,field:`id`,type:`objectId?slice=-7`},{name:`Name`,field:`.`,type:`objectName`},{name:`Revision`,field:`.`,type:`revision`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Updated At`,field:`updated_at`,type:`date`}];function bw({collection:e}){let n=Ye(),{client:r}=Z(),{registry:i}=sv(),a=async t=>{t.length>0&&await r.store.collections.addMembers(e.id,t).catch(e=>{n({title:`Failed to add objects to collection`,description:e.message,status:`error`})})},o=xw(e,i);return t(`div`,{className:`flex flex-col h-full`,children:e.dynamic?t(gw,{layout:o}):t(hw,{onUploadDone:a,layout:o})})}function xw(e,t){let n=e.table_layout;return n&&n.length>0||(e.type&&t&&(n=t?.getTypeLayout(Pi(e.type))),n&&n.length>0)?n:yw}function Sw({className:e,defaultValue:r,onChange:i,isClearable:a,multiple:o}){let{t:s}=X(),{registry:c}=sv(),[l,u]=Y(!1),d=e=>e===null?s(`store.none`):n(`div`,{children:[t(`div`,{className:`text-sm`,children:e.name}),t(`div`,{className:`text-xs text-muted truncate`,children:e.description})]}),[f,p]=Y(),[m,h]=Y([]);return K(()=>{if(!l&&(u(!0),c&&r)){if(o&&Array.isArray(r)){let e=c.types.filter(e=>r.includes(e.id));h(e)}let e=c.types.find(e=>e.id===r);e&&p(e)}},[l,c,r,o]),o?t(`div`,{className:`flex flex-col gap-4 content-between`,children:t(ve,{options:c?.types||[],value:m,onChange:e=>{h(e),i(e)},placeholder:s(`store.chooseContentTypes`),optionLabel:d,className:e||`text-sm bg-background`,filterBy:`name`,isClearable:a||!1,multiple:!0})}):t(`div`,{className:`flex flex-col gap-4 content-between`,children:t(ve,{options:c?.types||[],value:f,onChange:e=>{p(e||void 0),i(e)},placeholder:s(`store.chooseContentType`),optionLabel:d,className:e||`text-sm bg-background`,filterBy:`name`,isClearable:a||!1})})}function Cw({onClose:r,redirect:i=!0,onAddToCollection:a}){let s=_a(),c=Ye(),{t:l}=X(),[u,d]=Y(!1),{client:f}=Z(),[p,m]=Y({dynamic:!1,name:``,description:``});function h(e,t){m({...p,[e]:t})}return n(e,{children:[t(ae,{children:n(`form`,{onSubmit:e=>e.preventDefault(),children:[t(L,{label:l(`type.name`),required:!0,children:t(R,{type:`text`,value:p.name||``,onChange:e=>h(`name`,e)})}),t(L,{label:l(`type.description`),className:`mt-2`,children:t(Le,{value:p.description||``,onChange:e=>h(`description`,e.target.value)})}),t(L,{label:l(`store.dynamicCollection`),className:`mt-2`,direction:`row`,description:l(`store.dynamicCollectionDescription`),children:t(De,{value:p.dynamic||!1,onChange:e=>h(`dynamic`,e)})}),!p.dynamic&&t(L,{label:l(`store.allowedContentTypes`),className:`mt-4`,description:l(`store.allowedContentTypesOptionalDescription`),children:t(Sw,{defaultValue:p.allowed_types||null,onChange:e=>{Array.isArray(e)?h(`allowed_types`,e.map(e=>e.id)):h(`allowed_types`,e?[e.id]:[])},isClearable:!0,multiple:!0})}),t(L,{label:l(`store.contentType`),className:`mt-2`,description:l(`store.typeDescription`),children:t(Sw,{defaultValue:p.type||null,onChange:e=>{Array.isArray(e)?h(`type`,e.length>0?e[0].id:null):h(`type`,e?.id||null)},isClearable:!0})})]})}),t(oe,{children:t(o,{isDisabled:u,onClick:()=>{if(!p?.name?.trim()){c({title:l(`type.nameRequired`),description:l(`store.pleaseProvideName`),status:`error`,duration:5e3});return}p.name=p.name.trim(),p.description&&=p.description.trim(),p.dynamic??=!1,d(!0),f.store.collections.create(p).then(e=>{r(),c({title:l(`store.collectionCreated`),description:`Collection "${e.name}" created successfully`,status:`success`,duration:3e3}),i&&s(`/collections/${e.id}`),a&&a(e.id)}).catch(e=>{c({title:l(`store.failedToCreateCollection`),description:e.message,status:`error`,duration:5e3})}).finally(()=>d(!1))},children:l(`store.createCollection`)})})]})}function ww({isOpen:e,onClose:r}){let{t:i}=X();return n(ie,{onClose:r,isOpen:e,children:[t(se,{children:i(`store.createACollection`)}),t(Cw,{onClose:r})]})}Ki.extend(Sa);function Tw(){let{client:r}=Z(),i=Ye(),{t:a}=X(),[s,c]=Y(),[l,u]=Y(!0),[d,f]=Y(!1),{data:p,error:m,refetch:h}=Ue(()=>r.store.collections.search({}),[]);return K(()=>{(p||m)&&u(!1)},[p,m]),m?t(M,{title:a(`store.collectionFetchFailed`),children:ze(m)}):n(e,{children:[p&&(p.length>0?n(je,{className:`w-full`,children:[t(`thead`,{children:n(`tr`,{children:[t(`th`,{children:a(`type.name`)}),t(`th`,{children:a(`type.type`)}),t(`th`,{children:a(`store.created`)}),t(`th`,{})]})}),t(Oe,{columns:4,isLoading:l,children:p.map(e=>n(Ae,{children:[t(`td`,{children:n(`div`,{className:`flex items-center gap-2`,children:[t(Ew,{isDynamic:e.dynamic}),t(ga,{href:`/collections/${e.id}`,children:e.name})]})}),t(`td`,{children:e.type?.name||`-`}),t(`td`,{children:Ki(e.created_at).fromNow()}),t(`td`,{className:`text-end`,children:t(o,{variant:`destructive`,size:`sm`,onClick:()=>c(e.id),children:t($r,{className:`size-4`})})})]},e.id))})]}):t(j,{title:a(`store.noCollections`),buttonLabel:a(`store.newCollections`),onClick:()=>f(!0),children:a(`store.getStartedCollections`)})),t(ww,{isOpen:d,onClose:()=>f(!1)}),t(b,{isOpen:!!s,title:a(`store.deleteCollection`),content:a(`store.areYouSureDeleteCollection`),onConfirm:async()=>{if(s)try{await r.store.collections.delete(s),i({title:a(`store.collectionDeleted`),status:`success`,duration:3e3}),h()}catch(e){console.error(`Failed to delete collection:`,e),i({title:a(`store.failedToDeleteCollection`),description:ze(e),status:`error`,duration:5e3})}finally{c(void 0)}},onCancel:()=>c(void 0)})]})}function Ew({isDynamic:e}){let{t:n}=X();return t(Re,{description:n(e?`store.dynamicCollection`:`store.staticCollection`),className:`me-2`,children:t(e?Br:Vn,{className:`size-5`})})}Ki.extend(Sa);const Dw=`h-6 w-6 p-0 opacity-0 group-hover/field:opacity-100 text-muted hover:text-foreground transition-opacity shrink-0`;function Ow({objects:e,isLoading:r,onFilter:i,selectedIds:a,onToggleOne:s,allSelected:c,onToggleAll:l}){let{t:u}=X(),d=_a(),f=!!s;return n(je,{className:`w-full`,children:[t(ke,{children:n(`tr`,{children:[f&&t(`th`,{className:`w-[5%]`,children:t(`input`,{type:`checkbox`,checked:!!c,"aria-label":u(`store.actions.selectAllTypes`),onChange:e=>l?.(e.target.checked)})}),t(`th`,{children:u(`store.name`)}),t(`th`,{children:u(`store.strictMode`)}),t(`th`,{children:u(`store.semanticChunking`)}),t(`th`,{children:u(`store.updatedAt`)})]})}),t(Oe,{isLoading:r&&(!e||e.length===0),columns:f?5:4,children:e?.map(e=>n(`tr`,{onClick:()=>d(`/types/${e.id}`),className:`group cursor-pointer hover:bg-muted`,children:[f&&t(`td`,{className:`w-[5%]`,children:t(`input`,{type:`checkbox`,className:Ze(`checkbox group-hover:inline-block`,a?.includes(e.id)?`inline-block`:`hidden`),checked:a?.includes(e.id)??!1,"aria-label":u(`store.actions.selectType`,{name:e.name}),onClick:e=>e.stopPropagation(),onChange:t=>s?.(e.id,t.target.checked)})}),t(`td`,{className:`group/field`,children:n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:e.name}),t(x,{content:e.id,className:Dw}),i&&t(o,{variant:`ghost`,size:`sm`,title:`Filter by ${e.name}`,className:Dw,onClick:t=>{t.stopPropagation(),i(`name`,e.name)},children:t(Bn,{className:`size-3`})})]})}),t(`td`,{children:e.strict_mode?`Yes`:`No`}),t(`td`,{children:e.is_chunkable?`Yes`:`No`}),t(`td`,{children:t(Re,{description:Ki(e.updated_at).format(`YYYY-MM-DD HH:mm:ss`),children:Ki(e.updated_at).fromNow()})})]},e.id))})]})}function kw({title:e,isOpen:r,onClose:i,okLabel:a,initialPayload:s,isLoading:c}){let{t:l}=X(),u=Ye(),[d,f]=Y(s?.name),[p,m]=Y(s?.description),h=s?.strict_mode??!1,g=()=>{if(!d){u({status:`error`,title:l(`type.nameRequired`),duration:5e3});return}i({name:d,description:p,strict_mode:h}).then(()=>i())};return n(ie,{isOpen:r,onClose:()=>i(),children:[t(se,{children:e}),t(ae,{className:`pt-0`,children:n(`div`,{className:`h-full flex flex-col gap-4 content-between`,children:[n(`div`,{children:[t(`div`,{className:`block text-sm font-medium text-muted`,children:l(`type.name`)}),t(R,{value:d,onChange:f})]}),n(`div`,{children:[t(`div`,{className:`block text-sm font-medium text-muted`,children:l(`type.description`)}),t(Le,{value:p,onChange:e=>m(e.target.value),minLines:5})]})]})}),t(oe,{children:n(`div`,{className:`flex justify-end gap-4`,children:[t(o,{variant:`secondary`,onClick:()=>i(),children:l(`modal.cancel`)}),t(o,{variant:`primary`,onClick:()=>g(),isLoading:c,children:a})]})})]})}var Aw=class{client;limit;result=new xe({objects:[],isLoading:!1});query={};constructor(e,t=100){this.client=e,this.limit=t}get objects(){return this.result.value.objects}get error(){return this.result.value.error}get isRunning(){return this.result.value.isLoading}getFilterValue(e){return this.query[e]}setFilterValue(e,t){this.query[e]=t,this.search()}reset(e=!1){this.result.value={objects:[],isLoading:e}}_updateRunningState(e){let t=this.result.value;this.result.value={objects:t.objects,isLoading:e,error:t.error}}async _search(e=!1){if(this.isRunning)return Promise.resolve(!1);this.result.value={isLoading:!0,objects:e?this.objects:[]};let t=this.limit,n=this.objects.length;return this.client.types.list({limit:t,offset:n,query:this.query}).then(async e=>(this.result.value={isLoading:!1,objects:this.objects.concat(e)},!0)).catch(e=>{throw this.result.value={error:e,isLoading:!1,objects:this.objects},e})}search(){return this.isRunning?Promise.resolve(!1):this._search(!1)}loadMore(){return this.isRunning?Promise.resolve(!1):this._search(!0)}};const jw=nt(void 0);function Mw(){return at(jw)}function Nw(){let e=Mw();return{...Xe(e.result),search:e}}function Pw(){return Mw().objects.length}var Fw;(function(e){e.true=`Yes`,e.false=`No`})(Fw||={});function Iw({isDirty:r=!1}){let{store:i}=Z(),{reload:a}=sv(),{t:s}=X(),c=Ye(),[l,u]=Y(!1),{search:d,isLoading:f,error:p,objects:m}=Nw(),[h,g]=Y([]),[_,v]=Y(!1),[y,x]=Y(!1),S=h.length,C=!!m&&m.length>0&&m.every(e=>h.includes(e.id)),w=m?.filter(e=>h.includes(e.id))??[],T=(e,t)=>{g(n=>t?n.includes(e)?n:[...n,e]:n.filter(t=>t!==e))},E=e=>{g(e&&m?m.map(e=>e.id):[])},D=async()=>{if(!y){x(!0);try{let e=await Promise.allSettled(h.map(e=>i.types.delete(e))),t=e.filter(e=>e.status===`rejected`).length,n=e.length-t;v(!1),g([]),a(),await d.search(),c(t===0?{status:`success`,title:s(`store.actions.typeDeleted`,{count:n}),duration:3e3}:{status:`error`,title:s(`store.actions.typeDeletePartial`,{succeeded:n,failed:t}),duration:5e3})}catch(e){c({status:`error`,title:s(`store.actions.failedToDeleteTypes`),description:e instanceof Error?e.message:void 0,duration:5e3})}finally{x(!1)}}},[O,k]=Y(``),A=He(O,500),N=J(null);Ke(N,()=>{l&&d.loadMore()},{deps:[l,d]}),K(()=>{d.search().then(()=>u(!0))},[d]),K(()=>{d.query.name=A,d.search().then(()=>u(!0))},[A,d]);let[P,F]=Y(void 0),I=e=>{F(e)};K(()=>{d.query.chunkable=P?P===`Yes`:void 0,d.search().then(()=>u(!0))},[P,d]),K(()=>{r&&l&&d.search().then(()=>u(!0))},[r,l,d]);let[L,ee]=Y(!1);return p?t(M,{title:s(`store.failedToFetchTypes`),children:p.message}):n(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[n(`div`,{className:`flex flex-shrink-0 gap-4 items-center`,children:[t(R,{placeholder:s(`store.filterByName`),value:O,onChange:k}),t(ve,{className:`w-60`,isClearable:!0,options:Object.values(Fw),value:P,onChange:I,placeholder:s(`store.isChunkable`)}),S>0&&n(`div`,{className:`flex items-center gap-2 ms-auto`,children:[t(`span`,{className:`text-sm font-medium whitespace-nowrap`,children:s(`store.actions.selectedCount`,{n:S})}),t(Re,{description:s(`store.actions.clearSelection`),asChild:!0,children:t(o,{variant:`ghost`,"aria-label":s(`store.actions.clearSelection`),onClick:()=>g([]),children:t(ci,{className:`size-4`})})}),t(o,{variant:`destructive`,isDisabled:y,onClick:()=>v(!0),children:s(y?`store.actions.deleting`:`store.actions.deleteSelected`)})]})]}),t(`div`,{className:`flex flex-col w-full flex-1 min-h-0 border rounded-md my-2`,children:n(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:[!f&&m?.length===0?t(j,{title:s(`store.noType`),buttonLabel:s(`store.createType`),onClick:()=>{ee(!0)},children:s(`store.getStartedTypes`)}):n(e,{children:[t(Ow,{objects:m,isLoading:f,onFilter:(e,t)=>{e===`name`&&k(t)},selectedIds:h,onToggleOne:T,allSelected:C,onToggleAll:E}),t(`div`,{ref:N,className:`h-4 w-full`})]}),t(kw,{okLabel:`Create`,title:s(`store.createType`),isOpen:L,onClose:async e=>e?i.types.create(e).then(async()=>{c({status:`success`,title:s(`store.typeCreated`),duration:2e3}),a(),d.search().then(()=>u(!0))}).catch(e=>{c({status:`error`,title:s(`store.errorCreatingType`),description:e.message,duration:5e3})}):(ee(!1),Promise.resolve())}),t(b,{isOpen:_,title:s(`store.actions.deleteType`,{count:S}),content:n(`div`,{children:[t(`p`,{children:s(`store.actions.deleteTypeConfirm`,{count:S})}),w.length>0&&n(e,{children:[t(`div`,{className:`mt-2`,children:s(`store.actions.affectedItems`)}),t(`ul`,{className:`mt-1 max-h-40 overflow-y-auto rounded-md border p-2 text-sm`,children:w.map(e=>t(`li`,{className:`truncate py-0.5`,children:e.name||e.id},e.id))})]})]}),onConfirm:D,onCancel:()=>v(!1),confirmationValue:`delete`,confirmationLabel:s(`store.actions.typeToConfirmDelete`),confirmationPlaceholder:`delete`})]})})]})}function Lw(e,t,n){if(t.length===0)return e;let r=structuredClone(e),i=[r],a=r;for(let e of t.slice(0,-1)){let t=a[e],n=Hw(t)?t:{};a[e]=n,a=n,i.push(a)}let o=t[t.length-1];return n===void 0||n===``?(delete a[o],Vw(i,t)):a[o]=n,r}function Rw(e,t,n,r){let i=e?.map(e=>[e[0]??1,e[1]??1])??[],a=i[t]??[1,1];return a[n]=r,i[t]=a,i}function zw(e,t){let n={...e,environment:t};return delete n.model,delete n.model_options,Uw(n)?n:void 0}function Bw(e,t){let n={...e,model:t};return t!==e?.model&&delete n.model_options,Uw(n)?n:void 0}function Vw(e,t){for(let n=e.length-1;n>0;--n){let r=e[n];if(Object.keys(r).length>0)break;delete e[n-1][t[n-1]]}}function Hw(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Uw(e){return Object.values(e).some(e=>e!==void 0)}function Ww({policy:e,section:r,onChange:i,readonly:a=!1}){let{t:o}=X(),s=(t,n)=>i(Lw(e,t,n));if(r===`overview`)return n(Gw,{children:[n(Kw,{title:o(`intakePolicy.section.classification`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(Xw,{label:o(`intakePolicy.field.mode`),description:o(`intakePolicy.help.mode`),value:e.mode,options:tT(o,[`programmatic`,`agentic`]),onChange:e=>s([`mode`],e),readonly:a}),t(Xw,{label:o(`intakePolicy.field.defaultView`),value:e.default_view,options:tT(o,[`auto`,`text`,`pdf`,`image`,`properties`]),onChange:e=>s([`default_view`],e),readonly:a})]}),t(Jw,{label:o(`intakePolicy.field.identificationGuidance`),description:o(`intakePolicy.help.identificationGuidance`),value:e.identification?.guidance,onChange:e=>s([`identification`,`guidance`],e),readonly:a}),t(Jw,{label:o(`intakePolicy.field.distinguishFrom`),value:e.identification?.distinguish_from,onChange:e=>s([`identification`,`distinguish_from`],e),readonly:a}),t(L,{label:o(`intakePolicy.field.examples`),description:o(`intakePolicy.help.examples`),children:t(Ie,{options:e.identification?.examples??[],value:e.identification?.examples??[],onChange:e=>s([`identification`,`examples`],e.length?e:void 0),onOptionsChange:e=>s([`identification`,`examples`],e.length?e:void 0),creatable:!0,disabled:a,placeholder:o(`intakePolicy.placeholder.objectId`)})})]}),n(Kw,{title:o(`intakePolicy.section.locate`),last:!0,children:[t(Jw,{label:o(`intakePolicy.field.locateInstructions`),description:o(`intakePolicy.help.locateInstructions`),value:e.locate?.instructions,onChange:t=>s([`locate`],t?{...e.locate,instructions:t}:void 0),readonly:a}),n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(Xw,{label:o(`intakePolicy.field.contactSheetDetail`),value:e.locate?.detail,options:[{value:8,label:o(`intakePolicy.option.pagesPerSheet`,{count:8})},{value:16,label:o(`intakePolicy.option.pagesPerSheet`,{count:16})}],onChange:e=>s([`locate`,`detail`],e),readonly:a||!e.locate}),t(Yw,{label:o(`intakePolicy.field.locateMinPages`),value:e.locate?.min_pages,min:0,onChange:e=>s([`locate`,`min_pages`],e),readonly:a||!e.locate})]})]})]});if(r===`conversion`)return n(Gw,{children:[n(Kw,{title:o(`intakePolicy.section.conversion`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(Zw,{label:o(`intakePolicy.field.enabled`),value:e.text_conversion?.enabled,onChange:e=>s([`text_conversion`,`enabled`],e),readonly:a}),t(Xw,{label:o(`intakePolicy.field.method`),value:e.text_conversion?.method,options:tT(o,[`auto`,`basic`,`llm`,`custom`]),onChange:e=>s([`text_conversion`,`method`],e),readonly:a}),t(Xw,{label:o(`intakePolicy.field.outputFormat`),value:e.text_conversion?.output_format,options:tT(o,[`markdown`,`text`]),onChange:e=>s([`text_conversion`,`output_format`],e),readonly:a}),t(Xw,{label:o(`intakePolicy.field.pageScope`),value:e.text_conversion?.scope,options:tT(o,[`all`,`located`]),onChange:e=>s([`text_conversion`,`scope`],e),readonly:a}),t(Yw,{label:o(`intakePolicy.field.renderDpi`),value:e.text_conversion?.render_dpi,min:72,onChange:e=>s([`text_conversion`,`render_dpi`],e),readonly:a})]}),t(Jw,{label:o(`intakePolicy.field.instructions`),value:e.text_conversion?.instructions,onChange:e=>s([`text_conversion`,`instructions`],e),readonly:a})]}),t(Kw,{title:o(`intakePolicy.section.conversionModel`),children:t(eT,{title:o(`intakePolicy.field.model`),config:e.text_conversion?.config,onChange:e=>s([`text_conversion`,`config`],e),readonly:a})}),e.text_conversion?.method===`custom`&&t(Kw,{title:o(`intakePolicy.section.customConversion`),children:n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(qw,{label:o(`intakePolicy.field.interaction`),value:e.text_conversion.custom?.interaction,onChange:e=>s([`text_conversion`,`custom`,`interaction`],e),readonly:a}),t(qw,{label:o(`intakePolicy.field.agent`),value:e.text_conversion.custom?.agent,onChange:e=>s([`text_conversion`,`custom`,`agent`],e),readonly:a})]})}),t(Kw,{title:o(`intakePolicy.section.pageRanges`),last:!0,children:t($w,{value:e.text_conversion?.page_ranges,onChange:e=>s([`text_conversion`,`page_ranges`],e),readonly:a})})]});if(r===`extraction`)return n(Gw,{children:[n(Kw,{title:o(`intakePolicy.section.extraction`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(Zw,{label:o(`intakePolicy.field.enabled`),value:e.extraction?.enabled,onChange:e=>s([`extraction`,`enabled`],e),readonly:a}),t(Xw,{label:o(`intakePolicy.field.source`),value:e.extraction?.source,options:tT(o,[`auto`,`text`,`vision`,`mixed`]),onChange:e=>s([`extraction`,`source`],e),readonly:a}),t(Xw,{label:o(`intakePolicy.field.pageScope`),value:e.extraction?.scope,options:tT(o,[`all`,`located`]),onChange:e=>s([`extraction`,`scope`],e),readonly:a}),t(Yw,{label:o(`intakePolicy.field.maxPages`),value:e.extraction?.max_pages,min:1,onChange:e=>s([`extraction`,`max_pages`],e),readonly:a})]}),t(qw,{label:o(`intakePolicy.field.interaction`),value:e.extraction?.interaction,onChange:e=>s([`extraction`,`interaction`],e),readonly:a}),t(Jw,{label:o(`intakePolicy.field.instructions`),value:e.extraction?.instructions,onChange:e=>s([`extraction`,`instructions`],e),readonly:a}),t($w,{value:e.extraction?.page_ranges,onChange:e=>s([`extraction`,`page_ranges`],e),readonly:a})]}),t(Kw,{title:o(`intakePolicy.section.extractionModel`),children:t(eT,{title:o(`intakePolicy.field.model`),config:e.extraction?.config,onChange:e=>s([`extraction`,`config`],e),readonly:a})}),t(Kw,{title:o(`intakePolicy.section.visionBudget`),children:n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:[t(Xw,{label:o(`intakePolicy.field.defaultDetail`),value:e.extraction?.vision?.default_detail,options:tT(o,[`low`,`standard`,`high`]),onChange:e=>s([`extraction`,`vision`,`default_detail`],e),readonly:a}),t(Qw,{value:e.extraction?.vision?.allowed_details,onChange:e=>s([`extraction`,`vision`,`allowed_details`],e),readonly:a}),t(Yw,{label:o(`intakePolicy.field.maxImageTokens`),value:e.extraction?.vision?.max_image_tokens,min:1,onChange:e=>s([`extraction`,`vision`,`max_image_tokens`],e),readonly:a}),t(Yw,{label:o(`intakePolicy.field.maxPayloadMb`),value:e.extraction?.vision?.max_payload_mb,min:1,onChange:e=>s([`extraction`,`vision`,`max_payload_mb`],e),readonly:a}),t(Yw,{label:o(`intakePolicy.field.maxPagesPerCall`),value:e.extraction?.vision?.max_pages_per_call,min:1,onChange:e=>s([`extraction`,`vision`,`max_pages_per_call`],e),readonly:a})]})}),n(Kw,{title:o(`intakePolicy.section.verification`),last:!0,children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:[t(Zw,{label:o(`intakePolicy.field.enabled`),value:e.extraction?.verification?.enabled,onChange:e=>s([`extraction`,`verification`,`enabled`],e),readonly:a}),t(qw,{label:o(`intakePolicy.field.model`),value:e.extraction?.verification?.model,onChange:e=>s([`extraction`,`verification`,`model`],e),readonly:a}),t(qw,{label:o(`intakePolicy.field.environment`),value:e.extraction?.verification?.environment,onChange:e=>s([`extraction`,`verification`,`environment`],e),readonly:a}),t(Yw,{label:o(`intakePolicy.field.threshold`),value:e.extraction?.verification?.threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`verification`,`threshold`],e),readonly:a}),t(Yw,{label:o(`intakePolicy.field.maxRetries`),value:e.extraction?.verification?.max_retries,min:0,onChange:e=>s([`extraction`,`verification`,`max_retries`],e),readonly:a}),t(Xw,{label:o(`intakePolicy.field.onFailure`),value:e.extraction?.verification?.on_fail,options:tT(o,[`flag`,`block`]),onChange:e=>s([`extraction`,`verification`,`on_fail`],e),readonly:a})]}),t(Jw,{label:o(`intakePolicy.field.materiality`),value:e.extraction?.verification?.materiality,onChange:e=>s([`extraction`,`verification`,`materiality`],e),readonly:a})]})]});if(r===`grounding`){let r=e.extraction?.grounding,i=r?.review;return n(Gw,{children:[n(Kw,{title:o(`intakePolicy.section.grounding`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(Zw,{label:o(`intakePolicy.field.enabled`),value:r?.enabled,onChange:e=>s([`extraction`,`grounding`,`enabled`],e),readonly:a}),t(Yw,{label:o(`intakePolicy.field.maxPages`),value:r?.max_pages,min:1,onChange:e=>s([`extraction`,`grounding`,`max_pages`],e),readonly:a}),t(Yw,{label:o(`intakePolicy.field.windowPages`),value:r?.window_pages,min:1,onChange:e=>s([`extraction`,`grounding`,`window_pages`],e),readonly:a}),t(qw,{label:o(`intakePolicy.field.interaction`),value:r?.interaction,onChange:e=>s([`extraction`,`grounding`,`interaction`],e),readonly:a})]}),n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:[t(Zw,{label:o(`intakePolicy.field.useVision`),value:r?.use_vision,onChange:e=>s([`extraction`,`grounding`,`use_vision`],e),readonly:a}),t(Zw,{label:o(`intakePolicy.field.forceOcr`),value:r?.force_ocr,onChange:e=>s([`extraction`,`grounding`,`force_ocr`],e),readonly:a}),t(Zw,{label:o(`intakePolicy.field.refreshOcr`),value:r?.refresh_ocr,onChange:e=>s([`extraction`,`grounding`,`refresh_ocr`],e),readonly:a}),t(Zw,{label:o(`intakePolicy.field.omitBlockBoxes`),value:r?.omit_block_boxes,onChange:e=>s([`extraction`,`grounding`,`omit_block_boxes`],e),readonly:a}),t(Zw,{label:o(`intakePolicy.field.updateProperties`),value:r?.update_properties,onChange:e=>s([`extraction`,`grounding`,`update_properties`],e),readonly:a})]})]}),n(Kw,{title:o(`intakePolicy.section.models`),children:[t(eT,{title:o(`intakePolicy.field.primaryModel`),config:r?.config,onChange:e=>s([`extraction`,`grounding`,`config`],e),readonly:a}),t(eT,{title:o(`intakePolicy.field.hardModel`),config:r?.hard_config,onChange:e=>s([`extraction`,`grounding`,`hard_config`],e),readonly:a}),n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(Yw,{label:o(`intakePolicy.field.hardnessThreshold`),value:r?.hardness_threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`hardness_threshold`],e),readonly:a}),t(Yw,{label:o(`intakePolicy.field.minCitationDensity`),value:r?.min_citation_density,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`min_citation_density`],e),readonly:a})]})]}),n(Kw,{title:o(`intakePolicy.section.review`),last:!0,children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(Zw,{label:o(`intakePolicy.field.enabled`),value:i?.enabled,onChange:e=>s([`extraction`,`grounding`,`review`,`enabled`],e),readonly:a}),t(Zw,{label:o(`intakePolicy.field.forceReview`),value:i?.force,onChange:e=>s([`extraction`,`grounding`,`review`,`force`],e),readonly:a}),t(Yw,{label:o(`intakePolicy.field.reviewThreshold`),value:i?.threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`review`,`threshold`],e),readonly:a}),t(Yw,{label:o(`intakePolicy.field.coverageThreshold`),value:i?.coverage_threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`review`,`coverage_threshold`],e),readonly:a})]}),t(eT,{title:o(`intakePolicy.field.reviewModel`),config:i?.config,onChange:e=>s([`extraction`,`grounding`,`review`,`config`],e),readonly:a})]})]})}return n(Gw,{children:[t(Kw,{title:o(`intakePolicy.section.rendering`),children:t(Jw,{label:o(`intakePolicy.field.renderingTemplate`),description:o(`intakePolicy.help.renderingTemplate`),value:e.rendering_template,onChange:e=>s([`rendering_template`],e),readonly:a,monospace:!0,minLines:8})}),t(Kw,{title:o(`intakePolicy.section.embeddings`),last:!0,children:n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(Zw,{label:o(`intakePolicy.field.textEmbedding`),value:e.embeddings?.text,onChange:e=>s([`embeddings`,`text`],e),readonly:a}),t(Zw,{label:o(`intakePolicy.field.imageEmbedding`),value:e.embeddings?.image,onChange:e=>s([`embeddings`,`image`],e),readonly:a}),t(Zw,{label:o(`intakePolicy.field.propertiesEmbedding`),value:e.embeddings?.properties,onChange:e=>s([`embeddings`,`properties`],e),readonly:a}),t(Zw,{label:o(`intakePolicy.field.generateToc`),value:e.generate_toc,onChange:e=>s([`generate_toc`],e),readonly:a})]})})]})}function Gw({children:e}){return t(`div`,{className:`mx-auto w-full max-w-6xl px-1 py-4`,children:e})}function Kw({title:e,children:r,last:i=!1}){return n(`section`,{className:i?`pb-3`:`mb-6 border-b pb-6`,children:[t(`h3`,{className:`mb-4 text-sm font-semibold`,children:e}),t(`div`,{className:`space-y-4`,children:r})]})}function qw({label:e,value:n,onChange:r,readonly:i,description:a}){return t(L,{label:e,description:a,children:t(R,{value:n??``,onChange:e=>r(e||void 0),disabled:i})})}function Jw({label:e,value:n,onChange:r,readonly:i,description:a,minLines:o=3,monospace:s=!1}){return t(L,{label:e,description:a,children:t(Le,{value:n??``,onChange:e=>r(e.target.value||void 0),disabled:i,minLines:o,maxLines:14,className:s?`font-mono`:void 0})})}function Yw({label:e,value:n,onChange:r,readonly:i,min:a,max:o,step:s}){return t(L,{label:e,children:t(ce,{value:n,onChange:e=>r(e===void 0||Number.isFinite(e)?e:void 0),disabled:i,min:a,max:o,step:s??1,noScroll:!0})})}function Xw({label:e,description:n,value:r,options:i,onChange:a,readonly:o}){let{t:s}=X(),c=[{value:`__inherit__`,label:s(`intakePolicy.option.inherit`)},...i];return t(L,{label:e,description:n,children:t(ve,{options:c,value:c.find(e=>e.value===r)??c[0],by:`value`,optionLabel:e=>e.label,onChange:e=>a(e.value===`__inherit__`?void 0:e.value),disabled:o})})}function Zw({label:e,value:n,onChange:r,readonly:i}){let{t:a}=X(),o=[{value:`inherit`,label:a(`intakePolicy.option.inherit`)},{value:`enabled`,label:a(`intakePolicy.option.enabled`)},{value:`disabled`,label:a(`intakePolicy.option.disabled`)}],s=n===void 0?`inherit`:n?`enabled`:`disabled`;return t(L,{label:e,children:t(ve,{options:[...o],value:o.find(e=>e.value===s),by:`value`,optionLabel:e=>e.label,onChange:e=>r(e.value===`inherit`?void 0:e.value===`enabled`),disabled:i})})}function Qw({value:e,onChange:n,readonly:r}){let{t:i}=X(),a=tT(i,[`low`,`standard`,`high`]);return t(L,{label:i(`intakePolicy.field.allowedDetails`),children:t(ve,{multiple:!0,options:a,value:a.filter(t=>e?.includes(t.value)),by:`value`,optionLabel:e=>e.label,onChange:e=>n(e.length?e.map(e=>e.value):void 0),disabled:r})})}function $w({value:e,onChange:r,readonly:i}){let{t:a}=X(),s=t=>{let n=e?.filter((e,n)=>n!==t);r(n?.length?n:void 0)};return t(L,{label:a(`intakePolicy.field.pageRanges`),description:a(`intakePolicy.help.pageRanges`),children:n(`div`,{className:`space-y-2`,children:[e?.map((c,l)=>n(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_2.25rem] gap-2`,children:[t(ce,{"aria-label":a(`intakePolicy.field.rangeStart`),value:c[0],onChange:t=>{t!==void 0&&Number.isFinite(t)&&r(Rw(e,l,0,t))},disabled:i,step:1,noScroll:!0}),t(ce,{"aria-label":a(`intakePolicy.field.rangeEnd`),value:c[1],onChange:t=>{t!==void 0&&Number.isFinite(t)&&r(Rw(e,l,1,t))},disabled:i,step:1,noScroll:!0}),t(Re,{description:a(`intakePolicy.action.removeRange`),children:t(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":a(`intakePolicy.action.removeRange`),onClick:()=>s(l),disabled:i,children:t($r,{className:`size-4`})})})]},`${l}`)),n(o,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...e??[],[1,1]]),disabled:i,children:[t(kr,{className:`size-4`}),a(`intakePolicy.action.addRange`)]})]})})}function eT({title:e,config:r,onChange:i,readonly:a}){let{t:o}=X();return n(`div`,{children:[t(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:e}),n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(L,{label:o(`intakePolicy.field.environment`),children:t(Ox,{selectedEnvId:r?.environment,onChange:e=>i(zw(r,e?.id)),isClearable:!0,disabled:a})}),t(L,{label:o(`intakePolicy.field.model`),children:t(jx,{envId:r?.environment,selectedModelId:r?.model,onChange:e=>i(Bw(r,e?.id)),isClearable:!0,disabled:a||!r?.environment})})]})]})}function tT(e,t){return t.map(t=>({value:t,label:e(`intakePolicy.option.${t}`)}))}const nT=[{key:`minimal`,value:{identification:{guidance:`Documents that match this content type.`,distinguish_from:`Do not select this type for unrelated documents.`}}},{key:`extraction_only`,value:{text_conversion:{enabled:!1},extraction:{enabled:!0,source:`vision`,instructions:`Extract required fields only. Ignore cover pages, appendices, legal boilerplate, and marketing content.`},rendering_template:`# {{properties.title}}
|
|
452
|
+
+ `)||e.includes(`:!1}function zC(e){return e?`h-full overflow-auto`:`hidden`}var BC;(function(e){e.Text=`text`,e.Image=`image`,e.Video=`video`,e.Audio=`audio`,e.Pdf=`pdf`,e.Transcript=`transcript`})(BC||={});function VC({object:r,loadText:i,refetch:a,canEditProperties:o=!0,canCollaborate:s=!1}){let c=Xe(),{t:l}=Z(),{project:u,store:d}=Q(),f=_a(),p=r.revision?.root||r.id,m=u?.id?eC(u.id,p):void 0,[h,g]=X(r),[_,v]=X(()=>m?tC(m):!1),y=Y(null),b=Y(r.id),x=Y(r.id),S=Y(m);q(()=>{S.current!==m&&(S.current=m,v(m?tC(m):!1))},[m]);let C=K(()=>{v(e=>{let t=!e;return m&&nC(m,t),t})},[m]),w=K(()=>{m&&nC(m,!1),v(!1)},[m]);q(()=>{let e=x.current!==r.id;x.current=r.id,g(t=>!e&&t.id!==r.id?t:(b.current=r.id,t.id===r.id&&t.text&&!r.text?{...r,text:t.text}:r))},[r]);let T=K(async(e,t)=>{b.current=e;try{let[t,n]=await Promise.all([d.objects.retrieve(e),d.objects.getObjectText(e)]);b.current===e&&g({...t,text:n.text})}catch(e){console.error(`Failed to load the updated document revision`,e),c({status:`error`,title:l(`agent.failedToLoadDocument`),description:e instanceof Error?e.message:void 0,duration:5e3})}finally{t&&f(`/objects/${e}`)}},[f,d.objects,l,c]),E=async(e,t)=>{try{await navigator.clipboard.writeText(e),c({status:`success`,title:l(`store.contentCopied`,{type:l(t===`text`?`store.contentType`:`store.properties`)}),description:l(`store.successfullyCopied`,{type:t}),duration:2e3})}catch(e){console.error(`Failed to copy ${t}:`,e),c({status:`error`,title:l(`store.copyFailed`),description:l(`store.failedToCopy`,{type:t}),duration:5e3})}};return n(e,{children:[n(ye,{direction:`horizontal`,className:`h-full`,children:[t(ve,{defaultSize:67,className:`min-w-[100px]`,children:t(UC,{object:h,loadText:i??!1,handleCopyContent:E,refetch:a,canCollaborate:s,isCollaborating:_,onToggleCollaborate:C})}),t(_e,{withHandle:!0}),t(ve,{defaultSize:33,className:`min-w-[100px]`,children:t(HC,{object:h,refetch:a??(()=>Promise.resolve()),handleCopyContent:E,canEditProperties:o})})]}),_?t(EC,{object:h,initialContent:h.text??``,onClose:w,onDocumentUpdated:(e,t)=>void T(e,t),sendMessageRef:y}):null]})}function HC({object:r,refetch:i,handleCopyContent:a,canEditProperties:s}){let{t:c}=Z(),[l,u]=X(!1),[d,f]=X(!1);return n(e,{children:[n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`flex justify-between items-center px-2`,children:[n(`div`,{className:`flex items-center gap-1 bg-muted mb-2 p-1 rounded`,children:[t(o,{variant:`${l?`ghost`:`primary`}`,size:`sm`,title:c(`store.previewProperties`),onClick:()=>u(!l),children:`Properties`}),t(o,{variant:`${l?`primary`:`ghost`}`,size:`sm`,title:c(`store.viewInJsonFormat`),onClick:()=>u(!l),children:`JSON`})]}),n(`div`,{className:`flex items-center gap-2`,children:[r.properties&&t(o,{variant:`ghost`,size:`sm`,title:`Copy properties`,onClick:()=>a(JSON.stringify(r.properties,null,2),`properties`),children:t(En,{className:`size-4`})}),s&&t(jS,{permission:Ni.content_write,variant:`ghost`,size:`sm`,onClick:()=>{f(!0)},title:`Edit properties`,className:`flex items-center gap-2`,children:t(ei,{className:`size-4`})})]})]}),r.properties?t(`div`,{className:`flex-1 min-h-0 px-2`,children:t(St,{value:r.properties,viewCode:l})}):t(`div`,{className:`flex-1 min-h-0 px-2`,children:t(`div`,{children:c(`store.noPropertiesDefined`)})})]}),t(DC,{isOpen:d,onClose:()=>{f(!1)},object:r,refetch:i})]})}function UC(e){let{client:n}=Q(),r=e.object.type,i=r?.id,a=r?.default_view,{data:o}=U(async()=>!i||a?null:(await PS(n,i))?.intake?.default_view??null,[i,a]),s=a??o;return i&&!a&&o===void 0?t(`div`,{className:`flex h-full items-center justify-center`,children:t(De,{size:`lg`})}):t(WC,{...e,defaultView:s??void 0})}function WC({object:e,loadText:r,handleCopyContent:i,refetch:a,defaultView:s,canCollaborate:c,isCollaborating:l,onToggleCollaborate:u}){let{client:d}=Q(),{t:f}=Z(),p=e?.metadata?.type===wi.Image,m=e?.metadata?.type===wi.Video,h=e?.metadata?.type===wi.Audio,g=e?.content?.type===`application/pdf`,_=e?.content?.type?Ly(e.content.type):!1,v=IC(e?.status),y=!!(e.transcript&&(m||h)),b=e.metadata?.renditions?.find(e=>e.name===ji),x=()=>{switch(s){case`text`:return BC.Text;case`pdf`:if(g||_||b)return BC.Pdf;break;case`image`:if(p)return BC.Image;break;case`properties`:return BC.Text}return m?BC.Video:h?BC.Audio:p?BC.Image:BC.Text},S=Lx(e.id),[C,w]=X(x()),[T,E]=X(C===BC.Pdf);q(()=>{C===BC.Pdf&&E(!0)},[C]);let[D,O]=X(!1),k=sC(!!(e.content?.type&&!e.is_locked&&e.user_permissions?.can_write!==!1&&(e.content.type.startsWith(`text/`)||e.content.type===`application/json`||e.content.type===`application/xml`)),c),{fullText:A,displayText:j,isLoading:M,isCropped:N,loadText:P}=MC(e.id,e.text,r,e.revision?.root||e.id),F=(g||_)&&v&&(C===BC.Text||C===BC.Pdf),{progress:I,status:L,isComplete:ee}=NC(e.id,F),{pdfUrl:R,isConverting:te,error:z,triggerConversion:ne}=PC(e.id,_),B=J(()=>[{id:`office-pdf-rendition`,target:`pdf`,canConvert:({contentType:e,extension:t})=>_||(e?Ly(e):!1)||[`doc`,`docx`,`ppt`,`pptx`].includes(t),convert:async()=>{let t=await d.objects.getRendition(e.id,{format:Ai.pdf,generate_if_missing:!0,sign_url:!0,block_on_generation:!0});return t.status===`found`&&t.renditions?.length?{url:t.renditions[0],contentType:`application/pdf`,fileName:`${e.name||`document`}.pdf`}:null}}],[d,_,e.id,e.name]);q(()=>{ee&&L===zi.COMPLETED&&P()},[ee,L,P]);let re=(g||_)&&v&&!ee&&L===zi.RUNNING,ie=C===BC.Pdf&&!re,ae=re&&(C===BC.Text||C===BC.Pdf),oe=T&&!re,se=Y(null);return n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`flex justify-between items-center px-2 shrink-0`,children:[n(`div`,{className:`flex items-center gap-2 mb-2`,children:[n(`div`,{className:`flex items-center gap-1 bg-muted p-1 rounded`,children:[p&&t(o,{variant:C===BC.Image?`primary`:`ghost`,size:`sm`,title:f(`store.viewImage`),onClick:()=>w(BC.Image),children:`Image`}),m&&t(o,{variant:C===BC.Video?`primary`:`ghost`,size:`sm`,title:f(`store.viewVideo`),onClick:()=>w(BC.Video),children:`Video`}),h&&t(o,{variant:C===BC.Audio?`primary`:`ghost`,size:`sm`,title:f(`store.viewAudio`),onClick:()=>w(BC.Audio),children:`Audio`}),y&&t(o,{variant:C===BC.Transcript?`primary`:`ghost`,size:`sm`,title:f(`store.viewTranscript`),onClick:()=>w(BC.Transcript),children:`Transcript`}),t(o,{variant:C===BC.Text?`primary`:`ghost`,size:`sm`,title:f(`store.viewText`),onClick:()=>w(BC.Text),children:`Text`}),g&&t(o,{variant:C===BC.Pdf?`primary`:`ghost`,size:`sm`,title:f(`store.viewPdf`),onClick:()=>w(BC.Pdf),children:`PDF`}),_&&t(o,{variant:C===BC.Pdf?`primary`:`ghost`,size:`sm`,title:f(`store.viewAsPdf`),onClick:()=>{w(BC.Pdf),!b&&!R&&!te&&ne()},disabled:te,children:te?t(De,{size:`sm`}):`PDF`})]}),n(`div`,{className:`flex items-center gap-1`,children:[t(JC,{object:e}),t(YC,{objectId:e.id,available:S})]})]}),C===BC.Text&&!re&&!D&&t(GC,{object:e,text:j,fullText:A,handleCopyContent:i,textContainerRef:se,isEditing:D,onToggleEdit:()=>O(!0),canEdit:k.canEdit,isCollaborating:l,onToggleCollaborate:u,canCollaborate:k.canCollaborate}),C===BC.Pdf&&_&&(b||R)&&t(XC,{object:e,pdfRendition:b,officePdfUrl:R})]}),C===BC.Image&&t(`div`,{className:zC(!0),children:t(bS,{object:e})}),C===BC.Video&&t(`div`,{className:zC(!0),children:t(xS,{object:e})}),C===BC.Audio&&t(`div`,{className:zC(!0),children:t(yS,{object:e})}),y&&C===BC.Transcript&&t(`div`,{className:zC(!0),children:t(qC,{object:e,handleCopyContent:i})}),g&&oe&&t(`div`,{className:zC(ie),children:t(ZC,{object:e})}),_&&oe&&t(`div`,{className:zC(ie),children:t(QC,{object:e,pdfRendition:b,officePdfUrl:R,converters:B,officePdfConverting:te,officePdfError:z})}),ae&&t(`div`,{className:zC(!0),children:t($C,{progress:I,status:L})}),C===BC.Text&&!re&&!D&&M&&!j&&t(`div`,{className:zC(!0),children:t(`div`,{className:`flex justify-center items-center flex-1`,children:t(De,{size:`lg`})})}),C===BC.Text&&!re&&!D&&(!M||j)&&t(`div`,{className:zC(!0),children:t(KC,{object:e,text:j,isTextCropped:N,textContainerRef:se})}),D&&C===BC.Text&&A!=null&&t(AC,{object:e,text:A,onClose:()=>O(!1),onSaved:()=>{O(!1),P(),a?.()}})]})}function GC({object:r,text:i,fullText:a,handleCopyContent:s,onToggleEdit:c,canEdit:l,isCollaborating:u,onToggleCollaborate:d,canCollaborate:f}){let{client:p,project:m}=Q(),h=Xe(),{t:g}=Z(),_=r.content,{renderDocument:v,isDownloading:y}=Fd({client:p,toast:h}),{data:b}=U(()=>m?p.projects.retrieve(m.id):Promise.resolve(void 0),[m?.id]),x=b?.configuration?.pdf_template_object_id??void 0,S=lC(_?.type),C=uC(_?.type),T=async(e,t)=>{if(y)return;h({status:`info`,title:`Preparing ${e.toUpperCase()}`,description:g(`store.renderingDocument`),duration:2e3});let n=t===!1?void 0:x;await v(r.id,{format:e,title:r.name||`document`,useDefaultTemplate:t,templateObjectId:n})};return t(`div`,{className:`h-[41px] text-lg font-semibold flex justify-between items-center px-2`,children:n(`div`,{className:`flex items-center gap-2`,children:[a&&t(o,{variant:`ghost`,size:`sm`,title:`Copy text`,onClick:()=>s(a,`text`),children:t(En,{className:`size-4`})}),y?t(o,{variant:`ghost`,size:`sm`,disabled:!0,className:`h-8 w-8 p-0`,title:g(`agent.download`),"aria-label":g(`agent.download`),children:t(De,{size:`sm`})}):n(w,{trigger:t(o,{variant:`ghost`,size:`sm`,disabled:!i,className:`h-8 w-8 p-0`,title:g(`agent.download`),"aria-label":g(`agent.download`),children:t(An,{className:`size-4`})}),children:[a&&t(B,{onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!a)return;let t=`txt`,n=`text/plain`;_?.type===`application/xml`||_?.type===`text/xml`?(t=`xml`,n=`text/xml`):S&&(t=`md`,n=`text/markdown`);let i=new Blob([a],{type:n}),o=URL.createObjectURL(i),s=`${r.name||`document`}.${t}`,c=document.createElement(`a`);c.href=o,c.download=s,c.style.display=`none`,setTimeout(()=>{c.click(),URL.revokeObjectURL(o)},0)},children:n(`div`,{className:`flex items-center gap-2`,children:[t(An,{className:`size-4`}),`Download Text`]})}),S&&i&&n(e,{children:[t(B,{onClick:()=>T(Ai.docx),children:n(`div`,{className:`flex items-center gap-2`,children:[t(An,{className:`size-4`}),`Export as DOCX`]})}),t(B,{onClick:()=>T(Ai.pdf,!1),children:n(`div`,{className:`flex items-center gap-2`,children:[t(An,{className:`size-4`}),`Export as PDF`]})}),t(B,{onClick:()=>T(Ai.pdf),children:n(`div`,{className:`flex items-center gap-2`,children:[t(An,{className:`size-4`}),`Export as Branded PDF`]})})]})]}),a&&n(e,{children:[l&&c&&t(jS,{permission:Ni.content_write,variant:`ghost`,size:`sm`,onClick:c,title:g(`store.editText`),"aria-label":g(`store.editText`),className:`h-8 w-8 p-0`,children:t(ei,{className:`size-4`})}),f&&d&&C&&t(o,{variant:u?`primary`:`ghost`,size:`sm`,onClick:d,title:g(`agent.editWithAI`),"aria-label":g(`agent.editWithAI`),className:`h-8 w-8 p-0`,children:t(Qr,{className:`size-4`})})]})]})})}const KC=ct(({object:r,text:i,isTextCropped:a,textContainerRef:o})=>{let{t:s}=Z(),c=IC(r?.status),l=r.content,u=LC(r)===`xml`||l?.type===`application/xml`||l?.type===`text/xml`,d=uC(l?.type),f=!u&&(d||RC(i)),p={id:r.id,title:r.name,fileName:r.content?.name||r.name,contentType:u?`text/xml`:f?`text/markdown`:r.content?.type,content:i,sourcePath:r.content?.source};return i?n(e,{children:[a&&t(`div`,{className:`px-2 py-2 bg-attention/10 border-s-4 border-attention mx-2 mb-2 rounded`,children:n(`div`,{className:`flex items-center gap-2 text-attention`,children:[t(Kt,{className:`size-4`}),t(`span`,{className:`text-sm font-semibold`,children:s(`store.showingFirst128K`)})]})}),t(`div`,{className:`max-w-7xl px-2 h-full overflow-auto`,ref:o,children:t(kg,{source:p,className:`h-full`,bodyClassName:`overflow-auto`,markdownComponents:FC()})})]}):t(`div`,{className:`px-2`,children:t(`div`,{children:c?`Extracting content...`:`No content`})})});function qC({object:e,handleCopyContent:r}){let{t:i}=Z(),a=e.transcript,s=a?.text,c=a?.segments,l=s||(c?c.map(e=>e.text).join(` `):``),u=e=>{let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=Math.floor(e%60);return t>0?`${t}:${n.toString().padStart(2,`0`)}:${r.toString().padStart(2,`0`)}`:`${n}:${r.toString().padStart(2,`0`)}`};return n(`div`,{className:`flex flex-col h-full`,children:[t(`div`,{className:`flex justify-end items-center px-2 mb-2`,children:l&&t(o,{variant:`ghost`,size:`sm`,title:`Copy transcript`,onClick:()=>r(l,`text`),children:t(En,{className:`size-4`})})}),t(`div`,{className:`h-full} overflow-auto px-2`,children:c&&c.length>0?t(`div`,{className:`space-y-2`,children:c.map((e,r)=>n(`div`,{className:`flex gap-3 text-sm`,children:[n(`span`,{className:`text-muted font-mono text-xs shrink-0 pt-0.5`,children:[u(e.start),e.end&&` - ${u(e.end)}`]}),t(`span`,{className:`flex-1`,children:e.text})]},`segment-${r}`))}):s?t(`pre`,{className:`text-wrap bg-muted text-muted p-2 whitespace-pre-wrap`,children:s}):t(`div`,{className:`text-muted`,children:i(`store.noTranscriptAvailable`)})})]})}function JC({object:r}){let[i,a]=X(!1);return LC(r)===`markdown`?n(e,{children:[t(o,{variant:`ghost`,size:`sm`,onClick:()=>a(!0),title:`Side by side view`,children:t(Vn,{className:`size-4`})}),i&&t(me,{children:t(pS,{objectId:r.id,onClose:()=>a(!1)})})]}):null}function YC({objectId:r,available:i}){let{t:a}=Z(),[s,c]=X(!1);return i?n(e,{children:[t(o,{variant:`ghost`,size:`sm`,onClick:()=>c(!0),title:a(`grounded.title`),"aria-label":a(`grounded.title`),children:t(Gr,{className:`size-4`})}),s&&t(me,{children:t(Bx,{objectId:r,onClose:()=>c(!1)})})]}):null}function XC({object:e,pdfRendition:n,officePdfUrl:r}){let{client:i}=Q(),a=Xe(),{t:s}=Z(),[c,l]=X(!1);return t(`div`,{className:`flex items-center gap-2`,children:t(o,{variant:`ghost`,size:`sm`,onClick:async()=>{l(!0);try{let t=r;!t&&n?.content?.source&&(t=(await i.files.getDownloadUrl(n.content.source,`${e.name||`document`}.pdf`,`attachment`)).url),t&&window.open(t,`_blank`)}catch(e){console.error(`Failed to download PDF:`,e),a({status:`error`,title:s(`store.downloadFailed`),description:s(`store.failedToDownloadPdf`),duration:5e3})}finally{l(!1)}},disabled:c,title:`Download PDF`,children:c?t(De,{size:`sm`}):t(An,{className:`size-4`})})})}function ZC({object:e}){let n={id:e.id,title:e.name,fileName:e.content?.name||e.name,contentType:e.content?.type,sourcePath:e.content?.source};return t(`div`,{className:`h-full`,children:t(kg,{source:n,className:`h-full`,showHeader:!1})})}function QC({object:e,pdfRendition:r,officePdfUrl:i,converters:a,officePdfConverting:o,officePdfError:s}){let{t:c}=Z();if(o)return n(`div`,{className:`flex flex-col justify-center items-center flex-1 gap-2`,children:[t(De,{size:`lg`}),t(`span`,{className:`text-muted`,children:c(`store.convertingToPdf`)})]});if(s)return n(`div`,{className:`flex flex-col justify-center items-center flex-1 gap-2 text-destructive`,children:[t(Kt,{className:`size-8`}),t(`span`,{children:s})]});if(r?.content?.source){let n={id:e.id,title:e.name,fileName:`${e.name||`document`}.pdf`,contentType:`application/pdf`,sourcePath:r.content.source};return t(`div`,{className:`h-full`,children:t(kg,{source:n,className:`h-full`})})}if(i){let n={id:e.id,title:e.name,fileName:`${e.name||`document`}.pdf`,contentType:`application/pdf`,url:i};return t(`div`,{className:`h-full`,children:t(kg,{source:n,className:`h-full`})})}let l={id:e.id,title:e.name,fileName:e.content?.name||e.name,contentType:e.content?.type,sourcePath:e.content?.source};return t(`div`,{className:`h-full`,children:t(kg,{source:l,converters:a,className:`h-full`})})}function $C({progress:r,status:i}){let{t:a}=Z(),o=Wy(i),s=Gy(i),c=r?.phase===`grounded_extraction`,l=r?.percent!=null&&!Number.isNaN(r.percent)?r.percent:0;return n(`div`,{className:`px-4 py-4`,children:[r&&n(`div`,{className:`space-y-2`,children:[n(`div`,{className:`flex flex-col gap-1`,children:[t(ew,{name:c?`Prepare Evidence`:`Analyze Page`,progress:r.pages}),c&&n(e,{children:[t(ew,{name:`Run OCR`,progress:r.images}),t(ew,{name:`Extract Grounded Data`,progress:r.tables}),t(ew,{name:`Review and Annotate`,progress:r.visuals})]})]}),n(`div`,{className:`pt-2 text-sm text-muted`,children:[`Progress: `,l,`%`,t(`span`,{className:`px-2`,children:`•`}),t(`span`,{className:o,children:s}),r.started_at&&n(e,{children:[t(`span`,{className:`px-2`,children:`•`}),n(`span`,{children:[((Date.now()-r.started_at)/1e3).toFixed(0),` sec. elapsed`]})]})]}),t(Et,{percent:l})]}),!r&&n(`div`,{className:`flex items-center gap-2 text-muted`,children:[t(De,{size:`sm`}),t(`span`,{children:a(`store.loadingProcessingStatus`)})]})]})}function ew({name:e,progress:t}){return n(`div`,{className:`flex gap-2 text-sm`,children:[n(`span`,{className:`text-muted min-w-36`,children:[e,`:`]}),n(`span`,{children:[t.processed,` of `,t.total]})]})}const tw=Object.values(Fi),nw=Object.values(Li);function rw({onChange:e,isLoading:r,refresh:i,searchTypes:a}){let{client:s,project:c}=Q(),{t:l}=Z(),u=Xe(),[d,f]=X(void 0),[p,h]=X(void 0),g=!!c&&(!!p?.embeddings.text||!!p?.embeddings.image),[_,v]=X(void 0),y=Y(i),b=Y(void 0),[x,S]=X(!1),[C,w]=X(a||tw),[T,E]=X(100);q(()=>{a&&w(a)},[a]);let D={},O=!1,k=!1;C.forEach(e=>{e===Fi.full_text?O=!0:k=!0,nw.includes(e)&&(D[e]=!0)}),q(()=>{y.current!==i&&(y.current=i,f(void 0),v(void 0))}),q(()=>{c&&s.projects.retrieve(c.id).then(e=>{h(e.configuration)})},[s.projects.retrieve,c]),q(()=>{_&&u({title:_,status:`success`,duration:2e3})},[_,u]),q(()=>{let t=b.current;b.current=d,t&&(!d||d.length===0)&&e(void 0)},[e,d]);let A=()=>{!g||!d||(e({vector:k?{text:d,config:D}:void 0,full_text:O?d:void 0,limit:T}),v(`Searching...`))},j=e=>{e.key===`Enter`&&A()},M=e=>t=>{w(t?t=>Array.from(new Set([...t,e])):t=>t.filter(t=>t!==e))};return n(`div`,{className:`flex gap-1 items-center`,children:[t(R,{placeholder:l(`store.searchPlaceholder`),value:d,onChange:f,onKeyDown:j,className:`min-w-[200px]`}),t(o,{variant:`ghost`,onClick:()=>S(!0),title:l(`store.semanticSearchSettings`),className:`ms-1`,children:t(Jr,{size:18})}),n(ie,{isOpen:x,onClose:()=>S(!1),children:[t(se,{children:l(`store.searchTypes`)}),t(ae,{children:n(`div`,{className:`flex flex-col gap-2`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(m,{id:`search-type-full_text`,checked:C.includes(Fi.full_text),onCheckedChange:M(Fi.full_text)}),t(z,{htmlFor:`search-type-full_text`,children:l(`store.fullText`)})]}),t(`div`,{className:`font-semibold mt-2 mb-1`,children:l(`store.embeddings`)}),nw.map(e=>n(`div`,{className:`flex items-center gap-2`,children:[t(m,{id:`search-type-${e}`,checked:C.includes(e),onCheckedChange:M(e)}),t(z,{htmlFor:`search-type-${e}`,children:e.charAt(0).toUpperCase()+e.slice(1)})]},e)),n(`div`,{className:`mt-3`,children:[t(`span`,{className:`me-2`,children:l(`store.limit`)}),t(ce,{type:`number`,min:1,value:T,onChange:e=>E(Number(e??100)),style:{width:80}})]})]})}),t(oe,{children:t(o,{variant:`outline`,onClick:()=>S(!1),children:l(`store.close`)})})]}),t(o,{variant:`secondary`,isLoading:r,onClick:A,isDisabled:!g,title:l(`store.semanticSearch`),children:l(`store.search`)})]})}const iw=[{name:`ID`,field:`id`,type:`objectId?slice=-7`},{name:`Name`,field:`.`,type:`objectName`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Updated At`,field:`updated_at`,type:`date`}];function aw(e,t){return(t?e.getTypeLayout(t):iw)??iw}function ow({onUploadDone:e=async()=>{},layout:n,toolbarActions:r}){let i=cb(),a=Xe(),{t:o}=Z(),s=vb(K(async t=>{await e(t),setTimeout(()=>{console.log(`Delayed refresh after upload to ensure backend consistency`),i.search().then(e=>{e&&a({title:o(`store.documentListRefreshed`),description:o(`store.documentListRefreshedDesc`),status:`info`,duration:3e3})}).catch(e=>{console.error(`Failed to refresh search results:`,e)})},1e3)},[e,i,o,a])),c=K((e,t)=>{let n=i.collectionId;return s(e,t,n)},[i,s]);return t(sw,{layout:n,onUpload:c,toolbarActions:r})}function sw({layout:e,onUpload:r,allowFilter:i=!0,allowSearch:a=!0,toolbarActions:o}){let{t:s}=Z(),c=cb(),[l,u]=X(!1),[d,f]=X(null),{registry:p}=Tv(),{search:m,isLoading:h,error:g,objects:_,hasMore:v}=ub(),[y,b]=X(p?e||aw(p,m.query.type):iw);q(()=>{e&&b(e)},[e]);let[x,S]=X(0),[C,w]=X(0),[T,E]=X(localStorage.getItem(Db.LAST_DISPLAYED_VIEW)===`grid`),[D,O]=X([]),k=Y(null),A=Y(null),j=K((e,t)=>{u(!1),e.catch(e=>{console.error(t,e)}).finally(()=>{u(!0)})},[]);q(()=>{let e=!1;return m.initialized?(u(!0),()=>{e=!0}):(u(!1),w(0),m.search().catch(t=>{e||console.error(`Initial search failed:`,t)}).finally(()=>{e||u(!0)}),()=>{e=!0})},[m]),q(()=>{_.length<C&&w(_.length)},[_.length,C]),W(k,()=>{l&&_.length>0&&_.length!==C&&(u(!1),m.loadMore().catch(e=>{console.error(`Failed to load more search results:`,e)}).finally(()=>{w(_.length),u(!0)}))},{deps:[l,_.length]});let N=e=>{if(e?.vector){if(m.query.vector=e.vector,m.query.full_text=e.full_text,m.query.weights=e.weights,m.query.score_aggregation=e.score_aggregation,m.query.dynamic_scaling=e.dynamic_scaling,e.limit!==void 0&&(m.limit=e.limit,m.query.limit=e.limit),!y.find(e=>e.name===`Search Score`)){let e=[...y,{name:`Search Score`,field:`score`,render:e=>typeof e.score==`number`?e.score.toFixed(4):`0.0000`}];b(e)}j(m.search(),`Vector search failed:`)}else e?.full_text?(m.query.full_text=e.full_text,e.limit!==void 0&&(m.limit=e.limit,m.query.limit=e.limit),j(m.search(),`Text search failed:`)):e===void 0&&l&&(delete m.query.vector,delete m.query.full_text,j(m.search(),`Search reset failed:`))},P=lb(),F=cb(),I=()=>{j(m.search(),`Search refresh failed:`)},L=Lv(P),ee=Rv(F),R=e=>{let t=typeof e==`function`?e(D):e;O(t),ee(t)},te=(e,t)=>{let n=L.find(t=>t.name===e),r={name:e,type:n?.type,placeholder:n?.placeholder,multiple:n?.multiple};R(i=>{let a=i.filter(t=>t.name!==e);if(n?.type===`stringList`||Array.isArray(t)){let n=Array.isArray(t)?t:[t],o=i.find(t=>t.name===e)?.value??[];return[...a,{...r,value:Array.from(new Set([...o,...n]))}]}return[...a,{...r,value:[{value:t,label:t}]}]})},z=new URL(window.location.href),ne=z.searchParams.get(`filters`);if(ne)try{let e=ne.split(`;`),t=e.filter(e=>{let[t]=e.split(`:`),n=decodeURIComponent(t);return n!==`start`&&n!==`end`});if(t.length!==e.length){let e=t.length>0?t.join(`;`):``;e?z.searchParams.set(`filters`,e):z.searchParams.delete(`filters`),window.history.replaceState(window.history.state||{},``,z.toString())}}catch(e){console.error(`Failed to clean start/end filters from URL:`,e)}let B=_a();return n(`div`,{className:`flex flex-col gap-y-2 flex-1 min-h-0 `,children:[t(lw,{object:d,onClose:()=>f(null)}),g&&t(M,{title:s(`store.error`),children:g.message}),t(cw,{isLoading:h,refreshTrigger:x,allowFilter:i,allowSearch:a,filterGroups:L,filters:D,handleFilterChange:R,handleVectorSearch:N,handleRefetch:I,setIsGridView:E,toolbarActions:o}),t(`div`,{className:`flex flex-col w-full flex-1 min-h-0 border rounded-md mb-2`,children:n(`div`,{ref:A,className:`flex-1 min-h-0 overflow-y-auto`,children:[t(wy,{onFilter:te,children:t(bb,{objects:_,isLoading:!_.length&&h,layout:y,onRowClick:e=>{B(`/objects/${e.id}`)},previewObject:e=>{let t=_.find(t=>t.id===e)||null;f(t)},selectedObject:d,onUpload:r,isGridView:T,collectionId:c.collectionId})}),v?t(`div`,{ref:k,className:`w-full flex justify-center`,children:t(De,{size:`xl`})}):t(`div`,{className:`text-muted text-center text-sm py-1`,children:`All ${_.length} objects loaded.`})]})})]})}function cw(e){let{t:r}=Z(),{isLoading:i,refreshTrigger:a,allowFilter:s,allowSearch:c,filterGroups:l,filters:u,handleFilterChange:d,handleVectorSearch:f,handleRefetch:p,setIsGridView:m,toolbarActions:h}=e;return n(`div`,{className:`sticky top-0 z-10 bg-background py-2 flex justify-between items-center`,children:[s?t(I,{filterGroups:l,filters:u,setFilters:d,children:n(`div`,{children:[t(`div`,{className:`flex flex-row gap-4 items-center justify-between w-full`,children:n(`div`,{className:`flex gap-2 items-center w-2/3`,children:[c&&t(rw,{onChange:f,isLoading:i,refresh:a,className:`w-full`}),t(P,{})]})}),n(`div`,{className:`flex gap-2 items-center pt-2`,children:[t(N,{}),t(F,{})]})]})}):t(`div`,{className:`flex flex-row gap-4 items-center justify-between w-full`,children:t(`div`,{className:`flex gap-2 items-center w-2/3`,children:c&&t(rw,{onChange:f,isLoading:i,refresh:a})})}),n(`div`,{className:`flex gap-1 items-center`,children:[h,t(o,{variant:`outline`,onClick:p,title:r(`store.refresh`),children:t(zr,{size:16})}),t(Db,{onUpdate:m})]})]})}function lw({object:e,onClose:r}){let{store:i}=Q(),a=Xe(),s=_a(),{downloadFromContentSource:c}=Fd({client:i,toast:a}),l=e?.content?.source,u=typeof e?.properties?.title==`string`?e.properties.title:e?.name;return e?n(we,{title:u,isOpen:!0,onClose:r,children:[n(`div`,{className:`flex items-center gap-x-2`,children:[t(o,{variant:`ghost`,size:`sm`,title:`Open Object`,onClick:()=>s(`/objects/${e.id}`),children:t(Pn,{className:`size-4`})}),l&&t(o,{variant:`ghost`,size:`sm`,title:`Download`,onClick:()=>c(l,Pd(e)),children:t(An,{className:`size-4`})})]}),t(C,{className:`my-2`}),t(`div`,{className:`pt-2`,children:t(VC,{object:e,loadText:!0},e.id)})]}):null}const uw=[{name:`ID`,field:`id`,type:`objectId?slice=-7`},{name:`Name`,field:`.`,type:`objectName`},{name:`Revision`,field:`.`,type:`revision`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Updated At`,field:`updated_at`,type:`date`}];function dw({collection:e}){let n=Xe(),{client:r}=Q(),{registry:i}=Tv(),a=async t=>{t.length>0&&await r.store.collections.addMembers(e.id,t).catch(e=>{n({title:`Failed to add objects to collection`,description:e.message,status:`error`})})},o=fw(e,i);return t(`div`,{className:`flex flex-col h-full`,children:e.dynamic?t(sw,{layout:o}):t(ow,{onUploadDone:a,layout:o})})}function fw(e,t){let n=e.table_layout;return n&&n.length>0||(e.type&&t&&(n=t?.getTypeLayout(Bi(e.type))),n&&n.length>0)?n:uw}function pw({className:e,defaultValue:r,onChange:i,isClearable:a,multiple:o}){let{t:s}=Z(),{registry:c}=Tv(),[l,u]=X(!1),d=e=>e===null?s(`store.none`):n(`div`,{children:[t(`div`,{className:`text-sm`,children:e.name}),t(`div`,{className:`text-xs text-muted truncate`,children:e.description})]}),[f,p]=X(),[m,h]=X([]);return q(()=>{if(!l&&(u(!0),c&&r)){if(o&&Array.isArray(r)){let e=c.types.filter(e=>r.includes(e.id));h(e)}let e=c.types.find(e=>e.id===r);e&&p(e)}},[l,c,r,o]),o?t(`div`,{className:`flex flex-col gap-4 content-between`,children:t(be,{options:c?.types||[],value:m,onChange:e=>{h(e),i(e)},placeholder:s(`store.chooseContentTypes`),optionLabel:d,className:e||`text-sm bg-background`,filterBy:`name`,isClearable:a||!1,multiple:!0})}):t(`div`,{className:`flex flex-col gap-4 content-between`,children:t(be,{options:c?.types||[],value:f,onChange:e=>{p(e||void 0),i(e)},placeholder:s(`store.chooseContentType`),optionLabel:d,className:e||`text-sm bg-background`,filterBy:`name`,isClearable:a||!1})})}function mw({onClose:r,redirect:i=!0,onAddToCollection:a}){let s=_a(),c=Xe(),{t:l}=Z(),[u,d]=X(!1),{client:f}=Q(),[p,m]=X({dynamic:!1,name:``,description:``});function h(e,t){m({...p,[e]:t})}return n(e,{children:[t(ae,{children:n(`form`,{onSubmit:e=>e.preventDefault(),children:[t(L,{label:l(`type.name`),required:!0,children:t(R,{type:`text`,value:p.name||``,onChange:e=>h(`name`,e)})}),t(L,{label:l(`type.description`),className:`mt-2`,children:t(ze,{value:p.description||``,onChange:e=>h(`description`,e.target.value)})}),t(L,{label:l(`store.dynamicCollection`),className:`mt-2`,direction:`row`,description:l(`store.dynamicCollectionDescription`),children:t(ke,{value:p.dynamic||!1,onChange:e=>h(`dynamic`,e)})}),!p.dynamic&&t(L,{label:l(`store.allowedContentTypes`),className:`mt-4`,description:l(`store.allowedContentTypesOptionalDescription`),children:t(pw,{defaultValue:p.allowed_types||null,onChange:e=>{Array.isArray(e)?h(`allowed_types`,e.map(e=>e.id)):h(`allowed_types`,e?[e.id]:[])},isClearable:!0,multiple:!0})}),t(L,{label:l(`store.contentType`),className:`mt-2`,description:l(`store.typeDescription`),children:t(pw,{defaultValue:p.type||null,onChange:e=>{Array.isArray(e)?h(`type`,e.length>0?e[0].id:null):h(`type`,e?.id||null)},isClearable:!0})})]})}),t(oe,{children:t(o,{isDisabled:u,onClick:()=>{if(!p?.name?.trim()){c({title:l(`type.nameRequired`),description:l(`store.pleaseProvideName`),status:`error`,duration:5e3});return}p.name=p.name.trim(),p.description&&=p.description.trim(),p.dynamic??=!1,d(!0),f.store.collections.create(p).then(e=>{r(),c({title:l(`store.collectionCreated`),description:`Collection "${e.name}" created successfully`,status:`success`,duration:3e3}),i&&s(`/collections/${e.id}`),a&&a(e.id)}).catch(e=>{c({title:l(`store.failedToCreateCollection`),description:e.message,status:`error`,duration:5e3})}).finally(()=>d(!1))},children:l(`store.createCollection`)})})]})}function hw({isOpen:e,onClose:r}){let{t:i}=Z();return n(ie,{onClose:r,isOpen:e,children:[t(se,{children:i(`store.createACollection`)}),t(mw,{onClose:r})]})}function gw(){let{client:r}=Q(),i=Xe(),{t:a}=Z(),[s,c]=X(),[l,u]=X(!0),[d,f]=X(!1),{data:p,error:m,refetch:h}=U(()=>r.store.collections.search({}),[]);return q(()=>{(p||m)&&u(!1)},[p,m]),m?t(M,{title:a(`store.collectionFetchFailed`),children:Ve(m)}):n(e,{children:[p&&(p.length>0?n(Ne,{className:`w-full`,children:[t(`thead`,{children:n(`tr`,{children:[t(`th`,{children:a(`type.name`)}),t(`th`,{children:a(`type.type`)}),t(`th`,{children:a(`store.created`)}),t(`th`,{})]})}),t(Ae,{columns:4,isLoading:l,children:p.map(e=>n(Me,{children:[t(`td`,{children:n(`div`,{className:`flex items-center gap-2`,children:[t(_w,{isDynamic:e.dynamic}),t(ga,{href:`/collections/${e.id}`,children:e.name})]})}),t(`td`,{children:e.type?.name||`-`}),t(`td`,{children:fs(e.created_at).fromNow()}),t(`td`,{className:`text-end`,children:t(o,{variant:`destructive`,size:`sm`,onClick:()=>c(e.id),children:t(ai,{className:`size-4`})})})]},e.id))})]}):t(j,{title:a(`store.noCollections`),buttonLabel:a(`store.newCollections`),onClick:()=>f(!0),children:a(`store.getStartedCollections`)})),t(hw,{isOpen:d,onClose:()=>f(!1)}),t(b,{isOpen:!!s,title:a(`store.deleteCollection`),content:a(`store.areYouSureDeleteCollection`),onConfirm:async()=>{if(s)try{await r.store.collections.delete(s),i({title:a(`store.collectionDeleted`),status:`success`,duration:3e3}),h()}catch(e){console.error(`Failed to delete collection:`,e),i({title:a(`store.failedToDeleteCollection`),description:Ve(e),status:`error`,duration:5e3})}finally{c(void 0)}},onCancel:()=>c(void 0)})]})}function _w({isDynamic:e}){let{t:n}=Z(),r=n(e?`store.dynamicCollection`:`store.staticCollection`),i=t(e?Kr:Kn,{className:`size-5`});return t(Be,{description:r,className:`me-2`,children:i})}const vw=`h-6 w-6 p-0 opacity-0 group-hover/field:opacity-100 text-muted hover:text-foreground transition-opacity shrink-0`;function yw({objects:e,isLoading:r,onFilter:i,selectedIds:a,onToggleOne:s,allSelected:c,onToggleAll:l}){let{t:u}=Z(),d=_a(),f=!!s;return n(Ne,{className:`w-full`,children:[t(je,{children:n(`tr`,{children:[f&&t(`th`,{className:`w-[5%]`,children:t(`input`,{type:`checkbox`,checked:!!c,"aria-label":u(`store.actions.selectAllTypes`),onChange:e=>l?.(e.target.checked)})}),t(`th`,{children:u(`store.name`)}),t(`th`,{children:u(`store.strictMode`)}),t(`th`,{children:u(`store.semanticChunking`)}),t(`th`,{children:u(`store.updatedAt`)})]})}),t(Ae,{isLoading:r&&(!e||e.length===0),columns:f?5:4,children:e?.map(e=>n(`tr`,{onClick:()=>d(`/types/${e.id}`),className:`group cursor-pointer hover:bg-muted`,children:[f&&t(`td`,{className:`w-[5%]`,children:t(`input`,{type:`checkbox`,className:Qe(`checkbox group-hover:inline-block`,a?.includes(e.id)?`inline-block`:`hidden`),checked:a?.includes(e.id)??!1,"aria-label":u(`store.actions.selectType`,{name:e.name}),onClick:e=>e.stopPropagation(),onChange:t=>s?.(e.id,t.target.checked)})}),t(`td`,{className:`group/field`,children:n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:e.name}),t(x,{content:e.id,className:vw}),i&&t(o,{variant:`ghost`,size:`sm`,title:`Filter by ${e.name}`,className:vw,onClick:t=>{t.stopPropagation(),i(`name`,e.name)},children:t(Gn,{className:`size-3`})})]})}),t(`td`,{children:e.strict_mode?`Yes`:`No`}),t(`td`,{children:e.is_chunkable?`Yes`:`No`}),t(`td`,{children:t(Be,{description:fs(e.updated_at).format(`YYYY-MM-DD HH:mm:ss`),children:fs(e.updated_at).fromNow()})})]},e.id))})]})}function bw({title:e,isOpen:r,onClose:i,okLabel:a,initialPayload:s,isLoading:c}){let{t:l}=Z(),u=Xe(),[d,f]=X(s?.name),[p,m]=X(s?.description),h=s?.strict_mode??!1,g=()=>{if(!d){u({status:`error`,title:l(`type.nameRequired`),duration:5e3});return}i({name:d,description:p,strict_mode:h}).then(()=>i())};return n(ie,{isOpen:r,onClose:()=>i(),children:[t(se,{children:e}),t(ae,{className:`pt-0`,children:n(`div`,{className:`h-full flex flex-col gap-4 content-between`,children:[n(`div`,{children:[t(`div`,{className:`block text-sm font-medium text-muted`,children:l(`type.name`)}),t(R,{value:d,onChange:f})]}),n(`div`,{children:[t(`div`,{className:`block text-sm font-medium text-muted`,children:l(`type.description`)}),t(ze,{value:p,onChange:e=>m(e.target.value),minLines:5})]})]})}),t(oe,{children:n(`div`,{className:`flex justify-end gap-4`,children:[t(o,{variant:`secondary`,onClick:()=>i(),children:l(`modal.cancel`)}),t(o,{variant:`primary`,onClick:()=>g(),isLoading:c,children:a})]})})]})}var xw=class{client;limit;result=new Ce({objects:[],isLoading:!1});query={};constructor(e,t=100){this.client=e,this.limit=t}get objects(){return this.result.value.objects}get error(){return this.result.value.error}get isRunning(){return this.result.value.isLoading}getFilterValue(e){return this.query[e]}setFilterValue(e,t){this.query[e]=t,this.search()}reset(e=!1){this.result.value={objects:[],isLoading:e}}_updateRunningState(e){let t=this.result.value;this.result.value={objects:t.objects,isLoading:e,error:t.error}}async _search(e=!1){if(this.isRunning)return Promise.resolve(!1);this.result.value={isLoading:!0,objects:e?this.objects:[]};let t=this.limit,n=this.objects.length;return this.client.types.list({limit:t,offset:n,query:this.query}).then(async e=>(this.result.value={isLoading:!1,objects:this.objects.concat(e)},!0)).catch(e=>{throw this.result.value={error:e,isLoading:!1,objects:this.objects},e})}search(){return this.isRunning?Promise.resolve(!1):this._search(!1)}loadMore(){return this.isRunning?Promise.resolve(!1):this._search(!0)}};const Sw=ot(void 0);function Cw(){return lt(Sw)}function ww(){let e=Cw();return{...Ze(e.result),search:e}}function Tw(){return Cw().objects.length}var Ew;(function(e){e.true=`Yes`,e.false=`No`})(Ew||={});function Dw({isDirty:r=!1}){let{store:i}=Q(),{reload:a}=Tv(),{t:s}=Z(),c=Xe(),[l,u]=X(!1),{search:d,isLoading:f,error:p,objects:m}=ww(),[h,g]=X([]),[_,v]=X(!1),[y,x]=X(!1),S=h.length,C=!!m&&m.length>0&&m.every(e=>h.includes(e.id)),w=m?.filter(e=>h.includes(e.id))??[],T=(e,t)=>{g(n=>t?n.includes(e)?n:[...n,e]:n.filter(t=>t!==e))},E=e=>{g(e&&m?m.map(e=>e.id):[])},D=async()=>{if(!y){x(!0);try{let e=await Promise.allSettled(h.map(e=>i.types.delete(e))),t=e.filter(e=>e.status===`rejected`).length,n=e.length-t;v(!1),g([]),a(),await d.search(),c(t===0?{status:`success`,title:s(`store.actions.typeDeleted`,{count:n}),duration:3e3}:{status:`error`,title:s(`store.actions.typeDeletePartial`,{succeeded:n,failed:t}),duration:5e3})}catch(e){c({status:`error`,title:s(`store.actions.failedToDeleteTypes`),description:e instanceof Error?e.message:void 0,duration:5e3})}finally{x(!1)}}},[O,k]=X(``),A=We(O,500),N=Y(null);W(N,()=>{l&&d.loadMore()},{deps:[l,d]}),q(()=>{d.search().then(()=>u(!0))},[d]),q(()=>{d.query.name=A,d.search().then(()=>u(!0))},[A,d]);let[P,F]=X(void 0),I=e=>{F(e)};q(()=>{d.query.chunkable=P?P===`Yes`:void 0,d.search().then(()=>u(!0))},[P,d]),q(()=>{r&&l&&d.search().then(()=>u(!0))},[r,l,d]);let[L,ee]=X(!1);return p?t(M,{title:s(`store.failedToFetchTypes`),children:p.message}):n(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[n(`div`,{className:`flex flex-shrink-0 gap-4 items-center`,children:[t(R,{placeholder:s(`store.filterByName`),value:O,onChange:k}),t(be,{className:`w-60`,isClearable:!0,options:Object.values(Ew),value:P,onChange:I,placeholder:s(`store.isChunkable`)}),S>0&&n(`div`,{className:`flex items-center gap-2 ms-auto`,children:[t(`span`,{className:`text-sm font-medium whitespace-nowrap`,children:s(`store.actions.selectedCount`,{n:S})}),t(Be,{description:s(`store.actions.clearSelection`),asChild:!0,children:t(o,{variant:`ghost`,"aria-label":s(`store.actions.clearSelection`),onClick:()=>g([]),children:t(mi,{className:`size-4`})})}),t(o,{variant:`destructive`,isDisabled:y,onClick:()=>v(!0),children:s(y?`store.actions.deleting`:`store.actions.deleteSelected`)})]})]}),t(`div`,{className:`flex flex-col w-full flex-1 min-h-0 border rounded-md my-2`,children:n(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:[!f&&m?.length===0?t(j,{title:s(`store.noType`),buttonLabel:s(`store.createType`),onClick:()=>{ee(!0)},children:s(`store.getStartedTypes`)}):n(e,{children:[t(yw,{objects:m,isLoading:f,onFilter:(e,t)=>{e===`name`&&k(t)},selectedIds:h,onToggleOne:T,allSelected:C,onToggleAll:E}),t(`div`,{ref:N,className:`h-4 w-full`})]}),t(bw,{okLabel:`Create`,title:s(`store.createType`),isOpen:L,onClose:async e=>e?i.types.create(e).then(async()=>{c({status:`success`,title:s(`store.typeCreated`),duration:2e3}),a(),d.search().then(()=>u(!0))}).catch(e=>{c({status:`error`,title:s(`store.errorCreatingType`),description:e.message,duration:5e3})}):(ee(!1),Promise.resolve())}),t(b,{isOpen:_,title:s(`store.actions.deleteType`,{count:S}),content:n(`div`,{children:[t(`p`,{children:s(`store.actions.deleteTypeConfirm`,{count:S})}),w.length>0&&n(e,{children:[t(`div`,{className:`mt-2`,children:s(`store.actions.affectedItems`)}),t(`ul`,{className:`mt-1 max-h-40 overflow-y-auto rounded-md border p-2 text-sm`,children:w.map(e=>t(`li`,{className:`truncate py-0.5`,children:e.name||e.id},e.id))})]})]}),onConfirm:D,onCancel:()=>v(!1),confirmationValue:`delete`,confirmationLabel:s(`store.actions.typeToConfirmDelete`),confirmationPlaceholder:`delete`})]})})]})}function Ow(e,t,n){if(t.length===0)return e;let r=structuredClone(e),i=[r],a=r;for(let e of t.slice(0,-1)){let t=a[e],n=Nw(t)?t:{};a[e]=n,a=n,i.push(a)}let o=t[t.length-1];return n===void 0||n===``?(delete a[o],Mw(i,t)):a[o]=n,r}function kw(e,t,n,r){let i=e?.map(e=>[e[0]??1,e[1]??1])??[],a=i[t]??[1,1];return a[n]=r,i[t]=a,i}function Aw(e,t){let n={...e,environment:t};return delete n.model,delete n.model_options,Pw(n)?n:void 0}function jw(e,t){let n={...e,model:t};return t!==e?.model&&delete n.model_options,Pw(n)?n:void 0}function Mw(e,t){for(let n=e.length-1;n>0;--n){let r=e[n];if(Object.keys(r).length>0)break;delete e[n-1][t[n-1]]}}function Nw(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Pw(e){return Object.values(e).some(e=>e!==void 0)}function Fw({policy:e,section:r,onChange:i,readonly:a=!1}){let{t:o}=Z(),s=(t,n)=>i(Ow(e,t,n));if(r===`overview`)return n(Iw,{children:[n(Lw,{title:o(`intakePolicy.section.classification`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(Vw,{label:o(`intakePolicy.field.mode`),description:o(`intakePolicy.help.mode`),value:e.mode,options:Kw(o,[`programmatic`,`agentic`]),onChange:e=>s([`mode`],e),readonly:a}),t(Vw,{label:o(`intakePolicy.field.defaultView`),value:e.default_view,options:Kw(o,[`auto`,`text`,`pdf`,`image`,`properties`]),onChange:e=>s([`default_view`],e),readonly:a})]}),t(zw,{label:o(`intakePolicy.field.identificationGuidance`),description:o(`intakePolicy.help.identificationGuidance`),value:e.identification?.guidance,onChange:e=>s([`identification`,`guidance`],e),readonly:a}),t(zw,{label:o(`intakePolicy.field.distinguishFrom`),value:e.identification?.distinguish_from,onChange:e=>s([`identification`,`distinguish_from`],e),readonly:a}),t(L,{label:o(`intakePolicy.field.examples`),description:o(`intakePolicy.help.examples`),children:t(Re,{options:e.identification?.examples??[],value:e.identification?.examples??[],onChange:e=>s([`identification`,`examples`],e.length?e:void 0),onOptionsChange:e=>s([`identification`,`examples`],e.length?e:void 0),creatable:!0,disabled:a,placeholder:o(`intakePolicy.placeholder.objectId`)})})]}),n(Lw,{title:o(`intakePolicy.section.locate`),last:!0,children:[t(zw,{label:o(`intakePolicy.field.locateInstructions`),description:o(`intakePolicy.help.locateInstructions`),value:e.locate?.instructions,onChange:t=>s([`locate`],t?{...e.locate,instructions:t}:void 0),readonly:a}),n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(Vw,{label:o(`intakePolicy.field.contactSheetDetail`),value:e.locate?.detail,options:[{value:8,label:o(`intakePolicy.option.pagesPerSheet`,{count:8})},{value:16,label:o(`intakePolicy.option.pagesPerSheet`,{count:16})}],onChange:e=>s([`locate`,`detail`],e),readonly:a||!e.locate}),t(Bw,{label:o(`intakePolicy.field.locateMinPages`),value:e.locate?.min_pages,min:0,onChange:e=>s([`locate`,`min_pages`],e),readonly:a||!e.locate})]})]})]});if(r===`conversion`)return n(Iw,{children:[n(Lw,{title:o(`intakePolicy.section.conversion`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(Hw,{label:o(`intakePolicy.field.enabled`),value:e.text_conversion?.enabled,onChange:e=>s([`text_conversion`,`enabled`],e),readonly:a}),t(Vw,{label:o(`intakePolicy.field.method`),value:e.text_conversion?.method,options:Kw(o,[`auto`,`basic`,`llm`,`custom`]),onChange:e=>s([`text_conversion`,`method`],e),readonly:a}),t(Vw,{label:o(`intakePolicy.field.outputFormat`),value:e.text_conversion?.output_format,options:Kw(o,[`markdown`,`text`]),onChange:e=>s([`text_conversion`,`output_format`],e),readonly:a}),t(Vw,{label:o(`intakePolicy.field.pageScope`),value:e.text_conversion?.scope,options:Kw(o,[`all`,`located`]),onChange:e=>s([`text_conversion`,`scope`],e),readonly:a}),t(Bw,{label:o(`intakePolicy.field.renderDpi`),value:e.text_conversion?.render_dpi,min:72,onChange:e=>s([`text_conversion`,`render_dpi`],e),readonly:a})]}),t(zw,{label:o(`intakePolicy.field.instructions`),value:e.text_conversion?.instructions,onChange:e=>s([`text_conversion`,`instructions`],e),readonly:a})]}),t(Lw,{title:o(`intakePolicy.section.conversionModel`),children:t(Gw,{title:o(`intakePolicy.field.model`),config:e.text_conversion?.config,onChange:e=>s([`text_conversion`,`config`],e),readonly:a})}),e.text_conversion?.method===`custom`&&t(Lw,{title:o(`intakePolicy.section.customConversion`),children:n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(Rw,{label:o(`intakePolicy.field.interaction`),value:e.text_conversion.custom?.interaction,onChange:e=>s([`text_conversion`,`custom`,`interaction`],e),readonly:a}),t(Rw,{label:o(`intakePolicy.field.agent`),value:e.text_conversion.custom?.agent,onChange:e=>s([`text_conversion`,`custom`,`agent`],e),readonly:a})]})}),t(Lw,{title:o(`intakePolicy.section.pageRanges`),last:!0,children:t(Ww,{value:e.text_conversion?.page_ranges,onChange:e=>s([`text_conversion`,`page_ranges`],e),readonly:a})})]});if(r===`extraction`)return n(Iw,{children:[n(Lw,{title:o(`intakePolicy.section.extraction`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(Hw,{label:o(`intakePolicy.field.enabled`),value:e.extraction?.enabled,onChange:e=>s([`extraction`,`enabled`],e),readonly:a}),t(Vw,{label:o(`intakePolicy.field.source`),value:e.extraction?.source,options:Kw(o,[`auto`,`text`,`vision`,`mixed`]),onChange:e=>s([`extraction`,`source`],e),readonly:a}),t(Vw,{label:o(`intakePolicy.field.pageScope`),value:e.extraction?.scope,options:Kw(o,[`all`,`located`]),onChange:e=>s([`extraction`,`scope`],e),readonly:a}),t(Bw,{label:o(`intakePolicy.field.maxPages`),value:e.extraction?.max_pages,min:1,onChange:e=>s([`extraction`,`max_pages`],e),readonly:a})]}),t(Rw,{label:o(`intakePolicy.field.interaction`),value:e.extraction?.interaction,onChange:e=>s([`extraction`,`interaction`],e),readonly:a}),t(zw,{label:o(`intakePolicy.field.instructions`),value:e.extraction?.instructions,onChange:e=>s([`extraction`,`instructions`],e),readonly:a}),t(Ww,{value:e.extraction?.page_ranges,onChange:e=>s([`extraction`,`page_ranges`],e),readonly:a})]}),t(Lw,{title:o(`intakePolicy.section.extractionModel`),children:t(Gw,{title:o(`intakePolicy.field.model`),config:e.extraction?.config,onChange:e=>s([`extraction`,`config`],e),readonly:a})}),t(Lw,{title:o(`intakePolicy.section.visionBudget`),children:n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:[t(Vw,{label:o(`intakePolicy.field.defaultDetail`),value:e.extraction?.vision?.default_detail,options:Kw(o,[`low`,`standard`,`high`]),onChange:e=>s([`extraction`,`vision`,`default_detail`],e),readonly:a}),t(Uw,{value:e.extraction?.vision?.allowed_details,onChange:e=>s([`extraction`,`vision`,`allowed_details`],e),readonly:a}),t(Bw,{label:o(`intakePolicy.field.maxImageTokens`),value:e.extraction?.vision?.max_image_tokens,min:1,onChange:e=>s([`extraction`,`vision`,`max_image_tokens`],e),readonly:a}),t(Bw,{label:o(`intakePolicy.field.maxPayloadMb`),value:e.extraction?.vision?.max_payload_mb,min:1,onChange:e=>s([`extraction`,`vision`,`max_payload_mb`],e),readonly:a}),t(Bw,{label:o(`intakePolicy.field.maxPagesPerCall`),value:e.extraction?.vision?.max_pages_per_call,min:1,onChange:e=>s([`extraction`,`vision`,`max_pages_per_call`],e),readonly:a})]})}),n(Lw,{title:o(`intakePolicy.section.verification`),last:!0,children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:[t(Hw,{label:o(`intakePolicy.field.enabled`),value:e.extraction?.verification?.enabled,onChange:e=>s([`extraction`,`verification`,`enabled`],e),readonly:a}),t(Rw,{label:o(`intakePolicy.field.model`),value:e.extraction?.verification?.model,onChange:e=>s([`extraction`,`verification`,`model`],e),readonly:a}),t(Rw,{label:o(`intakePolicy.field.environment`),value:e.extraction?.verification?.environment,onChange:e=>s([`extraction`,`verification`,`environment`],e),readonly:a}),t(Bw,{label:o(`intakePolicy.field.threshold`),value:e.extraction?.verification?.threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`verification`,`threshold`],e),readonly:a}),t(Bw,{label:o(`intakePolicy.field.maxRetries`),value:e.extraction?.verification?.max_retries,min:0,onChange:e=>s([`extraction`,`verification`,`max_retries`],e),readonly:a}),t(Vw,{label:o(`intakePolicy.field.onFailure`),value:e.extraction?.verification?.on_fail,options:Kw(o,[`flag`,`block`]),onChange:e=>s([`extraction`,`verification`,`on_fail`],e),readonly:a})]}),t(zw,{label:o(`intakePolicy.field.materiality`),value:e.extraction?.verification?.materiality,onChange:e=>s([`extraction`,`verification`,`materiality`],e),readonly:a})]})]});if(r===`grounding`){let r=e.extraction?.grounding,i=r?.review;return n(Iw,{children:[n(Lw,{title:o(`intakePolicy.section.grounding`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(Hw,{label:o(`intakePolicy.field.enabled`),value:r?.enabled,onChange:e=>s([`extraction`,`grounding`,`enabled`],e),readonly:a}),t(Bw,{label:o(`intakePolicy.field.maxPages`),value:r?.max_pages,min:1,onChange:e=>s([`extraction`,`grounding`,`max_pages`],e),readonly:a}),t(Bw,{label:o(`intakePolicy.field.windowPages`),value:r?.window_pages,min:1,onChange:e=>s([`extraction`,`grounding`,`window_pages`],e),readonly:a}),t(Rw,{label:o(`intakePolicy.field.interaction`),value:r?.interaction,onChange:e=>s([`extraction`,`grounding`,`interaction`],e),readonly:a})]}),n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:[t(Hw,{label:o(`intakePolicy.field.useVision`),value:r?.use_vision,onChange:e=>s([`extraction`,`grounding`,`use_vision`],e),readonly:a}),t(Hw,{label:o(`intakePolicy.field.forceOcr`),value:r?.force_ocr,onChange:e=>s([`extraction`,`grounding`,`force_ocr`],e),readonly:a}),t(Hw,{label:o(`intakePolicy.field.refreshOcr`),value:r?.refresh_ocr,onChange:e=>s([`extraction`,`grounding`,`refresh_ocr`],e),readonly:a}),t(Hw,{label:o(`intakePolicy.field.omitBlockBoxes`),value:r?.omit_block_boxes,onChange:e=>s([`extraction`,`grounding`,`omit_block_boxes`],e),readonly:a}),t(Hw,{label:o(`intakePolicy.field.updateProperties`),value:r?.update_properties,onChange:e=>s([`extraction`,`grounding`,`update_properties`],e),readonly:a})]})]}),n(Lw,{title:o(`intakePolicy.section.models`),children:[t(Gw,{title:o(`intakePolicy.field.primaryModel`),config:r?.config,onChange:e=>s([`extraction`,`grounding`,`config`],e),readonly:a}),t(Gw,{title:o(`intakePolicy.field.hardModel`),config:r?.hard_config,onChange:e=>s([`extraction`,`grounding`,`hard_config`],e),readonly:a}),n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(Bw,{label:o(`intakePolicy.field.hardnessThreshold`),value:r?.hardness_threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`hardness_threshold`],e),readonly:a}),t(Bw,{label:o(`intakePolicy.field.minCitationDensity`),value:r?.min_citation_density,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`min_citation_density`],e),readonly:a})]})]}),n(Lw,{title:o(`intakePolicy.section.review`),last:!0,children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(Hw,{label:o(`intakePolicy.field.enabled`),value:i?.enabled,onChange:e=>s([`extraction`,`grounding`,`review`,`enabled`],e),readonly:a}),t(Hw,{label:o(`intakePolicy.field.forceReview`),value:i?.force,onChange:e=>s([`extraction`,`grounding`,`review`,`force`],e),readonly:a}),t(Bw,{label:o(`intakePolicy.field.reviewThreshold`),value:i?.threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`review`,`threshold`],e),readonly:a}),t(Bw,{label:o(`intakePolicy.field.coverageThreshold`),value:i?.coverage_threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`review`,`coverage_threshold`],e),readonly:a})]}),t(Gw,{title:o(`intakePolicy.field.reviewModel`),config:i?.config,onChange:e=>s([`extraction`,`grounding`,`review`,`config`],e),readonly:a})]})]})}return n(Iw,{children:[t(Lw,{title:o(`intakePolicy.section.rendering`),children:t(zw,{label:o(`intakePolicy.field.renderingTemplate`),description:o(`intakePolicy.help.renderingTemplate`),value:e.rendering_template,onChange:e=>s([`rendering_template`],e),readonly:a,monospace:!0,minLines:8})}),t(Lw,{title:o(`intakePolicy.section.embeddings`),last:!0,children:n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(Hw,{label:o(`intakePolicy.field.textEmbedding`),value:e.embeddings?.text,onChange:e=>s([`embeddings`,`text`],e),readonly:a}),t(Hw,{label:o(`intakePolicy.field.imageEmbedding`),value:e.embeddings?.image,onChange:e=>s([`embeddings`,`image`],e),readonly:a}),t(Hw,{label:o(`intakePolicy.field.propertiesEmbedding`),value:e.embeddings?.properties,onChange:e=>s([`embeddings`,`properties`],e),readonly:a}),t(Hw,{label:o(`intakePolicy.field.generateToc`),value:e.generate_toc,onChange:e=>s([`generate_toc`],e),readonly:a})]})})]})}function Iw({children:e}){return t(`div`,{className:`mx-auto w-full max-w-6xl px-1 py-4`,children:e})}function Lw({title:e,children:r,last:i=!1}){return n(`section`,{className:i?`pb-3`:`mb-6 border-b pb-6`,children:[t(`h3`,{className:`mb-4 text-sm font-semibold`,children:e}),t(`div`,{className:`space-y-4`,children:r})]})}function Rw({label:e,value:n,onChange:r,readonly:i,description:a}){return t(L,{label:e,description:a,children:t(R,{value:n??``,onChange:e=>r(e||void 0),disabled:i})})}function zw({label:e,value:n,onChange:r,readonly:i,description:a,minLines:o=3,monospace:s=!1}){return t(L,{label:e,description:a,children:t(ze,{value:n??``,onChange:e=>r(e.target.value||void 0),disabled:i,minLines:o,maxLines:14,className:s?`font-mono`:void 0})})}function Bw({label:e,value:n,onChange:r,readonly:i,min:a,max:o,step:s}){return t(L,{label:e,children:t(ce,{value:n,onChange:e=>r(e===void 0||Number.isFinite(e)?e:void 0),disabled:i,min:a,max:o,step:s??1,noScroll:!0})})}function Vw({label:e,description:n,value:r,options:i,onChange:a,readonly:o}){let{t:s}=Z(),c=[{value:`__inherit__`,label:s(`intakePolicy.option.inherit`)},...i],l=c.find(e=>e.value===r)??c[0];return t(L,{label:e,description:n,children:t(be,{options:c,value:l,by:`value`,optionLabel:e=>e.label,onChange:e=>a(e.value===`__inherit__`?void 0:e.value),disabled:o})})}function Hw({label:e,value:n,onChange:r,readonly:i}){let{t:a}=Z(),o=[{value:`inherit`,label:a(`intakePolicy.option.inherit`)},{value:`enabled`,label:a(`intakePolicy.option.enabled`)},{value:`disabled`,label:a(`intakePolicy.option.disabled`)}],s=n===void 0?`inherit`:n?`enabled`:`disabled`;return t(L,{label:e,children:t(be,{options:[...o],value:o.find(e=>e.value===s),by:`value`,optionLabel:e=>e.label,onChange:e=>r(e.value===`inherit`?void 0:e.value===`enabled`),disabled:i})})}function Uw({value:e,onChange:n,readonly:r}){let{t:i}=Z(),a=Kw(i,[`low`,`standard`,`high`]);return t(L,{label:i(`intakePolicy.field.allowedDetails`),children:t(be,{multiple:!0,options:a,value:a.filter(t=>e?.includes(t.value)),by:`value`,optionLabel:e=>e.label,onChange:e=>n(e.length?e.map(e=>e.value):void 0),disabled:r})})}function Ww({value:e,onChange:r,readonly:i}){let{t:a}=Z(),s=t=>{let n=e?.filter((e,n)=>n!==t);r(n?.length?n:void 0)};return t(L,{label:a(`intakePolicy.field.pageRanges`),description:a(`intakePolicy.help.pageRanges`),children:n(`div`,{className:`space-y-2`,children:[e?.map((c,l)=>n(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_2.25rem] gap-2`,children:[t(ce,{"aria-label":a(`intakePolicy.field.rangeStart`),value:c[0],onChange:t=>{t!==void 0&&Number.isFinite(t)&&r(kw(e,l,0,t))},disabled:i,step:1,noScroll:!0}),t(ce,{"aria-label":a(`intakePolicy.field.rangeEnd`),value:c[1],onChange:t=>{t!==void 0&&Number.isFinite(t)&&r(kw(e,l,1,t))},disabled:i,step:1,noScroll:!0}),t(Be,{description:a(`intakePolicy.action.removeRange`),children:t(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":a(`intakePolicy.action.removeRange`),onClick:()=>s(l),disabled:i,children:t(ai,{className:`size-4`})})})]},`${l}`)),n(o,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...e??[],[1,1]]),disabled:i,children:[t(Fr,{className:`size-4`}),a(`intakePolicy.action.addRange`)]})]})})}function Gw({title:e,config:r,onChange:i,readonly:a}){let{t:o}=Z();return n(`div`,{children:[t(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:e}),n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(L,{label:o(`intakePolicy.field.environment`),children:t(_x,{selectedEnvId:r?.environment,onChange:e=>i(Aw(r,e?.id)),isClearable:!0,disabled:a})}),t(L,{label:o(`intakePolicy.field.model`),children:t(bx,{envId:r?.environment,selectedModelId:r?.model,onChange:e=>i(jw(r,e?.id)),isClearable:!0,disabled:a||!r?.environment})})]})]})}function Kw(e,t){return t.map(t=>({value:t,label:e(`intakePolicy.option.${t}`)}))}const qw=[{key:`minimal`,value:{identification:{guidance:`Documents that match this content type.`,distinguish_from:`Do not select this type for unrelated documents.`}}},{key:`extraction_only`,value:{text_conversion:{enabled:!1},extraction:{enabled:!0,source:`vision`,instructions:`Extract required fields only. Ignore cover pages, appendices, legal boilerplate, and marketing content.`},rendering_template:`# {{properties.title}}
|
|
455
453
|
|
|
456
454
|
{{properties.summary}}`,embeddings:{text:!0,properties:!0},default_view:`pdf`}},{key:`grounded`,value:{extraction:{enabled:!0,grounding:{enabled:!0,use_vision:!0,config:{model:`publishers/google/models/gemini-3.5-flash`,model_options:{_option_id:`vertexai-gemini`,max_tokens:32e3,thinking_level:`LOW`,temperature:0}},hard_config:{model:`publishers/google/models/gemini-3.1-pro-preview`,model_options:{_option_id:`vertexai-gemini`,max_tokens:32e3,thinking_level:`LOW`,temperature:0}},hardness_threshold:.5,min_citation_density:.3,window_pages:3,review:{enabled:!0,config:{model:`publishers/google/models/gemini-3.5-flash`,model_options:{_option_id:`vertexai-gemini`,thinking_level:`MEDIUM`,max_tokens:32e3,temperature:0}},coverage_threshold:.2}}},default_view:`pdf`}},{key:`visual_first`,value:{identification:{guidance:`Presentation decks or visual reports with slides, charts, diagrams, tables, or callouts.`},text_conversion:{enabled:!0,method:`auto`},extraction:{enabled:!0,source:`auto`,instructions:`Use visual evidence when layout, charts, diagrams, or slide structure contain material information.`},default_view:`pdf`}},{key:`structured_spreadsheet`,value:{text_conversion:{enabled:!0,method:`auto`,instructions:`Preserve sheet names, headers, row labels, totals, and period columns.`},extraction:{enabled:!0,source:`text`,instructions:`Extract values from worksheet text. Do not infer values from charts.`},default_view:`properties`}},{key:`media_no_transcript`,value:{text_conversion:{enabled:!1},extraction:{enabled:!0,source:`auto`,instructions:`Analyze available metadata and source evidence without creating a transcript.`},default_view:`properties`}},{key:`full_reference`,value:{mode:`programmatic`,identification:{guidance:`Supplier invoices: billing documents with an invoice number, line items, amounts due, tax breakdown, and payment terms.`,distinguish_from:`Quotes and estimates are offers, not payment requests. Credit notes carry negative amounts. Receipts confirm a payment already made.`,examples:[]},text_conversion:{enabled:!0,method:`auto`,instructions:`Keep the commercial terms and totals. Drop boilerplate and legal footers.`,output_format:`markdown`,custom:{interaction:`my-project:ConvertSpecialDocument`,agent:`my-project:DocumentConversionAgent`}},extraction:{enabled:!0,source:`auto`,instructions:`Extract totals from the summary block, not from line items. Amounts include currency. Dates use ISO 8601.`,interaction:`sys:ExtractInformation`,verification:{enabled:!1,model:`publishers/anthropic/models/claude-sonnet`,environment:`default`,materiality:`Amounts, dates, identifiers, and party names are material. Typos in free text are not.`,threshold:.85,max_retries:1,on_fail:`flag`},grounding:{enabled:!0,interaction:`sys:ExtractInformationGrounded`,max_pages:20,force_ocr:!1,use_vision:!0,omit_block_boxes:!1,config:{model:`publishers/google/models/gemini-3.5-flash`},hard_config:{model:`publishers/google/models/gemini-3.1-pro-preview`},hardness_threshold:.5,window_pages:3,update_properties:!0,min_citation_density:.3,refresh_ocr:!1,review:{enabled:!0,config:{model:`publishers/google/models/gemini-3.5-flash`},coverage_threshold:.2}}},rendering_template:`# Invoice {{properties.invoice_number}}
|
|
457
455
|
|
|
458
456
|
- Vendor: {{properties.vendor_name}}
|
|
459
457
|
- Total: {{properties.currency}} {{properties.total_amount}}
|
|
460
|
-
- Due: {{properties.due_date}}`,embeddings:{text:!0,image:!1,properties:!0},generate_toc:!1,default_view:`auto`}}],
|
|
461
|
-
`):`The intake policy does not match the schema.`}function
|
|
458
|
+
- Due: {{properties.due_date}}`,embeddings:{text:!0,image:!1,properties:!0},generate_toc:!1,default_view:`auto`}}],Jw={};function Yw({objectType:r,value:a,onSave:s,onIntakeUpdate:c,readonly:l=!1}){let{store:u}=Q(),{t:d}=Z(),f=Xe(),{theme:p}=Ye(),m=Y(void 0),h=J(()=>rT(),[]),[g,_]=X(!1),v=r?.intake??a,[y,b]=X(()=>nT(v)),[x,S]=X(()=>nT(v)),[C,T]=X(void 0),[E,D]=X(`overview`),O=y!==x,k=J(()=>{let e=iT(y,h);return e.ok?e.policy:void 0},[y,h]),A=k??v??Jw,j=e=>{let t=e,n=t.languages?.json?.jsonDefaults??t.json?.jsonDefaults,r=structuredClone(Ei);n?.setDiagnosticsOptions({validate:!0,allowComments:!1,schemas:[{uri:`vertesia://schemas/content-type-intake-policy.json`,fileMatch:[`*`],schema:r}]})},M=()=>{let e=iT(E===`json`?m.current?.getValue()??y:y,h);if(!e.ok){T(e.message);return}return T(void 0),e.policy},N=()=>{let e=M();if(!e)return;let t=s??(r?e=>u.types.update(r.id,{intake:e,...r.edit_revision===void 0?{}:{expected_edit_revision:r.edit_revision}}).then(e=>(r.edit_revision=e.edit_revision,e.intake)):void 0);t&&(_(!0),t(e).then(t=>{let n=nT(t??e);b(n),S(n),c?.(t??e),f({status:`success`,title:d(`intakePolicy.toast.updated`),description:d(`intakePolicy.toast.saved`),duration:2e3})}).catch(e=>{f({status:`error`,title:d(`intakePolicy.toast.updateFailed`),description:Ve(e),duration:5e3})}).finally(()=>{_(!1)}))},P=()=>{let e=iT(E===`json`?m.current?.getValue()??y:y,h);T(e.ok?void 0:e.message),f({status:e.ok?`success`:`error`,title:e.ok?d(`intakePolicy.toast.valid`):d(`intakePolicy.toast.invalid`),description:e.ok?d(`intakePolicy.toast.schemaValid`):e.message,duration:3e3})},F=()=>{b(x),m.current?.setValue(x),T(void 0)},I=()=>{let e=M();if(!e)return;let t=nT(e);b(t),m.current?.setValue(t)},L=e=>{let t=nT(e.value);b(t),m.current?.setValue(t),T(void 0),D(`overview`)},ee=e=>{b(nT(e)),T(void 0)},R=e=>{let t=e;if(t!==`json`&&!k){T(d(`intakePolicy.error.fixJsonBeforeForm`)),D(`json`);return}D(t)},te=n(`div`,{className:`flex items-center gap-2`,children:[t(`div`,{className:`text-base font-semibold`,children:d(`intakePolicy.title`)}),O&&t(i,{variant:`attention`,children:d(`intakePolicy.status.unsaved`)})]}),z=l?void 0:n(e,{children:[t(w,{align:`right`,trigger:n(o,{variant:`outline`,size:`sm`,children:[t(di,{className:`size-4`}),d(`intakePolicy.action.examples`)]}),children:t(ne,{label:d(`intakePolicy.action.insertExample`),children:qw.map(e=>n(B,{onClick:()=>L(e),children:[t(Hn,{className:`size-4`}),n(`div`,{className:`flex flex-col`,children:[t(`span`,{children:d(`intakePolicy.example.${e.key}.label`)}),t(`span`,{className:`text-xs text-muted`,children:d(`intakePolicy.example.${e.key}.description`)})]})]},e.key))})}),E===`json`&&n(e,{children:[n(o,{variant:`outline`,size:`sm`,onClick:I,children:[t($t,{className:`size-4`}),d(`intakePolicy.action.format`)]}),n(o,{variant:`outline`,size:`sm`,onClick:P,children:[t(sn,{className:`size-4`}),d(`intakePolicy.action.validate`)]})]}),n(o,{variant:`outline`,size:`sm`,onClick:F,disabled:!O,children:[t(Vr,{className:`size-4`}),d(`intakePolicy.action.revert`)]}),n(o,{isLoading:g,size:`sm`,onClick:N,disabled:!O,children:[t(Wr,{className:`size-4`}),d(`intakePolicy.action.save`)]})]});return t(ue,{title:te,className:`bg-background! h-full`,action:z,children:n(`div`,{className:`flex h-full min-h-0 flex-col gap-3`,children:[t(Zw,{policy:A}),C&&t(`div`,{className:`rounded-sm border border-destructive bg-mixer-destructive/10 px-3 py-2 text-sm whitespace-pre-line text-destructive`,children:C}),n(Fe,{tabs:Xw(d,k??Jw,l,ee,y,{editorRef:m,beforeMount:j,onChange:e=>{b(e),T(void 0)},theme:p}),current:E,onTabChange:R,updateHash:!1,responsive:!0,fullHeight:!0,className:`px-0`,children:[t(Ie,{sticky:!0}),t(Le,{className:`min-h-0 flex-1 overflow-auto pt-1`})]})]})})}function Xw(e,r,i,a,o,s){let c=(e,n)=>({name:e,label:n,content:t(Fw,{policy:r,section:e,onChange:a,readonly:i})});return[c(`overview`,e(`intakePolicy.tab.overview`)),c(`conversion`,e(`intakePolicy.tab.conversion`)),c(`extraction`,e(`intakePolicy.tab.extraction`)),c(`grounding`,e(`intakePolicy.tab.grounding`)),c(`output`,e(`intakePolicy.tab.output`)),{name:`json`,label:e(`intakePolicy.tab.json`),content:n(`div`,{className:`flex h-full min-h-[36rem] gap-4 py-3`,children:[t(`div`,{className:`min-w-0 flex-1 overflow-hidden rounded-sm border`,children:t(Tt,{value:o,language:`json`,editorRef:s.editorRef,beforeMount:s.beforeMount,onChange:e=>s.onChange(e.state.doc.toString()),theme:s.theme===`dark`?`vs-dark`:`vs`,options:{readOnly:i,minimap:{enabled:!1},scrollBeyondLastLine:!1,wordWrap:`on`,lineNumbers:`on`,automaticLayout:!0,formatOnPaste:!0,formatOnType:!0,tabSize:2}})}),t(Qw,{})]})}]}function Zw({policy:e}){let{t:r}=Z(),a=e.extraction?.grounding,o=[[r(`intakePolicy.summary.mode`),tT(r,e.mode)],[r(`intakePolicy.summary.conversion`),eT(r,e.text_conversion?.enabled)],[r(`intakePolicy.summary.method`),tT(r,e.text_conversion?.method)],[r(`intakePolicy.summary.source`),tT(r,e.extraction?.source)],[r(`intakePolicy.summary.extraction`),eT(r,e.extraction?.enabled)],[r(`intakePolicy.summary.grounding`),eT(r,a?.enabled)],[r(`intakePolicy.summary.defaultView`),tT(r,e.default_view)],[r(`intakePolicy.summary.toc`),eT(r,e.generate_toc)],[r(`intakePolicy.summary.template`),e.rendering_template?r(`intakePolicy.option.set`):r(`intakePolicy.option.inherit`)]];return t(`div`,{className:`flex flex-wrap gap-2`,children:o.map(([e,r])=>n(i,{variant:`outline`,className:`gap-1`,children:[n(`span`,{className:`text-muted`,children:[e,`:`]}),t(`span`,{children:r})]},e))})}function Qw(){let{t:e}=Z();return n(`aside`,{className:`hidden w-80 shrink-0 overflow-y-auto rounded-sm border bg-mixer-muted/20 p-3 text-sm lg:block`,children:[t(`div`,{className:`mb-3 font-semibold`,children:e(`intakePolicy.help.title`)}),n(`div`,{className:`space-y-3 text-muted`,children:[t($w,{label:`identification`,text:e(`intakePolicy.help.identification`)}),t($w,{label:`text_conversion`,text:e(`intakePolicy.help.textConversion`)}),t($w,{label:`extraction.source`,text:e(`intakePolicy.help.extractionSource`)}),t($w,{label:`extraction.grounding`,text:e(`intakePolicy.help.grounding`)}),t($w,{label:`extraction.grounding.review`,text:e(`intakePolicy.help.review`)}),t($w,{label:`rendering_template`,text:e(`intakePolicy.help.renderingTemplate`)}),t($w,{label:`embeddings`,text:e(`intakePolicy.help.embeddings`)}),t($w,{label:`default_view`,text:e(`intakePolicy.help.defaultView`)})]})]})}function $w({label:e,text:r}){return n(`div`,{children:[t(`div`,{className:`font-medium text-foreground`,children:e}),t(`div`,{children:r})]})}function eT(e,t){return e(t===!0?`intakePolicy.option.enabled`:t===!1?`intakePolicy.option.disabled`:`intakePolicy.option.inherit`)}function tT(e,t){return e(t?`intakePolicy.option.${t}`:`intakePolicy.option.inherit`)}function nT(e){return JSON.stringify(e??Jw,null,2)}function rT(){let e=new ya({strict:!1,allErrors:!0});return Ta(e),e.compile(Ei)}function iT(e,t){let n;try{n=e.trim()?JSON.parse(e):{}}catch(e){return{ok:!1,message:`Invalid JSON: ${Ve(e)}`}}return t(n)?{ok:!0,policy:n}:{ok:!1,message:aT(t.errors)}}function aT(e){return e?.length?e.map(e=>`${e.instancePath||`/`} ${e.message??`is invalid`}`).join(`
|
|
459
|
+
`):`The intake policy does not match the schema.`}function oT({objectType:e,onSchemaUpdate:r,readonly:i=!1}){let{store:a}=Q(),{t:s}=Z(),c=Xe(),{theme:l}=Ye(),[u,d]=X(!1),f=zt(e.object_schema),p=Y(void 0),[m,h]=X(!1),g=J(()=>sT(f.schema),[f]),_=()=>{m&&!y()||(d(!0),a.types.update(e.id,{object_schema:f.schema,...e.edit_revision===void 0?{}:{expected_edit_revision:e.edit_revision}}).then(t=>{e.edit_revision=t.edit_revision,r(f),c({status:`success`,title:s(`store.schemaUpdated`),description:s(`store.schemaUpdatedSuccess`),duration:2e3})}).catch(e=>{c({status:`error`,title:s(`store.failedToUpdateSchema`),description:e.message,duration:5e3})}).finally(()=>{d(!1)}))},v=()=>{m&&!y()||h(e=>!e)},y=()=>{if(p.current){let e=p.current.getValue();try{let t=cT(e);lT(t),f.replaceSchema(t)}catch(e){return c({status:`error`,title:s(`store.invalidJsonSchema`),description:Ve(e),duration:5e3}),!1}}return!0},b=n(`div`,{className:`flex gap-2 items-center`,children:[t(`div`,{className:`text-base font-semibold`,children:s(`store.schemaEditor`)}),!i&&t(`div`,{children:t(o,{variant:`outline`,size:`sm`,onClick:v,children:s(m?`store.editSchema`:`store.editJson`)})})]});return t(ue,{title:b,className:`bg-background! h-full`,action:i?void 0:t(o,{isLoading:u,variant:`outline`,size:`sm`,onClick:_,children:s(`modal.saveChanges`)}),children:m?t(Tt,{value:g,language:`json`,editorRef:p,theme:l===`dark`?`vs-dark`:`vs`,options:{readOnly:i}}):t(Dt,{schema:f,readonly:i})})}function sT(e){return e?JSON.stringify(e,null,2):``}function cT(e){if(e?.trim())return JSON.parse(e.trim())}const lT=e=>{try{new ba({strict:!1}).compile(e)}catch(e){throw Error(`Invalid JSON Schema definition: ${Ve(e)}`,{cause:e})}};function uT({isOpen:e,onClose:r,title:i,children:a,initialSelectedType:s=null,allowNone:c=!0}){let{t:l}=Z(),u=i??l(`store.selectContentType`),{registry:d}=Tv(),[f,p]=X(s),m=d?.types||[],h=()=>{r(void 0)};return n(ie,{isOpen:e,onClose:h,className:`w-full max-w-xl mx-auto`,children:[t(se,{children:u}),n(ae,{children:[a,n(`div`,{className:`mb-4 mt-4`,children:[n(`div`,{className:`block text-sm font-medium mb-2`,children:[l(`store.contentType`),` `,c&&t(`span`,{className:`text-gray-500 font-normal`,children:l(`store.optional`)})]}),c?t(be,{options:m,value:f,optionLabel:e=>e?e.name:l(`store.selectContentTypeLabel`),placeholder:l(`store.selectContentTypeAuto`),onChange:e=>p(e||null),filterBy:`name`,isClearable:!0}):t(be,{options:m,value:f,optionLabel:e=>e?e.name:l(`store.selectContentTypeLabel`),placeholder:l(`store.selectContentTypeLabel`),onChange:e=>p(e||null),filterBy:`name`})]}),!f&&n(`div`,{className:`flex items-center text-attention`,children:[t(cn,{className:`size-4 me-1`}),l(`store.automaticTypeDetection`),t(Be,{description:l(`store.automaticTypeDetectionDescription`),placement:`top`,size:`xs`,children:t(rr,{className:`size-3 ms-2`})})]})]}),n(oe,{children:[t(o,{variant:`ghost`,onClick:h,title:l(`modal.cancel`),children:l(`modal.cancel`)}),t(o,{onClick:()=>{r(f?.id??null),p(null)},title:l(`store.confirmSelection`),children:l(`modal.confirm`)})]})]})}function dT({children:e,limit:n,name:r,chunkable:i}){let{store:a}=Q(),o=J(()=>{let e=new xw(a,n);return e.query.name=r,e.query.chunkable=i,e},[i,n,r,a]);return t(Sw.Provider,{value:o,children:e})}function fT({objectType:e,onLayoutUpdate:n,readonly:r=!1}){let i=Xe(),{theme:a}=Ye(),{t:s}=Z(),[c,l]=X(!1),{store:u}=Q(),d=Y(void 0),f=J(()=>pT(e.table_layout),[e.table_layout]),p=(e,t)=>{i({status:`error`,title:e,description:t,duration:5e3})};return t(ue,{title:`Table Layout Editor`,className:`bg-background! h-full`,action:r?void 0:t(o,{isLoading:c,variant:`outline`,size:`sm`,onClick:()=>{if(!d.current)return;let t=d.current.getValue(),r;if(!t)r=null;else try{r=JSON.parse(t)}catch(e){return p(`Invalid JSON`,Ve(e))}if(!Array.isArray(r))return p(`Invalid JSON`,`The table layout must be an array`);if(r.some(e=>!e?.name||!e.field))return p(`Invalid JSON`,`A table layout entry must contain the following properties:] {field, name, converter?}`);l(!0),u.types.update(e.id,{...e.edit_revision===void 0?{}:{expected_edit_revision:e.edit_revision},table_layout:r}).then(t=>{e.edit_revision=t.edit_revision,i({status:`success`,title:s(`store.tableLayoutUpdated`),description:s(`store.tableLayoutUpdatedDesc`),duration:2e3}),n(t.table_layout)}).catch(e=>{i({status:`error`,title:s(`store.failedToUpdateTableLayout`),description:e.message,duration:5e3})}).finally(()=>{l(!1)})},children:s(`store.saveChanges`)}),children:t(`div`,{className:`h-full`,children:t(Tt,{value:f,language:`json`,editorRef:d,theme:a===`dark`?`vs-dark`:`vs`,options:{readOnly:r}})})})}function pT(e){return e?JSON.stringify(e,null,2):`[
|
|
462
460
|
|
|
463
|
-
]`}function CT({collection:e}){let{client:n}=Z(),{t:r}=X(),[i,a]=Y(void 0),[s,c]=Y(e.shared_properties||[]),l=Ye();K(()=>{e.type?.id&&n.store.types.retrieve(e.type.id).then(a)},[n.store.types.retrieve,e.type?.id]);let u=i?Object.keys(i.object_schema?.properties||{}):[];return t(V,{title:r(`store.sharedProperties`),description:r(`store.sharedPropertiesDescription`),action:t(o,{size:`lg`,isLoading:!1,onClick:()=>{n.store.collections.update(e.id,{shared_properties:s}).then(()=>{l({title:r(`store.updatedSharedProperties`),status:`success`})}).catch(e=>{l({title:r(`store.failedToUpdateSharedProperties`),description:e.message,status:`error`})})},children:r(`modal.save`)}),children:t(`div`,{className:``,children:t(Ie,{value:s,onChange:e=>{c(e)},options:u,placeholder:r(`store.selectPropertiesToShare`)})})})}function wT({collection:e}){let{client:n}=Z(),{t:r}=X(),[i,a]=Y(e.skip_head_sync??!1),[o,s]=Y(!1),c=Ye();return t(V,{title:r(`store.syncMemberHeads`),description:r(`store.syncMemberHeadsDescription`),children:t(De,{disabled:o,value:!i,onChange:t=>{let i=!t;s(!0),n.store.collections.update(e.id,{skip_head_sync:i}).then(()=>{c({title:r(`store.updatedSkipHeadSync`),status:`success`}),a(i)}).catch(e=>{c({title:r(`store.failedToUpdateSkipHeadSync`),description:e.message,status:`error`})}).finally(()=>{s(!1)})},children:r(`store.enableSyncMemberHeads`)})})}function TT(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ET({refetch:r,collection:a}){let{t:s}=X(),c=a.type?Pi(a.type):void 0,l=J(void 0),u=Ye(),{theme:d}=Je(),{client:f}=Z(),p=at(My),[m,h]=Y(!1),[g,_]=Y({name:a.name,description:a.description||``,query:a.query?JSON.stringify(a.query,null,2):``,tags:a.tags||[],type:a.type?Pi(a.type):``,allowed_types:a.allowed_types||[],sensitivity:a.sensitivity,compartments:a.compartments||[]}),[v,y]=Y(``),b=q(()=>ST(a.table_layout),[a.table_layout]),x=()=>{let e;try{let t=g.query?JSON.parse(g.query):void 0;if(t!==void 0&&!TT(t))throw Error(s(`store.invalidQueryJson`));e=t}catch(e){u({title:s(`store.invalidQueryJson`),description:ze(e),status:`error`,duration:5e3});return}let t={name:g.name,description:g.description,query:e,tags:g.tags,type:g.type,allowed_types:g.allowed_types,sensitivity:g.sensitivity,compartments:g.compartments},n;if(t.name||(n=s(`type.nameRequired`)),t.type||=null,n){u({title:s(`store.validationFailed`),description:n,status:`error`,duration:5e3});return}if(l.current){let e=l.current.getValue();if(e)try{t.table_layout=JSON.parse(e)}catch(e){u({title:s(`store.invalidTableLayout`),description:ze(e),status:`error`,duration:5e3});return}else t.table_layout=null}h(!0),f.store.collections.update(a.id,t).then(()=>{r(),a.dynamic&&p&&(p.reset(),p.search()),u({title:s(`store.collectionUpdated`),description:s(`store.collectionUpdatedSuccess`),status:`success`,duration:3e3})}).catch(e=>{u({title:s(`store.failedToUpdateCollection`),description:ze(e),status:`error`,duration:5e3})}).finally(()=>{h(!1)})},S=(e,t)=>{_({...g,[e]:t})};return n(`div`,{className:`flex flex-col gap-4 py-2`,children:[n(V,{title:s(`store.configuration`),action:t(o,{size:`lg`,isDisabled:m,onClick:x,children:s(`modal.save`)}),children:[n(`div`,{className:`flex justify-between mb-2`,children:[n(`div`,{className:`w-1/2 gap-2 flex flex-col`,children:[t(`div`,{className:`text-sm font-medium mb-1`,children:s(`store.createdBy`)}),n(`div`,{className:`gap-2 flex items-center`,children:[t(q_,{userRef:a.created_by,showTitle:!0}),n(`span`,{children:[`at `,Ki(a.created_at).format(`YYYY-MM-DD HH:mm:ss`)]})]})]}),n(`div`,{className:`w-1/2 gap-2 flex flex-col`,children:[t(`div`,{className:`text-sm font-medium mb-1`,children:s(`store.updatedBy`)}),n(`div`,{className:`gap-2 flex items-center`,children:[t(q_,{userRef:a.updated_by,showTitle:!0}),n(`span`,{children:[`at `,Ki(a.updated_at).format(`YYYY-MM-DD HH:mm:ss`)]})]})]})]}),t(L,{label:s(`type.name`),required:!0,children:t(R,{value:g.name,onChange:e=>S(`name`,e)})}),t(L,{label:s(`type.description`),children:t(Le,{value:g.description,onChange:e=>S(`description`,e.target.value)})}),!a.dynamic&&t(L,{label:s(`store.allowedContentTypes`),description:s(`store.allowedContentTypesSelectDescription`),children:t(Sw,{defaultValue:g.allowed_types||null,onChange:e=>{Array.isArray(e)?S(`allowed_types`,e.map(e=>e.id)):S(`allowed_types`,e?[e.id]:[])},isClearable:!0,multiple:!0})}),a.dynamic&&t(L,{label:s(`store.query`),description:s(`store.queryDescription`),children:t(Le,{className:Ee.INPUT,minLines:1,maxLines:12,value:g.query,onChange:e=>S(`query`,e.target.value)})}),t(L,{label:s(`store.tableLayout`),description:s(`store.tableLayoutDescription`),className:`h-[200px]`,children:t(xt,{className:`border-1 rounded-md border-border`,value:b,language:`json`,editorRef:l,theme:d===`dark`?`vs-dark`:`vs`})}),t(L,{label:s(`store.contentType`),description:s(`store.typeSelectDescription`),children:t(Sw,{defaultValue:g.type||null,onChange:e=>{Array.isArray(e)?S(`type`,e.length>0?e[0].id:null):S(`type`,e?.id||null)},isClearable:!0})}),t(L,{label:`Sensitivity`,description:`BLP sensitivity level — propagated to member documents (max across collections)`,children:t(ve,{options:ji.map((e,t)=>({label:`${t} — ${e}`,value:t})),value:g.sensitivity===void 0?void 0:{label:`${g.sensitivity} — ${ji[g.sensitivity]??`Unknown`}`,value:g.sensitivity},onChange:e=>S(`sensitivity`,e.value),optionLabel:e=>e.label,by:`value`,placeholder:`Not set`})}),n(L,{label:`Compartments`,description:`Security compartments — propagated to member documents (union across collections)`,children:[n(`div`,{className:`flex gap-2`,children:[t(R,{value:v,onChange:y,placeholder:`Add a compartment`,onKeyDown:e=>{if(e.key===`Enter`){e.preventDefault();let t=v.trim();t&&!g.compartments.includes(t)&&(S(`compartments`,[...g.compartments,t]),y(``))}}}),t(o,{type:`button`,variant:`outline`,onClick:()=>{let e=v.trim();e&&!g.compartments.includes(e)&&(S(`compartments`,[...g.compartments,e]),y(``))},children:`Add`})]}),t(`div`,{className:`flex gap-1 flex-wrap mt-2`,children:g.compartments.map(e=>n(i,{variant:`secondary`,className:`cursor-pointer`,onClick:()=>S(`compartments`,g.compartments.filter(t=>t!==e)),children:[e,` ×`]},e))})]})]}),c&&t(DT,{typeId:c,collection:a}),!a.dynamic&&n(e,{children:[t(wT,{collection:a}),t(CT,{collection:a})]})]})}function DT({typeId:e,collection:n}){let{t:r}=X(),[i,a]=Y({}),s=Ye(),{client:c}=Z(),[l,u]=Y(!1),{data:d,error:f}=Ue(()=>c.store.types.catalog.resolve(e),[e]),p=d?.object_schema||{},m=q(()=>new yt(p,n.properties||{}),[p,n.properties]);if(f)return t(M,{title:r(`store.failedToLoadType`),children:ze(f)});if(!d)return null;let h=e=>{if(!e||!Object.keys(e).length)return;let t={properties:e||{}};u(!0),c.store.collections.update(n.id,t).then(()=>{s({title:r(`store.collectionPropertiesUpdated`),description:r(`store.collectionUpdatedSuccess`),status:`success`,duration:3e3})}).catch(e=>{s({title:r(`store.failedToUpdateCollectionProperties`),description:ze(e),status:`error`,duration:5e3})}).finally(()=>{u(!1)})};return t(V,{title:r(`store.properties`),action:t(o,{size:`lg`,isLoading:l,type:`submit`,onClick:()=>h(i),children:r(`modal.save`)}),children:t(gt,{object:m,onChange:e=>{e instanceof yt&&a(e.value)}})})}function OT({onChange:e,value:r,disabled:i=!1,placeholder:a,searchPlaceholder:s,filterOut:c,allowDynamic:l=!0,multiple:u=!1}){let{client:d}=Z(),{t:f}=X(),p=a??f(`store.selectACollection`),m=s??f(`store.searchCollections`),[b,x]=Y(``),[S,C]=Y(!1),[w,T]=Y(!1),E=He(b,300),D=G(async e=>{C(!0);let t=e.trim(),n=await d.store.collections.search({dynamic:l?void 0:!1,name:w&&t||void 0});return C(!1),!w&&n.length>=1e3&&T(!0),c&&c.length>0?n.filter(e=>!c.includes(e.id)):n},[d,l,c,w]),{data:O,error:k}=Ue(()=>D(w?E:``),[w?E:``,D]),A=q(()=>O?u&&Array.isArray(r)?O.filter(e=>r.includes(e.id)):!u&&typeof r==`string`?O.find(e=>e.id===r):u?[]:void 0:u?[]:void 0,[O,r,u]),j=G(t=>{if(u){let n=Array.isArray(r)?r:[];if(n.includes(t.id)){let r=n.filter(e=>e!==t.id);e(r,O?.filter(e=>r.includes(e.id))||[])}else{let r=[...n,t.id];e(r,O?.filter(e=>r.includes(e.id))||[])}}else e(t.id,t)},[e,r,O,u]),N=G(()=>{e(void 0,void 0)},[e]),P=G(e=>{x(e)},[]),F=b.trim().length>0,I=q(()=>{if(!O)return[];if(w||!F)return O;let e=b.toLowerCase();return O.filter(t=>t.name.toLowerCase().includes(e))},[O,w,F,b]),L=u?Array.isArray(A)&&A.length>0:!!A;return k?t(M,{title:f(`store.collectionFetchFailed`),children:ze(k)}):n(le,{children:[t(de,{asChild:!0,children:n(o,{variant:`outline`,role:`combobox`,"aria-haspopup":`listbox`,className:H(`w-full justify-between min-w-0`),disabled:i,children:[t(`span`,{className:`truncate flex-1 text-start min-w-0`,children:u&&Array.isArray(A)&&A.length>0?A.length===1?A[0].name:f(`store.collectionsSelected`,{count:A.length}):!u&&A&&!Array.isArray(A)?A.name:p}),L&&!i?t(o,{variant:`unstyled`,"aria-label":`Clear selection`,className:`ms-2 shrink-0 opacity-50 hover:opacity-100 hover:text-destructive cursor-pointer`,onClick:e=>{e.stopPropagation(),N()},children:t(ci,{className:`h-4 w-4`})}):t(hn,{className:`ms-2 h-4 w-4 shrink-0 opacity-50`})]})}),t(ue,{className:`mt-2 mb-2 w-[var(--radix-popover-trigger-width)] p-0`,align:`start`,children:n(h,{shouldFilter:!1,children:[n(`div`,{className:`flex justify-between items-center border-b px-3`,"cmdk-input-wrapper":``,children:[t(v,{placeholder:m,value:b,onValueChange:P,className:`flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50`}),S&&t(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent`})]}),t(g,{children:f(S?`store.searching`:F?`store.noCollectionsFound`:`store.noCollectionsAvailable`)}),n(_,{className:`max-h-[300px] overflow-auto`,children:[L&&!F&&t(y,{value:`__clear__`,onSelect:N,className:`text-destructive`,children:`Remove collection selection(s)`}),F&&t(y,{value:`__clear_search__`,onSelect:()=>x(``),className:`text-muted`,children:f(`store.clearSelection`)}),I.map(e=>{let i=u&&Array.isArray(r)?r.includes(e.id):r===e.id;return n(y,{value:e.id,onSelect:()=>j(e),className:`flex items-center justify-between`,children:[t(`span`,{className:`truncate`,children:e.name}),i&&t(Qt,{className:`ms-2 h-4 w-4 shrink-0`})]},e.id)})]})]})})]})}function kT({isOpen:e,onClose:r}){return n(ie,{onClose:()=>r(),isOpen:!!e,className:`min-w-[60vw]`,children:[t(se,{children:`Select Content`}),t(ae,{className:`pt-0 overflow-y-auto max-h-[80vh] min-h-[80vh]`,children:e&&t(eb,{onChange:r})})]})}const AT=/store:([a-f0-9]+)/;function jT({object:e}){let{client:r}=Z(),{off:i,on:a,isOn:s}=Ge(),[c,l]=Y(e.value==null?``:String(e.value)),[u,d]=Y(void 0),f=t=>{let n=t.target.value;l(n),e.value=n},p=G(()=>{l(``),e.value=``,d(void 0)},[e]);return K(()=>{if(!c||u)return;let e=c.match(AT);e&&r.objects.retrieve(e[1]).then(e=>{d(e)}).catch(()=>{p()})},[c,r.objects.retrieve,p,u]),n(`div`,{children:[n(`div`,{className:`relative`,children:[t(`input`,{value:c,onChange:f,className:Ze(Ee.INPUT,`pe-10 w-full`)}),u&&t(`div`,{className:`absolute inset-y-0 end-10 flex items-center justify-center `,children:t(o,{onClick:p,variant:`unstyled`,className:`hover:text-red-500 hover:bg-gray-100 dark:hover:bg-gray-600`,children:t(ci,{className:`size-5`})})}),t(`div`,{className:`absolute inset-y-0 end-0 flex items-center justify-center`,children:t(o,{onClick:a,variant:`unstyled`,className:`hover:bg-gray-100 dark:hover:bg-gray-600`,children:t(hn,{className:`size-5`})})}),t(kT,{value:c,isOpen:s,onClose:t=>{if(t){let n=`store:${t.id}`;l(n),d(t||void 0),e.value=n}i()}})]}),u&&t(`div`,{className:`p-1 semibold text-sm text-gray-600 dark:text-slate-300`,children:typeof u.properties?.title==`string`?u.properties.title:u.name})]})}function MT({objectId:e,isOpen:r,onClose:i}){let a=_a(),{client:s,store:c}=Z(),[l,u]=Y(null),[d,f]=Y(!1),[p,m]=Y(!1),[h,g]=Y(),[_,v]=Y(),[y,b]=Y(`preview`),{t:x}=X(),S=Ye(),C=G(async e=>{m(!0);try{let t=await c.objects.getObjectText(e);g(t.text)}catch(e){console.error(`Error loading text:`,e)}finally{m(!1)}},[c.objects]),w=G(async e=>{if(e.content?.source)try{(await s.objects.getRendition(e.id,{format:Ci.jpeg,generate_if_missing:!1})).status===`found`&&console.log(`Found rendition`);let t=await s.files.getDownloadUrl(e.content.source);v(t.url)}catch(e){console.error(`Error loading image:`,e)}},[s.files,s.objects]);K(()=>{e&&r?(f(!0),c.objects.retrieve(e,`+embeddings`).then(e=>{u(e),e.text?g(e.text):C(e.id);let t=e.content;t?.source&&t.type?.startsWith(`image/`)&&w(e)}).catch(e=>{console.error(`Error loading object:`,e),S({title:x(`agent.error`),description:x(`store.failedToLoadDocument`),status:`error`,duration:3e3})}).finally(()=>{f(!1)})):(u(null),g(void 0),v(void 0))},[e,r,c.objects,C,w,x,S]);let T=()=>{l&&(a(`/legal/objects/${l.id}`),i())},E=h&&(h.startsWith(`#`)||h.includes(`
|
|
461
|
+
]`}function mT({collection:e}){let{client:n}=Q(),{t:r}=Z(),[i,a]=X(void 0),[s,c]=X(e.shared_properties||[]),l=Xe();q(()=>{e.type?.id&&n.store.types.retrieve(e.type.id).then(a)},[n.store.types.retrieve,e.type?.id]);let u=i?Object.keys(i.object_schema?.properties||{}):[];return t(ue,{title:r(`store.sharedProperties`),description:r(`store.sharedPropertiesDescription`),action:t(o,{size:`lg`,isLoading:!1,onClick:()=>{n.store.collections.update(e.id,{shared_properties:s}).then(()=>{l({title:r(`store.updatedSharedProperties`),status:`success`})}).catch(e=>{l({title:r(`store.failedToUpdateSharedProperties`),description:e.message,status:`error`})})},children:r(`modal.save`)}),children:t(`div`,{className:``,children:t(Re,{value:s,onChange:e=>{c(e)},options:u,placeholder:r(`store.selectPropertiesToShare`)})})})}function hT({collection:e}){let{client:n}=Q(),{t:r}=Z(),[i,a]=X(e.skip_head_sync??!1),[o,s]=X(!1),c=Xe();return t(ue,{title:r(`store.syncMemberHeads`),description:r(`store.syncMemberHeadsDescription`),children:t(ke,{disabled:o,value:!i,onChange:t=>{let i=!t;s(!0),n.store.collections.update(e.id,{skip_head_sync:i}).then(()=>{c({title:r(`store.updatedSkipHeadSync`),status:`success`}),a(i)}).catch(e=>{c({title:r(`store.failedToUpdateSkipHeadSync`),description:e.message,status:`error`})}).finally(()=>{s(!1)})},children:r(`store.enableSyncMemberHeads`)})})}function gT(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function _T({refetch:r,collection:a}){let{t:s}=Z(),c=a.type?Bi(a.type):void 0,l=Y(void 0),u=Xe(),{theme:d}=Ye(),{client:f}=Q(),p=lt(sb),[m,h]=X(!1),[g,_]=X({name:a.name,description:a.description||``,query:a.query?JSON.stringify(a.query,null,2):``,tags:a.tags||[],type:a.type?Bi(a.type):``,allowed_types:a.allowed_types||[],sensitivity:a.sensitivity,compartments:a.compartments||[]}),[v,y]=X(``),b=J(()=>pT(a.table_layout),[a.table_layout]),x=()=>{let e;try{let t=g.query?JSON.parse(g.query):void 0;if(t!==void 0&&!gT(t))throw Error(s(`store.invalidQueryJson`));e=t}catch(e){u({title:s(`store.invalidQueryJson`),description:Ve(e),status:`error`,duration:5e3});return}let t={name:g.name,description:g.description,query:e,tags:g.tags,type:g.type,allowed_types:g.allowed_types,sensitivity:g.sensitivity,compartments:g.compartments},n;if(t.name||(n=s(`type.nameRequired`)),t.type||=null,n){u({title:s(`store.validationFailed`),description:n,status:`error`,duration:5e3});return}if(l.current){let e=l.current.getValue();if(e)try{t.table_layout=JSON.parse(e)}catch(e){u({title:s(`store.invalidTableLayout`),description:Ve(e),status:`error`,duration:5e3});return}else t.table_layout=null}h(!0),f.store.collections.update(a.id,t).then(()=>{r(),a.dynamic&&p&&(p.reset(),p.search()),u({title:s(`store.collectionUpdated`),description:s(`store.collectionUpdatedSuccess`),status:`success`,duration:3e3})}).catch(e=>{u({title:s(`store.failedToUpdateCollection`),description:Ve(e),status:`error`,duration:5e3})}).finally(()=>{h(!1)})},S=(e,t)=>{_({...g,[e]:t})};return n(`div`,{className:`flex flex-col gap-4 py-2`,children:[n(ue,{title:s(`store.configuration`),action:t(o,{size:`lg`,isDisabled:m,onClick:x,children:s(`modal.save`)}),children:[n(`div`,{className:`flex justify-between mb-2`,children:[n(`div`,{className:`w-1/2 gap-2 flex flex-col`,children:[t(`div`,{className:`text-sm font-medium mb-1`,children:s(`store.createdBy`)}),n(`div`,{className:`gap-2 flex items-center`,children:[t(uv,{userRef:a.created_by,showTitle:!0}),n(`span`,{children:[`at `,fs(a.created_at).format(`YYYY-MM-DD HH:mm:ss`)]})]})]}),n(`div`,{className:`w-1/2 gap-2 flex flex-col`,children:[t(`div`,{className:`text-sm font-medium mb-1`,children:s(`store.updatedBy`)}),n(`div`,{className:`gap-2 flex items-center`,children:[t(uv,{userRef:a.updated_by,showTitle:!0}),n(`span`,{children:[`at `,fs(a.updated_at).format(`YYYY-MM-DD HH:mm:ss`)]})]})]})]}),t(L,{label:s(`type.name`),required:!0,children:t(R,{value:g.name,onChange:e=>S(`name`,e)})}),t(L,{label:s(`type.description`),children:t(ze,{value:g.description,onChange:e=>S(`description`,e.target.value)})}),!a.dynamic&&t(L,{label:s(`store.allowedContentTypes`),description:s(`store.allowedContentTypesSelectDescription`),children:t(pw,{defaultValue:g.allowed_types||null,onChange:e=>{Array.isArray(e)?S(`allowed_types`,e.map(e=>e.id)):S(`allowed_types`,e?[e.id]:[])},isClearable:!0,multiple:!0})}),a.dynamic&&t(L,{label:s(`store.query`),description:s(`store.queryDescription`),children:t(ze,{className:Oe.INPUT,minLines:1,maxLines:12,value:g.query,onChange:e=>S(`query`,e.target.value)})}),t(L,{label:s(`store.tableLayout`),description:s(`store.tableLayoutDescription`),className:`h-[200px]`,children:t(Tt,{className:`border-1 rounded-md border-border`,value:b,language:`json`,editorRef:l,theme:d===`dark`?`vs-dark`:`vs`})}),t(L,{label:s(`store.contentType`),description:s(`store.typeSelectDescription`),children:t(pw,{defaultValue:g.type||null,onChange:e=>{Array.isArray(e)?S(`type`,e.length>0?e[0].id:null):S(`type`,e?.id||null)},isClearable:!0})}),t(L,{label:`Sensitivity`,description:`BLP sensitivity level — propagated to member documents (max across collections)`,children:t(be,{options:Ii.map((e,t)=>({label:`${t} — ${e}`,value:t})),value:g.sensitivity===void 0?void 0:{label:`${g.sensitivity} — ${Ii[g.sensitivity]??`Unknown`}`,value:g.sensitivity},onChange:e=>S(`sensitivity`,e.value),optionLabel:e=>e.label,by:`value`,placeholder:`Not set`})}),n(L,{label:`Compartments`,description:`Security compartments — propagated to member documents (union across collections)`,children:[n(`div`,{className:`flex gap-2`,children:[t(R,{value:v,onChange:y,placeholder:`Add a compartment`,onKeyDown:e=>{if(e.key===`Enter`){e.preventDefault();let t=v.trim();t&&!g.compartments.includes(t)&&(S(`compartments`,[...g.compartments,t]),y(``))}}}),t(o,{type:`button`,variant:`outline`,onClick:()=>{let e=v.trim();e&&!g.compartments.includes(e)&&(S(`compartments`,[...g.compartments,e]),y(``))},children:`Add`})]}),t(`div`,{className:`flex gap-1 flex-wrap mt-2`,children:g.compartments.map(e=>n(i,{variant:`secondary`,className:`cursor-pointer`,onClick:()=>S(`compartments`,g.compartments.filter(t=>t!==e)),children:[e,` ×`]},e))})]})]}),c&&t(vT,{typeId:c,collection:a}),!a.dynamic&&n(e,{children:[t(hT,{collection:a}),t(mT,{collection:a})]})]})}function vT({typeId:e,collection:n}){let{t:r}=Z(),[i,a]=X({}),s=Xe(),{client:c}=Q(),[l,u]=X(!1),{data:d,error:f}=U(()=>c.store.types.catalog.resolve(e),[e]),p=d?.object_schema||{},m=J(()=>new Ct(p,n.properties||{}),[p,n.properties]);if(f)return t(M,{title:r(`store.failedToLoadType`),children:Ve(f)});if(!d)return null;let h=e=>{if(!e||!Object.keys(e).length)return;let t={properties:e||{}};u(!0),c.store.collections.update(n.id,t).then(()=>{s({title:r(`store.collectionPropertiesUpdated`),description:r(`store.collectionUpdatedSuccess`),status:`success`,duration:3e3})}).catch(e=>{s({title:r(`store.failedToUpdateCollectionProperties`),description:Ve(e),status:`error`,duration:5e3})}).finally(()=>{u(!1)})};return t(ue,{title:r(`store.properties`),action:t(o,{size:`lg`,isLoading:l,type:`submit`,onClick:()=>h(i),children:r(`modal.save`)}),children:t(bt,{object:m,onChange:e=>{e instanceof Ct&&a(e.value)}})})}function yT({onChange:e,value:r,disabled:i=!1,placeholder:a,searchPlaceholder:s,filterOut:c,allowDynamic:l=!0,multiple:u=!1}){let{client:d}=Q(),{t:f}=Z(),p=a??f(`store.selectACollection`),m=s??f(`store.searchCollections`),[b,x]=X(``),[S,C]=X(!1),[w,T]=X(!1),E=We(b,300),D=K(async e=>{C(!0);let t=e.trim(),n=await d.store.collections.search({dynamic:l?void 0:!1,name:w&&t||void 0});return C(!1),!w&&n.length>=1e3&&T(!0),c&&c.length>0?n.filter(e=>!c.includes(e.id)):n},[d,l,c,w]),{data:O,error:k}=U(()=>D(w?E:``),[w?E:``,D]),A=J(()=>O?u&&Array.isArray(r)?O.filter(e=>r.includes(e.id)):!u&&typeof r==`string`?O.find(e=>e.id===r):u?[]:void 0:u?[]:void 0,[O,r,u]),j=K(t=>{if(u){let n=Array.isArray(r)?r:[];if(n.includes(t.id)){let r=n.filter(e=>e!==t.id);e(r,O?.filter(e=>r.includes(e.id))||[])}else{let r=[...n,t.id];e(r,O?.filter(e=>r.includes(e.id))||[])}}else e(t.id,t)},[e,r,O,u]),N=K(()=>{e(void 0,void 0)},[e]),P=K(e=>{x(e)},[]),F=b.trim().length>0,I=J(()=>{if(!O)return[];if(w||!F)return O;let e=b.toLowerCase();return O.filter(t=>t.name.toLowerCase().includes(e))},[O,w,F,b]),L=u?Array.isArray(A)&&A.length>0:!!A;return k?t(M,{title:f(`store.collectionFetchFailed`),children:Ve(k)}):n(de,{children:[t(pe,{asChild:!0,children:n(o,{variant:`outline`,role:`combobox`,"aria-haspopup":`listbox`,className:H(`w-full justify-between min-w-0`),disabled:i,children:[t(`span`,{className:`truncate flex-1 text-start min-w-0`,children:u&&Array.isArray(A)&&A.length>0?A.length===1?A[0].name:f(`store.collectionsSelected`,{count:A.length}):!u&&A&&!Array.isArray(A)?A.name:p}),L&&!i?t(o,{variant:`unstyled`,"aria-label":`Clear selection`,className:`ms-2 shrink-0 opacity-50 hover:opacity-100 hover:text-destructive cursor-pointer`,onClick:e=>{e.stopPropagation(),N()},children:t(mi,{className:`h-4 w-4`})}):t(bn,{className:`ms-2 h-4 w-4 shrink-0 opacity-50`})]})}),t(fe,{className:`mt-2 mb-2 w-[var(--radix-popover-trigger-width)] p-0`,align:`start`,children:n(h,{shouldFilter:!1,children:[n(`div`,{className:`flex justify-between items-center border-b px-3`,"cmdk-input-wrapper":``,children:[t(v,{placeholder:m,value:b,onValueChange:P,className:`flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50`}),S&&t(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent`})]}),t(g,{children:f(S?`store.searching`:F?`store.noCollectionsFound`:`store.noCollectionsAvailable`)}),n(_,{className:`max-h-[300px] overflow-auto`,children:[L&&!F&&t(y,{value:`__clear__`,onSelect:N,className:`text-destructive`,children:`Remove collection selection(s)`}),F&&t(y,{value:`__clear_search__`,onSelect:()=>x(``),className:`text-muted`,children:f(`store.clearSelection`)}),I.map(e=>{let i=u&&Array.isArray(r)?r.includes(e.id):r===e.id;return n(y,{value:e.id,onSelect:()=>j(e),className:`flex items-center justify-between`,children:[t(`span`,{className:`truncate`,children:e.name}),i&&t(rn,{className:`ms-2 h-4 w-4 shrink-0`})]},e.id)})]})]})})]})}function bT({isOpen:e,onClose:r}){return n(ie,{onClose:()=>r(),isOpen:!!e,className:`min-w-[60vw]`,children:[t(se,{children:`Select Content`}),t(ae,{className:`pt-0 overflow-y-auto max-h-[80vh] min-h-[80vh]`,children:e&&t(kb,{onChange:r})})]})}const xT=/store:([a-f0-9]+)/;function ST({object:e}){let{client:r}=Q(),{off:i,on:a,isOn:s}=Ke(),[c,l]=X(e.value==null?``:String(e.value)),[u,d]=X(void 0),f=t=>{let n=t.target.value;l(n),e.value=n},p=K(()=>{l(``),e.value=``,d(void 0)},[e]);return q(()=>{if(!c||u)return;let e=c.match(xT);e&&r.objects.retrieve(e[1]).then(e=>{d(e)}).catch(()=>{p()})},[c,r.objects.retrieve,p,u]),n(`div`,{children:[n(`div`,{className:`relative`,children:[t(`input`,{value:c,onChange:f,className:Qe(Oe.INPUT,`pe-10 w-full`)}),u&&t(`div`,{className:`absolute inset-y-0 end-10 flex items-center justify-center `,children:t(o,{onClick:p,variant:`unstyled`,className:`hover:text-red-500 hover:bg-gray-100 dark:hover:bg-gray-600`,children:t(mi,{className:`size-5`})})}),t(`div`,{className:`absolute inset-y-0 end-0 flex items-center justify-center`,children:t(o,{onClick:a,variant:`unstyled`,className:`hover:bg-gray-100 dark:hover:bg-gray-600`,children:t(bn,{className:`size-5`})})}),t(bT,{value:c,isOpen:s,onClose:t=>{if(t){let n=`store:${t.id}`;l(n),d(t||void 0),e.value=n}i()}})]}),u&&t(`div`,{className:`p-1 semibold text-sm text-gray-600 dark:text-slate-300`,children:typeof u.properties?.title==`string`?u.properties.title:u.name})]})}function CT({objectId:e,isOpen:r,onClose:i}){let a=_a(),{client:s,store:c}=Q(),[l,u]=X(null),[d,f]=X(!1),[p,m]=X(!1),[h,g]=X(),[_,v]=X(),[y,b]=X(`preview`),{t:x}=Z(),S=Xe(),C=K(async e=>{m(!0);try{let t=await c.objects.getObjectText(e);g(t.text)}catch(e){console.error(`Error loading text:`,e)}finally{m(!1)}},[c.objects]),w=K(async e=>{if(e.content?.source)try{(await s.objects.getRendition(e.id,{format:Oi.jpeg,generate_if_missing:!1})).status===`found`&&console.log(`Found rendition`);let t=await s.files.getDownloadUrl(e.content.source);v(t.url)}catch(e){console.error(`Error loading image:`,e)}},[s.files,s.objects]);q(()=>{e&&r?(f(!0),c.objects.retrieve(e,`+embeddings`).then(e=>{u(e),e.text?g(e.text):C(e.id);let t=e.content;t?.source&&t.type?.startsWith(`image/`)&&w(e)}).catch(e=>{console.error(`Error loading object:`,e),S({title:x(`agent.error`),description:x(`store.failedToLoadDocument`),status:`error`,duration:3e3})}).finally(()=>{f(!1)})):(u(null),g(void 0),v(void 0))},[e,r,c.objects,C,w,x,S]);let T=()=>{l&&(a(`/legal/objects/${l.id}`),i())},E=h&&(h.startsWith(`#`)||h.includes(`
|
|
464
462
|
#`)||h.includes(`
|
|
465
|
-
*`)),D=l?.content?.type?.startsWith(`image/`),O=l?.content?.type===`application/pdf`;return r?n(`div`,{className:`fixed inset-y-0 end-0 w-2/5 dark:bg-slate-900 shadow-xl z-50 flex flex-col transition-transform duration-300 transform ${r?`translate-x-0`:`translate-x-full rtl:-translate-x-full`}`,children:[n(`div`,{className:`flex items-center justify-between px-4 py-3 border-b dark:border-gray-700 bg-gradient-to-r from-indigo-50 to-gray-50 dark:from-gray-800 dark:to-gray-900`,children:[n(`div`,{className:`flex items-center`,children:[t(Ln,{className:`h-5 w-5 text-indigo-600 me-2`}),t(`h2`,{className:`text-lg font-semibold text-gray-800 dark:text-gray-200 truncate`,children:d?x(`store.loadingDocument`):l?.name||x(`store.documentPreview`)})]}),n(`div`,{className:`flex items-center gap-2`,children:[n(o,{variant:`ghost`,size:`sm`,onClick:T,className:`flex items-center gap-1 text-indigo-600 hover:text-indigo-800`,children:[t(fr,{className:`h-4 w-4`}),t(`span`,{children:x(`store.fullView`)})]}),t(o,{variant:`ghost`,size:`sm`,onClick:i,className:`flex items-center text-gray-600 hover:text-gray-800 dark:text-gray-300 dark:hover:text-gray-100`,children:t(ci,{className:`h-5 w-5`})})]})]}),d?t(`div`,{className:`flex-1 flex items-center justify-center`,children:n(`div`,{className:`text-center`,children:[t(Te,{size:`lg`,className:`text-indigo-600 dark:text-indigo-400 mb-2`}),t(`p`,{className:`text-gray-600 dark:text-gray-400`,children:x(`store.loadingDocument`)})]})}):n(`div`,{className:`flex-1 flex flex-col h-full`,children:[t(`div`,{className:`border-b`,children:n(`div`,{className:`flex px-4`,children:[t(o,{variant:`unstyled`,className:`py-2 px-4 font-medium border-b-2 ${y===`preview`?`border-indigo-600 text-indigo-700 dark:text-indigo-300`:`border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`}`,onClick:()=>b(`preview`),children:n(`div`,{className:`flex items-center gap-1`,children:[t(tr,{className:`h-4 w-4`}),t(`span`,{children:x(`store.preview`)})]})}),t(o,{variant:`unstyled`,className:`py-2 px-4 font-medium border-b-2 ${y===`properties`?`border-indigo-600 text-indigo-700 dark:text-indigo-300`:`border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`}`,onClick:()=>b(`properties`),children:n(`div`,{className:`flex items-center gap-1`,children:[t(Qn,{className:`h-4 w-4`}),t(`span`,{children:x(`store.properties`)})]})})]})}),n(`div`,{className:`flex-1 overflow-auto p-4`,children:[y===`preview`&&n(`div`,{className:`h-full`,children:[p?t(`div`,{className:`flex items-center justify-center h-40`,children:t(Te,{size:`md`,className:`text-indigo-600 dark:text-indigo-400`})}):h?t(`div`,{className:`shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800`,children:E?t(`div`,{className:`prose prose-sm max-w-none prose-p:my-2 prose-pre:bg-gray-800 prose-pre:my-2 prose-headings:text-indigo-700 dark:prose-invert dark:prose-headings:text-indigo-300`,children:t(bt,{children:h})}):t(`pre`,{className:`text-wrap whitespace-pre-wrap dark:text-gray-200`,children:h})}):null,D&&t(`div`,{className:`mt-4`,children:_?t(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-md p-2 bg-white dark:bg-gray-800`,children:t(`img`,{src:_,alt:l?.name,className:`mx-auto max-h-[70vh] object-contain`})}):t(`div`,{className:`flex items-center justify-center h-40`,children:t(Te,{size:`md`,className:`text-indigo-600 dark:text-indigo-400`})})}),O&&n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800`,children:[t(Ln,{className:`h-16 w-16 text-indigo-300 dark:text-indigo-400 mb-4`}),t(`p`,{className:`text-gray-600 dark:text-gray-400 text-center mb-4`,children:x(`store.pdfPreviewFullView`)}),t(o,{onClick:T,className:`bg-indigo-600 hover:bg-indigo-700 text-white`,children:x(`store.openFullDocumentView`)})]}),!D&&!h&&!O&&!p&&n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800`,children:[t(Ln,{className:`h-16 w-16 text-gray-300 dark:text-gray-600 mb-4`}),t(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:x(`store.noPreviewAvailable`)})]})]}),y===`properties`&&l&&n(`div`,{className:`h-full`,children:[l.properties?t(`div`,{className:`shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800`,children:t(vt,{value:l.properties})}):n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800`,children:[t(Qn,{className:`h-16 w-16 text-gray-300 dark:text-gray-600 mb-4`}),t(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:x(`store.noPropertiesAvailable`)})]}),n(`div`,{className:`mt-4`,children:[t(`h3`,{className:`text-sm font-semibold text-gray-700 dark:text-gray-300 mb-2`,children:x(`store.documentInformation`)}),t(`div`,{className:`shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800`,children:n(`div`,{className:`grid grid-cols-2 gap-y-2 gap-x-4 text-sm`,children:[t(`div`,{className:`text-gray-500 dark:text-gray-400`,children:x(`store.id`)}),t(`div`,{className:`font-medium dark:text-gray-200`,children:l.id}),t(`div`,{className:`text-gray-500 dark:text-gray-400`,children:x(`store.contentType`)}),t(`div`,{className:`font-medium dark:text-gray-200`,children:l.type?.name||x(`store.unknown`)}),t(`div`,{className:`text-gray-500 dark:text-gray-400`,children:x(`store.contentType`)}),t(`div`,{className:`font-medium dark:text-gray-200`,children:l.content?.type||x(`store.na`)}),t(`div`,{className:`text-gray-500`,children:x(`store.size`)}),t(`div`,{className:`font-medium`,children:l.content&&`size`in l.content?NT(l.content.size):x(`store.unknown`)}),t(`div`,{className:`text-gray-500`,children:x(`store.created`)}),t(`div`,{className:`font-medium`,children:l.created_at?new Date(l.created_at).toLocaleString():x(`store.na`)}),t(`div`,{className:`text-gray-500`,children:x(`store.updated`)}),t(`div`,{className:`font-medium`,children:l.updated_at?new Date(l.updated_at).toLocaleString():x(`store.na`)})]})})]})]})]})]}),n(`div`,{className:`flex items-center justify-between p-4 border-t bg-gray-50 dark:bg-gray-800 dark:border-gray-700`,children:[t(`div`,{children:l?.content?.source&&n(o,{onClick:()=>{l?.content?.source&&s.files.getDownloadUrl(l.content.source).then(e=>{window.open(e.url,`_blank`)}).catch(e=>{console.error(`Error getting download URL:`,e),S({title:x(`agent.error`),description:x(`store.failedToDownloadFile`),status:`error`,duration:3e3})})},variant:`outline`,className:`text-indigo-600 border-indigo-300 hover:bg-indigo-50`,children:[t(Tn,{className:`h-4 w-4 me-2`}),x(`pdf.download`)]})}),n(o,{onClick:T,className:`bg-indigo-600 hover:bg-indigo-700 text-white`,children:[x(`store.openFullDocument`),t(cn,{className:`h-4 w-4 ms-2 cn-rtl-flip`})]})]})]}):null}function NT(e){if(e===0)return`0 Bytes`;let t=1024,n=[`Bytes`,`KB`,`MB`,`GB`,`TB`],r=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/t**r).toFixed(2))} ${n[r]}`}var PT;(function(e){e.CSV=`CSV`,e.JSON=`JSON`})(PT||={});function FT({isExporting:e,isOpen:r,onClose:i}){return n(ie,{onClose:()=>i(void 0),isOpen:r,children:[t(se,{children:`Export Object Properties`}),n(ae,{children:[!e&&t(IT,{onClose:i}),e&&t(LT,{})]})]})}function IT({onClose:e}){let{t:r}=X(),[i,a]=Y(void 0),[s,c]=Y(void 0),l=[`Export selected objects`,`Export all objects`],u=e=>e===l[1];return n(ae,{className:`min-h-[104px] pt-0 flex flex-col gap-y-4`,children:[t(`div`,{className:`h-1/3`,children:t(ve,{options:l,value:s,onChange:c,placeholder:r(`store.chooseWhatToExport`),className:`h-full w-full text-sm`,filterBy:`name`,isClearable:!0})}),n(`div`,{className:`h-1/2 flex flex-col gap-y-8 content-between`,children:[t(ve,{options:Object.values(PT),value:i,onChange:a,placeholder:r(`store.chooseAFormat`),className:`h-full w-full text-sm`,filterBy:`name`,isClearable:!0}),t(o,{className:`w-full`,isDisabled:!i||!s,onClick:()=>{e(i,u(s))},children:r(`store.actions.exportProperties`)})]})]})}function LT(){let{t:e}=X();return t(ae,{className:`min-h-[84px] pt-0`,children:n(`div`,{className:`h-full grid flex-col gap-y-2 content-between justify-items-center`,children:[n(`div`,{className:`text-sm flex flex-col gap-x-2`,children:[t(`p`,{children:e(`store.exportInProgress`)}),t(`p`,{className:`pt-2 grid justify-items-center`,children:e(`store.pleaseWait`)})]}),t(Te,{size:`lg`})]})})}const RT=nt(void 0);function zT(){let e=at(RT);if(!e)throw Error(`You cannot use useActionContext outside an ActionProvider`);return e}function BT(e,t){let n=zT();return K(()=>n.registerCallback(e,t),[n,e,t]),n}function VT({action:e,objectIds:n}){let[r,i]=Y(!1),a=G(()=>(n.length>0&&i(!0),Promise.resolve(!0)),[n]);return BT(e.id,a),r&&t(fe,{children:t(WT,{objectIds:n,isOpen:r,onClose:()=>{i(!1)}})})}const HT=It.getFixedT(null,Ft),UT={id:`addToCollection`,name:HT(`store.actions.addToCollection`),description:HT(`store.actions.addToCollectionDesc`),confirm:!1,component:VT};function WT({isOpen:e,onClose:r,objectIds:i}){let{t:a}=X();return n(ie,{isOpen:e,onClose:r,className:`max-w-lg w-full min-w-0 overflow-hidden`,children:[t(se,{className:`flex flex-col min-w-0 overflow-hidden`,children:a(`store.actions.addToCollectionTitle`)}),t(S,{className:`min-w-0 overflow-hidden`,children:a(`store.actions.addToCollectionBody`)}),t(`div`,{className:`min-w-0 max-w-full overflow-hidden`,children:t(GT,{onClose:r,objectIds:i})})]})}function GT({onClose:e,objectIds:r}){let{t:i}=X(),a=Ye(),{client:s}=Z(),[c,l]=Y(),u=({collectionId:t})=>{!t||!r?.length||s.store.collections.addMembers(t,r).then(()=>{a({title:i(`store.actions.addToCollectionSuccess`),status:`success`,description:i(`store.actions.addToCollectionSuccessDesc`,{count:r.length}),duration:3e3}),e()}).catch(()=>{a({title:i(`store.actions.addToCollectionFailure`),status:`error`,description:i(`store.actions.addToCollectionFailureDesc`),duration:5e3})})};return n(Ne,{defaultValue:`select`,tabs:[{name:`select`,label:i(`store.actions.selectCollection`),content:n(`div`,{className:`p-4 min-w-0 max-w-full overflow-hidden`,children:[t(ee,{level:5,children:i(`store.actions.chooseExistingCollections`)}),t(ae,{className:`min-w-0 max-w-full overflow-hidden`,children:t(`div`,{className:`mb-4 min-w-0 max-w-full overflow-hidden`,children:t(OT,{onChange:(e,t)=>{typeof e==`string`||e===void 0?l(e):Array.isArray(e)&&e.length>0?l(e[0]):l(void 0)},value:c})})}),t(oe,{children:t(o,{isDisabled:!c,onClick:()=>c&&u({collectionId:c}),children:i(`store.actions.addToCollectionButton`)})})]})},{name:`create`,label:i(`store.actions.createNew`),content:t(`div`,{className:`p-4`,children:t(Cw,{onClose:e,onAddToCollection:e=>u({collectionId:e}),redirect:!1})})}],fullWidth:!0,children:[t(Pe,{}),t(Fe,{})]})}function KT({action:e,objectIds:r,children:i}){let{t:a}=X(),{store:o}=Z(),s=Ye(),[c,l]=Y(!1),u=G(()=>(l(!0),Promise.resolve(!0)),[]);return BT(e.id,u),n(`div`,{children:[i,t(yT,{isOpen:c,onClose:e=>{l(!1),e!==void 0&&o.runOperation({name:`change_type`,ids:r,params:{typeId:e}}).then(e=>{s({status:`success`,title:a(`store.actions.changeType`),description:`Change the type of ${r.length} objects is ${e.status===`in_progress`?`in progress`:`completed`}`,duration:2e3})}).catch(e=>{s({status:`error`,title:a(`store.actions.errorChangingType`),description:e.message,duration:5e3})})},title:`Change Content Type`,confirmLabel:`Change Type`,children:n(`p`,{className:`pt-2 text-xs`,children:[`Note: This action will raise the `,t(`code`,{children:`change_type`}),` event and will trigger the standard intake workflows which may reset the object properties.`]})})]})}const qT=It.getFixedT(null,Ft),JT={id:`changeType`,name:qT(`store.actions.changeContentType`),description:qT(`store.actions.changeContentTypeDesc`),confirm:!1,component:KT};function YT({action:r,callback:i,children:a}){let{t:o}=X(),[s,c]=Y(!1),l=r.confirmationText||`Are you sure you want to ${r.name}?`,u=G(e=>r.confirm?(c(!0),Promise.resolve(!0)):i(e),[r.confirm,i]),d=BT(r.id,u);return n(e,{children:[a,t(b,{onConfirm:()=>{c(!1),i({...d.params,action:r})},onCancel:()=>c(!1),title:o(`store.actions.areYouSure`),content:l,isOpen:s})]})}function XT({action:r,objectIds:i,children:a}){let{t:o}=X(),s=zT(),c=Ye(),{client:l}=Z(),u=Ny(),d=_a(),[f,p]=Y(!1),m=i?.length??0,h=s.params?.type?.name??`object`,g=G(()=>(p(!0),Promise.resolve(!0)),[]);BT(r.id,g);let _=G(()=>(p(!1),i?.length?l.store.objects.delete(i).then(e=>{let t=e.deleted>1?`s`:``;if(c({status:`success`,title:`${e.deleted} object${t} deleted`,duration:2e3}),e.failed.length>0&&c({status:`warning`,title:`${e.failed.length} object(s) could not be deleted`,duration:3e3}),u){s.params?.selection?.removeAll();let e=JSON.parse(JSON.stringify(u.facets));i.length===e._value.total&&u.resetFacets(),u.search()}else d(`/objects`)}).catch(e=>{c({status:`error`,title:o(`store.actions.errorDeletingObjects`),description:e.message,duration:5e3})}):(c({status:`error`,title:o(`store.actions.noObjectsSelected`),description:o(`store.actions.pleaseSelectObjectsToDelete`),duration:3e3}),Promise.resolve(!1))),[l.store.objects.delete,s.params?.selection?.removeAll,d,i,u,u?.facets,u?.resetFacets,u?.search,o,c]);return n(e,{children:[a,t(b,{isOpen:f,title:m===1?`Delete ${h}`:`Delete ${h}s`,content:n(`div`,{children:[n(`p`,{children:[`Delete `,m,` selected `,h,m===1?``:`s`,`? `,m===1?`This ${h}`:`These ${h}s`,` will be permanently removed.`]}),t(`p`,{children:t(`span`,{className:`text-destructive`,children:`This action cannot be undone.`})})]}),onConfirm:_,onCancel:()=>p(!1),confirmationValue:`delete`,confirmationLabel:`Type "delete" to confirm`,confirmationPlaceholder:`delete`})]})}const ZT=It.getFixedT(null,Ft),QT={id:`delete`,name:ZT(`store.actions.delete`),description:ZT(`store.actions.deleteTheSelectedObjects`),confirm:!0,confirmationText:ZT(`store.actions.confirmDeleteAll`),component:XT,destructive:!0},$T={id:`deleteFromCollections`,name:ZT(`store.actions.deleteObjects`),description:ZT(`store.actions.deleteTheSelectedObjects`),confirm:!0,confirmationText:ZT(`store.actions.confirmDeleteSelected`),component:XT,destructive:!0};function eE({action:e,objectIds:n}){let{t:r}=X(),{store:i}=Z(),a=Ye(),[o,s]=Y(!1),[c,l]=Y(!1),u=G(()=>(s(!0),Promise.resolve(!0)),[]),d=BT(e.id,u);return t(FT,{isExporting:c,isOpen:o,onClose:(e,t)=>{if(e&&(t||n.length>0)){l(!0);let o=d.params?.search?.query||{},c=d.params?.search?.result?.value?.objects?.map(e=>e.id)||void 0,u=async e=>i.objects.list({query:{parent:e}}).then(e=>e.map(e=>e.id)),f=async()=>t?c?o.vector?c:[]:n.length===0?[]:(await u(n[0])).concat(n):n,p=d.params?.type?.id??o.type,m=d.params?.type?.table_layout??void 0;f().then(c=>{i.objects.exportProperties({objectIds:c,type:e,query:t&&!o.vector?{...o,type:p}:{type:p},table_layout:m}).then(e=>{let i=new Blob([e.data],{type:e.type}),o=window.URL.createObjectURL(i),s=document.createElement(`a`);s.download=e.name,s.href=o,s.click(),a({status:`success`,title:r(`store.actions.exportProperties`),description:t?`Export the properties of all objects completed`:`Export the properties of ${n.length} object${n.length>1?`s`:``} is completed`,duration:2e3})}).catch(e=>{a({status:`error`,title:r(`store.actions.errorExportProperties`),description:e.message,duration:5e3})}).finally(()=>{l(!1),s(!1)})})}else s(!1),a({status:`error`,title:r(`store.actions.errorExportProperties`),description:`No objects selected for export`,duration:5e3})}})}const tE=It.getFixedT(null,Ft),nE={id:`exportProperties`,name:tE(`store.actions.exportProperties`),description:tE(`store.actions.exportAllObjectProperties`),confirm:!1,component:eE};function rE({action:e,objectIds:n,collectionId:r}){let{t:i}=X(),a=zT(),o=Ye(),{client:s}=Z(),c=Ny();return t(YT,{action:e,callback:G(()=>n?.length?r?s.store.collections.deleteMembers(r,n).then(()=>{let e=n.length>1?`s`:``;o({status:`success`,title:`${n.length} object${e} removed from collection`,description:`Objects have been removed from the collection`,duration:2e3}),c&&(a.params?.selection?.removeAll(),c.search())}).catch(e=>{o({status:`error`,title:i(`store.actions.errorRemovingObjects`),description:ze(e),duration:5e3})}):(o({status:`error`,title:i(`store.actions.noCollectionContext`),description:i(`store.actions.cannotRemoveNoCollection`),duration:3e3}),Promise.resolve(!1)):(o({status:`error`,title:i(`store.actions.noObjectsSelected`),description:i(`store.actions.pleaseSelectObjectsToRemove`),duration:3e3}),Promise.resolve(!1)),[s.store.collections.deleteMembers,r,a.params?.selection?.removeAll,n,c,c?.search,i,o])})}const iE=It.getFixedT(null,Ft),aE={id:`removeFromCollection`,name:iE(`store.actions.removeFromCollection`),description:iE(`store.actions.removeFromCollectionDesc`),confirm:!0,confirmationText:iE(`store.actions.confirmRemoveFromCollection`),component:rE,destructive:!0};var oE=class{params;allActions=[];callbacks={};constructor(e){this.params=e}get actions(){return this.params.selection?.collectionId?this.allActions.filter(e=>e.id!==`addToCollection`&&e.id!==`delete`):this.allActions.filter(e=>e.id!==`removeFromCollection`&&e.id!==`deleteFromCollections`)}registerCallback(e,t){return this.callbacks[e]=t,()=>{delete this.callbacks[e]}}unregisterCallback(e){delete this.callbacks[e]}findAction(e){return this.allActions.find(t=>t.id===e)}async run(e){let t=this.findAction(e);if(!t)throw Error(`Action ${e} not found`);let n={...this.params,action:t},r=this.callbacks[e];if(r)return r(n);throw Error(`No action callback set`)}};const sE=[nE,JT,UT,QT,aE,$T];function cE({children:e,type:r}){let i=Gv(),a=Ye(),{client:o}=Z(),s=Ny(),c=q(()=>{let e=new oE({selection:i,toast:a,client:o,search:s,type:r});return e.allActions=sE,e},[o,s,i,a,r]);return c&&n(RT.Provider,{value:c,children:[t(lE,{}),e]})}function lE(){let e=zT(),n=e.params.selection,r=n.getObjectId(),i=n.isSingleSelection()&&r?[r]:n.getObjectIds();return t(`div`,{style:{display:`none`},children:e.allActions.map(e=>t(e.component,{action:e,objectIds:i,collectionId:n.collectionId},e.id))})}function uE(){let{t:r}=X(),i=Gv(),[a,s]=Y(!1);return i?.hasSelection()?n(e,{children:[t(o,{onClick:()=>s(!0),children:r(`store.actions.startWorkflow`)}),a&&t(dE,{objectIds:i.getObjectIds(),onClose:()=>s(!1)})]}):null}function dE({objectIds:e,onClose:r}){let{t:i}=X(),{client:a}=Z(),s=Ye(),[c,l]=Y(void 0),[u,d]=Y(!1),{data:f,isLoading:p}=Ue(()=>a.store.workflows.rules.list(),[]);return n(ie,{isOpen:!0,onClose:r,size:`lg`,children:[t(se,{children:i(`store.actions.startWorkflowByRule`)}),n(ae,{children:[t(`div`,{className:`pb-2`,children:i(`store.actions.chooseWorkflowRule`)}),p?t(`div`,{className:`flex justify-center py-4`,children:t(Te,{})}):t(`div`,{className:`max-h-[420px] overflow-y-auto border-border border rounded-md`,children:t(ye,{className:`text-start w-full`,options:f??[],value:c,onChange:l,optionLayout:e=>({label:e.name})})})]}),n(oe,{align:`right`,children:[t(o,{variant:`outline`,onClick:r,disabled:u,children:`Cancel`}),t(o,{onClick:async()=>{if(!(!c||u)){d(!0);try{await a.store.workflows.rules.execute(c.id,e),s({title:i(`store.actions.workflowStarted`),status:`success`,duration:3e3}),r()}catch(e){s({title:i(`store.actions.errorStartingWorkflow`),description:e instanceof Error?e.message:void 0,status:`error`,duration:9e3})}finally{d(!1)}}},isDisabled:!c||u,isLoading:u,children:`Start`})]})]})}function fE({type:e,allowMutations:r=!0,allowDelete:i=!0,allowWorkflowRun:a=!1}){let s=Gv(),c=s.size(),l=c>1?`s`:``,u=s?.hasSelection(),d=s?.isSingleSelection();return t(cE,{type:e,children:n(`div`,{className:`flex items-center gap-x-2`,children:[u&&!d&&n(`div`,{className:`flex items-center gap-x-1 shrink-0`,children:[n(`div`,{className:`text-sm nowrap`,children:[c,` document`,l,` selected`]}),t(o,{title:`Clear selection`,variant:`ghost`,onClick:()=>{s?.removeAll()},children:t(ci,{className:`size-4`})})]}),a&&t(uE,{}),t(hE,{selection:s,allowMutations:r,allowDelete:i,children:e=>e.length>0?t(o,{variant:`ghost`,title:`More action`,size:`sm`,children:t(On,{size:16})}):null})]})})}function pE({collectionId:r,allowFolders:i=!0}){let{t:a}=X(),[s,c]=Y([]),[l,u]=Y(!1);return n(e,{children:[t(o,{onClick:()=>u(!0),children:a(`store.upload`)}),t(Hy,{collectionId:r??``,isOpen:l,onClose:()=>{u(!1),c([])},files:s,title:`Upload Files`,onUploadComplete:e=>{e?.success&&c([])},allowFolders:i})]})}function mE(e){return{label:e.name,className:Ze(`flex-1 px-2 py-2 hover:bg-accent nowrap`,e.destructive?`text-destructive`:``)}}function hE({selection:e,children:r,allowMutations:i=!0,allowDelete:a=!0}){let o=zT(),s=e=>{o.run(e.id)},c=_E(o.actions,e,{allowMutations:i,allowDelete:a}),l=r(c);return l?n(le,{hover:!0,children:[t(de,{children:l}),t(ue,{className:`p-0 w-50`,align:`end`,sideOffset:6,children:t(gE,{executeAction:s,actions:c})})]}):null}function gE({executeAction:e,actions:n}){return t(`div`,{className:`rounded-md shadow-md py-2`,children:t(`div`,{className:`px-1 text-sm`,children:t(ye,{options:n,optionLayout:mE,onChange:t=>{e(t)},noCheck:!0})})})}function _E(e,t,n){return t?.hasSelection()?e.filter(e=>e.hideInList?!1:e.id===`delete`||e.id===`deleteFromCollections`?n.allowDelete:e.id===`changeType`||e.id===`addToCollection`||e.id===`removeFromCollection`?n.allowMutations:!0):[nE]}function vE({user:e}){return n(`div`,{className:`flex items-center`,children:[t(`div`,{className:`w-9 h-9`,children:e.picture?t(`img`,{className:`inline-block h-9 w-9 rounded-full`,src:e.picture,alt:e.name}):t(`span`,{className:`inline-flex h-8 w-8 items-center justify-center rounded-full bg-indigo-600`,children:t(`span`,{className:`text-sm font-medium leading-none text-white`,children:e.name.split(` `).map(e=>e[0]).join(``)})})}),n(`div`,{className:`ms-3`,children:[t(`p`,{className:`text-sm font-medium text-gray-700 dark:text-slate-50 group-hover:text-gray-900`,children:e.name??`Deleted User`}),t(`p`,{className:`text-xs font-medium text-gray-500 dark:text-slate-300 group-hover:text-gray-700`,children:e.email??`Deleted User`})]})]})}function yE(e,t,n,r){return n?r===!1?[t]:e.includes(t)?e:[...e,t]:e.filter(e=>e!==t)}function bE({node:e}){return n(`span`,{className:`flex min-w-0 flex-1 items-center justify-between gap-2`,children:[t(`span`,{className:`truncate`,children:e.label}),t(`span`,{className:`text-xs tabular-nums text-muted`,children:e.count})]})}function xE({configuration:e,result:r,isLoading:i,onChange:a}){let{t:s}=X(),c=ot(),l=e.presentation??(e.source===`location`||e.source===`hierarchy`?`tree`:`list`),u=e.source!==`hierarchy`&&e.multi_select,d=r.breadcrumbs??[],f=(e,t)=>{a(yE(r.selected,e,t,u))};return n(`section`,{className:`space-y-2`,"aria-labelledby":`${c}-label`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`h2`,{id:`${c}-label`,className:`text-sm font-semibold`,children:e.label}),r.selected.length>0&&n(o,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,onClick:()=>a([]),"aria-label":`${s(`filter.clearAll`)}: ${e.label}`,children:[t(ci,{className:`size-3.5`}),s(`filter.clearAll`)]})]}),e.source===`hierarchy`&&d.length>0&&t(`nav`,{"aria-label":`${e.label} path`,children:t(`ol`,{className:`flex flex-wrap items-center gap-1 text-sm`,children:d.map((e,r)=>n(`li`,{className:`flex items-center gap-1`,children:[r>0&&t(cn,{"aria-hidden":`true`,className:`size-3.5 text-muted`}),t(o,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,onClick:()=>a([e.id]),"aria-current":r===d.length-1?`page`:void 0,children:e.label})]},e.id))})}),r.selected.length>0&&(e.source===`location`||e.source===`collection`)&&t(`div`,{className:`flex flex-wrap gap-1`,children:r.selected.map(e=>{let a=r.nodes.find(t=>t.id===e)?.label??e;return n(o,{type:`button`,variant:`secondary`,size:`sm`,disabled:i,onClick:()=>f(e,!1),"aria-label":s(`view.removeSelection`,{value:a}),children:[a,t(ci,{"aria-hidden":`true`,className:`size-3.5`})]},e)})}),l===`select`&&u===!1?t(ve,{options:r.nodes,value:r.nodes.find(e=>r.selected.includes(e.id)),onChange:e=>a([e.id]),optionLabel:e=>`${e.label} (${e.count})`,by:`id`,disabled:i,placeholder:e.label,"aria-label":e.label}):l===`select`?t(ve,{multiple:!0,options:r.nodes,value:r.nodes.filter(e=>r.selected.includes(e.id)),onChange:e=>a(e.map(e=>e.id)),optionLabel:e=>`${e.label} (${e.count})`,by:`id`,disabled:i,placeholder:e.label,"aria-label":e.label}):l===`chips`?t(`div`,{className:`flex flex-wrap gap-2`,children:r.nodes.map(e=>n(o,{type:`button`,variant:r.selected.includes(e.id)?`secondary`:`outline`,size:`sm`,disabled:i,onClick:()=>f(e.id,!r.selected.includes(e.id)),children:[e.label,t(`span`,{className:`text-xs tabular-nums text-muted`,children:e.count})]},e.id))}):e.source===`hierarchy`?t(`div`,{className:`space-y-1`,children:r.nodes.map(e=>n(o,{type:`button`,variant:r.selected.includes(e.id)?`secondary`:`ghost`,className:`w-full justify-start`,disabled:i,onClick:()=>a([e.id]),children:[t(bE,{node:e}),e.expandable&&t(cn,{"aria-hidden":`true`,className:`size-4 shrink-0 text-muted`})]},e.id))}):t(`div`,{className:`space-y-1`,children:r.nodes.map((e,a)=>{let o=`${c}-${a}`;return n(`div`,{className:`flex items-center gap-2 rounded-md px-2 py-1.5 hover:bg-muted`,children:[t(m,{id:o,checked:r.selected.includes(e.id),disabled:i,onCheckedChange:t=>f(e.id,t===!0)}),t(`label`,{htmlFor:o,className:`flex min-w-0 flex-1 cursor-pointer text-sm`,children:t(bE,{node:e})})]},e.id)})}),r.nodes.length===0&&t(`p`,{className:`text-sm text-muted`,children:s(`filter.noAvailableFilters`)})]})}const SE=`display`,CE=`sort`,wE=`offset`;function TE(e){if(e===null||e.trim()===``)return;let t=Number(e);return Number.isSafeInteger(t)&&t>=0?t:void 0}function EE(e,t){let n={};for(let r of new Set(e.keys())){if(!r.startsWith(t)||r.length===t.length)continue;let i=e.getAll(r).filter(e=>e!==``);i.length>0&&(n[r.slice(t.length)]=i)}return Object.keys(n).length>0?n:void 0}function DE(e){let t=new URLSearchParams(e.startsWith(`?`)?e.slice(1):e),n=t.get(`q`)?.trim(),r=t.get(SE)?.trim(),i=t.get(CE)?.trim(),a=TE(t.get(wE)),o=EE(t,`t.`),s=EE(t,`n.`);return{...n?{query:n}:{},...o?{key_terms:o}:{},...s?{navigation:s}:{},...r?{display:r}:{},...i?{sort:i}:{},...a?{offset:a}:{}}}function OE(e){for(let t of[...e.keys()])(t===`q`||t===SE||t===CE||t===wE||t.startsWith(`t.`)||t.startsWith(`n.`))&&e.delete(t)}function kE(e,t,n){if(n)for(let[r,i]of Object.entries(n).sort(([e],[t])=>e.localeCompare(t)))for(let n of i)n!==``&&e.append(`${t}${r}`,n)}function AE(e,t=``){let n=new URLSearchParams(t.startsWith(`?`)?t.slice(1):t);OE(n),e.query?.trim()&&n.set(`q`,e.query.trim()),e.display&&n.set(SE,e.display),e.sort&&n.set(CE,e.sort),e.offset&&e.offset>0&&n.set(wE,String(e.offset)),kE(n,`t.`,e.key_terms),kE(n,`n.`,e.navigation);let r=n.toString();return r?`?${r}`:``}function jE(e){let t=Object.fromEntries(Object.entries(e.navigation).filter(([,e])=>e.selected.length>0).map(([e,t])=>[e,t.selected]));return Object.keys(t).length>0?t:void 0}function ME(e,t){let n=new Set(t.definition.search?.key_terms?.map(e=>e.id)??[]),r=e.key_terms?Object.fromEntries(Object.entries(e.key_terms).filter(([e,t])=>n.has(e)&&t.length)):void 0,i=jE(t);return{...e.query?.trim()?{query:e.query.trim()}:{},...r&&Object.keys(r).length>0?{key_terms:r}:{},...i?{navigation:i}:{},...t.display?{display:t.display}:{},...t.sort?{sort:t.sort}:{},...e.offset&&e.offset>0?{offset:e.offset}:{},...e.limit?{limit:e.limit}:{}}}function NE(e,t,n){return t.sort??e.sort??(e.query?.trim()?void 0:n)}function PE(e){if(typeof window>`u`)return;let t=AE(e,window.location.search);window.history.replaceState(window.history.state||{},``,`${window.location.pathname}${t}`)}function FE(e,t){return!t||t===`.`?e:t.split(`.`).reduce((e,t)=>{if(!(!e||typeof e!=`object`||Array.isArray(e)))return e[t]},e)}function IE(e,t){return t===`score`?e.score:t.startsWith(`annotation.`)?FE(e.annotation,t.slice(11)):t.startsWith(`document.`)?FE(e.document,t.slice(9)):FE(e.document,t)}const LE=nt(void 0);function RE(e){if(e!=null&&e!==``)return Array.isArray(e)?e.map(RE).filter(Boolean).join(`, `):typeof e==`object`?JSON.stringify(e):String(e)}function zE(e,t,n){let r=IE(e,t.field),i=t.fallback??``;if(r==null||r===``)return i;if(t.format===`date`){let e=String(r),t=/^\d{4}-\d{2}-\d{2}$/.test(e),a=new Date(e);if(Number.isNaN(a.getTime()))return RE(r)??i;let o={year:`numeric`,month:`numeric`,day:`numeric`,...t?{timeZone:`UTC`}:{}};return n?.formatDate(a,o)??new Intl.DateTimeFormat(void 0,o).format(a)}if(t.format===`number`){let e=typeof r==`number`?r:Number(r);return Number.isFinite(e)?n?.formatNumber(e)??new Intl.NumberFormat().format(e):RE(r)??i}return RE(r)??i}function BE({hit:e,field:n,className:r}){let a=zE(e,n,at(LE));return a?n.format===`badge`||n.format===`content_type`?t(i,{className:r,children:a}):t(`span`,{className:r,children:a}):null}function VE({hit:e,onOpenHit:r,compact:i=!1}){let{t:a}=X();return r?i?t(Re,{description:a(`agent.openDocument`),asChild:!0,children:t(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":a(`agent.openDocument`),onClick:()=>r(e),children:t(kn,{className:`size-4`})})}):n(o,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r(e),children:[t(kn,{className:`size-4`}),a(`agent.openDocument`)]}):null}function HE(e,t){if(t.source!==`property`||!t.field)return;let n=RE(IE(e,t.field));if(n)try{let e=new URL(n,typeof window>`u`?`https://localhost`:window.location.origin);return e.protocol===`http:`||e.protocol===`https:`?e.toString():void 0}catch{return}}function UE({hit:e,media:n,resolveMedia:r,className:i}){let a=n?HE(e,n):void 0,[o,s]=Y(),[c,l]=Y(!1);K(()=>{if(s(void 0),l(!1),a||!n||!r)return;let t=!0;return Promise.resolve(r(e,n)).then(e=>{t&&s(e)}).catch(()=>{t&&l(!0)}),()=>{t=!1}},[a,e,n,r]);let u=c?void 0:a??o,d=n?.fit===`contain`?`object-contain`:`object-cover`;if(u)return t(`img`,{src:u,alt:``,className:`${d} ${i??``}`,onError:()=>l(!0)});let f=n?.source===`type_icon`?`type_icon`:n?.fallback??`type_icon`;return f===`none`?null:t(`div`,{className:`flex items-center justify-center bg-muted ${i??``}`,"aria-hidden":`true`,children:t(f===`placeholder`?Zn:Ln,{className:`size-10 text-muted-foreground`})})}function WE({hit:e}){let n=e.annotation?.why_match??e.annotation?.answer??e.annotation?.excerpt;return n?t(`p`,{className:`text-sm text-info`,children:n}):null}function GE({hit:e,fields:n}){return n?.length?t(`div`,{className:`flex flex-wrap gap-1`,children:n.map(n=>t(BE,{hit:e,field:n},`${n.field}-${n.label??``}`))}):null}function KE({hit:e,fields:r}){let i=at(LE);return r?.length?t(`dl`,{className:`space-y-1 text-sm`,children:r.map(r=>{let a=zE(e,r,i);return a?n(`div`,{className:`flex gap-2`,children:[r.label&&t(`dt`,{className:`shrink-0 text-muted`,children:r.label}),t(`dd`,{className:`min-w-0 truncate`,children:a})]},`${r.field}-${r.label??``}`):null})}):null}function qE({display:e,hits:r,onOpenHit:i,resolveMedia:a}){return t(`div`,{className:`divide-y divide-border rounded-md border`,children:r.map(r=>n(`article`,{className:`flex gap-4 p-4`,children:[e.media&&t(UE,{hit:r,media:e.media,resolveMedia:a,className:`size-20 shrink-0 rounded-md`}),n(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[n(`div`,{children:[t(`h3`,{className:`font-semibold`,children:t(BE,{hit:r,field:e.title})}),e.subtitle&&t(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-sm text-muted`,children:e.subtitle.map(e=>t(BE,{hit:r,field:e},e.field))})]}),e.description&&t(`p`,{className:`line-clamp-3 text-sm text-muted-foreground`,children:t(BE,{hit:r,field:e.description})}),t(GE,{hit:r,fields:e.badges}),t(WE,{hit:r})]}),t(`div`,{className:`shrink-0 self-center`,children:t(VE,{hit:r,onOpenHit:i,compact:!0})})]},r.id))})}function JE({display:e,hits:r,isLoading:i,onOpenHit:a,sortOptions:o,currentSort:s,onSortChange:c}){let{t:l}=X();return t(`div`,{className:`overflow-x-auto rounded-md border`,children:n(je,{className:`w-full`,children:[t(ke,{children:n(`tr`,{children:[e.columns.map(e=>{let n=e.sort_option?o?.find(t=>t.id===e.sort_option):void 0;return!e.sortable||!n?t(Me,{children:e.label??e.field},`${e.field}-${e.label??``}`):t(we,{sortDirection:s===n.id?n.sort[0]?.order===`desc`?`descending`:`ascending`:`none`,onSort:()=>c?.(n.id),disabled:i||!c,sortIndicator:e=>e===`ascending`?t(un,{className:`size-3`,"aria-hidden":`true`}):e===`descending`?t(an,{className:`size-3`,"aria-hidden":`true`}):t(hn,{className:`size-3 text-muted`,"aria-hidden":`true`}),children:e.label??e.field},`${e.field}-${e.label??``}`)}),a&&t(Me,{className:`w-0`,children:t(`span`,{className:`sr-only`,children:l(`agent.openDocument`)})})]})}),t(Oe,{isLoading:i&&r.length===0,columns:e.columns.length+ +!!a,children:r.map(r=>n(`tr`,{children:[e.columns.map(e=>t(`td`,{style:e.width?{width:e.width}:void 0,children:t(BE,{hit:r,field:e})},`${r.id}-${e.field}`)),a&&t(`td`,{className:`w-0 whitespace-nowrap text-end`,children:t(VE,{hit:r,onOpenHit:a,compact:!0})})]},r.id))})]})})}const YE={2:`md:grid-cols-2`,3:`md:grid-cols-2 xl:grid-cols-3`,4:`md:grid-cols-2 xl:grid-cols-4`,5:`md:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-5`,6:`md:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-6`};function XE({hit:e,configuration:r,onOpenHit:i,resolveMedia:a}){return n(s,{className:`flex h-full min-w-0 flex-col overflow-hidden`,children:[r.media&&t(UE,{hit:e,media:r.media,resolveMedia:a,className:`h-40 w-full border-b`}),n(d,{className:`gap-2 p-4`,children:[t(GE,{hit:e,fields:r.badges}),t(f,{className:`truncate text-base`,children:t(BE,{hit:e,field:r.title})}),r.description&&t(l,{className:`line-clamp-3`,children:t(BE,{hit:e,field:r.description})})]}),n(c,{className:`flex-1 p-4 pt-0`,children:[t(KE,{hit:e,fields:r.fields}),t(WE,{hit:e})]}),i&&t(u,{className:`justify-end p-4 pt-0`,children:t(VE,{hit:e,onOpenHit:i})})]})}function ZE({display:e,hits:n,onOpenHit:r,resolveMedia:i}){return t(`div`,{className:`grid grid-cols-1 gap-4 ${YE[e.columns??3]}`,children:n.map(n=>t(XE,{hit:n,configuration:e,onOpenHit:r,resolveMedia:i},n.id))})}function QE({display:e,hits:r,onOpenHit:i,resolveMedia:a}){return t(`div`,{className:`grid grid-cols-1 gap-4 ${YE[e.columns??4]}`,children:r.map(r=>n(s,{className:`overflow-hidden`,children:[t(UE,{hit:r,media:e.media,resolveMedia:a,className:`aspect-square w-full border-b`}),n(c,{className:`space-y-2 p-3`,children:[t(`h3`,{className:`truncate font-semibold`,children:t(BE,{hit:r,field:e.title})}),e.caption&&t(`div`,{className:`space-y-1 text-sm text-muted`,children:e.caption.map(e=>t(`div`,{className:`truncate`,children:t(BE,{hit:r,field:e})},e.field))}),t(VE,{hit:r,onOpenHit:i})]})]},r.id))})}function $E({display:e,hits:r,onOpenHit:a,resolveMedia:o}){let s=new Map;for(let t of r){let n=RE(IE(t,e.group_by))??``;s.set(n,[...s.get(n)??[],t])}return t(`div`,{className:`flex min-w-max gap-4 overflow-x-auto pb-2`,children:(e.columns?.length?[...e.columns].sort((e,t)=>(e.order??0)-(t.order??0)):[...s.keys()].sort().map(e=>({value:e,label:e||`—`}))).map(r=>{let c=s.get(r.value)??[];return n(`section`,{className:`w-80 shrink-0 space-y-3 rounded-lg bg-muted/40 p-3`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`h3`,{className:`font-semibold`,children:r.label}),t(i,{children:c.length})]}),t(`div`,{className:`space-y-3`,children:c.map(n=>t(XE,{hit:n,configuration:e.card,onOpenHit:a,resolveMedia:o},n.id))})]},r.value)})})}function eD(e,n,r,i,a,o,s,c){return e.type===`table`?t(JE,{display:e,hits:n,isLoading:r,onOpenHit:i,sortOptions:o,currentSort:s,onSortChange:c}):e.type===`cards`?t(ZE,{display:e,hits:n,onOpenHit:i,resolveMedia:a}):e.type===`gallery`?t(QE,{display:e,hits:n,onOpenHit:i,resolveMedia:a}):e.type===`board`?t($E,{display:e,hits:n,onOpenHit:i,resolveMedia:a}):t(qE,{display:e,hits:n,onOpenHit:i,resolveMedia:a})}function tD({configuration:e,definition:n,request:r,result:i,isLoading:a,onSortChange:o,onOpenHit:s,resolveMedia:c}){let{t:l}=X(),u=Lt();return!a&&i.hits.length===0?t(`p`,{className:`py-12 text-center text-sm text-muted`,children:l(`filter.noResultsFound`)}):t(LE.Provider,{value:u,children:eD(e,i.hits,a,s,c,n.results?.sort_options,NE(r,i,n.results?.default_sort),o)})}function nD(e,t){return t?`text`:e===`number`?`number`:e===`date`?`date`:`text`}function rD(e){let[t=``,n=``]=(e[0]??``).split(`..`,2);return[t,n]}function iD(e,t){return e||t?[`${e}..${t}`]:[]}function aD(e,t){return t?e.join(`, `):e[0]??``}function oD(e,t){return t?e.split(`,`).map(e=>e.trim()).filter(Boolean):e.trim()?[e.trim()]:[]}function sD({term:e,values:n,isLoading:r,onChange:i}){let a=J(!1),o=J(void 0),[s,c]=Y(()=>aD(n,e.multiple)),l=aD(n,e.multiple);return K(()=>{a.current&&o.current===l||c(l),o.current=void 0},[l]),t(L,{label:e.label,children:t(R,{type:nD(e.type,e.multiple),name:`view-key-term-${e.id}`,autoComplete:`off`,value:s,onFocus:()=>{a.current=!0},onBlur:()=>{a.current=!1;let t=oD(s,e.multiple);c(aD(t,e.multiple))},onChange:t=>{c(t);let n=oD(t,e.multiple);o.current=aD(n,e.multiple),i(n)},placeholder:e.label,disabled:r})})}function cD({configuration:e,query:r,keyTerms:i,isLoading:a,onQueryChange:s,onKeyTermsChange:c,onSubmit:l}){let{t:u}=X(),d=ot(),f=e.key_terms?.filter(e=>e.operator!==`range`)??[],p=e.key_terms?.filter(e=>e.operator===`range`)??[];return n(`form`,{className:`flex flex-col gap-3`,"aria-label":u(`layout.search`),autoComplete:`off`,onSubmit:e=>{e.preventDefault(),l()},children:[n(`div`,{className:`flex items-center gap-2`,children:[t(`label`,{htmlFor:d,className:`sr-only`,children:u(`layout.search`)}),t(R,{id:d,name:`view-query`,autoComplete:`off`,value:r,onChange:s,placeholder:e.placeholder??u(`store.searchPlaceholder`),disabled:a}),n(o,{type:`submit`,disabled:a,className:`shrink-0`,children:[t(Br,{className:`size-4`}),u(a?`store.searching`:`store.search`)]})]}),e.key_terms&&e.key_terms.length>0&&n(`div`,{className:`grid gap-3 lg:grid-cols-2`,children:[f.length>0&&n(`fieldset`,{className:`rounded-md border border-mixer-muted/30 bg-mixer-muted/5 p-3 ${p.length===0?`lg:col-span-2`:``}`,children:[t(`legend`,{className:`px-1 text-xs font-medium text-muted`,children:u(`view.searchFields`)}),t(`div`,{className:`grid gap-3 sm:grid-cols-2 ${p.length===0?`lg:grid-cols-4`:``}`,children:f.map(e=>t(sD,{term:e,values:i[e.id]??[],isLoading:a,onChange:t=>c(e.id,t)},e.id))})]}),p.length>0&&n(`fieldset`,{className:`rounded-md border border-mixer-muted/30 bg-mixer-muted/5 p-3 ${f.length===0?`lg:col-span-2`:``}`,children:[t(`legend`,{className:`px-1 text-xs font-medium text-muted`,children:u(`view.ranges`)}),t(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:p.map(e=>{let[r,o]=rD(i[e.id]??[]),s=e.type===`number`?`number`:e.type===`date`?`date`:`text`;return n(`fieldset`,{className:`min-w-0`,children:[t(`legend`,{className:`mb-1 text-sm font-medium`,children:e.label}),n(`div`,{className:`grid grid-cols-2 gap-2`,children:[t(R,{type:s,name:`view-key-term-${e.id}-from`,autoComplete:`off`,"aria-label":`${e.label}: ${u(`view.from`)}`,value:r,onChange:t=>c(e.id,iD(t.trim(),o)),placeholder:u(`view.from`),disabled:a}),t(R,{type:s,name:`view-key-term-${e.id}-to`,autoComplete:`off`,"aria-label":`${e.label}: ${u(`view.to`)}`,value:o,onChange:t=>c(e.id,iD(r,t.trim())),placeholder:u(`view.to`),disabled:a})]})]},e.id)})})]})]})]})}const lD={id:`default`,label:`Results`,type:`list`,title:{field:`name`},subtitle:[{field:`type.name`,format:`content_type`},{field:`location`,format:`location`}],description:{field:`description`}};function uD(e){return!e||typeof window>`u`?{}:DE(window.location.search)}function dD(e){let t=Object.fromEntries(Object.entries(e).filter(([,e])=>e.length>0));return Object.keys(t).length>0?t:void 0}function fD(e){let{client:n}=Z(),r=G(t=>n.views.execute(e.viewId,t),[n,e.viewId]),i=G(async(e,t)=>{if(t.source!==`content_thumbnail`)return;let r=e.document.content;try{let t=await n.objects.getRenditionSafe(e.id,r?.type,{format:Ci.jpeg,max_hw:512,generate_if_missing:!1,sign_url:!0});if(t?.status===`found`&&t.renditions?.length)return t.renditions[0]}catch{}if(r?.source&&r.type?.startsWith(`image/`))return(await n.files.getDownloadUrl(r.source)).url},[n]);return t(mD,{...e,execute:r,resolveMedia:e.resolveMedia??i})}function pD({execute:e,...n}){return e?t(mD,{...n,execute:e},n.viewId):t(fD,{...n},n.viewId)}function mD({execute:e,renderers:r,onOpenHit:i,resolveMedia:a,syncUrl:s=!0,showHeader:c=!0,className:l}){let{t:u}=X(),d=J(e);d.current=e;let f=J(0),[p,m]=Y(()=>uD(s)),[h,g]=Y(p.query??``),[_,v]=Y(p.key_terms??{}),[y,b]=Y(),[x,S]=Y(!0),[C,w]=Y(),T=G((e,t)=>{let n=++f.current;return m(e),t&&s&&PE(e),S(!0),w(void 0),d.current(e).then(t=>{if(n===f.current){let n=ME(e,t);m(n),s&&PE(n),b(t)}}).catch(e=>{n===f.current&&w(e instanceof Error?e:Error(String(e)))}).finally(()=>{n===f.current&&S(!1)})},[s]),E=G(()=>{let e=uD(s);return g(e.query??``),v(e.key_terms??{}),T(e,!1)},[T,s]);K(()=>(E(),()=>{f.current+=1}),[E]),K(()=>{if(!s||typeof window>`u`)return;let e=()=>void E();return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[E,s]);let D=y?.definition,O=q(()=>[...D?.navigation??[]].sort((e,t)=>(e.order??0)-(t.order??0)),[D?.navigation]),k=D?.results,A=y?.display??p.display??k?.default_display,j=k?.displays.find(e=>e.id===A)??lD,N=y?NE(p,y,k?.default_sort):p.sort,P=e=>{T(e,!0)},F=(e,t)=>{let n=dD({...p.navigation??{},[e.id]:t});P({...p,navigation:n,offset:void 0})},I=()=>{P({...p,query:h.trim()||void 0,key_terms:dD(_),offset:void 0})};if(!y&&x)return t(`div`,{className:`flex h-full min-h-48 items-center justify-center`,children:t(Te,{size:`xl`})});if(!y||!D)return t(`div`,{className:`flex h-full min-h-48 items-center justify-center p-4`,children:t(M,{title:u(`store.searchFailed`),action:()=>void E(),actionLabel:u(`agent.retry`),children:u(`store.searchFailed`)})});let L=D.search?.renderer?r?.search?.[D.search.renderer]??cD:cD,ee=j.renderer?r?.results?.[j.renderer]??tD:tD,R=O.length>0&&D.layout?.navigation_position!==`top`,te=D.layout?.mode===`worklist`,z=p.offset??0,ne=p.limit??j.page_size??20,B=z>0,ie=z+y.hits.length<y.total,ae=O.map(e=>{let n=y.navigation[e.id]??{id:e.id,selected:[],nodes:[]};return t(e.renderer?r?.navigation?.[e.renderer]??xE:xE,{configuration:e,result:n,isLoading:x,onChange:t=>F(e,t)},e.id)});return n(Oa,{className:l,children:[c&&t(Wx,{title:D.name,description:D.description}),n(Oa.Fixed,{heightClass:`h-auto`,className:`space-y-3 border-b p-3`,children:[D.search&&t(L,{configuration:D.search,query:h,keyTerms:_,isLoading:x,onQueryChange:g,onKeyTermsChange:(e,t)=>v(n=>({...n,[e]:t})),onSubmit:I}),O.length>0&&D.layout?.navigation_position===`top`&&t(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:ae})]}),t(Oa.Body,{className:`p-0`,children:n(`div`,{className:R?te?`grid min-h-full lg:grid-cols-[minmax(0,1fr)_18rem]`:`grid min-h-full lg:grid-cols-[18rem_minmax(0,1fr)]`:`min-h-full`,children:[R&&t(`aside`,{className:te?`space-y-5 border-b p-4 lg:order-2 lg:border-s lg:border-b-0`:`space-y-5 border-b p-4 lg:border-e lg:border-b-0`,children:ae}),n(`main`,{className:`min-w-0 space-y-4 p-4 ${te?`lg:order-1`:``}`,children:[C&&t(M,{title:u(`store.searchFailed`),action:()=>void T(p,!1),actionLabel:u(`agent.retry`),children:u(`store.searchFailed`)}),y.search.warnings.length>0&&t(re,{status:`warning`,title:u(`view.warning`),children:t(`ul`,{className:`list-disc space-y-1 ps-4`,children:y.search.warnings.map(e=>t(`li`,{children:e.message},`${e.code}-${e.path??``}`))})}),n(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2 text-sm text-muted`,children:[t(`span`,{children:u(`view.resultsCount`,{count:y.total})}),x&&t(Te,{size:`sm`})]}),n(`div`,{className:`flex flex-wrap items-center gap-3`,children:[k?.allow_display_switch&&k.displays.length>1&&n(`div`,{className:`flex items-center gap-2`,children:[t(`span`,{className:`text-sm text-muted`,children:u(`view.display`)}),t(ve,{options:k.displays,value:j,onChange:e=>P({...p,display:e.id,offset:void 0}),optionLabel:e=>e.label,by:`id`,disabled:x,"aria-label":u(`view.display`),className:`min-w-36`})]}),k?.sort_options&&k.sort_options.length>0&&n(`div`,{className:`flex items-center gap-2`,children:[t(`span`,{className:`text-sm text-muted`,children:u(`view.sort`)}),t(ve,{options:k.sort_options,value:k.sort_options.find(e=>e.id===N),onChange:e=>P({...p,sort:e.id,offset:void 0}),optionLabel:e=>e.label,by:`id`,disabled:x,"aria-label":u(`view.sort`),className:`min-w-44`})]})]})]}),t(ee,{configuration:j,definition:D,request:p,result:y,isLoading:x,onSortChange:e=>P({...p,sort:e,offset:void 0}),onOpenHit:i,resolveMedia:a}),(B||ie)&&n(`nav`,{className:`flex items-center justify-center gap-2`,"aria-label":u(`view.pagination`),children:[n(o,{type:`button`,variant:`outline`,disabled:!B||x,onClick:()=>P({...p,offset:Math.max(0,z-ne)||void 0}),children:[t(sn,{className:`size-4 cn-rtl-flip`}),u(`grounded.previousPage`)]}),n(o,{type:`button`,variant:`outline`,disabled:!ie||x,onClick:()=>P({...p,offset:z+ne}),children:[u(`grounded.nextPage`),t(cn,{className:`size-4 cn-rtl-flip`})]})]})]})]})})]})}export{La as ActivitiesDoc,za as ActivityDoc,UT as AddToCollectionAction,VT as AddToCollectionActionComponent,Ja as AgentApprovalModeSelector,yo as AgentChart,Jh as AgentChatFixtureReplay,Ao as AgentChatPlaybackControls,lt as AgentResourceResolverProvider,rv as AgentRunnerFacetsNav,PS as AllOf,yd as AnimatedThinkingDots,NS as AnyOf,Z_ as ApiKeyAvatar,Jl as AskUserWidget,kS as AudioPanel,bw as BrowseCollectionView,JT as ChangeTypeAction,KT as ChangeTypeActionComponent,Ew as CollectionIcon,uv as CollectionsFacetsNav,Tw as CollectionsTable,Yl as ConfirmationWidget,Qy as ContentDispositionButton,Iw as ContentObjectTypesSearch,Ow as ContentObjectTypesTable,XC as ContentOverview,Cw as CreateCollectionForm,ww as CreateCollectionModal,kw as CreateOrUpdateTypeModal,xE as DefaultViewNavigation,tD as DefaultViewResults,cD as DefaultViewSearch,QT as DeleteObjectsAction,XT as DeleteObjectsActionComponent,$T as DeleteObjectsFromCollectionsAction,IC as DocumentEditingPanel,FC as DocumentEditingWorkspace,Ay as DocumentGridView,Oy as DocumentIcon,Dy as DocumentIconSkeleton,jT as DocumentInput,MT as DocumentPreviewPanel,jy as DocumentSearch,Xy as DocumentSearchProvider,gw as DocumentSearchResults,hw as DocumentSearchResultsWithDropZone,Uv as DocumentSelection,qv as DocumentSelectionProvider,Gy as DocumentTable,Ey as DocumentTableColumn,ky as DocumentTableView,Hy as DocumentUploadModal,hv as DocumentsFacetsNav,ET as EditCollectionView,gv as EnvironmentFacet,nE as ExportPropertiesAction,eE as ExportPropertiesComponent,FT as ExportPropertiesModal,PT as ExportTypes,Ry as FileUploadAction,Wx as GenericPageNavHeader,Zx as GroundedExtractionPanel,Qx as GroundedExtractionView,b_ as Header,AS as ImagePanel,iT as IntakePolicyEditor,yv as InteractionsFacetsNav,Yh as JumpingDots,jf as MESSAGE_STYLES,CS as MagicPdfView,ig as McpConnectionsActionMenu,ng as McpConnectionsButton,tg as McpConnectionsDialog,rg as McpConnectionsInlineList,Nf as MessageItem,Rb as MessagesContainer,Nb as ModernAgentConversation,Gx as NotFoundView,MS as OAuthProviderConnectButton,hT as ObjectSchemaEditor,Aw as ObjectTypeSearch,jw as ObjectTypeSearchContext,bT as ObjectTypeSearchProvider,cE as ObjectsActionContextProvider,Ix as PanelErrorBoundary,g_ as PayloadBuilder,v_ as PayloadBuilderProvider,h_ as PayloadBuilderStore,__ as PayloadContext,Yb as PdfDocumentRenderer,Bb as PdfPageRenderer,Zb as PdfPageSlider,Jb as PdfThumbnailList,xv as ProcessDefinitionsFacetsNav,Cv as ProcessRunsFacetsNav,Dv as PromptsFacetsNav,LC as PropertiesEditorModal,bd as PulsatingCircle,Sd as PulsingMessageLoader,uc as RemoteMcpConnectionButton,aE as RemoveFromCollectionAction,rE as RemoveFromCollectionActionComponent,Rx as RowErrorBoundary,jv as RunsFacetsNav,DC as SaveVersionConfirmModal,My as SearchContext,VS as SecureButton,HS as SecureSidebarItem,OT as SelectCollection,Sw as SelectContentType,yT as SelectContentTypeModal,eb as SelectDocument,kT as SelectDocumentModal,Ox as SelectEnvironment,jx as SelectModel,Mx as SelectTrainingModel,fE as SelectionActions,Hb as SharedPdfProvider,CT as SharedPropsEditor,Gb as SimplePdfPage,ex as SimplePdfViewer,ub as SkillWidgetProvider,Kf as StreamingMessage,Mv as StringFacet,Nv as StringListFacet,wT as SyncMemberHeadsToggle,xT as TableLayoutEditor,Cd as ThinkingBar,Rd as ThinkingMessages,Fv as TypeFacet,iv as TypeRegistry,ov as TypeRegistryProvider,xd as TypedDots,Ex as UniversalDocumentViewer,pE as UploadObjectsButton,vE as UserAvatar,q_ as UserInfo,BS as UserPermissionProvider,IS as UserPermissions,RS as UserPermissionsContext,E_ as VInteractionFacet,A_ as VStringFacet,dv as VTypeFacet,ev as VUserFacet,ho as VegaLiteChart,Nx as VertesiaErrorBoundary,jS as VideoPanel,pD as ViewExperience,DS as WEB_SUPPORTED_AUDIO_FORMATS,TS as WEB_SUPPORTED_IMAGE_FORMATS,ES as WEB_SUPPORTED_VIDEO_FORMATS,wd as WavyThinking,Bx as WidgetErrorBoundary,Lv as WorkflowDefinitionsFacetsNav,Bv as WorkflowExecutionsFacetsNav,Hv as WorkflowRulesFacetsNav,ME as canonicalizeViewState,bo as clampPlaybackCursor,$h as countConnectedActiveGroups,nv as createAgentRunnerFilterHandler,MC as createDocumentChangeSummaryPrompt,jC as createDocumentReconcilePrompt,wo as createPlaybackState,w_ as filterValueToQueryValue,OS as formatDuration,zE as formatViewFieldValue,eg as getConnectedActiveGroupLabels,hf as getContentObjectDownloadName,Co as getNextUserTurnIndex,xo as getPlaybackCursorIndex,So as getPreviousUserTurnIndex,IE as getViewFieldValue,hy as getWorkflowStatusColor,gy as getWorkflowStatusName,GS as invalidateTypeCache,Eo as isAgentChatPlaybackAvailable,Do as isAgentChatPlaybackEnabled,FS as isAnyOf,iy as isCsv,Zh as isGroupDisabled,ay as isImage,Oo as isLocalhostAgentChatPlaybackAvailable,ko as isLocalhostAgentChatPlaybackEnabled,oy as isPdf,cy as isPreviewableAsPdf,_o as isRechartsSpec,go as isVegaLiteSpec,sy as isVideo,DE as parseViewState,ly as printElementToPdf,PE as replaceViewStateInUrl,WS as resolveTypeCached,NE as resolveViewSort,fy as retrieveRendition,AE as serializeViewState,Fx as setErrorBoundaryComponent,T_ as setSearchQueryValue,py as shortId,my as shortenString,ST as stringifyTableLayout,Qh as toggleGroupDisabled,C_ as unwrapFilterOptionValue,jt as useAgentResourceResolver,tv as useAgentRunnerFilterGroups,cv as useCollectionsFilterGroups,lv as useCollectionsFilterHandler,pv as useDocumentFilterGroups,mv as useDocumentFilterHandler,Ny as useDocumentSearch,Iy as useDocumentSearchCount,Gv as useDocumentSelection,Uy as useDocumentUploadHandler,gf as useDownloadFile,R_ as useFetchApiKeyInfo,L_ as useFetchGroupInfo,I_ as useFetchUserInfo,Yx as useGroundedExtractionAvailable,Xx as useGroundedSummary,_v as useInteractionsFilterGroups,vv as useInteractionsFilterHandler,Xh as useMcpConnections,lc as useOAuthPopup,Kv as useOptionalDocumentSelection,y_ as usePayloadBuilder,bv as useProcessDefinitionsFilterGroups,Sv as useProcessRunsFilterGroups,Tv as usePromptsFilterGroups,Ev as usePromptsFilterHandler,kv as useRunsFilterGroups,Av as useRunsFilterHandler,Mw as useSearch,Pw as useSearchCount,Ub as useSharedPdf,Vy as useSmartFileUploadProcessing,sv as useTypeRegistry,zS as useUserPermissions,Py as useWatchDocumentSearchFacets,Fy as useWatchDocumentSearchResult,Nw as useWatchSearchResult,Iv as useWorkflowDefinitionsFilterGroups,Rv as useWorkflowExecutionsFilterGroups,zv as useWorkflowExecutionsFilterHandler,Vv as useWorkflowRulesFilterGroups};
|
|
463
|
+
*`)),D=l?.content?.type?.startsWith(`image/`),O=l?.content?.type===`application/pdf`;return r?n(`div`,{className:`fixed inset-y-0 end-0 w-2/5 dark:bg-slate-900 shadow-xl z-50 flex flex-col transition-transform duration-300 transform ${r?`translate-x-0`:`translate-x-full rtl:-translate-x-full`}`,children:[n(`div`,{className:`flex items-center justify-between px-4 py-3 border-b dark:border-gray-700 bg-gradient-to-r from-indigo-50 to-gray-50 dark:from-gray-800 dark:to-gray-900`,children:[n(`div`,{className:`flex items-center`,children:[t(Hn,{className:`h-5 w-5 text-indigo-600 me-2`}),t(`h2`,{className:`text-lg font-semibold text-gray-800 dark:text-gray-200 truncate`,children:d?x(`store.loadingDocument`):l?.name||x(`store.documentPreview`)})]}),n(`div`,{className:`flex items-center gap-2`,children:[n(o,{variant:`ghost`,size:`sm`,onClick:T,className:`flex items-center gap-1 text-indigo-600 hover:text-indigo-800`,children:[t(_r,{className:`h-4 w-4`}),t(`span`,{children:x(`store.fullView`)})]}),t(o,{variant:`ghost`,size:`sm`,onClick:i,className:`flex items-center text-gray-600 hover:text-gray-800 dark:text-gray-300 dark:hover:text-gray-100`,children:t(mi,{className:`h-5 w-5`})})]})]}),d?t(`div`,{className:`flex-1 flex items-center justify-center`,children:n(`div`,{className:`text-center`,children:[t(De,{size:`lg`,className:`text-indigo-600 dark:text-indigo-400 mb-2`}),t(`p`,{className:`text-gray-600 dark:text-gray-400`,children:x(`store.loadingDocument`)})]})}):n(`div`,{className:`flex-1 flex flex-col h-full`,children:[t(`div`,{className:`border-b`,children:n(`div`,{className:`flex px-4`,children:[t(o,{variant:`unstyled`,className:`py-2 px-4 font-medium border-b-2 ${y===`preview`?`border-indigo-600 text-indigo-700 dark:text-indigo-300`:`border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`}`,onClick:()=>b(`preview`),children:n(`div`,{className:`flex items-center gap-1`,children:[t(or,{className:`h-4 w-4`}),t(`span`,{children:x(`store.preview`)})]})}),t(o,{variant:`unstyled`,className:`py-2 px-4 font-medium border-b-2 ${y===`properties`?`border-indigo-600 text-indigo-700 dark:text-indigo-300`:`border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`}`,onClick:()=>b(`properties`),children:n(`div`,{className:`flex items-center gap-1`,children:[t(rr,{className:`h-4 w-4`}),t(`span`,{children:x(`store.properties`)})]})})]})}),n(`div`,{className:`flex-1 overflow-auto p-4`,children:[y===`preview`&&n(`div`,{className:`h-full`,children:[p?t(`div`,{className:`flex items-center justify-center h-40`,children:t(De,{size:`md`,className:`text-indigo-600 dark:text-indigo-400`})}):h?t(`div`,{className:`shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800`,children:E?t(`div`,{className:`prose prose-sm max-w-none prose-p:my-2 prose-pre:bg-gray-800 prose-pre:my-2 prose-headings:text-indigo-700 dark:prose-invert dark:prose-headings:text-indigo-300`,children:t(wt,{children:h})}):t(`pre`,{className:`text-wrap whitespace-pre-wrap dark:text-gray-200`,children:h})}):null,D&&t(`div`,{className:`mt-4`,children:_?t(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-md p-2 bg-white dark:bg-gray-800`,children:t(`img`,{src:_,alt:l?.name,className:`mx-auto max-h-[70vh] object-contain`})}):t(`div`,{className:`flex items-center justify-center h-40`,children:t(De,{size:`md`,className:`text-indigo-600 dark:text-indigo-400`})})}),O&&n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800`,children:[t(Hn,{className:`h-16 w-16 text-indigo-300 dark:text-indigo-400 mb-4`}),t(`p`,{className:`text-gray-600 dark:text-gray-400 text-center mb-4`,children:x(`store.pdfPreviewFullView`)}),t(o,{onClick:T,className:`bg-indigo-600 hover:bg-indigo-700 text-white`,children:x(`store.openFullDocumentView`)})]}),!D&&!h&&!O&&!p&&n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800`,children:[t(Hn,{className:`h-16 w-16 text-gray-300 dark:text-gray-600 mb-4`}),t(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:x(`store.noPreviewAvailable`)})]})]}),y===`properties`&&l&&n(`div`,{className:`h-full`,children:[l.properties?t(`div`,{className:`shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800`,children:t(St,{value:l.properties})}):n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800`,children:[t(rr,{className:`h-16 w-16 text-gray-300 dark:text-gray-600 mb-4`}),t(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:x(`store.noPropertiesAvailable`)})]}),n(`div`,{className:`mt-4`,children:[t(`h3`,{className:`text-sm font-semibold text-gray-700 dark:text-gray-300 mb-2`,children:x(`store.documentInformation`)}),t(`div`,{className:`shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800`,children:n(`div`,{className:`grid grid-cols-2 gap-y-2 gap-x-4 text-sm`,children:[t(`div`,{className:`text-gray-500 dark:text-gray-400`,children:x(`store.id`)}),t(`div`,{className:`font-medium dark:text-gray-200`,children:l.id}),t(`div`,{className:`text-gray-500 dark:text-gray-400`,children:x(`store.contentType`)}),t(`div`,{className:`font-medium dark:text-gray-200`,children:l.type?.name||x(`store.unknown`)}),t(`div`,{className:`text-gray-500 dark:text-gray-400`,children:x(`store.contentType`)}),t(`div`,{className:`font-medium dark:text-gray-200`,children:l.content?.type||x(`store.na`)}),t(`div`,{className:`text-gray-500`,children:x(`store.size`)}),t(`div`,{className:`font-medium`,children:l.content&&`size`in l.content?wT(l.content.size):x(`store.unknown`)}),t(`div`,{className:`text-gray-500`,children:x(`store.created`)}),t(`div`,{className:`font-medium`,children:l.created_at?new Date(l.created_at).toLocaleString():x(`store.na`)}),t(`div`,{className:`text-gray-500`,children:x(`store.updated`)}),t(`div`,{className:`font-medium`,children:l.updated_at?new Date(l.updated_at).toLocaleString():x(`store.na`)})]})})]})]})]})]}),n(`div`,{className:`flex items-center justify-between p-4 border-t bg-gray-50 dark:bg-gray-800 dark:border-gray-700`,children:[t(`div`,{children:l?.content?.source&&n(o,{onClick:()=>{l?.content?.source&&s.files.getDownloadUrl(l.content.source).then(e=>{window.open(e.url,`_blank`)}).catch(e=>{console.error(`Error getting download URL:`,e),S({title:x(`agent.error`),description:x(`store.failedToDownloadFile`),status:`error`,duration:3e3})})},variant:`outline`,className:`text-indigo-600 border-indigo-300 hover:bg-indigo-50`,children:[t(An,{className:`h-4 w-4 me-2`}),x(`pdf.download`)]})}),n(o,{onClick:T,className:`bg-indigo-600 hover:bg-indigo-700 text-white`,children:[x(`store.openFullDocument`),t(pn,{className:`h-4 w-4 ms-2 cn-rtl-flip`})]})]})]}):null}function wT(e){if(e===0)return`0 Bytes`;let t=1024,n=[`Bytes`,`KB`,`MB`,`GB`,`TB`],r=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/t**r).toFixed(2))} ${n[r]}`}var TT;(function(e){e.CSV=`CSV`,e.JSON=`JSON`})(TT||={});function ET({isExporting:e,isOpen:r,onClose:i,allowExportAll:a=!0}){return n(ie,{onClose:()=>i(void 0),isOpen:r,children:[t(se,{children:`Export Object Properties`}),n(ae,{children:[!e&&t(DT,{onClose:i,allowExportAll:a}),e&&t(OT,{})]})]})}function DT({onClose:e,allowExportAll:r}){let{t:i}=Z(),[a,s]=X(void 0),c=[`Export selected objects`,`Export all objects`],[l,u]=X(r?void 0:c[0]),d=e=>e===c[1];return n(ae,{className:`min-h-[104px] pt-0 flex flex-col gap-y-4`,children:[r&&t(`div`,{className:`h-1/3`,children:t(be,{options:c,value:l,onChange:u,placeholder:i(`store.chooseWhatToExport`),className:`h-full w-full text-sm`,filterBy:`name`,isClearable:!0})}),n(`div`,{className:`h-1/2 flex flex-col gap-y-8 content-between`,children:[t(be,{options:Object.values(TT),value:a,onChange:s,placeholder:i(`store.chooseAFormat`),className:`h-full w-full text-sm`,filterBy:`name`,isClearable:!0}),t(o,{className:`w-full`,isDisabled:!a||!l,onClick:()=>{e(a,d(l))},children:i(`store.actions.exportProperties`)})]})]})}function OT(){let{t:e}=Z();return t(ae,{className:`min-h-[84px] pt-0`,children:n(`div`,{className:`h-full grid flex-col gap-y-2 content-between justify-items-center`,children:[n(`div`,{className:`text-sm flex flex-col gap-x-2`,children:[t(`p`,{children:e(`store.exportInProgress`)}),t(`p`,{className:`pt-2 grid justify-items-center`,children:e(`store.pleaseWait`)})]}),t(De,{size:`lg`})]})})}const kT=ot(void 0);function AT(){let e=lt(kT);if(!e)throw Error(`You cannot use useActionContext outside an ActionProvider`);return e}function jT(e,t){let n=AT();return q(()=>n.registerCallback(e,t),[n,e,t]),n}function MT({action:e,objectIds:n}){let[r,i]=X(!1),a=K(()=>(n.length>0&&i(!0),Promise.resolve(!0)),[n]);return jT(e.id,a),r&&t(me,{children:t(FT,{objectIds:n,isOpen:r,onClose:()=>{i(!1)}})})}const NT=Vt.getFixedT(null,Bt),PT={id:`addToCollection`,name:NT(`store.actions.addToCollection`),description:NT(`store.actions.addToCollectionDesc`),confirm:!1,component:MT};function FT({isOpen:e,onClose:r,objectIds:i}){let{t:a}=Z();return n(ie,{isOpen:e,onClose:r,className:`max-w-lg w-full min-w-0 overflow-hidden`,children:[t(se,{className:`flex flex-col min-w-0 overflow-hidden`,children:a(`store.actions.addToCollectionTitle`)}),t(S,{className:`min-w-0 overflow-hidden`,children:a(`store.actions.addToCollectionBody`)}),t(`div`,{className:`min-w-0 max-w-full overflow-hidden`,children:t(IT,{onClose:r,objectIds:i})})]})}function IT({onClose:e,objectIds:r}){let{t:i}=Z(),a=Xe(),{client:s}=Q(),[c,l]=X(),u=({collectionId:t})=>{!t||!r?.length||s.store.collections.addMembers(t,r).then(()=>{a({title:i(`store.actions.addToCollectionSuccess`),status:`success`,description:i(`store.actions.addToCollectionSuccessDesc`,{count:r.length}),duration:3e3}),e()}).catch(()=>{a({title:i(`store.actions.addToCollectionFailure`),status:`error`,description:i(`store.actions.addToCollectionFailureDesc`),duration:5e3})})},d=[{name:`select`,label:i(`store.actions.selectCollection`),content:n(`div`,{className:`p-4 min-w-0 max-w-full overflow-hidden`,children:[t(ee,{level:5,children:i(`store.actions.chooseExistingCollections`)}),t(ae,{className:`min-w-0 max-w-full overflow-hidden`,children:t(`div`,{className:`mb-4 min-w-0 max-w-full overflow-hidden`,children:t(yT,{onChange:(e,t)=>{typeof e==`string`||e===void 0?l(e):Array.isArray(e)&&e.length>0?l(e[0]):l(void 0)},value:c})})}),t(oe,{children:t(o,{isDisabled:!c,onClick:()=>c&&u({collectionId:c}),children:i(`store.actions.addToCollectionButton`)})})]})},{name:`create`,label:i(`store.actions.createNew`),content:t(`div`,{className:`p-4`,children:t(mw,{onClose:e,onAddToCollection:e=>u({collectionId:e}),redirect:!1})})}];return n(Fe,{defaultValue:`select`,tabs:d,fullWidth:!0,children:[t(Ie,{}),t(Le,{})]})}function LT({action:e,objectIds:r,children:i}){let{t:a}=Z(),{store:o}=Q(),s=Xe(),[c,l]=X(!1),u=K(()=>(l(!0),Promise.resolve(!0)),[]);return jT(e.id,u),n(`div`,{children:[i,t(uT,{isOpen:c,onClose:e=>{l(!1),e!==void 0&&o.runOperation({name:`change_type`,ids:r,params:{typeId:e}}).then(e=>{s({status:`success`,title:a(`store.actions.changeType`),description:`Change the type of ${r.length} objects is ${e.status===`in_progress`?`in progress`:`completed`}`,duration:2e3})}).catch(e=>{s({status:`error`,title:a(`store.actions.errorChangingType`),description:e.message,duration:5e3})})},title:`Change Content Type`,confirmLabel:`Change Type`,children:n(`p`,{className:`pt-2 text-xs`,children:[`Note: This action will raise the `,t(`code`,{children:`change_type`}),` event and will trigger the standard intake workflows which may reset the object properties.`]})})]})}const RT=Vt.getFixedT(null,Bt),zT={id:`changeType`,name:RT(`store.actions.changeContentType`),description:RT(`store.actions.changeContentTypeDesc`),confirm:!1,component:LT};function BT({action:r,callback:i,children:a}){let{t:o}=Z(),[s,c]=X(!1),l=r.confirmationText||`Are you sure you want to ${r.name}?`,u=K(e=>r.confirm?(c(!0),Promise.resolve(!0)):i(e),[r.confirm,i]),d=jT(r.id,u);return n(e,{children:[a,t(b,{onConfirm:()=>{c(!1),i({...d.params,action:r})},onCancel:()=>c(!1),title:o(`store.actions.areYouSure`),content:l,isOpen:s})]})}function VT({action:r,objectIds:i,children:a}){let{t:o}=Z(),s=AT(),c=Xe(),{client:l}=Q(),u=cb(),d=_a(),[f,p]=X(!1),m=i?.length??0,h=s.params?.type?.name??`object`,g=K(()=>(p(!0),Promise.resolve(!0)),[]);jT(r.id,g);let _=K(()=>(p(!1),i?.length?l.store.objects.delete(i).then(e=>{let t=e.deleted>1?`s`:``;if(c({status:`success`,title:`${e.deleted} object${t} deleted`,duration:2e3}),e.failed.length>0&&c({status:`warning`,title:`${e.failed.length} object(s) could not be deleted`,duration:3e3}),u){s.params?.selection?.removeAll();let e=JSON.parse(JSON.stringify(u.facets));i.length===e._value.total&&u.resetFacets(),u.search()}else d(`/objects`)}).catch(e=>{c({status:`error`,title:o(`store.actions.errorDeletingObjects`),description:e.message,duration:5e3})}):(c({status:`error`,title:o(`store.actions.noObjectsSelected`),description:o(`store.actions.pleaseSelectObjectsToDelete`),duration:3e3}),Promise.resolve(!1))),[l.store.objects.delete,s.params?.selection?.removeAll,d,i,u,u?.facets,u?.resetFacets,u?.search,o,c]);return n(e,{children:[a,t(b,{isOpen:f,title:m===1?`Delete ${h}`:`Delete ${h}s`,content:n(`div`,{children:[n(`p`,{children:[`Delete `,m,` selected `,h,m===1?``:`s`,`? `,m===1?`This ${h}`:`These ${h}s`,` will be permanently removed.`]}),t(`p`,{children:t(`span`,{className:`text-destructive`,children:`This action cannot be undone.`})})]}),onConfirm:_,onCancel:()=>p(!1),confirmationValue:`delete`,confirmationLabel:`Type "delete" to confirm`,confirmationPlaceholder:`delete`})]})}const HT=Vt.getFixedT(null,Bt),UT={id:`delete`,name:HT(`store.actions.delete`),description:HT(`store.actions.deleteTheSelectedObjects`),confirm:!0,confirmationText:HT(`store.actions.confirmDeleteAll`),component:VT,destructive:!0},WT={id:`deleteFromCollections`,name:HT(`store.actions.deleteObjects`),description:HT(`store.actions.deleteTheSelectedObjects`),confirm:!0,confirmationText:HT(`store.actions.confirmDeleteSelected`),component:VT,destructive:!0};function GT({action:e,objectIds:n}){let{t:r}=Z(),{store:i}=Q(),a=Xe(),[o,s]=X(!1),[c,l]=X(!1),u=K(()=>(s(!0),Promise.resolve(!0)),[]),d=jT(e.id,u);return t(ET,{isExporting:c,isOpen:o,onClose:(e,t)=>{if(e&&(t||n.length>0)){l(!0);let o=d.params?.search?.query||{},c=d.params?.search?.result?.value?.objects?.map(e=>e.id)||void 0,u=async e=>i.objects.list({query:{parent:e}}).then(e=>e.map(e=>e.id)),f=async()=>t?c?o.vector?c:[]:n.length===0?[]:(await u(n[0])).concat(n):n,p=d.params?.type?.id??o.type,m=d.params?.type?.table_layout??void 0;f().then(c=>{i.objects.exportProperties({objectIds:c,type:e,query:t&&!o.vector?{...o,type:p}:{type:p},table_layout:m}).then(e=>{let i=new Blob([e.data],{type:e.type}),o=window.URL.createObjectURL(i),s=document.createElement(`a`);s.download=e.name,s.href=o,s.click(),a({status:`success`,title:r(`store.actions.exportProperties`),description:t?`Export the properties of all objects completed`:`Export the properties of ${n.length} object${n.length>1?`s`:``} is completed`,duration:2e3})}).catch(e=>{a({status:`error`,title:r(`store.actions.errorExportProperties`),description:e.message,duration:5e3})}).finally(()=>{l(!1),s(!1)})})}else s(!1),a({status:`error`,title:r(`store.actions.errorExportProperties`),description:`No objects selected for export`,duration:5e3})}})}const KT=Vt.getFixedT(null,Bt),qT={id:`exportProperties`,name:KT(`store.actions.exportProperties`),description:KT(`store.actions.exportAllObjectProperties`),confirm:!1,component:GT};function JT({action:e,objectIds:n,collectionId:r}){let{t:i}=Z(),a=AT(),o=Xe(),{client:s}=Q(),c=cb(),l=K(()=>n?.length?r?s.store.collections.deleteMembers(r,n).then(()=>{let e=n.length>1?`s`:``;o({status:`success`,title:`${n.length} object${e} removed from collection`,description:`Objects have been removed from the collection`,duration:2e3}),c&&(a.params?.selection?.removeAll(),c.search())}).catch(e=>{o({status:`error`,title:i(`store.actions.errorRemovingObjects`),description:Ve(e),duration:5e3})}):(o({status:`error`,title:i(`store.actions.noCollectionContext`),description:i(`store.actions.cannotRemoveNoCollection`),duration:3e3}),Promise.resolve(!1)):(o({status:`error`,title:i(`store.actions.noObjectsSelected`),description:i(`store.actions.pleaseSelectObjectsToRemove`),duration:3e3}),Promise.resolve(!1)),[s.store.collections.deleteMembers,r,a.params?.selection?.removeAll,n,c,c?.search,i,o]);return t(BT,{action:e,callback:l})}const YT=Vt.getFixedT(null,Bt),XT={id:`removeFromCollection`,name:YT(`store.actions.removeFromCollection`),description:YT(`store.actions.removeFromCollectionDesc`),confirm:!0,confirmationText:YT(`store.actions.confirmRemoveFromCollection`),component:JT,destructive:!0};var ZT=class{params;allActions=[];callbacks={};constructor(e){this.params=e}get actions(){return this.params.selection?.collectionId?this.allActions.filter(e=>e.id!==`addToCollection`&&e.id!==`delete`):this.allActions.filter(e=>e.id!==`removeFromCollection`&&e.id!==`deleteFromCollections`)}registerCallback(e,t){return this.callbacks[e]=t,()=>{delete this.callbacks[e]}}unregisterCallback(e){delete this.callbacks[e]}findAction(e){return this.allActions.find(t=>t.id===e)}async run(e){let t=this.findAction(e);if(!t)throw Error(`Action ${e} not found`);let n={...this.params,action:t},r=this.callbacks[e];if(r)return r(n);throw Error(`No action callback set`)}};const QT=[qT,zT,PT,UT,XT,WT];function $T({children:e,type:r}){let i=by(),a=Xe(),{client:o}=Q(),s=cb(),c=J(()=>{let e=new ZT({selection:i,toast:a,client:o,search:s,type:r});return e.allActions=QT,e},[o,s,i,a,r]);return c&&n(kT.Provider,{value:c,children:[t(eE,{}),e]})}function eE(){let e=AT(),n=e.params.selection,r=n.getObjectId(),i=n.isSingleSelection()&&r?[r]:n.getObjectIds();return t(`div`,{style:{display:`none`},children:e.allActions.map(e=>t(e.component,{action:e,objectIds:i,collectionId:n.collectionId},e.id))})}function tE(){let{t:r}=Z(),i=by(),[a,s]=X(!1);return i?.hasSelection()?n(e,{children:[t(o,{onClick:()=>s(!0),children:r(`store.actions.startWorkflow`)}),a&&t(nE,{objectIds:i.getObjectIds(),onClose:()=>s(!1)})]}):null}function nE({objectIds:e,onClose:r}){let{t:i}=Z(),{client:a}=Q(),s=Xe(),[c,l]=X(void 0),[u,d]=X(!1),{data:f,isLoading:p}=U(()=>a.store.workflows.rules.list(),[]);return n(ie,{isOpen:!0,onClose:r,size:`lg`,children:[t(se,{children:i(`store.actions.startWorkflowByRule`)}),n(ae,{children:[t(`div`,{className:`pb-2`,children:i(`store.actions.chooseWorkflowRule`)}),p?t(`div`,{className:`flex justify-center py-4`,children:t(De,{})}):t(`div`,{className:`max-h-[420px] overflow-y-auto border-border border rounded-md`,children:t(xe,{className:`text-start w-full`,options:f??[],value:c,onChange:l,optionLayout:e=>({label:e.name})})})]}),n(oe,{align:`right`,children:[t(o,{variant:`outline`,onClick:r,disabled:u,children:`Cancel`}),t(o,{onClick:async()=>{if(!(!c||u)){d(!0);try{await a.store.workflows.rules.execute(c.id,e),s({title:i(`store.actions.workflowStarted`),status:`success`,duration:3e3}),r()}catch(e){s({title:i(`store.actions.errorStartingWorkflow`),description:e instanceof Error?e.message:void 0,status:`error`,duration:9e3})}finally{d(!1)}}},isDisabled:!c||u,isLoading:u,children:`Start`})]})]})}function rE({type:e,allowMutations:r=!0,allowDelete:i=!0,allowWorkflowRun:a=!1}){let s=by(),c=s.size(),l=c>1?`s`:``,u=s?.hasSelection(),d=s?.isSingleSelection();return t($T,{type:e,children:n(`div`,{className:`flex items-center gap-x-2`,children:[u&&!d&&n(`div`,{className:`flex items-center gap-x-1 shrink-0`,children:[n(`div`,{className:`text-sm nowrap`,children:[c,` document`,l,` selected`]}),t(o,{title:`Clear selection`,variant:`ghost`,onClick:()=>{s?.removeAll()},children:t(mi,{className:`size-4`})})]}),a&&t(tE,{}),t(oE,{selection:s,allowMutations:r,allowDelete:i,children:e=>e.length>0?t(o,{variant:`ghost`,title:`More action`,size:`sm`,children:t(Nn,{size:16})}):null})]})})}function iE({collectionId:r,allowFolders:i=!0}){let{t:a}=Z(),[s,c]=X([]),[l,u]=X(!1);return n(e,{children:[t(o,{onClick:()=>u(!0),children:a(`store.upload`)}),t(_b,{collectionId:r??``,isOpen:l,onClose:()=>{u(!1),c([])},files:s,title:`Upload Files`,onUploadComplete:e=>{e?.success&&c([])},allowFolders:i})]})}function aE(e){return{label:e.name,className:Qe(`flex-1 px-2 py-2 hover:bg-accent nowrap`,e.destructive?`text-destructive`:``)}}function oE({selection:e,children:r,allowMutations:i=!0,allowDelete:a=!0}){let o=AT(),s=e=>{o.run(e.id)},c=cE(o.actions,e,{allowMutations:i,allowDelete:a}),l=r(c);return l?n(de,{hover:!0,children:[t(pe,{children:l}),t(fe,{className:`p-0 w-50`,align:`end`,sideOffset:6,children:t(sE,{executeAction:s,actions:c})})]}):null}function sE({executeAction:e,actions:n}){return t(`div`,{className:`rounded-md shadow-md py-2`,children:t(`div`,{className:`px-1 text-sm`,children:t(xe,{options:n,optionLayout:aE,onChange:t=>{e(t)},noCheck:!0})})})}function cE(e,t,n){return t?.hasSelection()?e.filter(e=>e.hideInList?!1:e.id===`delete`||e.id===`deleteFromCollections`?n.allowDelete:e.id===`changeType`||e.id===`addToCollection`||e.id===`removeFromCollection`?n.allowMutations:!0):[qT]}function lE({user:e}){return n(`div`,{className:`flex items-center`,children:[t(`div`,{className:`w-9 h-9`,children:(()=>{if(e.picture)return t(`img`,{className:`inline-block h-9 w-9 rounded-full`,src:e.picture,alt:e.name});{let n=e.name.split(` `).map(e=>e[0]).join(``);return t(`span`,{className:`inline-flex h-8 w-8 items-center justify-center rounded-full bg-indigo-600`,children:t(`span`,{className:`text-sm font-medium leading-none text-white`,children:n})})}})()}),n(`div`,{className:`ms-3`,children:[t(`p`,{className:`text-sm font-medium text-gray-700 dark:text-slate-50 group-hover:text-gray-900`,children:e.name??`Deleted User`}),t(`p`,{className:`text-xs font-medium text-gray-500 dark:text-slate-300 group-hover:text-gray-700`,children:e.email??`Deleted User`})]})]})}const uE=ot(void 0);function dE(){return lt(uE)}function fE(e,t){let n=e.requires_selection??(e.placement===`toolbar`?`none`:`any`);return n===`none`?!0:n===`single`?t.length===1:n===`multiple`?t.length>1:t.length>0}function pE(e){let t=window.URL.createObjectURL(new Blob([e.data],{type:e.type})),n=document.createElement(`a`);n.download=e.name,n.href=t,n.click(),window.setTimeout(()=>window.URL.revokeObjectURL(t),0)}function mE({children:e,definition:r,request:i,result:a,selection:o,contributions:s,client:c,canDelete:l,refresh:u}){let{t:d}=Z(),f=Xe(),[p,m]=X(),[h,g]=X(),[_,v]=X(!1),[y,x]=X(),S=Y(!1),C=r.results?.actions,w=J(()=>({definition:r,request:i,result:a,refresh:u,clearSelection:()=>o?.clear()}),[r,u,i,a,o]),T=J(()=>{let e=(C?.items??[]).filter(e=>{let t=s?.actions?.[e.handler];return t!==void 0&&(t.isAvailable?.(w)??!0)});if(!o||C?.include_defaults===!1||!c)return e;let t=new Set(C?.exclude_defaults??[]),n=[];return t.has(`export`)||n.push({id:`export`,label:d(`store.actions.exportProperties`),handler:`export`,placement:`selection`,requires_selection:`any`}),l&&!t.has(`delete`)&&n.push({id:`delete`,label:d(`store.actions.delete`),handler:`delete`,placement:`selection`,requires_selection:`any`,destructive:!0,confirm:!0}),[...n,...e]},[C,w,l,c,s?.actions,o,d]),E=K(async({action:e,hits:t})=>{if(!S.current){S.current=!0,x(e.id);try{if(e.handler===`delete`){if(!c)return;let e=await c.store.objects.delete(t.map(e=>e.id));f({status:e.failed.length>0?`warning`:`success`,title:d(`view.deletedObjects`,{count:e.deleted})}),o?.clear(),await u();return}let n=s?.actions?.[e.handler];if(!n)return;await n.run({...w,action:e,hits:t})}catch(e){console.error(`View action failed:`,e),f({status:`error`,title:d(`view.actionFailed`),description:d(`view.actionFailedDescription`)})}finally{S.current=!1,x(void 0),m(void 0)}}},[w,c,s?.actions,u,o,d,f]),D=K((e,t)=>{if(!(!fE(e,t)||S.current)){if(e.handler===`export`){g(t);return}if(e.confirm){m({action:e,hits:t});return}E({action:e,hits:t})}},[E]),O=K(e=>{if(!e||!h?.length||!c){g(void 0);return}v(!0),c.store.objects.exportProperties({objectIds:h.map(e=>e.id),type:e}).then(e=>{pE(e),f({status:`success`,title:d(`store.actions.exportProperties`)}),g(void 0)}).catch(e=>{console.error(`View export failed:`,e),f({status:`error`,title:d(`store.actions.errorExportProperties`),description:d(`view.actionFailedDescription`)})}).finally(()=>v(!1))},[c,h,d,f]),k=J(()=>({actions:T,runningActionId:y,run:D}),[T,D,y]);return n(uE.Provider,{value:k,children:[e,t(ET,{isOpen:h!==void 0,isExporting:_,onClose:O,allowExportAll:!1}),t(b,{isOpen:p!==void 0,title:p?.action.label??d(`modal.confirm`),content:d(`view.confirmAction`,{action:p?.action.label??``,count:p?.hits.length??0}),isLoading:y!==void 0,onConfirm:()=>{p&&E(p)},onCancel:()=>m(void 0),confirmationValue:p?.action.handler===`delete`?`delete`:void 0,confirmationLabel:p?.action.handler===`delete`?d(`view.typeDeleteToConfirm`):void 0,confirmationPlaceholder:p?.action.handler===`delete`?`delete`:void 0})]})}function hE({selection:r,page:i,showSelectPage:a=!1}){let{t:s}=Z(),c=dE(),l=ut();if(!c)return null;let u=r?.selectedHits??[],d=r?i.filter(e=>r.isSelected(e.id)).length:0,f=i.length>0&&d===i.length,p=a&&r?.selectAll&&i.length>0,h=c.actions.filter(e=>((e.placement??`selection`)===`toolbar`||(e.placement??`selection`)===`selection`&&u.length>0)&&fE(e,u));return h.length===0&&u.length===0&&!p?null:n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[p&&r&&n(`div`,{className:`flex items-center gap-2`,children:[t(m,{id:l,checked:f?!0:d>0&&`indeterminate`,onCheckedChange:e=>r.togglePage(i,e===!0)}),t(`label`,{htmlFor:l,className:`text-sm text-muted`,children:s(`view.selectPage`)})]}),u.length>0&&n(e,{children:[t(`span`,{className:`text-sm text-muted`,children:s(`view.selectedCount`,{count:u.length})}),t(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":s(`view.clearSelection`),onClick:r?.clear,children:t(mi,{className:`size-4`})})]}),h.map(e=>n(o,{type:`button`,variant:e.destructive?`destructive`:`outline`,size:`sm`,disabled:c.runningActionId!==void 0,onClick:()=>c.run(e,u),children:[e.handler===`export`&&t(An,{className:`size-4`}),e.handler===`delete`&&t(ai,{className:`size-4`}),e.label]},e.id))]})}function gE({hit:e}){let{t:r}=Z(),i=dE(),a=i?.actions.filter(t=>(t.placement??`selection`)===`row`&&fE(t,[e]));return!i||!a?.length?null:n(de,{children:[t(pe,{children:t(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":r(`view.actions`),children:t(Nn,{className:`size-4`})})}),t(fe,{className:`w-52 p-1`,align:`end`,sideOffset:6,children:t(xe,{options:a,optionLayout:e=>({label:e.label,className:e.destructive?`text-destructive`:void 0}),onChange:t=>i.run(t,[e]),noCheck:!0})})]})}function _E(e){return e.dataTransfer.items?Array.from(e.dataTransfer.items).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>e!==null):Array.from(e.dataTransfer.files)}function vE({children:r,definition:i,request:a,result:o,contribution:s,canWrite:c,refresh:l}){let{t:u}=Z(),d=Xe(),f=i.results?.drop,p=f?.handler===`upload`&&c,m=s!==void 0||p,[h,g]=X(!1),[_,v]=X(!1),[y,b]=X([]),x=Y(!1),S=K(async e=>{if(e.length){if(s){if(x.current)return;x.current=!0,v(!0);try{await s.run({configuration:f,files:e,definition:i,request:a,result:o,refresh:l})}catch(e){console.error(`View drop action failed:`,e),d({status:`error`,title:u(`view.dropFailed`),description:u(`view.actionFailedDescription`)})}finally{x.current=!1,v(!1)}return}p&&b(e)}},[p,f,s,i,l,a,o,u,d]);if(!m)return r;let C=f?.params;return n(e,{children:[n(`div`,{className:`relative min-h-48`,onDragEnter:e=>{e.preventDefault(),g(!0)},onDragOver:e=>{e.preventDefault(),g(!0)},onDragLeave:e=>{e.preventDefault(),e.currentTarget.contains(e.relatedTarget)||g(!1)},onDrop:e=>{e.preventDefault(),e.stopPropagation(),g(!1),!e.target.closest(`[data-view-drop-zone]`)&&S(_E(e))},children:[r,_&&t(`div`,{className:`absolute inset-0 z-40 flex items-center justify-center bg-background/80`,children:t(De,{size:`xl`})}),t(`div`,{"data-view-drop-zone":!0,className:`pointer-events-none absolute inset-0 ${h?`z-50`:`-z-10`}`,children:t(yt,{onDrop:e=>void S(e),message:u(`view.dropFiles`),buttonLabel:u(`view.selectFiles`),allowFolders:C?.allow_folders??!0,className:`pointer-events-auto absolute inset-0 bg-background/90 ${h?`flex`:`hidden`}`})})]}),p&&t(_b,{isOpen:y.length>0,onClose:()=>b([]),files:y,collectionId:C?.collection_id,selectedFolder:C?.location,initialTypeId:C?.type_id,defaultProperties:C?.properties,allowFolders:C?.allow_folders??!0,title:u(`view.uploadToView`),onUploadComplete:e=>{e.success&&l()}})]})}function yE(e,t,n,r){return n?r===!1?[t]:e.includes(t)?e:[...e,t]:e.filter(e=>e!==t)}function bE({node:e}){return n(`span`,{className:`flex min-w-0 flex-1 items-center justify-between gap-2`,children:[t(`span`,{className:`truncate`,children:e.label}),t(`span`,{className:`text-xs tabular-nums text-muted`,children:e.count})]})}function xE({configuration:e,result:r,isLoading:i,onChange:a,onQueryChange:s}){let{t:c}=Z(),l=ut(),u=e.presentation??(e.source===`location`||e.source===`hierarchy`?`tree`:`list`),d=e.source!==`hierarchy`&&e.multi_select,f=r.breadcrumbs??[],[p,h]=X(r.query??``);q(()=>{h(r.query??``)},[r.query]);let g=(e,t)=>{a(yE(r.selected,e,t,d))};return n(`section`,{className:`space-y-2`,"aria-labelledby":`${l}-label`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`h2`,{id:`${l}-label`,className:`text-sm font-semibold`,children:e.label}),r.selected.length>0&&n(o,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,onClick:()=>a([]),"aria-label":`${c(`filter.clearAll`)}: ${e.label}`,children:[t(mi,{className:`size-3.5`}),c(`filter.clearAll`)]})]}),e.source===`collection`&&s&&n(`form`,{className:`flex items-center gap-1`,onSubmit:e=>{e.preventDefault(),s?.(p.trim())},children:[t(R,{value:p,onChange:h,disabled:i,placeholder:c(`view.filterNavigation`,{label:e.label}),"aria-label":c(`view.filterNavigation`,{label:e.label})}),t(o,{type:`submit`,variant:`outline`,size:`icon`,disabled:i,"aria-label":c(`view.searchNavigation`,{label:e.label}),children:t(Kr,{"aria-hidden":`true`,className:`size-4`})})]}),f.length>0&&t(`nav`,{"aria-label":`${e.label} path`,children:t(`ol`,{className:`flex flex-wrap items-center gap-1 text-sm`,children:f.map((e,r)=>n(`li`,{className:`flex items-center gap-1`,children:[r>0&&t(pn,{"aria-hidden":`true`,className:`size-3.5 text-muted`}),t(o,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,onClick:()=>a([e.id]),"aria-current":r===f.length-1?`page`:void 0,children:e.label})]},e.id))})}),r.selected.length>0&&f.length===0&&(e.source===`location`||e.source===`collection`)&&t(`div`,{className:`flex flex-wrap gap-1`,children:r.selected.map(e=>{let a=r.nodes.find(t=>t.id===e)?.label??e;return n(o,{type:`button`,variant:`secondary`,size:`sm`,disabled:i,onClick:()=>g(e,!1),"aria-label":c(`view.removeSelection`,{value:a}),children:[a,t(mi,{"aria-hidden":`true`,className:`size-3.5`})]},e)})}),u===`select`&&d===!1?t(be,{options:r.nodes,value:r.nodes.find(e=>r.selected.includes(e.id)),onChange:e=>a([e.id]),optionLabel:e=>`${e.label} (${e.count})`,by:`id`,disabled:i,placeholder:e.label,"aria-label":e.label}):u===`select`?t(be,{multiple:!0,options:r.nodes,value:r.nodes.filter(e=>r.selected.includes(e.id)),onChange:e=>a(e.map(e=>e.id)),optionLabel:e=>`${e.label} (${e.count})`,by:`id`,disabled:i,placeholder:e.label,"aria-label":e.label}):u===`chips`?t(`div`,{className:`flex flex-wrap gap-2`,children:r.nodes.map(e=>n(o,{type:`button`,variant:r.selected.includes(e.id)?`secondary`:`outline`,size:`sm`,disabled:i,onClick:()=>g(e.id,!r.selected.includes(e.id)),children:[e.label,t(`span`,{className:`text-xs tabular-nums text-muted`,children:e.count})]},e.id))}):e.source===`hierarchy`?t(`div`,{className:`space-y-1`,children:r.nodes.map(e=>n(o,{type:`button`,variant:r.selected.includes(e.id)?`secondary`:`ghost`,className:`w-full justify-start`,disabled:i,onClick:()=>a([e.id]),children:[t(bE,{node:e}),e.expandable&&t(pn,{"aria-hidden":`true`,className:`size-4 shrink-0 text-muted`})]},e.id))}):t(`div`,{className:`space-y-1`,children:r.nodes.map((e,a)=>{let o=`${l}-${a}`;return n(`div`,{className:`flex items-center gap-2 rounded-md px-2 py-1.5 hover:bg-muted`,children:[t(m,{id:o,checked:r.selected.includes(e.id),disabled:i,onCheckedChange:t=>g(e.id,t===!0)}),t(`label`,{htmlFor:o,className:`flex min-w-0 flex-1 cursor-pointer text-sm`,children:t(bE,{node:e})})]},e.id)})}),r.nodes.length===0&&t(`p`,{className:`text-sm text-muted`,children:c(`filter.noAvailableFilters`)})]})}const SE=`display`,CE=`sort`,wE=`offset`;function TE(e){if(e===null||e.trim()===``)return;let t=Number(e);return Number.isSafeInteger(t)&&t>=0?t:void 0}function EE(e,t){let n={};for(let r of new Set(e.keys())){if(!r.startsWith(t)||r.length===t.length)continue;let i=e.getAll(r).filter(e=>e!==``);i.length>0&&(n[r.slice(t.length)]=i)}return Object.keys(n).length>0?n:void 0}function DE(e,t){let n={};for(let r of new Set(e.keys())){if(!r.startsWith(t)||r.length===t.length)continue;let i=e.get(r)?.trim();i&&(n[r.slice(t.length)]=i)}return Object.keys(n).length>0?n:void 0}function OE(e){let t=new URLSearchParams(e.startsWith(`?`)?e.slice(1):e),n=t.get(`q`)?.trim(),r=t.get(SE)?.trim(),i=t.get(CE)?.trim(),a=TE(t.get(wE)),o=EE(t,`t.`),s=EE(t,`n.`),c=DE(t,`nq.`);return{...n?{query:n}:{},...o?{key_terms:o}:{},...s?{navigation:s}:{},...c?{navigation_queries:c}:{},...r?{display:r}:{},...i?{sort:i}:{},...a?{offset:a}:{}}}function kE(e){for(let t of[...e.keys()])(t===`q`||t===SE||t===CE||t===wE||t.startsWith(`t.`)||t.startsWith(`nq.`)||t.startsWith(`n.`))&&e.delete(t)}function AE(e,t,n){if(n)for(let[r,i]of Object.entries(n).sort(([e],[t])=>e.localeCompare(t)))for(let n of i)n!==``&&e.append(`${t}${r}`,n)}function jE(e,t,n){if(n)for(let[r,i]of Object.entries(n).sort(([e],[t])=>e.localeCompare(t)))i.trim()&&e.set(`${t}${r}`,i.trim())}function ME(e,t=``){let n=new URLSearchParams(t.startsWith(`?`)?t.slice(1):t);kE(n),e.query?.trim()&&n.set(`q`,e.query.trim()),e.display&&n.set(SE,e.display),e.sort&&n.set(CE,e.sort),e.offset&&e.offset>0&&n.set(wE,String(e.offset)),AE(n,`t.`,e.key_terms),AE(n,`n.`,e.navigation),jE(n,`nq.`,e.navigation_queries);let r=n.toString();return r?`?${r}`:``}function NE(e){let t=Object.fromEntries(Object.entries(e.navigation).filter(([,e])=>e.selected.length>0).map(([e,t])=>[e,t.selected]));return Object.keys(t).length>0?t:void 0}function PE(e){let t={};for(let[n,r]of Object.entries(e.navigation))r.query&&(t[n]=r.query);return Object.keys(t).length>0?t:void 0}function FE(e,t){let n=new Set(t.definition.search?.key_terms?.map(e=>e.id)??[]),r=e.key_terms?Object.fromEntries(Object.entries(e.key_terms).filter(([e,t])=>n.has(e)&&t.length)):void 0,i=NE(t),a=PE(t);return{...e.query?.trim()?{query:e.query.trim()}:{},...r&&Object.keys(r).length>0?{key_terms:r}:{},...i?{navigation:i}:{},...a?{navigation_queries:a}:{},...t.display?{display:t.display}:{},...t.sort?{sort:t.sort}:{},...e.offset&&e.offset>0?{offset:e.offset}:{},...e.limit?{limit:e.limit}:{}}}function IE(e,t,n){return t.sort??e.sort??(e.query?.trim()?void 0:n)}function LE(e){if(typeof window>`u`)return;let t=ME(e,window.location.search);window.history.replaceState(window.history.state||{},``,`${window.location.pathname}${t}`)}function RE(e,t){return!t||t===`.`?e:t.split(`.`).reduce((e,t)=>{if(!(!e||typeof e!=`object`||Array.isArray(e)))return e[t]},e)}function zE(e,t){return t===`score`?e.score:t.startsWith(`annotation.`)?RE(e.annotation,t.slice(11)):t.startsWith(`document.`)?RE(e.document,t.slice(9)):RE(e.document,t)}const BE=ot(void 0);function VE(e){if(e!=null&&e!==``)return Array.isArray(e)?e.map(VE).filter(Boolean).join(`, `):typeof e==`object`?JSON.stringify(e):String(e)}function HE(e,t,n){let r=zE(e,t.field),i=t.fallback??``;if(r==null||r===``)return i;if(t.format===`date`){let e=String(r),t=/^\d{4}-\d{2}-\d{2}$/.test(e),a=new Date(e);if(Number.isNaN(a.getTime()))return VE(r)??i;let o={year:`numeric`,month:`numeric`,day:`numeric`,...t?{timeZone:`UTC`}:{}};return n?.formatDate(a,o)??new Intl.DateTimeFormat(void 0,o).format(a)}if(t.format===`number`){let e=typeof r==`number`?r:Number(r);return Number.isFinite(e)?n?.formatNumber(e)??new Intl.NumberFormat().format(e):VE(r)??i}return VE(r)??i}function UE({hit:e,field:n,className:r}){let a=HE(e,n,lt(BE));return a?n.format===`badge`||n.format===`content_type`?t(i,{className:r,children:a}):t(`span`,{className:r,children:a}):null}function WE({hit:e,onOpenHit:r,compact:i=!1}){let{t:a}=Z();return r?i?t(Be,{description:a(`agent.openDocument`),asChild:!0,children:t(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":a(`agent.openDocument`),onClick:()=>r(e),children:t(Pn,{className:`size-4`})})}):n(o,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r(e),children:[t(Pn,{className:`size-4`}),a(`agent.openDocument`)]}):null}function GE(e,t){if(t.source!==`property`||!t.field)return;let n=VE(zE(e,t.field));if(n)try{let e=new URL(n,typeof window>`u`?`https://localhost`:window.location.origin);return e.protocol===`http:`||e.protocol===`https:`?e.toString():void 0}catch{return}}const KE=new WeakMap,qE=[2e3,4e3,8e3];function JE(e){let t=KE.get(e);if(t)return t;let n=new Map;return KE.set(e,n),n}function YE(e,t,n){let r=JE(e),i=r.get(t);if(i)return i;let a=n().finally(()=>{r.delete(t)});return r.set(t,a),a}function XE({hit:e,media:n,resolveMedia:r,className:i}){let a=n?GE(e,n):void 0,[o,s]=X(),[c,l]=X(!1),u=!a&&n?`${e.id}|${JSON.stringify(n)}`:void 0,d=Y(e),f=Y(n);d.current=e,f.current=n,q(()=>{if(s(void 0),l(!1),!u||!r)return;let e=!0,t,n=i=>{YE(r,u,async()=>r(d.current,f.current)).then(r=>{if(!e)return;if(r){s(r);return}let a=qE[i];a!==void 0&&(t=setTimeout(()=>n(i+1),a))}).catch(()=>{e&&l(!0)})};return n(0),()=>{e=!1,t&&clearTimeout(t)}},[u,r,a]);let p=c?void 0:a??o,m=n?.fit===`contain`?`object-contain`:`object-cover`;if(p)return t(`img`,{src:p,alt:``,className:`${m} ${i??``}`,onError:()=>l(!0)});let h=n?.source===`type_icon`?`type_icon`:n?.fallback??`type_icon`;return h===`none`?null:t(`div`,{className:`flex items-center justify-center bg-muted ${i??``}`,"aria-hidden":`true`,children:t(h===`placeholder`?nr:Hn,{className:`size-10 text-muted-foreground`})})}function ZE({hit:e}){let n=e.annotation?.why_match??e.annotation?.answer??e.annotation?.excerpt;return n?t(`p`,{className:`text-sm text-info`,children:n}):null}function QE({hit:e,page:n,selection:r}){let{t:i}=Z(),a=Y(!1);return r?t(m,{checked:r.isSelected(e.id),"aria-label":i(`view.selectResult`,{name:e.document.name}),onClick:e=>{a.current=e.shiftKey,e.stopPropagation()},onCheckedChange:t=>{r.toggle(e,t===!0,{page:n,range:r.mode===`multiple`&&a.current}),a.current=!1}}):null}function $E({hit:e,fields:n}){return n?.length?t(`div`,{className:`flex flex-wrap gap-1`,children:n.map(n=>t(UE,{hit:e,field:n},`${n.field}-${n.label??``}`))}):null}function eD({hit:e,fields:r}){let i=lt(BE);return r?.length?t(`dl`,{className:`space-y-1 text-sm`,children:r.map(r=>{let a=HE(e,r,i);return a?n(`div`,{className:`flex gap-2`,children:[r.label&&t(`dt`,{className:`shrink-0 text-muted`,children:r.label}),t(`dd`,{className:`min-w-0 truncate`,children:a})]},`${r.field}-${r.label??``}`):null})}):null}function tD({display:e,hits:r,onOpenHit:i,resolveMedia:a,selection:o}){return t(`div`,{className:`divide-y divide-border rounded-md border`,children:r.map(s=>n(`article`,{className:`flex gap-4 p-4 ${o?.isSelected(s.id)?`bg-muted/40`:``}`,children:[o&&t(`div`,{className:`pt-1`,children:t(QE,{hit:s,page:r,selection:o})}),e.media&&t(XE,{hit:s,media:e.media,resolveMedia:a,className:`size-20 shrink-0 rounded-md`}),n(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[n(`div`,{children:[t(`h3`,{className:`font-semibold`,children:t(UE,{hit:s,field:e.title})}),e.subtitle&&t(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-sm text-muted`,children:e.subtitle.map(e=>t(UE,{hit:s,field:e},e.field))})]}),e.description&&t(`p`,{className:`line-clamp-3 text-sm text-muted-foreground`,children:t(UE,{hit:s,field:e.description})}),t($E,{hit:s,fields:e.badges}),t(ZE,{hit:s})]}),n(`div`,{className:`shrink-0 self-center`,children:[t(WE,{hit:s,onOpenHit:i,compact:!0}),t(gE,{hit:s})]})]},s.id))})}function nD({display:e,hits:r,isLoading:i,onOpenHit:a,sortOptions:o,currentSort:s,onSortChange:c,selection:l}){let{t:u}=Z(),d=dE()?.actions.some(e=>e.placement===`row`)??!1,f=l?r.filter(e=>l.isSelected(e.id)).length:0,p=r.length>0&&f===r.length;return t(`div`,{className:`overflow-x-auto rounded-md border`,children:n(Ne,{className:`w-full`,children:[t(je,{children:n(`tr`,{children:[l&&t(Pe,{className:`w-0`,children:l.selectAll&&t(m,{checked:p?!0:f>0&&`indeterminate`,"aria-label":u(`view.selectPage`),onCheckedChange:e=>l.togglePage(r,e===!0)})}),e.columns.map(e=>{let n=e.sort_option?o?.find(t=>t.id===e.sort_option):void 0;if(!e.sortable||!n)return t(Pe,{children:e.label??e.field},`${e.field}-${e.label??``}`);let r=s===n.id?n.sort[0]?.order===`desc`?`descending`:`ascending`:`none`;return t(Ee,{sortDirection:r,onSort:()=>c?.(n.id),disabled:i||!c,sortIndicator:e=>e===`ascending`?t(hn,{className:`size-3`,"aria-hidden":`true`}):e===`descending`?t(un,{className:`size-3`,"aria-hidden":`true`}):t(bn,{className:`size-3 text-muted`,"aria-hidden":`true`}),children:e.label??e.field},`${e.field}-${e.label??``}`)}),(a||d)&&t(Pe,{className:`w-0`,children:t(`span`,{className:`sr-only`,children:u(d?`view.actions`:`agent.openDocument`)})})]})}),t(Ae,{isLoading:i&&r.length===0,columns:e.columns.length+ +!!l+(a||d?1:0),children:r.map(i=>n(`tr`,{className:l?.isSelected(i.id)?`bg-muted/40`:void 0,children:[l&&t(`td`,{className:`w-0`,children:t(QE,{hit:i,page:r,selection:l})}),e.columns.map(e=>t(`td`,{style:e.width?{width:e.width}:void 0,children:t(UE,{hit:i,field:e})},`${i.id}-${e.field}`)),(a||d)&&t(`td`,{className:`w-0 whitespace-nowrap text-end`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[t(WE,{hit:i,onOpenHit:a,compact:!0}),t(gE,{hit:i})]})})]},i.id))})]})})}const rD={2:`md:grid-cols-2`,3:`md:grid-cols-2 xl:grid-cols-3`,4:`md:grid-cols-2 xl:grid-cols-4`,5:`md:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-5`,6:`md:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-6`};function iD({hit:e,configuration:r,onOpenHit:i,resolveMedia:a,selection:o,page:p}){let m=dE()?.actions.some(e=>e.placement===`row`)??!1;return n(s,{className:`relative flex h-full min-w-0 flex-col overflow-hidden ${o?.isSelected(e.id)?`ring-2 ring-primary`:``}`,children:[o&&t(`div`,{className:`absolute start-2 top-2 z-10 rounded bg-background/80 p-1`,children:t(QE,{hit:e,page:p,selection:o})}),r.media&&t(XE,{hit:e,media:r.media,resolveMedia:a,className:`h-40 w-full border-b`}),n(d,{className:`gap-2 p-4`,children:[t($E,{hit:e,fields:r.badges}),t(f,{className:`truncate text-base`,children:t(UE,{hit:e,field:r.title})}),r.description&&t(l,{className:`line-clamp-3`,children:t(UE,{hit:e,field:r.description})})]}),n(c,{className:`flex-1 p-4 pt-0`,children:[t(eD,{hit:e,fields:r.fields}),t(ZE,{hit:e})]}),(i||m)&&n(u,{className:`justify-end p-4 pt-0`,children:[t(WE,{hit:e,onOpenHit:i}),t(gE,{hit:e})]})]})}function aD({display:e,hits:n,onOpenHit:r,resolveMedia:i,selection:a}){return t(`div`,{className:`grid grid-cols-1 gap-4 ${rD[e.columns??3]}`,children:n.map(o=>t(iD,{hit:o,configuration:e,onOpenHit:r,resolveMedia:i,selection:a,page:n},o.id))})}function oD({display:e,hits:r,onOpenHit:i,resolveMedia:a,selection:o}){return t(`div`,{className:`grid grid-cols-1 gap-4 ${rD[e.columns??4]}`,children:r.map(l=>n(s,{className:`relative overflow-hidden ${o?.isSelected(l.id)?`ring-2 ring-primary`:``}`,children:[o&&t(`div`,{className:`absolute start-2 top-2 z-10 rounded bg-background/80 p-1`,children:t(QE,{hit:l,page:r,selection:o})}),t(XE,{hit:l,media:e.media,resolveMedia:a,className:`aspect-square w-full border-b`}),n(c,{className:`space-y-2 p-3`,children:[t(`h3`,{className:`truncate font-semibold`,children:t(UE,{hit:l,field:e.title})}),e.caption&&t(`div`,{className:`space-y-1 text-sm text-muted`,children:e.caption.map(e=>t(`div`,{className:`truncate`,children:t(UE,{hit:l,field:e})},e.field))}),n(`div`,{className:`flex items-center justify-end gap-1`,children:[t(WE,{hit:l,onOpenHit:i}),t(gE,{hit:l})]})]})]},l.id))})}function sD({display:e,hits:r,onOpenHit:a,resolveMedia:o,selection:s}){let c=new Map;for(let t of r){let n=VE(zE(t,e.group_by))??``;c.set(n,[...c.get(n)??[],t])}let l=e.columns?.length?[...e.columns].sort((e,t)=>(e.order??0)-(t.order??0)):[...c.keys()].sort().map(e=>({value:e,label:e||`—`}));return t(`div`,{className:`flex min-w-max gap-4 overflow-x-auto pb-2`,children:l.map(l=>{let u=c.get(l.value)??[];return n(`section`,{className:`w-80 shrink-0 space-y-3 rounded-lg bg-muted/40 p-3`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`h3`,{className:`font-semibold`,children:l.label}),t(i,{children:u.length})]}),t(`div`,{className:`space-y-3`,children:u.map(n=>t(iD,{hit:n,configuration:e.card,onOpenHit:a,resolveMedia:o,selection:s,page:r},n.id))})]},l.value)})})}function cD(e,n,r,i,a,o,s,c,l){return e.type===`table`?t(nD,{display:e,hits:n,isLoading:r,onOpenHit:i,sortOptions:o,currentSort:s,onSortChange:c,selection:l}):e.type===`cards`?t(aD,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):e.type===`gallery`?t(oD,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):e.type===`board`?t(sD,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):t(tD,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l})}function lD({configuration:e,definition:n,request:r,result:i,isLoading:a,onSortChange:o,onOpenHit:s,resolveMedia:c,selection:l}){let{t:u}=Z(),d=Ht();return!a&&i.hits.length===0?t(`p`,{className:`py-12 text-center text-sm text-muted`,children:u(`filter.noResultsFound`)}):t(BE.Provider,{value:d,children:cD(e,i.hits,a,s,c,n.results?.sort_options,IE(r,i,n.results?.default_sort),o,l)})}function uD(e,t){return t?`text`:e===`number`?`number`:e===`date`?`date`:`text`}function dD(e){let[t=``,n=``]=(e[0]??``).split(`..`,2);return[t,n]}function fD(e,t){return e||t?[`${e}..${t}`]:[]}function pD(e,t){return t?e.join(`, `):e[0]??``}function mD(e,t){return t?e.split(`,`).map(e=>e.trim()).filter(Boolean):e.trim()?[e.trim()]:[]}function hD({term:e,values:n,isLoading:r,onChange:i}){let a=Y(!1),o=Y(void 0),[s,c]=X(()=>pD(n,e.multiple)),l=pD(n,e.multiple);return q(()=>{a.current&&o.current===l||c(l),o.current=void 0},[l]),t(L,{label:e.label,children:t(R,{type:uD(e.type,e.multiple),name:`view-key-term-${e.id}`,autoComplete:`off`,value:s,onFocus:()=>{a.current=!0},onBlur:()=>{a.current=!1;let t=mD(s,e.multiple);c(pD(t,e.multiple))},onChange:t=>{c(t);let n=mD(t,e.multiple);o.current=pD(n,e.multiple),i(n)},placeholder:e.label,disabled:r})})}function gD({configuration:e,query:r,keyTerms:i,isLoading:a,onQueryChange:s,onKeyTermsChange:c,onSubmit:l}){let{t:u}=Z(),d=ut(),f=e.key_terms?.filter(e=>e.operator!==`range`)??[],p=e.key_terms?.filter(e=>e.operator===`range`)??[];return n(`form`,{className:`flex flex-col gap-3`,"aria-label":u(`layout.search`),autoComplete:`off`,onSubmit:e=>{e.preventDefault(),l()},children:[n(`div`,{className:`flex items-center gap-2`,children:[t(`label`,{htmlFor:d,className:`sr-only`,children:u(`layout.search`)}),t(R,{id:d,name:`view-query`,autoComplete:`off`,value:r,onChange:s,placeholder:e.placeholder??u(`store.searchPlaceholder`),disabled:a}),n(o,{type:`submit`,disabled:a,className:`shrink-0`,children:[t(Kr,{className:`size-4`}),u(a?`store.searching`:`store.search`)]})]}),e.key_terms&&e.key_terms.length>0&&n(`div`,{className:`grid gap-3 lg:grid-cols-2`,children:[f.length>0&&n(`fieldset`,{className:`rounded-md border border-mixer-muted/30 bg-mixer-muted/5 p-3 ${p.length===0?`lg:col-span-2`:``}`,children:[t(`legend`,{className:`px-1 text-xs font-medium text-muted`,children:u(`view.searchFields`)}),t(`div`,{className:`grid gap-3 sm:grid-cols-2 ${p.length===0?`lg:grid-cols-4`:``}`,children:f.map(e=>t(hD,{term:e,values:i[e.id]??[],isLoading:a,onChange:t=>c(e.id,t)},e.id))})]}),p.length>0&&n(`fieldset`,{className:`rounded-md border border-mixer-muted/30 bg-mixer-muted/5 p-3 ${f.length===0?`lg:col-span-2`:``}`,children:[t(`legend`,{className:`px-1 text-xs font-medium text-muted`,children:u(`view.ranges`)}),t(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:p.map(e=>{let[r,o]=dD(i[e.id]??[]),s=e.type===`number`?`number`:e.type===`date`?`date`:`text`;return n(`fieldset`,{className:`min-w-0`,children:[t(`legend`,{className:`mb-1 text-sm font-medium`,children:e.label}),n(`div`,{className:`grid grid-cols-2 gap-2`,children:[t(R,{type:s,name:`view-key-term-${e.id}-from`,autoComplete:`off`,"aria-label":`${e.label}: ${u(`view.from`)}`,value:r,onChange:t=>c(e.id,fD(t.trim(),o)),placeholder:u(`view.from`),disabled:a}),t(R,{type:s,name:`view-key-term-${e.id}-to`,autoComplete:`off`,"aria-label":`${e.label}: ${u(`view.to`)}`,value:o,onChange:t=>c(e.id,fD(r,t.trim())),placeholder:u(`view.to`),disabled:a})]})]},e.id)})})]})]})]})}const _D={id:`default`,label:`Results`,type:`list`,title:{field:`name`},subtitle:[{field:`type.name`,format:`content_type`},{field:`location`,format:`location`}],description:{field:`description`}};function vD(e){return!e||typeof window>`u`?{}:OE(window.location.search)}function yD(e){let t=Object.fromEntries(Object.entries(e).filter(([,e])=>e.length>0));return Object.keys(t).length>0?t:void 0}function bD(e){let t=Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.trim()]).filter(([,e])=>e.length>0));return Object.keys(t).length>0?t:void 0}function xD(e){let{client:n}=Q(),r=lt(OS),i=K(t=>n.views.execute(e.viewId,t),[n,e.viewId]),a=K(async(e,t)=>{if(t.source!==`content_thumbnail`)return;let r=e.document.content;try{let t=await n.objects.getRenditionSafe(e.id,r?.type,{format:Oi.jpeg,max_hw:512,generate_if_missing:!1,sign_url:!0});if(t?.status===`found`&&t.renditions?.length)return t.renditions[0]}catch{}if(r?.source&&r.type?.startsWith(`image/`))return(await n.files.getDownloadUrl(r.source)).url},[n]),o=e=>r!==void 0&&e.some(e=>r.hasPermission(e));return t(CD,{...e,execute:i,resolveMedia:e.resolveMedia??a,client:n,canDelete:o([Ni.content_delete,Ni.content_admin,Ni.content_superadmin]),canWrite:o([Ni.content_write,Ni.content_admin,Ni.content_superadmin])})}function SD({execute:e,...n}){return e?t(CD,{...n,execute:e},n.viewId):t(xD,{...n},n.viewId)}function CD({execute:e,renderers:r,contributions:i,onOpenHit:a,resolveMedia:s,syncUrl:c=!0,showHeader:l=!0,className:u,client:d,canDelete:f=!1,canWrite:p=!1}){let{t:m}=Z(),h=Y(e);h.current=e;let g=Y(0),[_,v]=X(()=>vD(c)),[y,b]=X(_.query??``),[x,S]=X(_.key_terms??{}),[C,w]=X(),[T,E]=X(!0),[D,O]=X(),[k,A]=X({}),j=Y(void 0),N=K(()=>{j.current=void 0,A({})},[]),P=K((e,t,n=!1)=>{let r=++g.current;return n||N(),v(e),t&&c&&LE(e),E(!0),O(void 0),h.current(e).then(t=>{if(r===g.current){let n=FE(e,t);v(n),c&&LE(n),w(t)}}).catch(e=>{r===g.current&&O(e instanceof Error?e:Error(String(e)))}).finally(()=>{r===g.current&&E(!1)})},[N,c]),F=K(()=>{let e=vD(c);return b(e.query??``),S(e.key_terms??{}),P(e,!1)},[P,c]);q(()=>(F(),()=>{g.current+=1}),[F]),q(()=>{if(!c||typeof window>`u`)return;let e=()=>void F();return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[F,c]);let I=C?.definition,L=J(()=>[...I?.navigation??[]].sort((e,t)=>(e.order??0)-(t.order??0)),[I?.navigation]),ee=I?.results,R=ee?.selection,te=C?.display??_.display??ee?.default_display,z=ee?.displays.find(e=>e.id===te)??_D,ne=C?IE(_,C,ee?.default_sort):_.sort,B=e=>{P(e,!0)},ie=(e,t)=>{let n=yD({..._.navigation??{},[e.id]:t});B({..._,navigation:n,offset:void 0})},ae=(e,t)=>{let n=bD({..._.navigation_queries??{},[e.id]:t});B({..._,navigation_queries:n,offset:void 0})},oe=()=>{B({..._,query:y.trim()||void 0,key_terms:yD(x),offset:void 0})},se=J(()=>{if(!R)return;let e=Object.keys(k);return{mode:R.mode,selectAll:R.mode===`multiple`&&R.select_all===`page`,selectedIds:e,selectedHits:e.map(e=>k[e]).filter(e=>e!==void 0),isSelected:e=>k[e]!==void 0,toggle:(e,t,n)=>{A(r=>{if(!t){let t={...r};return delete t[e.id],t}if(R.mode===`single`)return j.current=e.id,{[e.id]:e};let i={...r,[e.id]:e};if(n?.range&&n.page&&j.current){let t=n.page.findIndex(e=>e.id===j.current),r=n.page.findIndex(t=>t.id===e.id);if(t>=0&&r>=0){let e=Math.min(t,r),a=Math.max(t,r);for(let t of n.page.slice(e,a+1))i[t.id]=t}}return j.current=e.id,i})},togglePage:(e,t)=>{R.mode===`multiple`&&A(n=>{let r={...n};for(let n of e)t?r[n.id]=n:delete r[n.id];return r})},clear:N}},[N,k,R]);if(!C&&T)return t(`div`,{className:`flex h-full min-h-48 items-center justify-center`,children:t(De,{size:`xl`})});if(!C||!I)return t(`div`,{className:`flex h-full min-h-48 items-center justify-center p-4`,children:t(M,{title:m(`store.searchFailed`),action:()=>void F(),actionLabel:m(`agent.retry`),children:m(`store.searchFailed`)})});let ce=I.search?.renderer?r?.search?.[I.search.renderer]??gD:gD,V=z.renderer?r?.results?.[z.renderer]??lD:lD,le=L.length>0&&I.layout?.navigation_position!==`top`,ue=I.layout?.mode===`worklist`,de=_.offset??0,fe=_.limit??z.page_size??20,pe=de>0,me=de+C.hits.length<C.total,he=L.map(e=>{let n=C.navigation[e.id]??{id:e.id,selected:[],nodes:[]},i=e.renderer?r?.navigation?.[e.renderer]??xE:xE;return t(i,{configuration:e,result:n,isLoading:T,onChange:t=>ie(e,t),onQueryChange:e.source===`collection`?t=>ae(e,t):void 0},e.id)}),ge=()=>P(_,!1,!0),_e=n(Ca,{className:u,children:[l&&t(Nx,{title:I.name,description:I.description}),n(Ca.Fixed,{heightClass:`h-auto`,className:`space-y-3 border-b p-3`,children:[I.search&&t(ce,{configuration:I.search,query:y,keyTerms:x,isLoading:T,onQueryChange:b,onKeyTermsChange:(e,t)=>S(n=>({...n,[e]:t})),onSubmit:oe}),L.length>0&&I.layout?.navigation_position===`top`&&t(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:he})]}),t(Ca.Body,{className:`p-0`,children:n(`div`,{className:le?ue?`grid min-h-full lg:grid-cols-[minmax(0,1fr)_18rem]`:`grid min-h-full lg:grid-cols-[18rem_minmax(0,1fr)]`:`min-h-full`,children:[le&&t(`aside`,{className:ue?`space-y-5 border-b p-4 lg:order-2 lg:border-s lg:border-b-0`:`space-y-5 border-b p-4 lg:border-e lg:border-b-0`,children:he}),n(`main`,{className:`min-w-0 space-y-4 p-4 ${ue?`lg:order-1`:``}`,children:[D&&t(M,{title:m(`store.searchFailed`),action:()=>void P(_,!1),actionLabel:m(`agent.retry`),children:m(`store.searchFailed`)}),C.search.warnings.length>0&&t(re,{status:`warning`,title:m(`view.warning`),children:t(`ul`,{className:`list-disc space-y-1 ps-4`,children:C.search.warnings.map(e=>t(`li`,{children:e.message},`${e.code}-${e.path??``}`))})}),n(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2 text-sm text-muted`,children:[t(`span`,{children:m(`view.resultsCount`,{count:C.total})}),T&&t(De,{size:`sm`})]}),n(`div`,{className:`flex flex-wrap items-center gap-3`,children:[t(hE,{selection:se,page:C.hits,showSelectPage:z.type!==`table`}),ee?.allow_display_switch&&ee.displays.length>1&&n(`div`,{className:`flex items-center gap-2`,children:[t(`span`,{className:`text-sm text-muted`,children:m(`view.display`)}),t(be,{options:ee.displays,value:z,onChange:e=>void P({..._,display:e.id,offset:void 0},!0,!0),optionLabel:e=>e.label,by:`id`,disabled:T,"aria-label":m(`view.display`),className:`min-w-36`})]}),ee?.sort_options&&ee.sort_options.length>0&&n(`div`,{className:`flex items-center gap-2`,children:[t(`span`,{className:`text-sm text-muted`,children:m(`view.sort`)}),t(be,{options:ee.sort_options,value:ee.sort_options.find(e=>e.id===ne),onChange:e=>void P({..._,sort:e.id,offset:void 0},!0,!0),optionLabel:e=>e.label,by:`id`,disabled:T,"aria-label":m(`view.sort`),className:`min-w-44`})]})]})]}),t(vE,{definition:I,request:_,result:C,contribution:i?.drop,canWrite:p,refresh:ge,children:t(V,{configuration:z,definition:I,request:_,result:C,isLoading:T,onSortChange:e=>void P({..._,sort:e,offset:void 0},!0,!0),onOpenHit:a,resolveMedia:s,selection:se})}),(pe||me)&&n(`nav`,{className:`flex items-center justify-center gap-2`,"aria-label":m(`view.pagination`),children:[n(o,{type:`button`,variant:`outline`,disabled:!pe||T,onClick:()=>void P({..._,offset:Math.max(0,de-fe)||void 0},!0,!0),children:[t(fn,{className:`size-4 cn-rtl-flip`}),m(`grounded.previousPage`)]}),n(o,{type:`button`,variant:`outline`,disabled:!me||T,onClick:()=>void P({..._,offset:de+fe},!0,!0),children:[m(`grounded.nextPage`),t(pn,{className:`size-4 cn-rtl-flip`})]})]})]})]})})]});return t(mE,{definition:I,request:_,result:C,selection:se,contributions:i,client:d,canDelete:f,refresh:ge,children:_e})}Jh(),tg(),rg(),Ag();export{Ma as ActivitiesDoc,Pa as ActivityDoc,PT as AddToCollectionAction,MT as AddToCollectionActionComponent,Ua as AgentApprovalModeSelector,_o as AgentChart,mh as AgentChatFixtureReplay,Oo as AgentChatPlaybackControls,pt as AgentResourceResolverProvider,xv as AgentRunnerFacetsNav,wS as AllOf,Lu as AnimatedThinkingDots,CS as AnyOf,mv as ApiKeyAvatar,dl as AskUserWidget,yS as AudioPanel,dw as BrowseCollectionView,zT as ChangeTypeAction,LT as ChangeTypeActionComponent,_w as CollectionIcon,kv as CollectionsFacetsNav,gw as CollectionsTable,fl as ConfirmationWidget,Db as ContentDispositionButton,Dw as ContentObjectTypesSearch,yw as ContentObjectTypesTable,VC as ContentOverview,mw as CreateCollectionForm,hw as CreateCollectionModal,bw as CreateOrUpdateTypeModal,xE as DefaultViewNavigation,lD as DefaultViewResults,gD as DefaultViewSearch,UT as DeleteObjectsAction,VT as DeleteObjectsActionComponent,WT as DeleteObjectsFromCollectionsAction,EC as DocumentEditingPanel,TC as DocumentEditingWorkspace,ab as DocumentGridView,rb as DocumentIcon,nb as DocumentIconSkeleton,ST as DocumentInput,CT as DocumentPreviewPanel,ob as DocumentSearch,Tb as DocumentSearchProvider,sw as DocumentSearchResults,ow as DocumentSearchResultsWithDropZone,vy as DocumentSelection,Sy as DocumentSelectionProvider,bb as DocumentTable,tb as DocumentTableColumn,ib as DocumentTableView,_b as DocumentUploadModal,zv as DocumentsFacetsNav,_T as EditCollectionView,Bv as EnvironmentFacet,qT as ExportPropertiesAction,GT as ExportPropertiesComponent,ET as ExportPropertiesModal,TT as ExportTypes,pb as FileUploadAction,Nx as GenericPageNavHeader,zx as GroundedExtractionPanel,Bx as GroundedExtractionView,I_ as Header,bS as ImagePanel,Yw as IntakePolicyEditor,Wv as InteractionsFacetsNav,hh as JumpingDots,Xd as MESSAGE_STYLES,pS as MagicPdfView,wh as McpConnectionsActionMenu,Sh as McpConnectionsButton,xh as McpConnectionsDialog,Ch as McpConnectionsInlineList,Qd as MessageItem,hx as MessagesContainer,ux as ModernAgentConversation,Px as NotFoundView,SS as OAuthProviderConnectButton,oT as ObjectSchemaEditor,xw as ObjectTypeSearch,Sw as ObjectTypeSearchContext,dT as ObjectTypeSearchProvider,$T as ObjectsActionContextProvider,Tx as PanelErrorBoundary,M_ as PayloadBuilder,P_ as PayloadBuilderProvider,j_ as PayloadBuilderStore,N_ as PayloadContext,Gh as PdfDocumentRenderer,Rh as PdfPageRenderer,Yh as PdfPageSlider,Wh as PdfThumbnailList,Kv as ProcessDefinitionsFacetsNav,Jv as ProcessRunsFacetsNav,$v as PromptsFacetsNav,DC as PropertiesEditorModal,Ru as PulsatingCircle,Bu as PulsingMessageLoader,ys as RemoteMcpConnectionButton,XT as RemoveFromCollectionAction,JT as RemoveFromCollectionActionComponent,Dx as RowErrorBoundary,ay as RunsFacetsNav,_C as SaveVersionConfirmModal,sb as SearchContext,jS as SecureButton,MS as SecureSidebarItem,yT as SelectCollection,pw as SelectContentType,uT as SelectContentTypeModal,kb as SelectDocument,bT as SelectDocumentModal,_x as SelectEnvironment,bx as SelectModel,xx as SelectTrainingModel,rE as SelectionActions,zh as SharedPdfProvider,mT as SharedPropsEditor,Vh as SimplePdfPage,ng as SimplePdfViewer,zb as SkillWidgetProvider,ff as StreamingMessage,oy as StringFacet,sy as StringListFacet,hT as SyncMemberHeadsToggle,fT as TableLayoutEditor,Vu as ThinkingBar,nd as ThinkingMessages,ly as TypeFacet,Sv as TypeRegistry,wv as TypeRegistryProvider,zu as TypedDots,kg as UniversalDocumentViewer,iE as UploadObjectsButton,lE as UserAvatar,uv as UserInfo,AS as UserPermissionProvider,ES as UserPermissions,OS as UserPermissionsContext,U_ as VInteractionFacet,q_ as VStringFacet,Av as VTypeFacet,_v as VUserFacet,po as VegaLiteChart,Sx as VertesiaErrorBoundary,xS as VideoPanel,mE as ViewActionsProvider,hE as ViewActionsToolbar,SD as ViewExperience,gE as ViewRowActions,_S as WEB_SUPPORTED_AUDIO_FORMATS,hS as WEB_SUPPORTED_IMAGE_FORMATS,gS as WEB_SUPPORTED_VIDEO_FORMATS,Hu as WavyThinking,kx as WidgetErrorBoundary,dy as WorkflowDefinitionsFacetsNav,hy as WorkflowExecutionsFacetsNav,_y as WorkflowRulesFacetsNav,FE as canonicalizeViewState,vo as clampPlaybackCursor,yh as countConnectedActiveGroups,bv as createAgentRunnerFilterHandler,SC as createDocumentChangeSummaryPrompt,xC as createDocumentReconcilePrompt,So as createPlaybackState,H_ as createSearchQueryKeyGuard,B_ as filterValueToQueryValue,vS as formatDuration,HE as formatViewFieldValue,bh as getConnectedActiveGroupLabels,Pd as getContentObjectDownloadName,xo as getNextUserTurnIndex,yo as getPlaybackCursorIndex,bo as getPreviousUserTurnIndex,zE as getViewFieldValue,Wy as getWorkflowStatusColor,Gy as getWorkflowStatusName,FS as invalidateTypeCache,wo as isAgentChatPlaybackAvailable,To as isAgentChatPlaybackEnabled,TS as isAnyOf,Ny as isCsv,_h as isGroupDisabled,Py as isImage,Eo as isLocalhostAgentChatPlaybackAvailable,Do as isLocalhostAgentChatPlaybackEnabled,Fy as isPdf,Ly as isPreviewableAsPdf,ho as isRechartsSpec,mo as isVegaLiteSpec,Iy as isVideo,OE as parseViewState,Ry as printElementToPdf,LE as replaceViewStateInUrl,PS as resolveTypeCached,IE as resolveViewSort,Vy as retrieveRendition,ME as serializeViewState,wx as setErrorBoundaryComponent,V_ as setSearchQueryValue,Hy as shortId,Uy as shortenString,pT as stringifyTableLayout,vh as toggleGroupDisabled,z_ as unwrapFilterOptionValue,It as useAgentResourceResolver,yv as useAgentRunnerFilterGroups,Dv as useCollectionsFilterGroups,Ov as useCollectionsFilterHandler,Lv as useDocumentFilterGroups,Rv as useDocumentFilterHandler,cb as useDocumentSearch,db as useDocumentSearchCount,by as useDocumentSelection,vb as useDocumentUploadHandler,Fd as useDownloadFile,tv as useFetchApiKeyInfo,ev as useFetchGroupInfo,$_ as useFetchUserInfo,Lx as useGroundedExtractionAvailable,Rx as useGroundedSummary,Hv as useInteractionsFilterGroups,Uv as useInteractionsFilterHandler,gh as useMcpConnections,vs as useOAuthPopup,xy as useOptionalDocumentSelection,F_ as usePayloadBuilder,Gv as useProcessDefinitionsFilterGroups,qv as useProcessRunsFilterGroups,Zv as usePromptsFilterGroups,Qv as usePromptsFilterHandler,ry as useRunsFilterGroups,iy as useRunsFilterHandler,Cw as useSearch,Tw as useSearchCount,Bh as useSharedPdf,gb as useSmartFileUploadProcessing,Tv as useTypeRegistry,kS as useUserPermissions,dE as useViewActions,lb as useWatchDocumentSearchFacets,ub as useWatchDocumentSearchResult,ww as useWatchSearchResult,uy as useWorkflowDefinitionsFilterGroups,py as useWorkflowExecutionsFilterGroups,my as useWorkflowExecutionsFilterHandler,gy as useWorkflowRulesFilterGroups};
|
|
466
464
|
//# sourceMappingURL=vertesia-ui-features.js.map
|