From 62bb830338adaf14f1acde10758f5f0027294f0d Mon Sep 17 00:00:00 2001 From: aether <144865106+aether-png@users.noreply.github.com> Date: Tue, 14 Apr 2026 13:16:58 +0530 Subject: [PATCH 01/44] refactor: convert InvokeFrom if/elif to match/case (#35143) --- .../apps/workflow/generate_task_pipeline.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/api/core/app/apps/workflow/generate_task_pipeline.py b/api/core/app/apps/workflow/generate_task_pipeline.py index f1b8b08eaa..96387133b1 100644 --- a/api/core/app/apps/workflow/generate_task_pipeline.py +++ b/api/core/app/apps/workflow/generate_task_pipeline.py @@ -682,15 +682,16 @@ class WorkflowAppGenerateTaskPipeline(GraphRuntimeStateSupport): def _save_workflow_app_log(self, *, session: Session, workflow_run_id: str | None): invoke_from = self._application_generate_entity.invoke_from - if invoke_from == InvokeFrom.SERVICE_API: - created_from = WorkflowAppLogCreatedFrom.SERVICE_API - elif invoke_from == InvokeFrom.EXPLORE: - created_from = WorkflowAppLogCreatedFrom.INSTALLED_APP - elif invoke_from == InvokeFrom.WEB_APP: - created_from = WorkflowAppLogCreatedFrom.WEB_APP - else: - # not save log for debugging - return + match invoke_from: + case InvokeFrom.SERVICE_API: + created_from = WorkflowAppLogCreatedFrom.SERVICE_API + case InvokeFrom.EXPLORE: + created_from = WorkflowAppLogCreatedFrom.INSTALLED_APP + case InvokeFrom.WEB_APP: + created_from = WorkflowAppLogCreatedFrom.WEB_APP + case InvokeFrom.DEBUGGER | InvokeFrom.TRIGGER | InvokeFrom.PUBLISHED_PIPELINE | InvokeFrom.VALIDATION: + # not save log for debugging + return if not workflow_run_id: return From 173e0d6f35f37eaad58e7d9beeb6ce571dfd1b4b Mon Sep 17 00:00:00 2001 From: bohdansolovie <153934212+bohdansolovie@users.noreply.github.com> Date: Tue, 14 Apr 2026 03:56:07 -0400 Subject: [PATCH 02/44] test: migrate clean_dataset integration tests to SQLAlchemy 2.0 APIs (#35146) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../tasks/test_clean_dataset_task.py | 147 ++++++++++++------ 1 file changed, 98 insertions(+), 49 deletions(-) diff --git a/api/tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py b/api/tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py index 1dd37fbc92..32bc2fc0bd 100644 --- a/api/tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py +++ b/api/tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py @@ -16,6 +16,7 @@ from unittest.mock import MagicMock, patch import pytest from faker import Faker +from sqlalchemy import delete, select from sqlalchemy.orm import Session from core.rag.index_processor.constant.index_type import IndexStructureType, IndexTechniqueType @@ -52,18 +53,18 @@ class TestCleanDatasetTask: from extensions.ext_redis import redis_client # Clear all test data using the provided session fixture - db_session_with_containers.query(DatasetMetadataBinding).delete() - db_session_with_containers.query(DatasetMetadata).delete() - db_session_with_containers.query(AppDatasetJoin).delete() - db_session_with_containers.query(DatasetQuery).delete() - db_session_with_containers.query(DatasetProcessRule).delete() - db_session_with_containers.query(DocumentSegment).delete() - db_session_with_containers.query(Document).delete() - db_session_with_containers.query(Dataset).delete() - db_session_with_containers.query(UploadFile).delete() - db_session_with_containers.query(TenantAccountJoin).delete() - db_session_with_containers.query(Tenant).delete() - db_session_with_containers.query(Account).delete() + db_session_with_containers.execute(delete(DatasetMetadataBinding)) + db_session_with_containers.execute(delete(DatasetMetadata)) + db_session_with_containers.execute(delete(AppDatasetJoin)) + db_session_with_containers.execute(delete(DatasetQuery)) + db_session_with_containers.execute(delete(DatasetProcessRule)) + db_session_with_containers.execute(delete(DocumentSegment)) + db_session_with_containers.execute(delete(Document)) + db_session_with_containers.execute(delete(Dataset)) + db_session_with_containers.execute(delete(UploadFile)) + db_session_with_containers.execute(delete(TenantAccountJoin)) + db_session_with_containers.execute(delete(Tenant)) + db_session_with_containers.execute(delete(Account)) db_session_with_containers.commit() # Clear Redis cache @@ -302,28 +303,40 @@ class TestCleanDatasetTask: # Verify results # Check that dataset-related data was cleaned up - documents = db_session_with_containers.query(Document).filter_by(dataset_id=dataset.id).all() + documents = db_session_with_containers.scalars(select(Document).where(Document.dataset_id == dataset.id)).all() assert len(documents) == 0 - segments = db_session_with_containers.query(DocumentSegment).filter_by(dataset_id=dataset.id).all() + segments = db_session_with_containers.scalars( + select(DocumentSegment).where(DocumentSegment.dataset_id == dataset.id) + ).all() assert len(segments) == 0 # Check that metadata and bindings were cleaned up - metadata = db_session_with_containers.query(DatasetMetadata).filter_by(dataset_id=dataset.id).all() + metadata = db_session_with_containers.scalars( + select(DatasetMetadata).where(DatasetMetadata.dataset_id == dataset.id) + ).all() assert len(metadata) == 0 - bindings = db_session_with_containers.query(DatasetMetadataBinding).filter_by(dataset_id=dataset.id).all() + bindings = db_session_with_containers.scalars( + select(DatasetMetadataBinding).where(DatasetMetadataBinding.dataset_id == dataset.id) + ).all() assert len(bindings) == 0 # Check that process rules and queries were cleaned up - process_rules = db_session_with_containers.query(DatasetProcessRule).filter_by(dataset_id=dataset.id).all() + process_rules = db_session_with_containers.scalars( + select(DatasetProcessRule).where(DatasetProcessRule.dataset_id == dataset.id) + ).all() assert len(process_rules) == 0 - queries = db_session_with_containers.query(DatasetQuery).filter_by(dataset_id=dataset.id).all() + queries = db_session_with_containers.scalars( + select(DatasetQuery).where(DatasetQuery.dataset_id == dataset.id) + ).all() assert len(queries) == 0 # Check that app dataset joins were cleaned up - app_joins = db_session_with_containers.query(AppDatasetJoin).filter_by(dataset_id=dataset.id).all() + app_joins = db_session_with_containers.scalars( + select(AppDatasetJoin).where(AppDatasetJoin.dataset_id == dataset.id) + ).all() assert len(app_joins) == 0 # Verify index processor was called @@ -414,24 +427,32 @@ class TestCleanDatasetTask: # Verify results # Check that all documents were deleted - remaining_documents = db_session_with_containers.query(Document).filter_by(dataset_id=dataset.id).all() + remaining_documents = db_session_with_containers.scalars( + select(Document).where(Document.dataset_id == dataset.id) + ).all() assert len(remaining_documents) == 0 # Check that all segments were deleted - remaining_segments = db_session_with_containers.query(DocumentSegment).filter_by(dataset_id=dataset.id).all() + remaining_segments = db_session_with_containers.scalars( + select(DocumentSegment).where(DocumentSegment.dataset_id == dataset.id) + ).all() assert len(remaining_segments) == 0 # Check that all upload files were deleted - remaining_files = db_session_with_containers.query(UploadFile).where(UploadFile.id.in_(upload_file_ids)).all() + remaining_files = db_session_with_containers.scalars( + select(UploadFile).where(UploadFile.id.in_(upload_file_ids)) + ).all() assert len(remaining_files) == 0 # Check that metadata and bindings were cleaned up - remaining_metadata = db_session_with_containers.query(DatasetMetadata).filter_by(dataset_id=dataset.id).all() + remaining_metadata = db_session_with_containers.scalars( + select(DatasetMetadata).where(DatasetMetadata.dataset_id == dataset.id) + ).all() assert len(remaining_metadata) == 0 - remaining_bindings = ( - db_session_with_containers.query(DatasetMetadataBinding).filter_by(dataset_id=dataset.id).all() - ) + remaining_bindings = db_session_with_containers.scalars( + select(DatasetMetadataBinding).where(DatasetMetadataBinding.dataset_id == dataset.id) + ).all() assert len(remaining_bindings) == 0 # Verify index processor was called @@ -485,12 +506,14 @@ class TestCleanDatasetTask: # Check that all data was cleaned up - remaining_documents = db_session_with_containers.query(Document).filter_by(dataset_id=dataset.id).all() + remaining_documents = db_session_with_containers.scalars( + select(Document).where(Document.dataset_id == dataset.id) + ).all() assert len(remaining_documents) == 0 - remaining_segments = ( - db_session_with_containers.query(DocumentSegment).filter_by(dataset_id=dataset.id).all() - ) + remaining_segments = db_session_with_containers.scalars( + select(DocumentSegment).where(DocumentSegment.dataset_id == dataset.id) + ).all() assert len(remaining_segments) == 0 # Recreate data for next test case @@ -538,11 +561,15 @@ class TestCleanDatasetTask: # Verify results - even with vector cleanup failure, documents and segments should be deleted # Check that documents were still deleted despite vector cleanup failure - remaining_documents = db_session_with_containers.query(Document).filter_by(dataset_id=dataset.id).all() + remaining_documents = db_session_with_containers.scalars( + select(Document).where(Document.dataset_id == dataset.id) + ).all() assert len(remaining_documents) == 0 # Check that segments were still deleted despite vector cleanup failure - remaining_segments = db_session_with_containers.query(DocumentSegment).filter_by(dataset_id=dataset.id).all() + remaining_segments = db_session_with_containers.scalars( + select(DocumentSegment).where(DocumentSegment.dataset_id == dataset.id) + ).all() assert len(remaining_segments) == 0 # Verify that index processor was called and failed @@ -622,18 +649,22 @@ class TestCleanDatasetTask: # Verify results # Check that all documents were deleted - remaining_documents = db_session_with_containers.query(Document).filter_by(dataset_id=dataset.id).all() + remaining_documents = db_session_with_containers.scalars( + select(Document).where(Document.dataset_id == dataset.id) + ).all() assert len(remaining_documents) == 0 # Check that all segments were deleted - remaining_segments = db_session_with_containers.query(DocumentSegment).filter_by(dataset_id=dataset.id).all() + remaining_segments = db_session_with_containers.scalars( + select(DocumentSegment).where(DocumentSegment.dataset_id == dataset.id) + ).all() assert len(remaining_segments) == 0 # Check that all image files were deleted from database image_file_ids = [f.id for f in image_files] - remaining_image_files = ( - db_session_with_containers.query(UploadFile).where(UploadFile.id.in_(image_file_ids)).all() - ) + remaining_image_files = db_session_with_containers.scalars( + select(UploadFile).where(UploadFile.id.in_(image_file_ids)) + ).all() assert len(remaining_image_files) == 0 # Verify that storage.delete was called for each image file @@ -738,24 +769,32 @@ class TestCleanDatasetTask: # Verify results # Check that all documents were deleted - remaining_documents = db_session_with_containers.query(Document).filter_by(dataset_id=dataset.id).all() + remaining_documents = db_session_with_containers.scalars( + select(Document).where(Document.dataset_id == dataset.id) + ).all() assert len(remaining_documents) == 0 # Check that all segments were deleted - remaining_segments = db_session_with_containers.query(DocumentSegment).filter_by(dataset_id=dataset.id).all() + remaining_segments = db_session_with_containers.scalars( + select(DocumentSegment).where(DocumentSegment.dataset_id == dataset.id) + ).all() assert len(remaining_segments) == 0 # Check that all upload files were deleted - remaining_files = db_session_with_containers.query(UploadFile).where(UploadFile.id.in_(upload_file_ids)).all() + remaining_files = db_session_with_containers.scalars( + select(UploadFile).where(UploadFile.id.in_(upload_file_ids)) + ).all() assert len(remaining_files) == 0 # Check that all metadata and bindings were deleted - remaining_metadata = db_session_with_containers.query(DatasetMetadata).filter_by(dataset_id=dataset.id).all() + remaining_metadata = db_session_with_containers.scalars( + select(DatasetMetadata).where(DatasetMetadata.dataset_id == dataset.id) + ).all() assert len(remaining_metadata) == 0 - remaining_bindings = ( - db_session_with_containers.query(DatasetMetadataBinding).filter_by(dataset_id=dataset.id).all() - ) + remaining_bindings = db_session_with_containers.scalars( + select(DatasetMetadataBinding).where(DatasetMetadataBinding.dataset_id == dataset.id) + ).all() assert len(remaining_bindings) == 0 # Verify performance expectations @@ -826,7 +865,9 @@ class TestCleanDatasetTask: # Check that upload file was still deleted from database despite storage failure # Note: When storage operations fail, the upload file may not be deleted # This demonstrates that the cleanup process continues even with storage errors - remaining_files = db_session_with_containers.query(UploadFile).filter_by(id=upload_file.id).all() + remaining_files = db_session_with_containers.scalars( + select(UploadFile).where(UploadFile.id == upload_file.id) + ).all() # The upload file should still be deleted from the database even if storage cleanup fails # However, this depends on the specific implementation of clean_dataset_task if len(remaining_files) > 0: @@ -976,19 +1017,27 @@ class TestCleanDatasetTask: # Verify results # Check that all documents were deleted - remaining_documents = db_session_with_containers.query(Document).filter_by(dataset_id=dataset.id).all() + remaining_documents = db_session_with_containers.scalars( + select(Document).where(Document.dataset_id == dataset.id) + ).all() assert len(remaining_documents) == 0 # Check that all segments were deleted - remaining_segments = db_session_with_containers.query(DocumentSegment).filter_by(dataset_id=dataset.id).all() + remaining_segments = db_session_with_containers.scalars( + select(DocumentSegment).where(DocumentSegment.dataset_id == dataset.id) + ).all() assert len(remaining_segments) == 0 # Check that all upload files were deleted - remaining_files = db_session_with_containers.query(UploadFile).filter_by(id=upload_file_id).all() + remaining_files = db_session_with_containers.scalars( + select(UploadFile).where(UploadFile.id == upload_file_id) + ).all() assert len(remaining_files) == 0 # Check that all metadata was deleted - remaining_metadata = db_session_with_containers.query(DatasetMetadata).filter_by(dataset_id=dataset.id).all() + remaining_metadata = db_session_with_containers.scalars( + select(DatasetMetadata).where(DatasetMetadata.dataset_id == dataset.id) + ).all() assert len(remaining_metadata) == 0 # Verify that storage.delete was called From a951cc996b234660c2498d2c0a093a589ab0c1ff Mon Sep 17 00:00:00 2001 From: bohdansolovie <153934212+bohdansolovie@users.noreply.github.com> Date: Tue, 14 Apr 2026 03:56:11 -0400 Subject: [PATCH 03/44] test: migrate document indexing task tests to SQLAlchemy 2.0 select API (#35145) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../tasks/test_disable_segments_from_index_task.py | 7 ++++--- .../tasks/test_document_indexing_update_task.py | 11 ++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/api/tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py b/api/tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py index 3e9a0c8f7f..6e03bd9351 100644 --- a/api/tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py +++ b/api/tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py @@ -9,6 +9,7 @@ The task is responsible for removing document segments from the search index whe from unittest.mock import MagicMock, patch from faker import Faker +from sqlalchemy import select from sqlalchemy.orm import Session from core.rag.index_processor.constant.index_type import IndexStructureType, IndexTechniqueType @@ -471,9 +472,9 @@ class TestDisableSegmentsFromIndexTask: db_session_with_containers.refresh(segments[1]) # Check that segments are re-enabled after error - updated_segments = ( - db_session_with_containers.query(DocumentSegment).where(DocumentSegment.id.in_(segment_ids)).all() - ) + updated_segments = db_session_with_containers.scalars( + select(DocumentSegment).where(DocumentSegment.id.in_(segment_ids)) + ).all() for segment in updated_segments: assert segment.enabled is True diff --git a/api/tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py b/api/tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py index d94abf2b40..a9a8c0f30c 100644 --- a/api/tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py +++ b/api/tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py @@ -2,6 +2,7 @@ from unittest.mock import MagicMock, patch import pytest from faker import Faker +from sqlalchemy import func, select from core.rag.index_processor.constant.index_type import IndexStructureType, IndexTechniqueType from models import Account, Tenant, TenantAccountJoin, TenantAccountRole @@ -123,13 +124,13 @@ class TestDocumentIndexingUpdateTask: db_session_with_containers.expire_all() # Assert document status updated before reindex - updated = db_session_with_containers.query(Document).where(Document.id == document.id).first() + updated = db_session_with_containers.scalar(select(Document).where(Document.id == document.id).limit(1)) assert updated.indexing_status == IndexingStatus.PARSING assert updated.processing_started_at is not None # Segments should be deleted - remaining = ( - db_session_with_containers.query(DocumentSegment).where(DocumentSegment.document_id == document.id).count() + remaining = db_session_with_containers.scalar( + select(func.count()).select_from(DocumentSegment).where(DocumentSegment.document_id == document.id) ) assert remaining == 0 @@ -167,8 +168,8 @@ class TestDocumentIndexingUpdateTask: mock_external_dependencies["runner_instance"].run.assert_called_once() # Segments should remain (since clean failed before DB delete) - remaining = ( - db_session_with_containers.query(DocumentSegment).where(DocumentSegment.document_id == document.id).count() + remaining = db_session_with_containers.scalar( + select(func.count()).select_from(DocumentSegment).where(DocumentSegment.document_id == document.id) ) assert remaining > 0 From d7ad2baf7958992199aa69648a46cc00cb863784 Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 14 Apr 2026 16:15:07 +0800 Subject: [PATCH 04/44] chore: clarify tracing error copy to direct users to the Tracing tab (#35153) --- pnpm-lock.yaml | 12 ---- .../base/ui/select/__tests__/index.spec.tsx | 13 ++-- .../panel/__tests__/workflow-preview.spec.tsx | 40 +++++++++++- .../workflow/panel/workflow-preview.tsx | 5 ++ .../workflow/run/__tests__/status.spec.tsx | 65 ++++++++++++++++++- web/app/components/workflow/run/index.tsx | 1 + .../components/workflow/run/result-panel.tsx | 3 + web/app/components/workflow/run/status.tsx | 32 ++++++++- web/i18n/ar-TN/workflow.json | 2 +- web/i18n/de-DE/workflow.json | 2 +- web/i18n/en-US/workflow.json | 2 +- web/i18n/es-ES/workflow.json | 2 +- web/i18n/fa-IR/workflow.json | 2 +- web/i18n/fr-FR/workflow.json | 2 +- web/i18n/hi-IN/workflow.json | 2 +- web/i18n/id-ID/workflow.json | 2 +- web/i18n/it-IT/workflow.json | 2 +- web/i18n/ja-JP/workflow.json | 2 +- web/i18n/ko-KR/workflow.json | 2 +- web/i18n/nl-NL/workflow.json | 2 +- web/i18n/pl-PL/workflow.json | 2 +- web/i18n/pt-BR/workflow.json | 2 +- web/i18n/ro-RO/workflow.json | 2 +- web/i18n/ru-RU/workflow.json | 2 +- web/i18n/sl-SI/workflow.json | 2 +- web/i18n/th-TH/workflow.json | 2 +- web/i18n/tr-TR/workflow.json | 2 +- web/i18n/uk-UA/workflow.json | 2 +- web/i18n/vi-VN/workflow.json | 2 +- web/i18n/zh-Hans/workflow.json | 2 +- web/i18n/zh-Hant/workflow.json | 2 +- web/package.json | 2 - 32 files changed, 167 insertions(+), 52 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8901c7948f..4444981601 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,9 +24,6 @@ catalogs: '@cucumber/cucumber': specifier: 12.8.0 version: 12.8.0 - '@date-fns/tz': - specifier: 1.4.1 - version: 1.4.1 '@egoist/tailwindcss-icons': specifier: 1.9.2 version: 1.9.2 @@ -270,9 +267,6 @@ catalogs: cron-parser: specifier: 5.5.0 version: 5.5.0 - date-fns: - specifier: 4.1.0 - version: 4.1.0 dayjs: specifier: 1.11.20 version: 1.11.20 @@ -655,9 +649,6 @@ importers: '@base-ui/react': specifier: 'catalog:' version: 1.4.0(@date-fns/tz@1.4.1)(@types/react@19.2.14)(date-fns@4.1.0)(react-dom@19.2.5(react@19.2.5))(react@19.2.5) - '@date-fns/tz': - specifier: 'catalog:' - version: 1.4.1 '@emoji-mart/data': specifier: 'catalog:' version: 1.2.1 @@ -760,9 +751,6 @@ importers: cron-parser: specifier: 'catalog:' version: 5.5.0 - date-fns: - specifier: 'catalog:' - version: 4.1.0 dayjs: specifier: 'catalog:' version: 1.11.20 diff --git a/web/app/components/base/ui/select/__tests__/index.spec.tsx b/web/app/components/base/ui/select/__tests__/index.spec.tsx index f33b1eb650..124eb4d60e 100644 --- a/web/app/components/base/ui/select/__tests__/index.spec.tsx +++ b/web/app/components/base/ui/select/__tests__/index.spec.tsx @@ -42,12 +42,10 @@ const renderOpenSelect = ({ describe('Select wrappers', () => { describe('Select root integration', () => { - it('should associate the hidden input with an external form and preserve autocomplete hints', () => { - const formId = 'profile-form' + it('should submit the hidden input value and preserve autocomplete hints inside a form', () => { const { container } = render( - <> -
- @@ -56,13 +54,12 @@ describe('Select wrappers', () => { New York - , +
, ) const hiddenInput = container.querySelector('input[name="city"]') - const form = container.querySelector(`#${formId}`) as HTMLFormElement + const form = screen.getByRole('form', { name: 'profile form' }) as HTMLFormElement - expect(hiddenInput).toHaveAttribute('form', formId) expect(hiddenInput).toHaveAttribute('autocomplete', 'address-level2') expect(new FormData(form).get('city')).toBe('seattle') }) diff --git a/web/app/components/workflow/panel/__tests__/workflow-preview.spec.tsx b/web/app/components/workflow/panel/__tests__/workflow-preview.spec.tsx index 860322d729..e3c85bd2ad 100644 --- a/web/app/components/workflow/panel/__tests__/workflow-preview.spec.tsx +++ b/web/app/components/workflow/panel/__tests__/workflow-preview.spec.tsx @@ -33,7 +33,18 @@ vi.mock('@/app/components/workflow/hooks', () => ({ })) vi.mock('@/app/components/workflow/run/result-panel', () => ({ - default: ({ status }: { status?: string }) =>
{status}
, + default: ({ + status, + onOpenTracingTab, + }: { + status?: string + onOpenTracingTab?: () => void + }) => ( +
+
{status}
+ +
+ ), })) vi.mock('@/app/components/workflow/run/result-text', () => ({ @@ -329,6 +340,33 @@ describe('WorkflowPreview', () => { expect(screen.getByTestId('result-panel')).toBeInTheDocument() }) + it('should switch to the tracing tab when result panel requests it', async () => { + const user = userEvent.setup() + + renderWorkflowComponent( + , + { + initialStoreState: { + workflowRunningData: { + ...createWorkflowRunningData({ + result: createWorkflowResult({ + status: 'partial-succeeded', + files: [], + }), + tracing: [createNodeTracing()], + }), + resultText: 'ready', + } as NonNullable, + }, + }, + ) + + await user.click(screen.getByText('runLog.detail')) + await user.click(screen.getByRole('button', { name: 'open-tracing' })) + + expect(screen.getByTestId('tracing-panel')).toHaveTextContent('1') + }) + it('should resize the preview panel within the allowed workflow canvas bounds', async () => { const { container, store } = renderWorkflowComponent( , diff --git a/web/app/components/workflow/panel/workflow-preview.tsx b/web/app/components/workflow/panel/workflow-preview.tsx index d3950dcbca..e1e442c0cb 100644 --- a/web/app/components/workflow/panel/workflow-preview.tsx +++ b/web/app/components/workflow/panel/workflow-preview.tsx @@ -101,6 +101,10 @@ const WorkflowPreview = () => { await submitHumanInputForm(formToken, formData) }, []) + const handleOpenTracingTab = useCallback(() => { + switchTab('TRACING') + }, []) + return (
{ created_by={(workflowRunningData?.result?.created_by as any)?.name} steps={workflowRunningData?.result?.total_steps} exceptionCounts={workflowRunningData?.result?.exceptions_count} + onOpenTracingTab={handleOpenTracingTab} /> )} {currentTab === 'DETAIL' && !workflowRunningData?.result && ( diff --git a/web/app/components/workflow/run/__tests__/status.spec.tsx b/web/app/components/workflow/run/__tests__/status.spec.tsx index 01f32c4c47..24682aa47f 100644 --- a/web/app/components/workflow/run/__tests__/status.spec.tsx +++ b/web/app/components/workflow/run/__tests__/status.spec.tsx @@ -1,11 +1,60 @@ import type { WorkflowPausedDetailsResponse } from '@/models/log' -import { render, screen } from '@testing-library/react' +import { fireEvent, render, screen } from '@testing-library/react' +import { cloneElement, isValidElement } from 'react' import { createDocLinkMock, resolveDocLink } from '../../__tests__/i18n' import Status from '../status' const mockDocLink = createDocLinkMock() const mockUseWorkflowPausedDetails = vi.fn() +vi.mock('react-i18next', () => ({ + useTranslation: () => ({ + t: (key: string, options?: Record) => { + const fullKey = options?.ns ? `${options.ns}.${key}` : key + if (fullKey === 'workflow.nodes.common.errorHandle.partialSucceeded.tip') + return 'There are {{num}} nodes in the process running abnormally, please go to TRACING to check the logs.' + + const params = { ...options } + delete params.ns + const suffix = Object.keys(params).length > 0 ? `:${JSON.stringify(params)}` : '' + return `${fullKey}${suffix}` + }, + }), + Trans: ({ + i18nKey, + values, + components, + }: { + i18nKey: string + values?: { + num?: string | number + } + components?: Record + }) => { + if (i18nKey !== 'nodes.common.errorHandle.partialSucceeded.tip') + return {i18nKey} + + const tracingLink = components?.tracingLink + const tracingNode = isValidElement(tracingLink) + ? cloneElement(tracingLink, undefined, 'TRACING') + : 'TRACING' + + return ( + + There are + {' '} + {values?.num} + {' '} + nodes in the process running abnormally, please go to + {' '} + {tracingNode} + {' '} + to check the logs. + + ) + }, +})) + vi.mock('@/context/i18n', () => ({ useDocLink: () => mockDocLink, })) @@ -64,14 +113,24 @@ describe('Status', () => { expect(screen.getByText('FAIL')).toBeInTheDocument() expect(screen.getByText('Something broke')).toBeInTheDocument() - expect(screen.getByText('workflow.nodes.common.errorHandle.partialSucceeded.tip:{"num":2}')).toBeInTheDocument() + expect(screen.getAllByText((_, element) => element?.textContent === 'There are 2 nodes in the process running abnormally, please go to TRACING to check the logs.')).toHaveLength(2) }) it('renders the partial-succeeded warning summary', () => { render() expect(screen.getByText('PARTIAL SUCCESS')).toBeInTheDocument() - expect(screen.getByText('workflow.nodes.common.errorHandle.partialSucceeded.tip:{"num":3}')).toBeInTheDocument() + expect(screen.getAllByText((_, element) => element?.textContent === 'There are 3 nodes in the process running abnormally, please go to TRACING to check the logs.')).toHaveLength(2) + }) + + it('opens the tracing tab when clicking the TRACING link', () => { + const onOpenTracingTab = vi.fn() + + render() + + fireEvent.click(screen.getByRole('link', { name: 'TRACING' })) + + expect(onOpenTracingTab).toHaveBeenCalledTimes(1) }) it('renders the exception learn-more link', () => { diff --git a/web/app/components/workflow/run/index.tsx b/web/app/components/workflow/run/index.tsx index d39e6d43c3..417d38657e 100644 --- a/web/app/components/workflow/run/index.tsx +++ b/web/app/components/workflow/run/index.tsx @@ -174,6 +174,7 @@ const RunPanel: FC = ({ exceptionCounts={runDetail.exceptions_count} isListening={isListening} workflowRunId={runDetail.id} + onOpenTracingTab={() => switchTab('TRACING')} /> )} {!loading && currentTab === 'DETAIL' && !runDetail && isListening && ( diff --git a/web/app/components/workflow/run/result-panel.tsx b/web/app/components/workflow/run/result-panel.tsx index 58f783e6c4..c7f4a45540 100644 --- a/web/app/components/workflow/run/result-panel.tsx +++ b/web/app/components/workflow/run/result-panel.tsx @@ -42,6 +42,7 @@ export type ResultPanelProps = { execution_metadata?: any isListening?: boolean workflowRunId?: string + onOpenTracingTab?: () => void handleShowIterationResultList?: (detail: NodeTracing[][], iterDurationMap: any) => void handleShowLoopResultList?: (detail: NodeTracing[][], loopDurationMap: any) => void onShowRetryDetail?: (detail: NodeTracing[]) => void @@ -69,6 +70,7 @@ const ResultPanel: FC = ({ execution_metadata, isListening = false, workflowRunId, + onOpenTracingTab, handleShowIterationResultList, handleShowLoopResultList, onShowRetryDetail, @@ -92,6 +94,7 @@ const ResultPanel: FC = ({ exceptionCounts={exceptionCounts} isListening={isListening} workflowRunId={workflowRunId} + onOpenTracingTab={onOpenTracingTab} />
diff --git a/web/app/components/workflow/run/status.tsx b/web/app/components/workflow/run/status.tsx index d4ecfcc0fd..233c6207a9 100644 --- a/web/app/components/workflow/run/status.tsx +++ b/web/app/components/workflow/run/status.tsx @@ -1,7 +1,7 @@ 'use client' import type { FC } from 'react' import { useMemo } from 'react' -import { useTranslation } from 'react-i18next' +import { Trans, useTranslation } from 'react-i18next' import Indicator from '@/app/components/header/indicator' import StatusContainer from '@/app/components/workflow/run/status-container' import { useDocLink } from '@/context/i18n' @@ -16,6 +16,7 @@ type ResultProps = { exceptionCounts?: number isListening?: boolean workflowRunId?: string + onOpenTracingTab?: () => void } const StatusPanel: FC = ({ @@ -26,6 +27,7 @@ const StatusPanel: FC = ({ exceptionCounts, isListening = false, workflowRunId, + onOpenTracingTab, }) => { const { t } = useTranslation() const docLink = useDocLink() @@ -65,6 +67,30 @@ const StatusPanel: FC = ({ return inputURLs }, [pausedDetails]) + const partialSucceededTip = exceptionCounts + ? ( + { + e.preventDefault() + onOpenTracingTab() + }} + /> + ) + : , + }} + /> + ) + : null + return (
@@ -160,7 +186,7 @@ const StatusPanel: FC = ({ <>
- {t('nodes.common.errorHandle.partialSucceeded.tip', { ns: 'workflow', num: exceptionCounts })} + {partialSucceededTip}
) @@ -172,7 +198,7 @@ const StatusPanel: FC = ({ <>
- {t('nodes.common.errorHandle.partialSucceeded.tip', { ns: 'workflow', num: exceptionCounts })} + {partialSucceededTip}
) diff --git a/web/i18n/ar-TN/workflow.json b/web/i18n/ar-TN/workflow.json index e0e498e8d4..56192350c3 100644 --- a/web/i18n/ar-TN/workflow.json +++ b/web/i18n/ar-TN/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "فرع الفشل", "nodes.common.errorHandle.none.desc": "ستتوقف العقدة عن العمل في حالة حدوث استثناء ولم يتم التعامل معه", "nodes.common.errorHandle.none.title": "لا شيء", - "nodes.common.errorHandle.partialSucceeded.tip": "هناك {{num}} عقد في العملية تعمل بشكل غير طبيعي، يرجى الانتقال إلى التتبع للتحقق من السجلات.", + "nodes.common.errorHandle.partialSucceeded.tip": "هناك {{num}} عقد في العملية تعمل بشكل غير طبيعي، يرجى الانتقال إلى التتبع للتحقق من السجلات.", "nodes.common.errorHandle.tip": "استراتيجية التعامل مع الاستثناءات، يتم تشغيلها عندما تواجه العقدة استثناءً.", "nodes.common.errorHandle.title": "معالجة الأخطاء", "nodes.common.inputVars": "متغيرات الإدخال", diff --git a/web/i18n/de-DE/workflow.json b/web/i18n/de-DE/workflow.json index 7a1ddeeb1c..75cb0d30ca 100644 --- a/web/i18n/de-DE/workflow.json +++ b/web/i18n/de-DE/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Fehlgeschlagener Zweig", "nodes.common.errorHandle.none.desc": "Der Knoten wird nicht mehr ausgeführt, wenn eine Ausnahme auftritt und nicht behandelt wird", "nodes.common.errorHandle.none.title": "Nichts", - "nodes.common.errorHandle.partialSucceeded.tip": "Es gibt {{num}} Knoten im Prozess, die nicht normal laufen, bitte gehen Sie zur Ablaufverfolgung, um die Protokolle zu überprüfen.", + "nodes.common.errorHandle.partialSucceeded.tip": "Es gibt {{num}} Knoten im Prozess, die nicht normal laufen, bitte gehen Sie zur Ablaufverfolgung, um die Protokolle zu überprüfen.", "nodes.common.errorHandle.tip": "Ausnahmebehandlungsstrategie, die ausgelöst wird, wenn ein Knoten auf eine Ausnahme stößt.", "nodes.common.errorHandle.title": "Fehlerbehandlung", "nodes.common.inputVars": "Eingabevariablen", diff --git a/web/i18n/en-US/workflow.json b/web/i18n/en-US/workflow.json index 6f6e5de2cc..42522950b8 100644 --- a/web/i18n/en-US/workflow.json +++ b/web/i18n/en-US/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Fail Branch", "nodes.common.errorHandle.none.desc": "The node will stop running if an exception occurs and is not handled", "nodes.common.errorHandle.none.title": "None", - "nodes.common.errorHandle.partialSucceeded.tip": "There are {{num}} nodes in the process running abnormally, please go to tracing to check the logs.", + "nodes.common.errorHandle.partialSucceeded.tip": "There are {{num}} nodes in the process running abnormally, please go to TRACING to check the logs.", "nodes.common.errorHandle.tip": "Exception handling strategy, triggered when a node encounters an exception.", "nodes.common.errorHandle.title": "Error Handling", "nodes.common.inputVars": "Input Variables", diff --git a/web/i18n/es-ES/workflow.json b/web/i18n/es-ES/workflow.json index 1955357c45..5545707b4f 100644 --- a/web/i18n/es-ES/workflow.json +++ b/web/i18n/es-ES/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Rama de error", "nodes.common.errorHandle.none.desc": "El nodo dejará de ejecutarse si se produce una excepción y no se controla", "nodes.common.errorHandle.none.title": "Ninguno", - "nodes.common.errorHandle.partialSucceeded.tip": "Hay nodos {{num}} en el proceso que se ejecutan de manera anormal, vaya a rastreo para verificar los registros.", + "nodes.common.errorHandle.partialSucceeded.tip": "Hay nodos {{num}} en el proceso que se ejecutan de manera anormal, vaya a rastreo para verificar los registros.", "nodes.common.errorHandle.tip": "Estrategia de control de excepciones, que se desencadena cuando un nodo encuentra una excepción.", "nodes.common.errorHandle.title": "Manejo de errores", "nodes.common.inputVars": "Variables de entrada", diff --git a/web/i18n/fa-IR/workflow.json b/web/i18n/fa-IR/workflow.json index e957d45267..fbe6685681 100644 --- a/web/i18n/fa-IR/workflow.json +++ b/web/i18n/fa-IR/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "شاخه شکست", "nodes.common.errorHandle.none.desc": "اگر استثنایی رخ دهد و مدیریت نشود، گره از کار می‌افتد", "nodes.common.errorHandle.none.title": "هیچ‌کدام", - "nodes.common.errorHandle.partialSucceeded.tip": "{{num}} گره با خطا مواجه شدند؛ برای بررسی لاگ‌ها به ردیابی مراجعه کنید.", + "nodes.common.errorHandle.partialSucceeded.tip": "{{num}} گره با خطا مواجه شدند؛ برای بررسی لاگ‌ها به ردیابی مراجعه کنید.", "nodes.common.errorHandle.tip": "استراتژی مدیریت استثنا؛ زمانی که گره با خطا مواجه شود فعال می‌شود.", "nodes.common.errorHandle.title": "مدیریت خطا", "nodes.common.inputVars": "متغیرهای ورودی", diff --git a/web/i18n/fr-FR/workflow.json b/web/i18n/fr-FR/workflow.json index ec23ac5c98..b7f7048ad2 100644 --- a/web/i18n/fr-FR/workflow.json +++ b/web/i18n/fr-FR/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Branche d’échec", "nodes.common.errorHandle.none.desc": "Le nœud cessera de s’exécuter si une exception se produit et n’est pas gérée", "nodes.common.errorHandle.none.title": "Aucun", - "nodes.common.errorHandle.partialSucceeded.tip": "Il y a des nœuds {{num}} dans le processus qui fonctionnent anormalement, veuillez aller dans le traçage pour vérifier les journaux.", + "nodes.common.errorHandle.partialSucceeded.tip": "Il y a des nœuds {{num}} dans le processus qui fonctionnent anormalement, veuillez aller dans le traçage pour vérifier les journaux.", "nodes.common.errorHandle.tip": "Stratégie de gestion des exceptions, déclenchée lorsqu’un nœud rencontre une exception.", "nodes.common.errorHandle.title": "Gestion des erreurs", "nodes.common.inputVars": "Variables d’entrée", diff --git a/web/i18n/hi-IN/workflow.json b/web/i18n/hi-IN/workflow.json index f18de6aa3c..9166eb43d8 100644 --- a/web/i18n/hi-IN/workflow.json +++ b/web/i18n/hi-IN/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "असफल शाखा", "nodes.common.errorHandle.none.desc": "यदि कोई अपवाद होता है और हैंडल नहीं किया जाता है, तो नोड चलना बंद कर देगा", "nodes.common.errorHandle.none.title": "कोई नहीं", - "nodes.common.errorHandle.partialSucceeded.tip": "प्रक्रिया में {{num}} नोड्स असामान्य रूप से चल रहे हैं, कृपया लॉग की जांच करने के लिए ट्रेसिंग पर जाएं।", + "nodes.common.errorHandle.partialSucceeded.tip": "प्रक्रिया में {{num}} नोड्स असामान्य रूप से चल रहे हैं, कृपया लॉग की जांच करने के लिए ट्रेसिंग पर जाएं।", "nodes.common.errorHandle.tip": "अपवाद हैंडलिंग रणनीति, ट्रिगर जब एक नोड एक अपवाद का सामना करता है।", "nodes.common.errorHandle.title": "त्रुटि हैंडलिंग", "nodes.common.inputVars": "इनपुट चर", diff --git a/web/i18n/id-ID/workflow.json b/web/i18n/id-ID/workflow.json index 5030489cb1..7e72577e3b 100644 --- a/web/i18n/id-ID/workflow.json +++ b/web/i18n/id-ID/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Cabang Gagal", "nodes.common.errorHandle.none.desc": "Node akan berhenti berjalan jika pengecualian terjadi dan tidak ditangani", "nodes.common.errorHandle.none.title": "Tidak", - "nodes.common.errorHandle.partialSucceeded.tip": "Ada {{num}} node dalam proses yang berjalan tidak normal, silakan pergi ke tracing untuk memeriksa log.", + "nodes.common.errorHandle.partialSucceeded.tip": "Ada {{num}} node dalam proses yang berjalan tidak normal, silakan pergi ke tracing untuk memeriksa log.", "nodes.common.errorHandle.tip": "Strategi penanganan pengecualian, dipicu ketika simpul menemukan pengecualian.", "nodes.common.errorHandle.title": "Penanganan Kesalahan", "nodes.common.inputVars": "Variabel Masukan", diff --git a/web/i18n/it-IT/workflow.json b/web/i18n/it-IT/workflow.json index a39e00c5d8..2fde43f694 100644 --- a/web/i18n/it-IT/workflow.json +++ b/web/i18n/it-IT/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Ramo fallito", "nodes.common.errorHandle.none.desc": "L'esecuzione del nodo verrà interrotta se si verifica un'eccezione e non viene gestita", "nodes.common.errorHandle.none.title": "Nessuno", - "nodes.common.errorHandle.partialSucceeded.tip": "Ci sono {{num}} nodi nel processo che funzionano in modo anomalo, si prega di andare su tracing per controllare i log.", + "nodes.common.errorHandle.partialSucceeded.tip": "Ci sono {{num}} nodi nel processo che funzionano in modo anomalo, si prega di andare su tracing per controllare i log.", "nodes.common.errorHandle.tip": "Strategia di gestione delle eccezioni, attivata quando un nodo rileva un'eccezione.", "nodes.common.errorHandle.title": "Gestione degli errori", "nodes.common.inputVars": "Variabili di input", diff --git a/web/i18n/ja-JP/workflow.json b/web/i18n/ja-JP/workflow.json index 089468053a..11cf9caa34 100644 --- a/web/i18n/ja-JP/workflow.json +++ b/web/i18n/ja-JP/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "例外分岐", "nodes.common.errorHandle.none.desc": "例外発生時に処理を停止", "nodes.common.errorHandle.none.title": "処理なし", - "nodes.common.errorHandle.partialSucceeded.tip": "{{num}}個のノードで異常発生。ログはトレース画面で確認可能", + "nodes.common.errorHandle.partialSucceeded.tip": "{{num}}個のノードで異常発生。ログはトレース画面で確認可能", "nodes.common.errorHandle.tip": "ノード例外発生時の処理ポリシーを設定", "nodes.common.errorHandle.title": "例外処理", "nodes.common.inputVars": "入力変数", diff --git a/web/i18n/ko-KR/workflow.json b/web/i18n/ko-KR/workflow.json index ab602c391c..c93f417361 100644 --- a/web/i18n/ko-KR/workflow.json +++ b/web/i18n/ko-KR/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "실패 분기", "nodes.common.errorHandle.none.desc": "예외가 발생하고 처리되지 않으면 노드 실행이 중지됩니다", "nodes.common.errorHandle.none.title": "없음", - "nodes.common.errorHandle.partialSucceeded.tip": "프로세스에 {{num}} 노드가 비정상적으로 실행 중입니다. 추적으로 이동하여 로그를 확인하십시오.", + "nodes.common.errorHandle.partialSucceeded.tip": "프로세스에 {{num}} 노드가 비정상적으로 실행 중입니다. 추적으로 이동하여 로그를 확인하십시오.", "nodes.common.errorHandle.tip": "노드에 예외가 발생할 때 트리거되는 예외 처리 전략입니다.", "nodes.common.errorHandle.title": "오류 처리", "nodes.common.inputVars": "입력 변수", diff --git a/web/i18n/nl-NL/workflow.json b/web/i18n/nl-NL/workflow.json index b706c42962..4a6ccd8937 100644 --- a/web/i18n/nl-NL/workflow.json +++ b/web/i18n/nl-NL/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Fail Branch", "nodes.common.errorHandle.none.desc": "The node will stop running if an exception occurs and is not handled", "nodes.common.errorHandle.none.title": "None", - "nodes.common.errorHandle.partialSucceeded.tip": "There are {{num}} nodes in the process running abnormally, please go to tracing to check the logs.", + "nodes.common.errorHandle.partialSucceeded.tip": "There are {{num}} nodes in the process running abnormally, please go to tracing to check the logs.", "nodes.common.errorHandle.tip": "Exception handling strategy, triggered when a node encounters an exception.", "nodes.common.errorHandle.title": "Error Handling", "nodes.common.inputVars": "Input Variables", diff --git a/web/i18n/pl-PL/workflow.json b/web/i18n/pl-PL/workflow.json index 1f54fe6437..57aa50dd4e 100644 --- a/web/i18n/pl-PL/workflow.json +++ b/web/i18n/pl-PL/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Gałąź Fail (Gałąź Niepowodzenia", "nodes.common.errorHandle.none.desc": "Węzeł przestanie działać, jeśli wystąpi wyjątek i nie zostanie obsłużony", "nodes.common.errorHandle.none.title": "Żaden", - "nodes.common.errorHandle.partialSucceeded.tip": "W procesie {{num}} węzły działają nieprawidłowo, przejdź do śledzenia, aby sprawdzić dzienniki.", + "nodes.common.errorHandle.partialSucceeded.tip": "W procesie {{num}} węzły działają nieprawidłowo, przejdź do śledzenia, aby sprawdzić dzienniki.", "nodes.common.errorHandle.tip": "Strategia obsługi wyjątków, wyzwalana, gdy węzeł napotka wyjątek.", "nodes.common.errorHandle.title": "Obsługa błędów", "nodes.common.inputVars": "Zmienne wejściowe", diff --git a/web/i18n/pt-BR/workflow.json b/web/i18n/pt-BR/workflow.json index ab1fea2990..a0635ad814 100644 --- a/web/i18n/pt-BR/workflow.json +++ b/web/i18n/pt-BR/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Ramificação com falha", "nodes.common.errorHandle.none.desc": "O nó deixará de ser executado se ocorrer uma exceção e não for tratada", "nodes.common.errorHandle.none.title": "Nenhum", - "nodes.common.errorHandle.partialSucceeded.tip": "Existem {{num}} nós no processo em execução anormal, vá para rastreamento para verificar os logs.", + "nodes.common.errorHandle.partialSucceeded.tip": "Existem {{num}} nós no processo em execução anormal, vá para rastreamento para verificar os logs.", "nodes.common.errorHandle.tip": "Estratégia de tratamento de exceções, disparada quando um nó encontra uma exceção.", "nodes.common.errorHandle.title": "Tratamento de erros", "nodes.common.inputVars": "Variáveis de entrada", diff --git a/web/i18n/ro-RO/workflow.json b/web/i18n/ro-RO/workflow.json index dbe331e316..58a0786894 100644 --- a/web/i18n/ro-RO/workflow.json +++ b/web/i18n/ro-RO/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Ramură Fail", "nodes.common.errorHandle.none.desc": "Nodul se va opri din rulare dacă apare o excepție și nu este gestionat", "nodes.common.errorHandle.none.title": "Niciunul", - "nodes.common.errorHandle.partialSucceeded.tip": "Există {{num}} noduri în proces care rulează anormal, vă rugăm să mergeți la urmărire pentru a verifica jurnalele.", + "nodes.common.errorHandle.partialSucceeded.tip": "Există {{num}} noduri în proces care rulează anormal, vă rugăm să mergeți la urmărire pentru a verifica jurnalele.", "nodes.common.errorHandle.tip": "Strategie de gestionare a excepțiilor, declanșată atunci când un nod întâlnește o excepție.", "nodes.common.errorHandle.title": "Gestionarea erorilor", "nodes.common.inputVars": "Variabile de intrare", diff --git a/web/i18n/ru-RU/workflow.json b/web/i18n/ru-RU/workflow.json index 48a253b31b..585c9fae93 100644 --- a/web/i18n/ru-RU/workflow.json +++ b/web/i18n/ru-RU/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Неудачная ветвь", "nodes.common.errorHandle.none.desc": "Узел перестанет работать, если произойдет исключение и оно не будет обработано", "nodes.common.errorHandle.none.title": "Никакой", - "nodes.common.errorHandle.partialSucceeded.tip": "В процессе есть {{num}} узлов, которые работают ненормально, пожалуйста, перейдите к трассировке, чтобы проверить логи.", + "nodes.common.errorHandle.partialSucceeded.tip": "В процессе есть {{num}} узлов, которые работают ненормально, пожалуйста, перейдите к трассировке, чтобы проверить логи.", "nodes.common.errorHandle.tip": "Стратегия обработки исключений, запускаемая при обнаружении исключения на узле.", "nodes.common.errorHandle.title": "Обработка ошибок", "nodes.common.inputVars": "Входные переменные", diff --git a/web/i18n/sl-SI/workflow.json b/web/i18n/sl-SI/workflow.json index f2b032cfaa..f29c211ed8 100644 --- a/web/i18n/sl-SI/workflow.json +++ b/web/i18n/sl-SI/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Napaka veja", "nodes.common.errorHandle.none.desc": "Vozlišče se bo prenehalo izvajati, če pride do izjeme, ki ni obravnavana.", "nodes.common.errorHandle.none.title": "Noben", - "nodes.common.errorHandle.partialSucceeded.tip": "V procesu je {{num}} vozlišč, ki delujejo nenormalno, prosim, pojdite na sledenje, da preverite dnevnike.", + "nodes.common.errorHandle.partialSucceeded.tip": "V procesu je {{num}} vozlišč, ki delujejo nenormalno, prosim, pojdite na sledenje, da preverite dnevnike.", "nodes.common.errorHandle.tip": "Strategija ravnanja z izjemo, ki se sproži, ko vozlišče naleti na izjemo.", "nodes.common.errorHandle.title": "Obvladovanje napak", "nodes.common.inputVars": "Vhodne spremenljivke", diff --git a/web/i18n/th-TH/workflow.json b/web/i18n/th-TH/workflow.json index fb49264d71..130e2c0269 100644 --- a/web/i18n/th-TH/workflow.json +++ b/web/i18n/th-TH/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "สาขาล้มเหลว", "nodes.common.errorHandle.none.desc": "โหนดจะหยุดทํางานหากเกิดข้อยกเว้นและไม่ได้รับการจัดการ", "nodes.common.errorHandle.none.title": "ไม่มีใคร", - "nodes.common.errorHandle.partialSucceeded.tip": "มีโหนด {{num}} ในกระบวนการที่ทํางานผิดปกติ โปรดไปที่การติดตามเพื่อตรวจสอบบันทึก", + "nodes.common.errorHandle.partialSucceeded.tip": "มีโหนด {{num}} ในกระบวนการที่ทํางานผิดปกติ โปรดไปที่การติดตามเพื่อตรวจสอบบันทึก", "nodes.common.errorHandle.tip": "กลยุทธ์การจัดการข้อยกเว้น ทริกเกอร์เมื่อโหนดพบข้อยกเว้น", "nodes.common.errorHandle.title": "การจัดการข้อผิดพลาด", "nodes.common.inputVars": "ตัวแปรอินพุต", diff --git a/web/i18n/tr-TR/workflow.json b/web/i18n/tr-TR/workflow.json index 6b87b4e1e8..c6893cfb84 100644 --- a/web/i18n/tr-TR/workflow.json +++ b/web/i18n/tr-TR/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Başarısız Dal", "nodes.common.errorHandle.none.desc": "Bir özel durum oluşursa ve işlenmezse düğüm çalışmayı durdurur", "nodes.common.errorHandle.none.title": "Hiç kimse", - "nodes.common.errorHandle.partialSucceeded.tip": "İşlemde anormal şekilde çalışan {{num}} düğümleri var, lütfen günlükleri kontrol etmek için izlemeye gidin.", + "nodes.common.errorHandle.partialSucceeded.tip": "İşlemde anormal şekilde çalışan {{num}} düğümleri var, lütfen günlükleri kontrol etmek için izlemeye gidin.", "nodes.common.errorHandle.tip": "Bir düğüm bir özel durumla karşılaştığında tetiklenen özel durum işleme stratejisi.", "nodes.common.errorHandle.title": "Hata İşleme", "nodes.common.inputVars": "Giriş Değişkenleri", diff --git a/web/i18n/uk-UA/workflow.json b/web/i18n/uk-UA/workflow.json index 70d5378d22..90ee940ae7 100644 --- a/web/i18n/uk-UA/workflow.json +++ b/web/i18n/uk-UA/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Гілка невдачі", "nodes.common.errorHandle.none.desc": "Вузол припинить роботу, якщо виникне виняток і не буде оброблений", "nodes.common.errorHandle.none.title": "Ніхто", - "nodes.common.errorHandle.partialSucceeded.tip": "У процесі є вузли {{num}}, які працюють ненормально, будь ласка, перейдіть до трасування, щоб перевірити логи.", + "nodes.common.errorHandle.partialSucceeded.tip": "У процесі є вузли {{num}}, які працюють ненормально, будь ласка, перейдіть до трасування, щоб перевірити логи.", "nodes.common.errorHandle.tip": "Стратегія обробки винятків, що спрацьовує, коли вузол стикається з винятком.", "nodes.common.errorHandle.title": "Обробка помилок", "nodes.common.inputVars": "Вхідні змінні", diff --git a/web/i18n/vi-VN/workflow.json b/web/i18n/vi-VN/workflow.json index 9bf9b4d61c..6ba72b8b3d 100644 --- a/web/i18n/vi-VN/workflow.json +++ b/web/i18n/vi-VN/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "Chi nhánh thất bại", "nodes.common.errorHandle.none.desc": "Nút sẽ ngừng chạy nếu xảy ra ngoại lệ và không được xử lý", "nodes.common.errorHandle.none.title": "Không ai", - "nodes.common.errorHandle.partialSucceeded.tip": "Có {{num}} node trong quá trình chạy bất thường, vui lòng truy tìm để kiểm tra nhật ký.", + "nodes.common.errorHandle.partialSucceeded.tip": "Có {{num}} node trong quá trình chạy bất thường, vui lòng vào truy tìm để kiểm tra nhật ký.", "nodes.common.errorHandle.tip": "Chiến lược xử lý ngoại lệ, được kích hoạt khi một nút gặp phải ngoại lệ.", "nodes.common.errorHandle.title": "Xử lý lỗi", "nodes.common.inputVars": "Biến đầu vào", diff --git a/web/i18n/zh-Hans/workflow.json b/web/i18n/zh-Hans/workflow.json index 6bb832f925..c02cad5145 100644 --- a/web/i18n/zh-Hans/workflow.json +++ b/web/i18n/zh-Hans/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "异常分支", "nodes.common.errorHandle.none.desc": "当发生异常且未处理时,节点将停止运行", "nodes.common.errorHandle.none.title": "无", - "nodes.common.errorHandle.partialSucceeded.tip": "流程中有 {{num}} 个节点运行异常,请前往追踪查看日志。", + "nodes.common.errorHandle.partialSucceeded.tip": "流程中有 {{num}} 个节点运行异常,请前往追踪查看日志。", "nodes.common.errorHandle.tip": "配置异常处理策略,当节点发生异常时触发。", "nodes.common.errorHandle.title": "异常处理", "nodes.common.inputVars": "输入变量", diff --git a/web/i18n/zh-Hant/workflow.json b/web/i18n/zh-Hant/workflow.json index 865d8b66ae..5c7c9cfc95 100644 --- a/web/i18n/zh-Hant/workflow.json +++ b/web/i18n/zh-Hant/workflow.json @@ -433,7 +433,7 @@ "nodes.common.errorHandle.failBranch.title": "失敗分支", "nodes.common.errorHandle.none.desc": "如果發生異常且未得到處理,節點將停止運行", "nodes.common.errorHandle.none.title": "沒有", - "nodes.common.errorHandle.partialSucceeded.tip": "進程中有 {{num}} 個節點運行異常,請前往 tracing 查看日誌。", + "nodes.common.errorHandle.partialSucceeded.tip": "進程中有 {{num}} 個節點運行異常,請前往tracing查看日誌。", "nodes.common.errorHandle.tip": "異常處理策略,當節點遇到異常時觸發。", "nodes.common.errorHandle.title": "錯誤處理", "nodes.common.inputVars": "輸入變數", diff --git a/web/package.json b/web/package.json index 3ce16d8fb0..8bc31dce31 100644 --- a/web/package.json +++ b/web/package.json @@ -56,7 +56,6 @@ "@amplitude/analytics-browser": "catalog:", "@amplitude/plugin-session-replay-browser": "catalog:", "@base-ui/react": "catalog:", - "@date-fns/tz": "catalog:", "@emoji-mart/data": "catalog:", "@floating-ui/react": "catalog:", "@formatjs/intl-localematcher": "catalog:", @@ -91,7 +90,6 @@ "cmdk": "catalog:", "copy-to-clipboard": "catalog:", "cron-parser": "catalog:", - "date-fns": "catalog:", "dayjs": "catalog:", "decimal.js": "catalog:", "dompurify": "catalog:", From 9a47bb2f80946a14838cc4906379860713c4836b Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 14 Apr 2026 16:16:19 +0800 Subject: [PATCH 05/44] fix: doc modal hidden by config modal (#35157) --- web/app/components/plugins/readme-panel/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/app/components/plugins/readme-panel/index.tsx b/web/app/components/plugins/readme-panel/index.tsx index 516ef63415..182da360c4 100644 --- a/web/app/components/plugins/readme-panel/index.tsx +++ b/web/app/components/plugins/readme-panel/index.tsx @@ -87,7 +87,7 @@ const ReadmePanel: FC = () => { const portalContent = showType === ReadmeShowType.drawer ? ( -
+
{
) : ( -
+
Date: Tue, 14 Apr 2026 11:18:30 +0200 Subject: [PATCH 06/44] refactor: replace bare dict with dict[str, Any] in model provider service and core modules (#35122) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: Asuka Minato --- .../agent/output_parser/cot_output_parser.py | 4 +-- api/core/schemas/resolver.py | 2 +- api/services/model_provider_service.py | 27 +++++++++++++------ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/api/core/agent/output_parser/cot_output_parser.py b/api/core/agent/output_parser/cot_output_parser.py index 46c1f1230d..8cccd2be6d 100644 --- a/api/core/agent/output_parser/cot_output_parser.py +++ b/api/core/agent/output_parser/cot_output_parser.py @@ -1,7 +1,7 @@ import json import re from collections.abc import Generator -from typing import Union +from typing import Any, Union from graphon.model_runtime.entities.llm_entities import LLMResultChunk @@ -11,7 +11,7 @@ from core.agent.entities import AgentScratchpadUnit class CotAgentOutputParser: @classmethod def handle_react_stream_output( - cls, llm_response: Generator[LLMResultChunk, None, None], usage_dict: dict + cls, llm_response: Generator[LLMResultChunk, None, None], usage_dict: dict[str, Any] ) -> Generator[Union[str, AgentScratchpadUnit.Action], None, None]: def parse_action(action) -> Union[str, AgentScratchpadUnit.Action]: action_name = None diff --git a/api/core/schemas/resolver.py b/api/core/schemas/resolver.py index 6e26664ac2..e267c1abd9 100644 --- a/api/core/schemas/resolver.py +++ b/api/core/schemas/resolver.py @@ -254,7 +254,7 @@ def resolve_dify_schema_refs( return resolver.resolve(schema) -def _remove_metadata_fields(schema: dict) -> dict: +def _remove_metadata_fields(schema: dict[str, Any]) -> dict[str, Any]: """ Remove metadata fields from schema that shouldn't be included in resolved output diff --git a/api/services/model_provider_service.py b/api/services/model_provider_service.py index 3f37c9b176..bf208c9bc7 100644 --- a/api/services/model_provider_service.py +++ b/api/services/model_provider_service.py @@ -1,4 +1,5 @@ import logging +from typing import Any from graphon.model_runtime.entities.model_entities import ModelType, ParameterRule @@ -168,7 +169,9 @@ class ModelProviderService: model_name=model, ) - def get_provider_credential(self, tenant_id: str, provider: str, credential_id: str | None = None) -> dict | None: + def get_provider_credential( + self, tenant_id: str, provider: str, credential_id: str | None = None + ) -> dict[str, Any] | None: """ get provider credentials. @@ -180,7 +183,7 @@ class ModelProviderService: provider_configuration = self._get_provider_configuration(tenant_id, provider) return provider_configuration.get_provider_credential(credential_id=credential_id) - def validate_provider_credentials(self, tenant_id: str, provider: str, credentials: dict): + def validate_provider_credentials(self, tenant_id: str, provider: str, credentials: dict[str, Any]): """ validate provider credentials before saving. @@ -192,7 +195,7 @@ class ModelProviderService: provider_configuration.validate_provider_credentials(credentials) def create_provider_credential( - self, tenant_id: str, provider: str, credentials: dict, credential_name: str | None + self, tenant_id: str, provider: str, credentials: dict[str, Any], credential_name: str | None ) -> None: """ Create and save new provider credentials. @@ -210,7 +213,7 @@ class ModelProviderService: self, tenant_id: str, provider: str, - credentials: dict, + credentials: dict[str, Any], credential_id: str, credential_name: str | None, ) -> None: @@ -254,7 +257,7 @@ class ModelProviderService: def get_model_credential( self, tenant_id: str, provider: str, model_type: str, model: str, credential_id: str | None - ) -> dict | None: + ) -> dict[str, Any] | None: """ Retrieve model-specific credentials. @@ -270,7 +273,9 @@ class ModelProviderService: model_type=ModelType.value_of(model_type), model=model, credential_id=credential_id ) - def validate_model_credentials(self, tenant_id: str, provider: str, model_type: str, model: str, credentials: dict): + def validate_model_credentials( + self, tenant_id: str, provider: str, model_type: str, model: str, credentials: dict[str, Any] + ): """ validate model credentials. @@ -287,7 +292,13 @@ class ModelProviderService: ) def create_model_credential( - self, tenant_id: str, provider: str, model_type: str, model: str, credentials: dict, credential_name: str | None + self, + tenant_id: str, + provider: str, + model_type: str, + model: str, + credentials: dict[str, Any], + credential_name: str | None, ) -> None: """ create and save model credentials. @@ -314,7 +325,7 @@ class ModelProviderService: provider: str, model_type: str, model: str, - credentials: dict, + credentials: dict[str, Any], credential_id: str, credential_name: str | None, ) -> None: From 736880e046581ca5b0b65441cee1c1e96cc5caac Mon Sep 17 00:00:00 2001 From: Blackoutta <37723456+Blackoutta@users.noreply.github.com> Date: Tue, 14 Apr 2026 17:31:41 +0800 Subject: [PATCH 07/44] feat: support configurable redis key prefix (#35139) --- api/.env.example | 3 + api/configs/middleware/cache/redis_config.py | 5 + api/extensions/ext_celery.py | 24 +- api/extensions/ext_redis.py | 217 ++++++++++++------ api/extensions/redis_names.py | 32 +++ api/libs/broadcast_channel/redis/channel.py | 6 +- .../redis/sharded_channel.py | 6 +- .../redis/streams_channel.py | 3 +- api/libs/db_migration_lock.py | 5 +- api/tests/integration_tests/.env.example | 1 + .../unit_tests/configs/test_dify_config.py | 35 +++ .../unit_tests/extensions/test_celery_ssl.py | 87 +++++++ .../extensions/test_pubsub_channel.py | 2 + api/tests/unit_tests/extensions/test_redis.py | 101 +++++++- .../redis/test_channel_unit_tests.py | 44 ++++ .../redis/test_streams_channel_unit_tests.py | 20 ++ docker/.env.example | 3 + docker/README.md | 1 + docker/docker-compose.yaml | 1 + 19 files changed, 522 insertions(+), 74 deletions(-) create mode 100644 api/extensions/redis_names.py diff --git a/api/.env.example b/api/.env.example index a04a18944a..beb820e797 100644 --- a/api/.env.example +++ b/api/.env.example @@ -57,6 +57,9 @@ REDIS_SSL_CERTFILE= REDIS_SSL_KEYFILE= # Path to client private key file for SSL authentication REDIS_DB=0 +# Optional global prefix for Redis keys, topics, streams, and Celery Redis transport artifacts. +# Leave empty to preserve current unprefixed behavior. +REDIS_KEY_PREFIX= # redis Sentinel configuration. REDIS_USE_SENTINEL=false diff --git a/api/configs/middleware/cache/redis_config.py b/api/configs/middleware/cache/redis_config.py index b49275758a..2def0a0d4e 100644 --- a/api/configs/middleware/cache/redis_config.py +++ b/api/configs/middleware/cache/redis_config.py @@ -32,6 +32,11 @@ class RedisConfig(BaseSettings): default=0, ) + REDIS_KEY_PREFIX: str = Field( + description="Optional global prefix for Redis keys, topics, and transport artifacts", + default="", + ) + REDIS_USE_SSL: bool = Field( description="Enable SSL/TLS for the Redis connection", default=False, diff --git a/api/extensions/ext_celery.py b/api/extensions/ext_celery.py index 86b0550187..340f514fcc 100644 --- a/api/extensions/ext_celery.py +++ b/api/extensions/ext_celery.py @@ -9,6 +9,7 @@ from typing_extensions import TypedDict from configs import dify_config from dify_app import DifyApp +from extensions.redis_names import normalize_redis_key_prefix class _CelerySentinelKwargsDict(TypedDict): @@ -16,9 +17,10 @@ class _CelerySentinelKwargsDict(TypedDict): password: str | None -class CelerySentinelTransportDict(TypedDict): +class CelerySentinelTransportDict(TypedDict, total=False): master_name: str | None sentinel_kwargs: _CelerySentinelKwargsDict + global_keyprefix: str class CelerySSLOptionsDict(TypedDict): @@ -61,15 +63,31 @@ def get_celery_ssl_options() -> CelerySSLOptionsDict | None: def get_celery_broker_transport_options() -> CelerySentinelTransportDict | dict[str, Any]: """Get broker transport options (e.g. Redis Sentinel) for Celery connections.""" + transport_options: CelerySentinelTransportDict | dict[str, Any] if dify_config.CELERY_USE_SENTINEL: - return CelerySentinelTransportDict( + transport_options = CelerySentinelTransportDict( master_name=dify_config.CELERY_SENTINEL_MASTER_NAME, sentinel_kwargs=_CelerySentinelKwargsDict( socket_timeout=dify_config.CELERY_SENTINEL_SOCKET_TIMEOUT, password=dify_config.CELERY_SENTINEL_PASSWORD, ), ) - return {} + else: + transport_options = {} + + global_keyprefix = get_celery_redis_global_keyprefix() + if global_keyprefix: + transport_options["global_keyprefix"] = global_keyprefix + + return transport_options + + +def get_celery_redis_global_keyprefix() -> str | None: + """Return the Redis transport prefix for Celery when namespace isolation is enabled.""" + normalized_prefix = normalize_redis_key_prefix(dify_config.REDIS_KEY_PREFIX) + if not normalized_prefix: + return None + return f"{normalized_prefix}:" def init_app(app: DifyApp) -> Celery: diff --git a/api/extensions/ext_redis.py b/api/extensions/ext_redis.py index 20f05b8b9e..9f7f73765e 100644 --- a/api/extensions/ext_redis.py +++ b/api/extensions/ext_redis.py @@ -3,7 +3,7 @@ import logging import ssl from collections.abc import Callable from datetime import timedelta -from typing import TYPE_CHECKING, Any, Union +from typing import Any, Union, cast import redis from redis import RedisError @@ -18,17 +18,26 @@ from typing_extensions import TypedDict from configs import dify_config from dify_app import DifyApp +from extensions.redis_names import ( + normalize_redis_key_prefix, + serialize_redis_name, + serialize_redis_name_arg, + serialize_redis_name_args, +) from libs.broadcast_channel.channel import BroadcastChannel as BroadcastChannelProtocol from libs.broadcast_channel.redis.channel import BroadcastChannel as RedisBroadcastChannel from libs.broadcast_channel.redis.sharded_channel import ShardedRedisBroadcastChannel from libs.broadcast_channel.redis.streams_channel import StreamsBroadcastChannel -if TYPE_CHECKING: - from redis.lock import Lock - logger = logging.getLogger(__name__) +_normalize_redis_key_prefix = normalize_redis_key_prefix +_serialize_redis_name = serialize_redis_name +_serialize_redis_name_arg = serialize_redis_name_arg +_serialize_redis_name_args = serialize_redis_name_args + + class RedisClientWrapper: """ A wrapper class for the Redis client that addresses the issue where the global @@ -59,68 +68,148 @@ class RedisClientWrapper: if self._client is None: self._client = client - if TYPE_CHECKING: - # Type hints for IDE support and static analysis - # These are not executed at runtime but provide type information - def get(self, name: str | bytes) -> Any: ... - - def set( - self, - name: str | bytes, - value: Any, - ex: int | None = None, - px: int | None = None, - nx: bool = False, - xx: bool = False, - keepttl: bool = False, - get: bool = False, - exat: int | None = None, - pxat: int | None = None, - ) -> Any: ... - - def setex(self, name: str | bytes, time: int | timedelta, value: Any) -> Any: ... - def setnx(self, name: str | bytes, value: Any) -> Any: ... - def delete(self, *names: str | bytes) -> Any: ... - def incr(self, name: str | bytes, amount: int = 1) -> Any: ... - def expire( - self, - name: str | bytes, - time: int | timedelta, - nx: bool = False, - xx: bool = False, - gt: bool = False, - lt: bool = False, - ) -> Any: ... - def lock( - self, - name: str, - timeout: float | None = None, - sleep: float = 0.1, - blocking: bool = True, - blocking_timeout: float | None = None, - thread_local: bool = True, - ) -> Lock: ... - def zadd( - self, - name: str | bytes, - mapping: dict[str | bytes | int | float, float | int | str | bytes], - nx: bool = False, - xx: bool = False, - ch: bool = False, - incr: bool = False, - gt: bool = False, - lt: bool = False, - ) -> Any: ... - def zremrangebyscore(self, name: str | bytes, min: float | str, max: float | str) -> Any: ... - def zcard(self, name: str | bytes) -> Any: ... - def getdel(self, name: str | bytes) -> Any: ... - def pubsub(self) -> PubSub: ... - def pipeline(self, transaction: bool = True, shard_hint: str | None = None) -> Any: ... - - def __getattr__(self, item: str) -> Any: + def _require_client(self) -> redis.Redis | RedisCluster: if self._client is None: raise RuntimeError("Redis client is not initialized. Call init_app first.") - return getattr(self._client, item) + return self._client + + def _get_prefix(self) -> str: + return dify_config.REDIS_KEY_PREFIX + + def get(self, name: str | bytes) -> Any: + return self._require_client().get(_serialize_redis_name_arg(name, self._get_prefix())) + + def set( + self, + name: str | bytes, + value: Any, + ex: int | None = None, + px: int | None = None, + nx: bool = False, + xx: bool = False, + keepttl: bool = False, + get: bool = False, + exat: int | None = None, + pxat: int | None = None, + ) -> Any: + return self._require_client().set( + _serialize_redis_name_arg(name, self._get_prefix()), + value, + ex=ex, + px=px, + nx=nx, + xx=xx, + keepttl=keepttl, + get=get, + exat=exat, + pxat=pxat, + ) + + def setex(self, name: str | bytes, time: int | timedelta, value: Any) -> Any: + return self._require_client().setex(_serialize_redis_name_arg(name, self._get_prefix()), time, value) + + def setnx(self, name: str | bytes, value: Any) -> Any: + return self._require_client().setnx(_serialize_redis_name_arg(name, self._get_prefix()), value) + + def delete(self, *names: str | bytes) -> Any: + return self._require_client().delete(*_serialize_redis_name_args(names, self._get_prefix())) + + def incr(self, name: str | bytes, amount: int = 1) -> Any: + return self._require_client().incr(_serialize_redis_name_arg(name, self._get_prefix()), amount) + + def expire( + self, + name: str | bytes, + time: int | timedelta, + nx: bool = False, + xx: bool = False, + gt: bool = False, + lt: bool = False, + ) -> Any: + return self._require_client().expire( + _serialize_redis_name_arg(name, self._get_prefix()), + time, + nx=nx, + xx=xx, + gt=gt, + lt=lt, + ) + + def exists(self, *names: str | bytes) -> Any: + return self._require_client().exists(*_serialize_redis_name_args(names, self._get_prefix())) + + def ttl(self, name: str | bytes) -> Any: + return self._require_client().ttl(_serialize_redis_name_arg(name, self._get_prefix())) + + def getdel(self, name: str | bytes) -> Any: + return self._require_client().getdel(_serialize_redis_name_arg(name, self._get_prefix())) + + def lock( + self, + name: str, + timeout: float | None = None, + sleep: float = 0.1, + blocking: bool = True, + blocking_timeout: float | None = None, + thread_local: bool = True, + ) -> Any: + return self._require_client().lock( + _serialize_redis_name(name, self._get_prefix()), + timeout=timeout, + sleep=sleep, + blocking=blocking, + blocking_timeout=blocking_timeout, + thread_local=thread_local, + ) + + def hset(self, name: str | bytes, *args: Any, **kwargs: Any) -> Any: + return self._require_client().hset(_serialize_redis_name_arg(name, self._get_prefix()), *args, **kwargs) + + def hgetall(self, name: str | bytes) -> Any: + return self._require_client().hgetall(_serialize_redis_name_arg(name, self._get_prefix())) + + def hdel(self, name: str | bytes, *keys: str | bytes) -> Any: + return self._require_client().hdel(_serialize_redis_name_arg(name, self._get_prefix()), *keys) + + def hlen(self, name: str | bytes) -> Any: + return self._require_client().hlen(_serialize_redis_name_arg(name, self._get_prefix())) + + def zadd( + self, + name: str | bytes, + mapping: dict[str | bytes | int | float, float | int | str | bytes], + nx: bool = False, + xx: bool = False, + ch: bool = False, + incr: bool = False, + gt: bool = False, + lt: bool = False, + ) -> Any: + return self._require_client().zadd( + _serialize_redis_name_arg(name, self._get_prefix()), + cast(Any, mapping), + nx=nx, + xx=xx, + ch=ch, + incr=incr, + gt=gt, + lt=lt, + ) + + def zremrangebyscore(self, name: str | bytes, min: float | str, max: float | str) -> Any: + return self._require_client().zremrangebyscore(_serialize_redis_name_arg(name, self._get_prefix()), min, max) + + def zcard(self, name: str | bytes) -> Any: + return self._require_client().zcard(_serialize_redis_name_arg(name, self._get_prefix())) + + def pubsub(self) -> PubSub: + return self._require_client().pubsub() + + def pipeline(self, transaction: bool = True, shard_hint: str | None = None) -> Any: + return self._require_client().pipeline(transaction=transaction, shard_hint=shard_hint) + + def __getattr__(self, item: str) -> Any: + return getattr(self._require_client(), item) redis_client: RedisClientWrapper = RedisClientWrapper() diff --git a/api/extensions/redis_names.py b/api/extensions/redis_names.py new file mode 100644 index 0000000000..9e63416daf --- /dev/null +++ b/api/extensions/redis_names.py @@ -0,0 +1,32 @@ +from configs import dify_config + + +def normalize_redis_key_prefix(prefix: str | None) -> str: + """Normalize the configured Redis key prefix for consistent runtime use.""" + if prefix is None: + return "" + return prefix.strip() + + +def get_redis_key_prefix() -> str: + """Read and normalize the current Redis key prefix from config.""" + return normalize_redis_key_prefix(dify_config.REDIS_KEY_PREFIX) + + +def serialize_redis_name(name: str, prefix: str | None = None) -> str: + """Convert a logical Redis name into the physical name used in Redis.""" + normalized_prefix = get_redis_key_prefix() if prefix is None else normalize_redis_key_prefix(prefix) + if not normalized_prefix: + return name + return f"{normalized_prefix}:{name}" + + +def serialize_redis_name_arg(name: str | bytes, prefix: str | None = None) -> str | bytes: + """Prefix string Redis names while preserving bytes inputs unchanged.""" + if isinstance(name, bytes): + return name + return serialize_redis_name(name, prefix) + + +def serialize_redis_name_args(names: tuple[str | bytes, ...], prefix: str | None = None) -> tuple[str | bytes, ...]: + return tuple(serialize_redis_name_arg(name, prefix) for name in names) diff --git a/api/libs/broadcast_channel/redis/channel.py b/api/libs/broadcast_channel/redis/channel.py index 36aa1cd3e8..b76a23eb3c 100644 --- a/api/libs/broadcast_channel/redis/channel.py +++ b/api/libs/broadcast_channel/redis/channel.py @@ -2,6 +2,7 @@ from __future__ import annotations from typing import Any +from extensions.redis_names import serialize_redis_name from libs.broadcast_channel.channel import Producer, Subscriber, Subscription from redis import Redis, RedisCluster @@ -32,12 +33,13 @@ class Topic: def __init__(self, redis_client: Redis | RedisCluster, topic: str): self._client = redis_client self._topic = topic + self._redis_topic = serialize_redis_name(topic) def as_producer(self) -> Producer: return self def publish(self, payload: bytes) -> None: - self._client.publish(self._topic, payload) + self._client.publish(self._redis_topic, payload) def as_subscriber(self) -> Subscriber: return self @@ -46,7 +48,7 @@ class Topic: return _RedisSubscription( client=self._client, pubsub=self._client.pubsub(), - topic=self._topic, + topic=self._redis_topic, ) diff --git a/api/libs/broadcast_channel/redis/sharded_channel.py b/api/libs/broadcast_channel/redis/sharded_channel.py index dddc92d099..919d8d622e 100644 --- a/api/libs/broadcast_channel/redis/sharded_channel.py +++ b/api/libs/broadcast_channel/redis/sharded_channel.py @@ -2,6 +2,7 @@ from __future__ import annotations from typing import Any +from extensions.redis_names import serialize_redis_name from libs.broadcast_channel.channel import Producer, Subscriber, Subscription from redis import Redis, RedisCluster @@ -30,12 +31,13 @@ class ShardedTopic: def __init__(self, redis_client: Redis | RedisCluster, topic: str): self._client = redis_client self._topic = topic + self._redis_topic = serialize_redis_name(topic) def as_producer(self) -> Producer: return self def publish(self, payload: bytes) -> None: - self._client.spublish(self._topic, payload) # type: ignore[attr-defined,union-attr] + self._client.spublish(self._redis_topic, payload) # type: ignore[attr-defined,union-attr] def as_subscriber(self) -> Subscriber: return self @@ -44,7 +46,7 @@ class ShardedTopic: return _RedisShardedSubscription( client=self._client, pubsub=self._client.pubsub(), - topic=self._topic, + topic=self._redis_topic, ) diff --git a/api/libs/broadcast_channel/redis/streams_channel.py b/api/libs/broadcast_channel/redis/streams_channel.py index 983f785027..55ff6cd4f9 100644 --- a/api/libs/broadcast_channel/redis/streams_channel.py +++ b/api/libs/broadcast_channel/redis/streams_channel.py @@ -6,6 +6,7 @@ import threading from collections.abc import Iterator from typing import Self +from extensions.redis_names import serialize_redis_name from libs.broadcast_channel.channel import Producer, Subscriber, Subscription from libs.broadcast_channel.exc import SubscriptionClosedError from redis import Redis, RedisCluster @@ -35,7 +36,7 @@ class StreamsTopic: def __init__(self, redis_client: Redis | RedisCluster, topic: str, *, retention_seconds: int = 600): self._client = redis_client self._topic = topic - self._key = f"stream:{topic}" + self._key = serialize_redis_name(f"stream:{topic}") self._retention_seconds = retention_seconds self.max_length = 5000 diff --git a/api/libs/db_migration_lock.py b/api/libs/db_migration_lock.py index ca8956e397..b5fe38342a 100644 --- a/api/libs/db_migration_lock.py +++ b/api/libs/db_migration_lock.py @@ -103,7 +103,10 @@ class DbMigrationAutoRenewLock: timeout=self._ttl_seconds, thread_local=False, ) - acquired = bool(self._lock.acquire(*args, **kwargs)) + lock = self._lock + if lock is None: + raise RuntimeError("Redis lock initialization failed.") + acquired = bool(lock.acquire(*args, **kwargs)) self._acquired = acquired if acquired: self._start_heartbeat() diff --git a/api/tests/integration_tests/.env.example b/api/tests/integration_tests/.env.example index f84d39aeb5..c07ab6d6bf 100644 --- a/api/tests/integration_tests/.env.example +++ b/api/tests/integration_tests/.env.example @@ -33,6 +33,7 @@ REDIS_USERNAME= REDIS_PASSWORD=difyai123456 REDIS_USE_SSL=false REDIS_DB=0 +REDIS_KEY_PREFIX= # PostgreSQL database configuration DB_USERNAME=postgres diff --git a/api/tests/unit_tests/configs/test_dify_config.py b/api/tests/unit_tests/configs/test_dify_config.py index 3089750c3e..bad246a4bb 100644 --- a/api/tests/unit_tests/configs/test_dify_config.py +++ b/api/tests/unit_tests/configs/test_dify_config.py @@ -236,6 +236,41 @@ def test_pubsub_redis_url_required_when_default_unavailable(monkeypatch: pytest. _ = DifyConfig().normalized_pubsub_redis_url +def test_dify_config_exposes_redis_key_prefix_default(monkeypatch: pytest.MonkeyPatch): + os.environ.clear() + + monkeypatch.setenv("CONSOLE_API_URL", "https://example.com") + monkeypatch.setenv("CONSOLE_WEB_URL", "https://example.com") + monkeypatch.setenv("DB_TYPE", "postgresql") + monkeypatch.setenv("DB_USERNAME", "postgres") + monkeypatch.setenv("DB_PASSWORD", "postgres") + monkeypatch.setenv("DB_HOST", "localhost") + monkeypatch.setenv("DB_PORT", "5432") + monkeypatch.setenv("DB_DATABASE", "dify") + + config = DifyConfig(_env_file=None) + + assert config.REDIS_KEY_PREFIX == "" + + +def test_dify_config_reads_redis_key_prefix_from_env(monkeypatch: pytest.MonkeyPatch): + os.environ.clear() + + monkeypatch.setenv("CONSOLE_API_URL", "https://example.com") + monkeypatch.setenv("CONSOLE_WEB_URL", "https://example.com") + monkeypatch.setenv("DB_TYPE", "postgresql") + monkeypatch.setenv("DB_USERNAME", "postgres") + monkeypatch.setenv("DB_PASSWORD", "postgres") + monkeypatch.setenv("DB_HOST", "localhost") + monkeypatch.setenv("DB_PORT", "5432") + monkeypatch.setenv("DB_DATABASE", "dify") + monkeypatch.setenv("REDIS_KEY_PREFIX", "enterprise-a") + + config = DifyConfig(_env_file=None) + + assert config.REDIS_KEY_PREFIX == "enterprise-a" + + @pytest.mark.parametrize( ("broker_url", "expected_host", "expected_port", "expected_username", "expected_password", "expected_db"), [ diff --git a/api/tests/unit_tests/extensions/test_celery_ssl.py b/api/tests/unit_tests/extensions/test_celery_ssl.py index 81687ce5f8..366e45d86d 100644 --- a/api/tests/unit_tests/extensions/test_celery_ssl.py +++ b/api/tests/unit_tests/extensions/test_celery_ssl.py @@ -7,6 +7,47 @@ from unittest.mock import MagicMock, patch class TestCelerySSLConfiguration: """Test suite for Celery SSL configuration.""" + def test_get_celery_broker_transport_options_includes_global_keyprefix_for_redis(self): + mock_config = MagicMock() + mock_config.CELERY_USE_SENTINEL = False + mock_config.REDIS_KEY_PREFIX = "enterprise-a" + + with patch("extensions.ext_celery.dify_config", mock_config): + from extensions.ext_celery import get_celery_broker_transport_options + + result = get_celery_broker_transport_options() + + assert result["global_keyprefix"] == "enterprise-a:" + + def test_get_celery_broker_transport_options_omits_global_keyprefix_when_prefix_empty(self): + mock_config = MagicMock() + mock_config.CELERY_USE_SENTINEL = False + mock_config.REDIS_KEY_PREFIX = " " + + with patch("extensions.ext_celery.dify_config", mock_config): + from extensions.ext_celery import get_celery_broker_transport_options + + result = get_celery_broker_transport_options() + + assert "global_keyprefix" not in result + + def test_get_celery_broker_transport_options_keeps_sentinel_and_adds_global_keyprefix(self): + mock_config = MagicMock() + mock_config.CELERY_USE_SENTINEL = True + mock_config.CELERY_SENTINEL_MASTER_NAME = "mymaster" + mock_config.CELERY_SENTINEL_SOCKET_TIMEOUT = 0.1 + mock_config.CELERY_SENTINEL_PASSWORD = "secret" + mock_config.REDIS_KEY_PREFIX = "enterprise-a" + + with patch("extensions.ext_celery.dify_config", mock_config): + from extensions.ext_celery import get_celery_broker_transport_options + + result = get_celery_broker_transport_options() + + assert result["master_name"] == "mymaster" + assert result["sentinel_kwargs"]["password"] == "secret" + assert result["global_keyprefix"] == "enterprise-a:" + def test_get_celery_ssl_options_when_ssl_disabled(self): """Test SSL options when BROKER_USE_SSL is False.""" from configs import DifyConfig @@ -151,3 +192,49 @@ class TestCelerySSLConfiguration: # Check that SSL is also applied to Redis backend assert "redis_backend_use_ssl" in celery_app.conf assert celery_app.conf["redis_backend_use_ssl"] is not None + + def test_celery_init_applies_global_keyprefix_to_broker_and_backend_transport(self): + mock_config = MagicMock() + mock_config.BROKER_USE_SSL = False + mock_config.REDIS_KEY_PREFIX = "enterprise-a" + mock_config.HUMAN_INPUT_TIMEOUT_TASK_INTERVAL = 1 + mock_config.CELERY_BROKER_URL = "redis://localhost:6379/0" + mock_config.CELERY_BACKEND = "redis" + mock_config.CELERY_RESULT_BACKEND = "redis://localhost:6379/0" + mock_config.CELERY_USE_SENTINEL = False + mock_config.LOG_FORMAT = "%(message)s" + mock_config.LOG_TZ = "UTC" + mock_config.LOG_FILE = None + mock_config.CELERY_TASK_ANNOTATIONS = {} + + mock_config.CELERY_BEAT_SCHEDULER_TIME = 1 + mock_config.ENABLE_CLEAN_EMBEDDING_CACHE_TASK = False + mock_config.ENABLE_CLEAN_UNUSED_DATASETS_TASK = False + mock_config.ENABLE_CREATE_TIDB_SERVERLESS_TASK = False + mock_config.ENABLE_UPDATE_TIDB_SERVERLESS_STATUS_TASK = False + mock_config.ENABLE_CLEAN_MESSAGES = False + mock_config.ENABLE_MAIL_CLEAN_DOCUMENT_NOTIFY_TASK = False + mock_config.ENABLE_DATASETS_QUEUE_MONITOR = False + mock_config.ENABLE_HUMAN_INPUT_TIMEOUT_TASK = False + mock_config.ENABLE_CHECK_UPGRADABLE_PLUGIN_TASK = False + mock_config.MARKETPLACE_ENABLED = False + mock_config.WORKFLOW_LOG_CLEANUP_ENABLED = False + mock_config.ENABLE_WORKFLOW_RUN_CLEANUP_TASK = False + mock_config.ENABLE_WORKFLOW_SCHEDULE_POLLER_TASK = False + mock_config.WORKFLOW_SCHEDULE_POLLER_INTERVAL = 1 + mock_config.ENABLE_TRIGGER_PROVIDER_REFRESH_TASK = False + mock_config.TRIGGER_PROVIDER_REFRESH_INTERVAL = 15 + mock_config.ENABLE_API_TOKEN_LAST_USED_UPDATE_TASK = False + mock_config.API_TOKEN_LAST_USED_UPDATE_INTERVAL = 30 + mock_config.ENTERPRISE_ENABLED = False + mock_config.ENTERPRISE_TELEMETRY_ENABLED = False + + with patch("extensions.ext_celery.dify_config", mock_config): + from dify_app import DifyApp + from extensions.ext_celery import init_app + + app = DifyApp(__name__) + celery_app = init_app(app) + + assert celery_app.conf["broker_transport_options"]["global_keyprefix"] == "enterprise-a:" + assert celery_app.conf["result_backend_transport_options"]["global_keyprefix"] == "enterprise-a:" diff --git a/api/tests/unit_tests/extensions/test_pubsub_channel.py b/api/tests/unit_tests/extensions/test_pubsub_channel.py index a5b41a7266..926c406ad4 100644 --- a/api/tests/unit_tests/extensions/test_pubsub_channel.py +++ b/api/tests/unit_tests/extensions/test_pubsub_channel.py @@ -6,6 +6,7 @@ from libs.broadcast_channel.redis.sharded_channel import ShardedRedisBroadcastCh def test_get_pubsub_broadcast_channel_defaults_to_pubsub(monkeypatch): monkeypatch.setattr(dify_config, "PUBSUB_REDIS_CHANNEL_TYPE", "pubsub") + monkeypatch.setattr(ext_redis, "_pubsub_redis_client", object()) channel = ext_redis.get_pubsub_broadcast_channel() @@ -14,6 +15,7 @@ def test_get_pubsub_broadcast_channel_defaults_to_pubsub(monkeypatch): def test_get_pubsub_broadcast_channel_sharded(monkeypatch): monkeypatch.setattr(dify_config, "PUBSUB_REDIS_CHANNEL_TYPE", "sharded") + monkeypatch.setattr(ext_redis, "_pubsub_redis_client", object()) channel = ext_redis.get_pubsub_broadcast_channel() diff --git a/api/tests/unit_tests/extensions/test_redis.py b/api/tests/unit_tests/extensions/test_redis.py index 5e9be4ab9b..21248439bf 100644 --- a/api/tests/unit_tests/extensions/test_redis.py +++ b/api/tests/unit_tests/extensions/test_redis.py @@ -1,12 +1,15 @@ -from unittest.mock import patch +from unittest.mock import MagicMock, patch from redis import RedisError from redis.retry import Retry from extensions.ext_redis import ( + RedisClientWrapper, _get_base_redis_params, _get_cluster_connection_health_params, _get_connection_health_params, + _normalize_redis_key_prefix, + _serialize_redis_name, redis_fallback, ) @@ -123,3 +126,99 @@ class TestRedisFallback: assert test_func.__name__ == "test_func" assert test_func.__doc__ == "Test function docstring" + + +class TestRedisKeyPrefixHelpers: + def test_normalize_redis_key_prefix_trims_whitespace(self): + assert _normalize_redis_key_prefix(" enterprise-a ") == "enterprise-a" + + def test_normalize_redis_key_prefix_treats_whitespace_only_as_empty(self): + assert _normalize_redis_key_prefix(" ") == "" + + def test_serialize_redis_name_returns_original_when_prefix_empty(self): + assert _serialize_redis_name("model_lb_index:test", "") == "model_lb_index:test" + + def test_serialize_redis_name_adds_single_colon_separator(self): + assert _serialize_redis_name("model_lb_index:test", "enterprise-a") == "enterprise-a:model_lb_index:test" + + +class TestRedisClientWrapperKeyPrefix: + def test_wrapper_get_prefixes_string_keys(self): + mock_client = MagicMock() + wrapper = RedisClientWrapper() + wrapper.initialize(mock_client) + + with patch("extensions.ext_redis.dify_config") as mock_config: + mock_config.REDIS_KEY_PREFIX = "enterprise-a" + + wrapper.get("oauth_state:abc") + + mock_client.get.assert_called_once_with("enterprise-a:oauth_state:abc") + + def test_wrapper_delete_prefixes_multiple_keys(self): + mock_client = MagicMock() + wrapper = RedisClientWrapper() + wrapper.initialize(mock_client) + + with patch("extensions.ext_redis.dify_config") as mock_config: + mock_config.REDIS_KEY_PREFIX = "enterprise-a" + + wrapper.delete("key:a", "key:b") + + mock_client.delete.assert_called_once_with("enterprise-a:key:a", "enterprise-a:key:b") + + def test_wrapper_lock_prefixes_lock_name(self): + mock_client = MagicMock() + wrapper = RedisClientWrapper() + wrapper.initialize(mock_client) + + with patch("extensions.ext_redis.dify_config") as mock_config: + mock_config.REDIS_KEY_PREFIX = "enterprise-a" + + wrapper.lock("resource-lock", timeout=10) + + mock_client.lock.assert_called_once() + args, kwargs = mock_client.lock.call_args + assert args == ("enterprise-a:resource-lock",) + assert kwargs["timeout"] == 10 + + def test_wrapper_hash_operations_prefix_key_name(self): + mock_client = MagicMock() + wrapper = RedisClientWrapper() + wrapper.initialize(mock_client) + + with patch("extensions.ext_redis.dify_config") as mock_config: + mock_config.REDIS_KEY_PREFIX = "enterprise-a" + + wrapper.hset("hash:key", "field", "value") + wrapper.hgetall("hash:key") + + mock_client.hset.assert_called_once_with("enterprise-a:hash:key", "field", "value") + mock_client.hgetall.assert_called_once_with("enterprise-a:hash:key") + + def test_wrapper_zadd_prefixes_sorted_set_name(self): + mock_client = MagicMock() + wrapper = RedisClientWrapper() + wrapper.initialize(mock_client) + + with patch("extensions.ext_redis.dify_config") as mock_config: + mock_config.REDIS_KEY_PREFIX = "enterprise-a" + + wrapper.zadd("zset:key", {"member": 1}) + + mock_client.zadd.assert_called_once() + args, kwargs = mock_client.zadd.call_args + assert args == ("enterprise-a:zset:key", {"member": 1}) + assert kwargs["nx"] is False + + def test_wrapper_preserves_keys_when_prefix_is_empty(self): + mock_client = MagicMock() + wrapper = RedisClientWrapper() + wrapper.initialize(mock_client) + + with patch("extensions.ext_redis.dify_config") as mock_config: + mock_config.REDIS_KEY_PREFIX = " " + + wrapper.get("plain:key") + + mock_client.get.assert_called_once_with("plain:key") diff --git a/api/tests/unit_tests/libs/broadcast_channel/redis/test_channel_unit_tests.py b/api/tests/unit_tests/libs/broadcast_channel/redis/test_channel_unit_tests.py index 460374b6f6..8bef01c1ed 100644 --- a/api/tests/unit_tests/libs/broadcast_channel/redis/test_channel_unit_tests.py +++ b/api/tests/unit_tests/libs/broadcast_channel/redis/test_channel_unit_tests.py @@ -139,6 +139,28 @@ class TestTopic: mock_redis_client.publish.assert_called_once_with("test-topic", payload) + def test_publish_prefixes_regular_topic(self, mock_redis_client: MagicMock): + with patch("extensions.redis_names.dify_config") as mock_config: + mock_config.REDIS_KEY_PREFIX = "enterprise-a" + topic = Topic(mock_redis_client, "test-topic") + + topic.publish(b"test message") + + mock_redis_client.publish.assert_called_once_with("enterprise-a:test-topic", b"test message") + + def test_subscribe_prefixes_regular_topic(self, mock_redis_client: MagicMock): + with patch("extensions.redis_names.dify_config") as mock_config: + mock_config.REDIS_KEY_PREFIX = "enterprise-a" + topic = Topic(mock_redis_client, "test-topic") + + subscription = topic.subscribe() + try: + subscription._start_if_needed() + finally: + subscription.close() + + mock_redis_client.pubsub.return_value.subscribe.assert_called_once_with("enterprise-a:test-topic") + class TestShardedTopic: """Test cases for the ShardedTopic class.""" @@ -176,6 +198,15 @@ class TestShardedTopic: mock_redis_client.spublish.assert_called_once_with("test-sharded-topic", payload) + def test_publish_prefixes_sharded_topic(self, mock_redis_client: MagicMock): + with patch("extensions.redis_names.dify_config") as mock_config: + mock_config.REDIS_KEY_PREFIX = "enterprise-a" + sharded_topic = ShardedTopic(mock_redis_client, "test-sharded-topic") + + sharded_topic.publish(b"test sharded message") + + mock_redis_client.spublish.assert_called_once_with("enterprise-a:test-sharded-topic", b"test sharded message") + def test_subscribe_returns_sharded_subscription(self, sharded_topic: ShardedTopic, mock_redis_client: MagicMock): """Test that subscribe() returns a _RedisShardedSubscription instance.""" subscription = sharded_topic.subscribe() @@ -185,6 +216,19 @@ class TestShardedTopic: assert subscription._pubsub is mock_redis_client.pubsub.return_value assert subscription._topic == "test-sharded-topic" + def test_subscribe_prefixes_sharded_topic(self, mock_redis_client: MagicMock): + with patch("extensions.redis_names.dify_config") as mock_config: + mock_config.REDIS_KEY_PREFIX = "enterprise-a" + sharded_topic = ShardedTopic(mock_redis_client, "test-sharded-topic") + + subscription = sharded_topic.subscribe() + try: + subscription._start_if_needed() + finally: + subscription.close() + + mock_redis_client.pubsub.return_value.ssubscribe.assert_called_once_with("enterprise-a:test-sharded-topic") + @dataclasses.dataclass(frozen=True) class SubscriptionTestCase: diff --git a/api/tests/unit_tests/libs/broadcast_channel/redis/test_streams_channel_unit_tests.py b/api/tests/unit_tests/libs/broadcast_channel/redis/test_streams_channel_unit_tests.py index 0886b70ee5..fd9e5ca5b3 100644 --- a/api/tests/unit_tests/libs/broadcast_channel/redis/test_streams_channel_unit_tests.py +++ b/api/tests/unit_tests/libs/broadcast_channel/redis/test_streams_channel_unit_tests.py @@ -2,6 +2,7 @@ import threading import time from dataclasses import dataclass from typing import cast +from unittest.mock import patch import pytest @@ -150,6 +151,25 @@ class TestStreamsBroadcastChannel: # Expire called after publish assert fake_redis._expire_calls.get("stream:beta", 0) >= 1 + def test_topic_uses_prefixed_stream_key(self, fake_redis: FakeStreamsRedis): + with patch("extensions.redis_names.dify_config") as mock_config: + mock_config.REDIS_KEY_PREFIX = "enterprise-a" + + topic = StreamsBroadcastChannel(fake_redis, retention_seconds=60).topic("alpha") + + assert topic._topic == "alpha" + assert topic._key == "enterprise-a:stream:alpha" + + def test_publish_uses_prefixed_stream_key(self, fake_redis: FakeStreamsRedis): + with patch("extensions.redis_names.dify_config") as mock_config: + mock_config.REDIS_KEY_PREFIX = "enterprise-a" + topic = StreamsBroadcastChannel(fake_redis, retention_seconds=60).topic("beta") + + topic.publish(b"hello") + + assert fake_redis._store["enterprise-a:stream:beta"][0][1] == {b"data": b"hello"} + assert fake_redis._expire_calls.get("enterprise-a:stream:beta", 0) >= 1 + def test_topic_exposes_self_as_producer_and_subscriber(self, streams_channel: StreamsBroadcastChannel): topic = streams_channel.topic("producer-subscriber") diff --git a/docker/.env.example b/docker/.env.example index 4426a882f1..856b04a3df 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -351,6 +351,9 @@ REDIS_SSL_CERTFILE= REDIS_SSL_KEYFILE= # Path to client private key file for SSL authentication REDIS_DB=0 +# Optional global prefix for Redis keys, topics, streams, and Celery Redis transport artifacts. +# Leave empty to preserve current unprefixed behavior. +REDIS_KEY_PREFIX= # Optional: limit total Redis connections used by API/Worker (unset for default) # Align with API's REDIS_MAX_CONNECTIONS in configs REDIS_MAX_CONNECTIONS= diff --git a/docker/README.md b/docker/README.md index 4c40317f37..3130fa9886 100644 --- a/docker/README.md +++ b/docker/README.md @@ -88,6 +88,7 @@ The `.env.example` file provided in the Docker setup is extensive and covers a w 1. **Redis Configuration**: - `REDIS_HOST`, `REDIS_PORT`, `REDIS_PASSWORD`: Redis server connection settings. + - `REDIS_KEY_PREFIX`: Optional global namespace prefix for Redis keys, topics, streams, and Celery Redis transport artifacts. 1. **Celery Configuration**: diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 1fc1cfdf9e..c1ddba4f80 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -90,6 +90,7 @@ x-shared-env: &shared-api-worker-env REDIS_SSL_CERTFILE: ${REDIS_SSL_CERTFILE:-} REDIS_SSL_KEYFILE: ${REDIS_SSL_KEYFILE:-} REDIS_DB: ${REDIS_DB:-0} + REDIS_KEY_PREFIX: ${REDIS_KEY_PREFIX:-} REDIS_MAX_CONNECTIONS: ${REDIS_MAX_CONNECTIONS:-} REDIS_USE_SENTINEL: ${REDIS_USE_SENTINEL:-false} REDIS_SENTINELS: ${REDIS_SENTINELS:-} From d4783e8c1427975f8b90aa4dd9a01d6fd55e43d7 Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 14 Apr 2026 17:55:55 +0800 Subject: [PATCH 08/44] chore: url in tool description support clicking jump directly (#35163) --- .../tool-form/__tests__/item.spec.tsx | 26 +++++++++++ .../nodes/tool/components/tool-form/item.tsx | 45 ++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/web/app/components/workflow/nodes/tool/components/tool-form/__tests__/item.spec.tsx b/web/app/components/workflow/nodes/tool/components/tool-form/__tests__/item.spec.tsx index e5760310a9..896897a777 100644 --- a/web/app/components/workflow/nodes/tool/components/tool-form/__tests__/item.spec.tsx +++ b/web/app/components/workflow/nodes/tool/components/tool-form/__tests__/item.spec.tsx @@ -78,6 +78,7 @@ describe('tool/tool-form/item', () => { mockUseLanguage.mockReturnValue('en_US') }) + // Text input fields render their descriptions inline above the input. it('should render text input labels and forward props to form input item', () => { const handleChange = vi.fn() const handleManageInputField = vi.fn() @@ -121,6 +122,31 @@ describe('tool/tool-form/item', () => { }) }) + // URL fragments inside descriptions should be rendered as external links. + it('should render URLs in descriptions as external links', () => { + render( + , + ) + + const link = screen.getByRole('link', { name: 'https://docs.dify.ai/tools' }) + expect(link).toHaveAttribute('href', 'https://docs.dify.ai/tools') + expect(link).toHaveAttribute('target', '_blank') + expect(link).toHaveAttribute('rel', 'noopener noreferrer') + expect(link.parentElement).toHaveTextContent('Visit https://docs.dify.ai/tools for docs') + }) + + // Non-text fields keep their descriptions inside the tooltip and support JSON schema preview. it('should show tooltip for non-description fields and open the schema modal', () => { const objectSchema = createSchema({ name: 'tool_config', diff --git a/web/app/components/workflow/nodes/tool/components/tool-form/item.tsx b/web/app/components/workflow/nodes/tool/components/tool-form/item.tsx index d83f445c2c..5011cf9486 100644 --- a/web/app/components/workflow/nodes/tool/components/tool-form/item.tsx +++ b/web/app/components/workflow/nodes/tool/components/tool-form/item.tsx @@ -1,5 +1,5 @@ 'use client' -import type { FC } from 'react' +import type { FC, ReactNode } from 'react' import type { ToolVarInputs } from '../../types' import type { CredentialFormSchema } from '@/app/components/header/account-setting/model-provider-page/declarations' import type { Tool } from '@/app/components/tools/types' @@ -15,6 +15,45 @@ import { useLanguage } from '@/app/components/header/account-setting/model-provi import { SchemaModal } from '@/app/components/plugins/plugin-detail-panel/tool-selector/components' import FormInputItem from '@/app/components/workflow/nodes/_base/components/form-input-item' +const URL_REGEX = /(https?:\/\/\S+)/g + +const renderDescriptionWithLinks = (description: string): ReactNode => { + const matches = [...description.matchAll(URL_REGEX)] + + if (!matches.length) + return description + + const parts: ReactNode[] = [] + let currentIndex = 0 + + matches.forEach((match, index) => { + const [url] = match + const start = match.index ?? 0 + + if (start > currentIndex) + parts.push(description.slice(currentIndex, start)) + + parts.push( + + {url} + , + ) + + currentIndex = start + url.length + }) + + if (currentIndex < description.length) + parts.push(description.slice(currentIndex)) + + return parts +} + type Props = { readOnly: boolean nodeId: string @@ -87,7 +126,9 @@ const ToolFormItem: FC = ({ )}
{showDescription && tooltip && ( -
{tooltip[language] || tooltip.en_US}
+
+ {renderDescriptionWithLinks(tooltip[language] || tooltip.en_US)} +
)}
Date: Tue, 14 Apr 2026 21:22:23 +0800 Subject: [PATCH 09/44] refactor(web): re-design button api (#35166) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../tracing/provider-config-modal.tsx | 4 +- .../(humanInputLayout)/form/[token]/form.tsx | 22 +- .../webapp-reset-password/check-code/page.tsx | 10 +- .../webapp-reset-password/page.tsx | 10 +- .../set-password/page.tsx | 10 +- .../webapp-signin/check-code/page.tsx | 10 +- .../components/mail-and-code-auth.tsx | 4 +- .../components/mail-and-password-auth.tsx | 4 +- .../webapp-signin/components/sso-auth.tsx | 2 +- .../account-page/AvatarWithEdit.tsx | 6 +- .../account-page/email-change-modal.tsx | 54 +- .../(commonLayout)/account-page/index.tsx | 32 +- .../delete-account/components/check-email.tsx | 8 +- .../delete-account/components/feed-back.tsx | 4 +- .../components/verify-email.tsx | 10 +- web/app/account/(commonLayout)/header.tsx | 6 +- web/app/account/oauth/authorize/page.tsx | 12 +- web/app/activate/activateForm.tsx | 2 +- .../__tests__/app-info-detail-panel.spec.tsx | 4 +- .../__tests__/app-operations.spec.tsx | 4 +- .../app-info/app-info-detail-panel.tsx | 12 +- .../app-sidebar/app-info/app-operations.tsx | 12 +- .../components/app-sidebar/toggle-button.tsx | 4 +- .../annotation/add-annotation-modal/index.tsx | 6 +- .../csv-uploader.tsx | 4 +- .../batch-add-annotation-modal/index.tsx | 8 +- .../edit-annotation-modal/edit-item/index.tsx | 12 +- .../app/annotation/header-opts/index.tsx | 16 +- .../add-member-or-group-pop.tsx | 8 +- .../app/app-access-control/index.tsx | 6 +- .../components/app/app-publisher/index.tsx | 4 +- .../publish-with-multiple-model.tsx | 2 +- .../components/app/app-publisher/sections.tsx | 2 +- .../app/app-publisher/version-info-modal.tsx | 10 +- .../warning-mask/cannot-query-dataset.tsx | 2 +- .../base/warning-mask/formatting-changed.tsx | 2 +- .../config-prompt/advanced-prompt-input.tsx | 12 +- .../config-prompt/confirm-add-var/index.tsx | 4 +- .../conversation-history/edit-modal.tsx | 6 +- .../app/configuration/config-prompt/index.tsx | 2 +- .../configuration/config-var/modal-foot.tsx | 2 +- .../config-vision/param-config.tsx | 2 +- .../config/agent-setting-button.tsx | 2 +- .../config/agent/agent-setting/index.tsx | 16 +- .../config/agent/agent-tools/index.tsx | 12 +- .../agent-tools/setting-built-in-tool.tsx | 18 +- .../config/automatic/automatic-btn.tsx | 2 +- .../config/automatic/get-automatic-res.tsx | 10 +- .../configuration/config/automatic/result.tsx | 4 +- .../code-generator/get-code-generator-res.tsx | 6 +- .../app/configuration/configuration-view.tsx | 2 +- .../configuration/ctrl-btn-group/index.tsx | 4 +- .../dataset-config/params-config/index.tsx | 2 +- .../dataset-config/select-dataset/index.tsx | 4 +- .../dataset-config/settings-modal/index.tsx | 16 +- .../app/configuration/debug/index.tsx | 16 +- .../prompt-value-panel/index.tsx | 8 +- .../tools/external-data-tool-modal.tsx | 8 +- .../app/create-app-dialog/app-card/index.tsx | 8 +- .../components/app/create-app-modal/index.tsx | 38 +- .../dsl-confirm-modal.tsx | 4 +- .../app/create-from-dsl-modal/index.tsx | 12 +- .../components/app/duplicate-modal/index.tsx | 10 +- .../components/app/in-site-message/index.tsx | 12 +- .../app/overview/apikey-info-panel/index.tsx | 8 +- .../app/overview/app-card-sections.tsx | 2 +- .../app/overview/customize/index.tsx | 20 +- .../app/overview/settings/index.tsx | 46 +- .../components/app/switch-app-modal/index.tsx | 10 +- .../saved-items/no-data/index.tsx | 6 +- .../components/base/app-icon-picker/index.tsx | 4 +- .../base/button/__tests__/add-button.spec.tsx | 49 - .../button/__tests__/sync-button.spec.tsx | 52 - .../base/button/add-button.stories.tsx | 52 - web/app/components/base/button/add-button.tsx | 21 - .../base/button/sync-button.stories.tsx | 57 - .../components/base/button/sync-button.tsx | 26 - .../chat-with-history/inputs-form/index.tsx | 8 +- .../sidebar/__tests__/rename-modal.spec.tsx | 10 +- .../chat/chat-with-history/sidebar/index.tsx | 4 +- .../sidebar/rename-modal.tsx | 4 +- .../human-input-content/human-input-form.tsx | 4 +- .../chat/chat/chat-input-area/operation.tsx | 2 +- web/app/components/base/chat/chat/index.tsx | 2 +- .../components/base/chat/chat/question.tsx | 6 +- .../components/base/chat/chat/try-to-ask.tsx | 6 +- .../embedded-chatbot/inputs-form/index.tsx | 8 +- .../components/base/checkbox-list/index.tsx | 14 +- .../components/base/confirm/index.stories.tsx | 2 +- web/app/components/base/confirm/index.tsx | 12 +- .../date-picker/footer.tsx | 8 +- .../time-picker/footer.tsx | 2 +- .../year-and-month-picker/footer.tsx | 2 +- web/app/components/base/drawer/index.tsx | 4 +- .../components/base/emoji-picker/index.tsx | 4 +- .../components/base/error-boundary/index.tsx | 6 +- .../annotation-reply/config-param-modal.tsx | 4 +- .../annotation-reply/index.tsx | 12 +- .../conversation-opener/index.tsx | 6 +- .../conversation-opener/modal.tsx | 12 +- .../new-feature-panel/feature-bar.tsx | 6 +- .../new-feature-panel/file-upload/index.tsx | 8 +- .../file-upload/setting-content.tsx | 4 +- .../new-feature-panel/image-upload/index.tsx | 8 +- .../new-feature-panel/moderation/index.tsx | 12 +- .../moderation/moderation-setting-modal.tsx | 18 +- .../text-to-speech/index.tsx | 10 +- .../file-from-link-or-local/index.tsx | 8 +- .../file-uploader-in-attachment/index.tsx | 2 +- .../file-image-item.tsx | 8 +- .../file-uploader-in-chat-input/file-item.tsx | 10 +- .../base/form/components/form/actions.tsx | 2 +- .../components/base/form/index.stories.tsx | 2 +- .../base/image-uploader/image-link-input.tsx | 4 +- .../base/inline-delete-confirm/index.tsx | 4 +- .../base/markdown-blocks/button.tsx | 4 +- .../components/base/markdown-blocks/form.tsx | 6 +- .../components/base/modal-like-wrap/index.tsx | 6 +- .../components/base/modal/modal.stories.tsx | 4 +- web/app/components/base/modal/modal.tsx | 12 +- .../base/notion-connector/index.tsx | 6 +- web/app/components/base/pagination/index.tsx | 14 +- .../plugins/hitl-input-block/input-field.tsx | 12 +- .../base/tag-management/tag-remove-modal.tsx | 8 +- .../components/base/ui/alert-dialog/index.tsx | 6 +- .../{ => ui}/button/__tests__/index.spec.tsx | 9 +- .../components/base/{ => ui}/button/index.css | 185 +-- .../base/{ => ui}/button/index.stories.tsx | 11 +- .../components/base/{ => ui}/button/index.tsx | 47 +- .../billing/apps-full-in-dialog/index.tsx | 8 +- .../billing/plan-upgrade-modal/index.tsx | 4 +- web/app/components/billing/plan/index.tsx | 2 +- web/app/components/billing/pricing/header.tsx | 6 +- .../components/billing/upgrade-btn/index.tsx | 2 +- .../components/chat-preview-card.tsx | 12 +- .../components/workflow-preview-card.tsx | 10 +- .../custom/custom-web-app-brand/index.tsx | 16 +- .../datasets/common/image-previewer/index.tsx | 12 +- .../image-uploader-in-chunk/image-item.tsx | 4 +- .../image-item.tsx | 4 +- .../dsl-confirm-modal.tsx | 4 +- .../create-from-dsl-modal/index.tsx | 4 +- .../datasets/create-from-pipeline/header.tsx | 6 +- .../list/template-card/actions.tsx | 2 +- .../list/template-card/details/index.tsx | 12 +- .../list/template-card/edit-pipeline-info.tsx | 10 +- .../create/embedding-process/index.tsx | 4 +- .../empty-dataset-creation-modal/index.tsx | 2 +- .../step-one/components/next-step-button.tsx | 2 +- .../components/general-chunking-options.tsx | 10 +- .../components/indexing-mode-section.tsx | 20 +- .../components/parent-child-options.tsx | 6 +- .../step-two/components/step-two-footer.tsx | 2 +- .../create/stop-embedding-modal/index.tsx | 2 +- .../website/base/__tests__/url-input.spec.tsx | 9 +- .../website/base/crawled-result-item.tsx | 4 +- .../datasets/create/website/base/header.tsx | 4 +- .../create/website/base/url-input.tsx | 3 +- .../base/__tests__/url-input.spec.tsx | 8 +- .../website/jina-reader/base/url-input.tsx | 2 +- .../datasets/create/website/no-data.tsx | 6 +- .../documents/components/documents-header.tsx | 2 +- .../documents/components/empty-element.tsx | 4 +- .../documents/components/rename-modal.tsx | 4 +- .../create-from-pipeline/actions/index.tsx | 6 +- .../base/__tests__/header.spec.tsx | 4 +- .../data-source/base/header.tsx | 4 +- .../online-drive/connect/index.tsx | 6 +- .../file-list/list/empty-search-result.tsx | 2 +- .../data-source/online-drive/header.tsx | 4 +- .../__tests__/crawled-result-item.spec.tsx | 4 +- .../base/crawled-result-item.tsx | 8 +- .../website-crawl/base/options/index.tsx | 5 +- .../create-from-pipeline/left-header.tsx | 12 +- .../preview/chunk-preview.tsx | 2 +- .../__tests__/header.spec.tsx | 4 +- .../process-documents/actions.tsx | 2 +- .../process-documents/header.tsx | 4 +- .../processing/embedding-process/index.tsx | 12 +- .../detail/batch-modal/csv-uploader.tsx | 4 +- .../documents/detail/batch-modal/index.tsx | 6 +- .../completed/common/action-buttons.tsx | 2 +- .../detail/completed/common/batch-action.tsx | 6 +- .../completed/common/regeneration-modal.tsx | 6 +- .../metadata/components/doc-type-selector.tsx | 2 +- .../documents/detail/metadata/index.tsx | 2 +- .../pipeline-settings/left-header.tsx | 12 +- .../process-documents/actions.tsx | 2 +- .../external-api/external-api-modal/index.tsx | 18 +- .../external-api/external-api-panel/index.tsx | 10 +- .../create/ExternalApiSelection.tsx | 2 +- .../external-knowledge-base/create/index.tsx | 10 +- .../datasets/extra-info/service-api/card.tsx | 10 +- .../modify-external-retrieval-modal.spec.tsx | 4 +- .../__tests__/modify-retrieval-modal.spec.tsx | 4 +- .../query-input/__tests__/index.spec.tsx | 6 +- .../components/query-input/index.tsx | 8 +- .../modify-external-retrieval-modal.tsx | 6 +- .../hit-testing/modify-retrieval-modal.tsx | 8 +- web/app/components/datasets/list/index.tsx | 6 +- .../datasets/metadata/add-metadata-button.tsx | 2 +- .../metadata/edit-metadata-batch/modal.tsx | 12 +- .../dataset-metadata-drawer.tsx | 12 +- .../metadata/metadata-document/index.tsx | 2 +- .../metadata/metadata-document/no-data.tsx | 6 +- .../datasets/rename-modal/index.tsx | 8 +- .../datasets/settings/form/index.tsx | 2 +- .../develop/secret-key/secret-key-button.tsx | 4 +- .../secret-key/secret-key-generate.tsx | 6 +- .../develop/secret-key/secret-key-modal.tsx | 6 +- web/app/components/explore/app-card/index.tsx | 12 +- web/app/components/explore/app-list/index.tsx | 6 +- .../explore/create-app-modal/index.tsx | 18 +- .../explore/try-app/app-info/index.tsx | 14 +- web/app/components/explore/try-app/index.tsx | 4 +- .../components/header/account-about/index.tsx | 4 +- .../__tests__/compliance.spec.tsx | 32 +- .../header/account-dropdown/compliance.tsx | 23 +- .../api-based-extension-page/index.tsx | 2 +- .../api-based-extension-page/item.tsx | 2 +- .../api-based-extension-page/modal.tsx | 6 +- .../data-source-page-new/configure.tsx | 4 +- .../data-source-page-new/item.tsx | 8 +- .../header/account-setting/index.tsx | 20 +- .../edit-workspace-modal/index.tsx | 4 +- .../members-page/invite-button.tsx | 2 +- .../members-page/invite-modal/index.tsx | 10 +- .../members-page/invited-modal/index.tsx | 4 +- .../transfer-ownership-modal/index.tsx | 44 +- .../model-auth/add-custom-model.tsx | 10 +- .../model-auth/authorized/index.tsx | 6 +- .../model-auth/config-model.tsx | 6 +- .../model-auth/config-provider.tsx | 4 +- .../manage-custom-model-credentials.tsx | 2 +- .../switch-credential-in-load-balancing.tsx | 2 +- .../model-provider-page/model-modal/index.tsx | 23 +- .../configuration-button.tsx | 2 +- .../presets-parameter.tsx | 4 +- .../model-selector/popup.tsx | 28 +- .../model-auth-dropdown/api-key-section.tsx | 8 +- .../model-auth-dropdown/index.tsx | 4 +- .../model-load-balancing-modal.tsx | 6 +- .../provider-added-card/priority-selector.tsx | 6 +- .../provider-card-actions.tsx | 4 +- .../system-model-selector/index.tsx | 14 +- .../plugins/install-plugin/base/installed.tsx | 2 +- .../install-bundle/steps/install.tsx | 4 +- .../install-bundle/steps/installed.tsx | 2 +- .../install-from-github/steps/loaded.tsx | 2 +- .../steps/selectPackage.tsx | 2 +- .../install-from-github/steps/setURL.tsx | 8 +- .../steps/install.tsx | 6 +- .../steps/uploading.tsx | 2 +- .../steps/install.tsx | 6 +- .../plugins/marketplace/list/card-wrapper.tsx | 6 +- .../authorize/add-api-key-button.tsx | 4 +- .../authorize/add-oauth-button.tsx | 12 +- .../authorize/oauth-client-settings.tsx | 2 +- .../authorized-in-data-source-node.tsx | 2 +- .../plugin-auth/authorized-in-node.tsx | 2 +- .../plugins/plugin-auth/authorized/index.tsx | 6 +- .../plugins/plugin-auth/authorized/item.tsx | 6 +- .../plugin-auth/plugin-auth-in-agent.tsx | 2 +- .../plugin-auth-in-datasource-node.tsx | 2 +- .../datasource-action-list.tsx | 6 +- .../detail-header/__tests__/index.spec.tsx | 4 +- .../detail-header/index.tsx | 6 +- .../plugin-detail-panel/endpoint-modal.tsx | 10 +- .../subscription-list/create/index.tsx | 6 +- .../subscription-list/create/oauth-client.tsx | 8 +- .../components/tool-credentials-form.tsx | 2 +- .../tool-selector/components/tool-item.tsx | 6 +- .../plugins/plugin-mutation-model/index.tsx | 4 +- .../plugin-page/__tests__/debug-info.spec.tsx | 4 +- .../install-plugin-dropdown.spec.tsx | 4 +- .../plugins/plugin-page/debug-info.tsx | 4 +- .../plugins/plugin-page/empty/index.tsx | 10 +- .../components/plugins/plugin-page/index.tsx | 4 +- .../plugin-page/install-plugin-dropdown.tsx | 6 +- .../components/error-plugin-item.tsx | 2 +- .../components/plugin-task-list.tsx | 4 +- .../plugins/plugin-page/plugins-panel.tsx | 4 +- web/app/components/plugins/provider-card.tsx | 6 +- .../__tests__/plugins-picker.spec.tsx | 4 +- .../__tests__/strategy-picker.spec.tsx | 4 +- .../auto-update-setting/plugins-picker.tsx | 4 +- .../auto-update-setting/strategy-picker.tsx | 4 +- .../plugins/reference-setting-modal/index.tsx | 6 +- .../__tests__/from-market-place.spec.tsx | 4 +- .../update-plugin/downgrade-warning.tsx | 6 +- .../update-plugin/from-market-place.tsx | 6 +- .../components/__tests__/conversion.spec.tsx | 4 +- ...blish-as-knowledge-pipeline-modal.spec.tsx | 4 +- .../__tests__/update-dsl-modal.spec.tsx | 8 +- .../rag-pipeline/components/conversion.tsx | 4 +- .../panel/input-field/editor/form/index.tsx | 2 +- .../components/panel/input-field/index.tsx | 6 +- .../test-run/preparation/actions/index.tsx | 2 +- .../document-processing/actions.tsx | 2 +- .../test-run/result/result-preview/index.tsx | 4 +- .../publish-as-knowledge-pipeline-modal.tsx | 10 +- .../input-field-button.tsx | 2 +- .../publisher/__tests__/popup.spec.tsx | 4 +- .../rag-pipeline-header/publisher/index.tsx | 2 +- .../rag-pipeline-header/publisher/popup.tsx | 16 +- .../components/update-dsl-modal.tsx | 11 +- .../components/version-mismatch-modal.tsx | 4 +- .../share/text-generation/result/index.tsx | 6 +- .../share/text-generation/run-batch/index.tsx | 4 +- .../run-batch/res-download/index.tsx | 2 +- .../share/text-generation/run-once/index.tsx | 8 +- .../config-credentials.tsx | 14 +- .../get-schema.tsx | 12 +- .../edit-custom-collection-modal/index.tsx | 26 +- .../edit-custom-collection-modal/test-api.tsx | 16 +- .../components/tools/mcp/detail/content.tsx | 20 +- .../components/tools/mcp/headers-input.tsx | 6 +- .../components/tools/mcp/mcp-server-modal.tsx | 10 +- .../components/tools/mcp/mcp-service-card.tsx | 12 +- web/app/components/tools/mcp/modal.tsx | 8 +- web/app/components/tools/provider/detail.tsx | 8 +- .../setting/build-in/config-credentials.tsx | 4 +- .../tools/workflow-tool/configure-button.tsx | 8 +- .../confirm-modal/__tests__/index.spec.tsx | 3 +- .../workflow-tool/confirm-modal/index.tsx | 8 +- .../components/tools/workflow-tool/index.tsx | 4 +- .../workflow-header/features-trigger.tsx | 2 +- .../block-selector/all-start-blocks.tsx | 6 +- .../workflow/block-selector/all-tools.tsx | 4 +- .../market-place-plugin/action.tsx | 6 +- .../workflow/dsl-export-confirm-modal.tsx | 16 +- .../workflow/header/chat-variable-button.tsx | 2 +- .../header/checklist/plugin-group.tsx | 4 +- .../components/workflow/header/env-button.tsx | 2 +- .../header/global-variable-button.tsx | 2 +- .../workflow/header/header-in-restoring.tsx | 4 +- .../header/header-in-view-history.tsx | 2 +- .../header/version-history-button.tsx | 4 +- .../nodes/_base/components/add-button.tsx | 2 +- .../_base/components/before-run-form/form.tsx | 7 +- .../components/before-run-form/index.tsx | 2 +- .../error-handle-type-selector.tsx | 4 +- .../components/install-plugin-button.tsx | 2 +- .../nodes/_base/components/next-step/item.tsx | 4 +- .../_base/components/next-step/operator.tsx | 4 +- .../variable/var-reference-picker.trigger.tsx | 23 +- .../workflow-panel/last-run/no-data.tsx | 4 +- .../components/workflow/nodes/code/panel.tsx | 28 +- .../nodes/data-source-empty/index.tsx | 4 +- .../nodes/data-source/before-run-form.tsx | 2 +- .../components/workflow/nodes/end/panel.tsx | 9 +- .../http/components/authorization/index.tsx | 4 +- .../nodes/http/components/curl-panel.tsx | 2 +- .../__tests__/button-style-dropdown.spec.tsx | 5 +- .../__tests__/form-content-preview.spec.tsx | 5 +- .../components/__tests__/user-action.spec.tsx | 5 +- .../components/button-style-dropdown.tsx | 2 +- .../delivery-method/email-configure-modal.tsx | 10 +- .../delivery-method/method-item.tsx | 6 +- .../recipient/member-selector.tsx | 2 +- .../delivery-method/test-email-sender.tsx | 12 +- .../delivery-method/upgrade-modal.tsx | 6 +- .../components/form-content-preview.tsx | 6 +- .../components/single-run-form.tsx | 8 +- .../human-input/components/user-action.tsx | 2 +- .../workflow/nodes/human-input/panel.tsx | 8 +- .../if-else/components/condition-add.tsx | 2 +- .../condition-list/condition-operator.tsx | 2 +- .../components/condition-number-input.tsx | 6 +- .../if-else/components/condition-wrap.tsx | 10 +- .../workflow/nodes/if-else/panel.tsx | 4 +- .../components/chunk-structure/index.tsx | 4 +- .../components/chunk-structure/selector.tsx | 4 +- .../components/add-dataset.tsx | 5 +- .../components/metadata/add-condition.tsx | 6 +- .../condition-list/condition-operator.tsx | 2 +- .../condition-list/condition-value-method.tsx | 2 +- .../metadata-filter-selector.tsx | 2 +- .../components/metadata/metadata-trigger.tsx | 4 +- .../components/retrieval-config.tsx | 4 +- .../json-importer.tsx | 10 +- .../json-schema-config.tsx | 10 +- .../generated-result.tsx | 10 +- .../json-schema-generator/prompt-editor.tsx | 14 +- .../visual-editor/add-field.tsx | 2 +- .../edit-card/advanced-actions.tsx | 2 +- .../nodes/llm/components/structure-output.tsx | 6 +- .../components/workflow/nodes/llm/panel.tsx | 11 +- .../nodes/loop/components/condition-add.tsx | 2 +- .../condition-list/condition-operator.tsx | 2 +- .../components/condition-number-input.tsx | 6 +- .../nodes/loop/components/condition-wrap.tsx | 4 +- .../components/extract-parameter/update.tsx | 9 +- .../components/workflow/nodes/start/panel.tsx | 9 +- .../nodes/template-transform/panel.tsx | 9 +- .../nodes/tool/components/tool-form/item.tsx | 10 +- .../components/trigger-form/item.tsx | 10 +- .../plugins/link-editor-plugin/component.tsx | 4 +- .../components/array-bool-list.tsx | 2 +- .../components/array-value-list.tsx | 2 +- .../components/variable-modal-trigger.tsx | 2 +- .../components/variable-modal.sections.tsx | 12 +- .../components/variable-modal.tsx | 4 +- .../panel/env-panel/variable-modal.tsx | 24 +- .../panel/env-panel/variable-trigger.tsx | 2 +- .../workflow/panel/inputs-panel.tsx | 4 +- .../context-menu/index.tsx | 2 +- .../delete-confirm-modal.tsx | 6 +- .../panel/version-history-panel/empty.tsx | 4 +- .../restore-confirm-modal.tsx | 4 +- .../workflow/panel/workflow-preview.tsx | 12 +- .../workflow/run/agent-log/agent-log-item.tsx | 8 +- .../run/agent-log/agent-log-nav-more.tsx | 4 +- .../workflow/run/agent-log/agent-log-nav.tsx | 12 +- .../iteration-log/iteration-log-trigger.tsx | 4 +- .../run/loop-log/loop-log-trigger.tsx | 4 +- .../run/retry-log/retry-log-trigger.tsx | 2 +- .../components/workflow/update-dsl-modal.tsx | 19 +- .../workflow/variable-inspect/group.tsx | 10 +- .../workflow/variable-inspect/left.tsx | 6 +- .../workflow/variable-inspect/listening.tsx | 6 +- .../education-apply/education-apply-page.tsx | 24 +- .../education-apply/expire-notice-modal.tsx | 10 +- web/app/education-apply/user-info.tsx | 8 +- .../education-apply/verify-state-modal.tsx | 12 +- .../forgot-password/ChangePasswordForm.tsx | 2 +- .../forgot-password/ForgotPasswordForm.tsx | 2 +- web/app/init/InitPasswordPopup.tsx | 4 +- web/app/install/installForm.tsx | 2 +- web/app/reset-password/check-code/page.tsx | 10 +- web/app/reset-password/page.tsx | 10 +- web/app/reset-password/set-password/page.tsx | 10 +- web/app/signin/check-code/page.tsx | 10 +- .../signin/components/mail-and-code-auth.tsx | 4 +- .../components/mail-and-password-auth.tsx | 6 +- web/app/signin/components/social-auth.tsx | 2 +- web/app/signin/components/sso-auth.tsx | 2 +- web/app/signin/invite-settings/page.tsx | 18 +- web/app/signin/one-more-step.tsx | 10 +- web/app/signup/check-code/page.tsx | 10 +- web/app/signup/components/input-mail.tsx | 10 +- web/app/signup/set-password/page.tsx | 10 +- web/app/styles/globals.css | 2 +- web/eslint-suppressions.json | 1239 ----------------- 444 files changed, 1636 insertions(+), 3169 deletions(-) delete mode 100644 web/app/components/base/button/__tests__/add-button.spec.tsx delete mode 100644 web/app/components/base/button/__tests__/sync-button.spec.tsx delete mode 100644 web/app/components/base/button/add-button.stories.tsx delete mode 100644 web/app/components/base/button/add-button.tsx delete mode 100644 web/app/components/base/button/sync-button.stories.tsx delete mode 100644 web/app/components/base/button/sync-button.tsx rename web/app/components/base/{ => ui}/button/__tests__/index.spec.tsx (93%) rename web/app/components/base/{ => ui}/button/index.css (66%) rename web/app/components/base/{ => ui}/button/index.stories.tsx (88%) rename web/app/components/base/{ => ui}/button/index.tsx (57%) diff --git a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/tracing/provider-config-modal.tsx b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/tracing/provider-config-modal.tsx index 72913b4934..caf6562a3e 100644 --- a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/tracing/provider-config-modal.tsx +++ b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/tracing/provider-config-modal.tsx @@ -5,7 +5,6 @@ import { useBoolean } from 'ahooks' import * as React from 'react' import { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' -import Button from '@/app/components/base/button' import Confirm from '@/app/components/base/confirm' import Divider from '@/app/components/base/divider' import { LinkExternal02 } from '@/app/components/base/icons/src/vender/line/general' @@ -14,6 +13,7 @@ import { PortalToFollowElem, PortalToFollowElemContent, } from '@/app/components/base/portal-to-follow-elem' +import { Button } from '@/app/components/base/ui/button' import { toast } from '@/app/components/base/ui/toast' import { addTracingConfig, removeTracingConfig, updateTracingConfig } from '@/service/apps' import { docURL } from './config' @@ -621,7 +621,7 @@ const ProviderConfigModal: FC = ({
diff --git a/web/app/(humanInputLayout)/form/[token]/form.tsx b/web/app/(humanInputLayout)/form/[token]/form.tsx index 221420aade..898dab8f4a 100644 --- a/web/app/(humanInputLayout)/form/[token]/form.tsx +++ b/web/app/(humanInputLayout)/form/[token]/form.tsx @@ -1,5 +1,5 @@ 'use client' -import type { ButtonProps } from '@/app/components/base/button' +import type { ButtonProps } from '@/app/components/base/ui/button' import type { FormInputItem, UserAction } from '@/app/components/workflow/nodes/human-input/types' import type { SiteInfo } from '@/models/share' import type { HumanInputFormError } from '@/service/use-share' @@ -13,12 +13,12 @@ import * as React from 'react' import { useEffect, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import AppIcon from '@/app/components/base/app-icon' -import Button from '@/app/components/base/button' import ContentItem from '@/app/components/base/chat/chat/answer/human-input-content/content-item' import ExpirationTime from '@/app/components/base/chat/chat/answer/human-input-content/expiration-time' import { getButtonStyle } from '@/app/components/base/chat/chat/answer/human-input-content/utils' import Loading from '@/app/components/base/loading' import DifyLogo from '@/app/components/base/logo/dify-logo' +import { Button } from '@/app/components/base/ui/button' import useDocumentTitle from '@/hooks/use-document-title' import { useParams } from '@/next/navigation' import { useGetHumanInputForm, useSubmitHumanInputForm } from '@/service/use-share' @@ -100,7 +100,7 @@ const FormContent = () => { if (success) { return (
-
+
@@ -109,7 +109,7 @@ const FormContent = () => {
{t('humanInput.thanks', { ns: 'share' })}
{t('humanInput.recorded', { ns: 'share' })}
-
{t('humanInput.submissionID', { id: token, ns: 'share' })}
+
{t('humanInput.submissionID', { id: token, ns: 'share' })}
{ if (expired) { return (
-
+
@@ -137,7 +137,7 @@ const FormContent = () => {
{t('humanInput.sorry', { ns: 'share' })}
{t('humanInput.expired', { ns: 'share' })}
-
{t('humanInput.submissionID', { id: token, ns: 'share' })}
+
{t('humanInput.submissionID', { id: token, ns: 'share' })}
{ if (submitted) { return (
-
+
@@ -165,7 +165,7 @@ const FormContent = () => {
{t('humanInput.sorry', { ns: 'share' })}
{t('humanInput.completed', { ns: 'share' })}
-
{t('humanInput.submissionID', { id: token, ns: 'share' })}
+
{t('humanInput.submissionID', { id: token, ns: 'share' })}
{ if (rateLimitExceeded) { return (
-
+
@@ -210,7 +210,7 @@ const FormContent = () => { if (!formData) { return (
-
+
@@ -245,7 +245,7 @@ const FormContent = () => { background={site.icon_background} imageUrl={site.icon_url} /> -
{site.title}
+
{site.title}
diff --git a/web/app/(shareLayout)/webapp-reset-password/check-code/page.tsx b/web/app/(shareLayout)/webapp-reset-password/check-code/page.tsx index b71e6b4767..d19e5a7d2d 100644 --- a/web/app/(shareLayout)/webapp-reset-password/check-code/page.tsx +++ b/web/app/(shareLayout)/webapp-reset-password/check-code/page.tsx @@ -2,8 +2,8 @@ import { RiArrowLeftLine, RiMailSendFill } from '@remixicon/react' import { useState } from 'react' import { useTranslation } from 'react-i18next' -import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' +import { Button } from '@/app/components/base/ui/button' import { toast } from '@/app/components/base/ui/toast' import Countdown from '@/app/components/signin/countdown' import { useLocale } from '@/context/i18n' @@ -62,9 +62,9 @@ export default function CheckCode() {
-
+

{t('checkCode.checkYourEmail', { ns: 'login' })}

-

+

{t('checkCode.tipsPrefix', { ns: 'login' })} {email} @@ -76,7 +76,7 @@ export default function CheckCode() {

- + setVerifyCode(e.target.value)} maxLength={6} className="mt-1" placeholder={t('checkCode.verificationCodePlaceholder', { ns: 'login' }) || ''} /> @@ -88,7 +88,7 @@ export default function CheckCode() {
- {t('back', { ns: 'login' })} + {t('back', { ns: 'login' })}
) diff --git a/web/app/(shareLayout)/webapp-reset-password/page.tsx b/web/app/(shareLayout)/webapp-reset-password/page.tsx index a25b4bb4ef..cb6ece219c 100644 --- a/web/app/(shareLayout)/webapp-reset-password/page.tsx +++ b/web/app/(shareLayout)/webapp-reset-password/page.tsx @@ -3,8 +3,8 @@ import { RiArrowLeftLine, RiLockPasswordLine } from '@remixicon/react' import { noop } from 'es-toolkit/function' import { useState } from 'react' import { useTranslation } from 'react-i18next' -import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' +import { Button } from '@/app/components/base/ui/button' import { toast } from '@/app/components/base/ui/toast' import { COUNT_DOWN_KEY, COUNT_DOWN_TIME_MS } from '@/app/components/signin/countdown' import { emailRegex } from '@/config' @@ -64,9 +64,9 @@ export default function CheckCode() {
-
+

{t('resetPassword', { ns: 'login' })}

-

+

{t('resetPasswordDesc', { ns: 'login' })}

@@ -74,7 +74,7 @@ export default function CheckCode() {
- +
setEmail(e.target.value)} />
@@ -90,7 +90,7 @@ export default function CheckCode() {
- {t('backToLogin', { ns: 'login' })} + {t('backToLogin', { ns: 'login' })}
) diff --git a/web/app/(shareLayout)/webapp-reset-password/set-password/page.tsx b/web/app/(shareLayout)/webapp-reset-password/set-password/page.tsx index bc8f651d17..5b89084ea1 100644 --- a/web/app/(shareLayout)/webapp-reset-password/set-password/page.tsx +++ b/web/app/(shareLayout)/webapp-reset-password/set-password/page.tsx @@ -3,8 +3,8 @@ import { RiCheckboxCircleFill } from '@remixicon/react' import { useCountDown } from 'ahooks' import { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' -import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' +import { Button } from '@/app/components/base/ui/button' import { toast } from '@/app/components/base/ui/toast' import { validPassword } from '@/config' import { useRouter, useSearchParams } from '@/next/navigation' @@ -91,7 +91,7 @@ const ChangePasswordForm = () => {

{t('changePassword', { ns: 'login' })}

-

+

{t('changePasswordTip', { ns: 'login' })}

@@ -100,7 +100,7 @@ const ChangePasswordForm = () => {
{/* Password */}
-
-
{t('error.passwordInvalid', { ns: 'login' })}
+
{t('error.passwordInvalid', { ns: 'login' })}
{/* Confirm Password */}
-
) diff --git a/web/app/(shareLayout)/webapp-signin/components/mail-and-code-auth.tsx b/web/app/(shareLayout)/webapp-signin/components/mail-and-code-auth.tsx index fbd6b216df..f600dba8b2 100644 --- a/web/app/(shareLayout)/webapp-signin/components/mail-and-code-auth.tsx +++ b/web/app/(shareLayout)/webapp-signin/components/mail-and-code-auth.tsx @@ -1,8 +1,8 @@ import { noop } from 'es-toolkit/function' import { useState } from 'react' import { useTranslation } from 'react-i18next' -import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' +import { Button } from '@/app/components/base/ui/button' import { toast } from '@/app/components/base/ui/toast' import { COUNT_DOWN_KEY, COUNT_DOWN_TIME_MS } from '@/app/components/signin/countdown' import { emailRegex } from '@/config' @@ -52,7 +52,7 @@ export default function MailAndCodeAuth() {
- +
setEmail(e.target.value)} />
diff --git a/web/app/(shareLayout)/webapp-signin/components/mail-and-password-auth.tsx b/web/app/(shareLayout)/webapp-signin/components/mail-and-password-auth.tsx index 1e9355e7ba..7fe5363927 100644 --- a/web/app/(shareLayout)/webapp-signin/components/mail-and-password-auth.tsx +++ b/web/app/(shareLayout)/webapp-signin/components/mail-and-password-auth.tsx @@ -2,8 +2,8 @@ import { noop } from 'es-toolkit/function' import { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' -import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' +import { Button } from '@/app/components/base/ui/button' import { toast } from '@/app/components/base/ui/toast' import { emailRegex } from '@/config' import { useLocale } from '@/context/i18n' @@ -103,7 +103,7 @@ export default function MailAndPasswordAuth({ isEmailSetup }: MailAndPasswordAut return (
-