diff --git a/Makefile b/Makefile index 388c367fdf..d82f6f24ad 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ prepare-web: prepare-api: @echo "🔧 Setting up API environment..." @cp -n api/.env.example api/.env 2>/dev/null || echo "API .env already exists" - @cd api && uv sync --dev --extra all + @cd api && uv sync --dev @cd api && uv run flask db upgrade @echo "✅ API environment prepared (not started)" diff --git a/api/.env.example b/api/.env.example index d24615f463..1efda9594f 100644 --- a/api/.env.example +++ b/api/.env.example @@ -75,6 +75,7 @@ DB_PASSWORD=difyai123456 DB_HOST=localhost DB_PORT=5432 DB_DATABASE=dify +SQLALCHEMY_POOL_PRE_PING=true # Storage configuration # use for store upload files, private keys... diff --git a/api/controllers/console/auth/oauth_server.py b/api/controllers/console/auth/oauth_server.py index f730cfa3fe..a8ba417847 100644 --- a/api/controllers/console/auth/oauth_server.py +++ b/api/controllers/console/auth/oauth_server.py @@ -2,7 +2,7 @@ from functools import wraps from typing import cast import flask_login -from flask import request +from flask import jsonify, request from flask_restx import Resource, reqparse from werkzeug.exceptions import BadRequest, NotFound @@ -46,23 +46,38 @@ def oauth_server_access_token_required(view): authorization_header = request.headers.get("Authorization") if not authorization_header: - raise BadRequest("Authorization header is required") + response = jsonify({"error": "Authorization header is required"}) + response.status_code = 401 + response.headers["WWW-Authenticate"] = "Bearer" + return response - parts = authorization_header.strip().split(" ") + parts = authorization_header.strip().split(None, 1) if len(parts) != 2: - raise BadRequest("Invalid Authorization header format") + response = jsonify({"error": "Invalid Authorization header format"}) + response.status_code = 401 + response.headers["WWW-Authenticate"] = "Bearer" + return response token_type = parts[0].strip() if token_type.lower() != "bearer": - raise BadRequest("token_type is invalid") + response = jsonify({"error": "token_type is invalid"}) + response.status_code = 401 + response.headers["WWW-Authenticate"] = "Bearer" + return response access_token = parts[1].strip() if not access_token: - raise BadRequest("access_token is required") + response = jsonify({"error": "access_token is required"}) + response.status_code = 401 + response.headers["WWW-Authenticate"] = "Bearer" + return response account = OAuthServerService.validate_oauth_access_token(oauth_provider_app.client_id, access_token) if not account: - raise BadRequest("access_token or client_id is invalid") + response = jsonify({"error": "access_token or client_id is invalid"}) + response.status_code = 401 + response.headers["WWW-Authenticate"] = "Bearer" + return response kwargs["account"] = account diff --git a/api/core/app/apps/advanced_chat/generate_task_pipeline.py b/api/core/app/apps/advanced_chat/generate_task_pipeline.py index 65a147dcdd..314b0a8f73 100644 --- a/api/core/app/apps/advanced_chat/generate_task_pipeline.py +++ b/api/core/app/apps/advanced_chat/generate_task_pipeline.py @@ -305,7 +305,7 @@ class AdvancedChatAppGenerateTaskPipeline: err = self._base_task_pipeline._handle_error(event=event, session=session, message_id=self._message_id) yield self._base_task_pipeline._error_to_stream_response(err) - def _handle_workflow_started_event(self, **kwargs) -> Generator[StreamResponse, None, None]: + def _handle_workflow_started_event(self, *args, **kwargs) -> Generator[StreamResponse, None, None]: """Handle workflow started events.""" with self._database_session() as session: workflow_execution = self._workflow_cycle_manager.handle_workflow_run_start() diff --git a/api/core/entities/provider_configuration.py b/api/core/entities/provider_configuration.py index 81e273ae54..c0c884bb17 100644 --- a/api/core/entities/provider_configuration.py +++ b/api/core/entities/provider_configuration.py @@ -410,10 +410,9 @@ class ProviderConfiguration(BaseModel): :return: """ with Session(db.engine) as session: - if credential_name and self._check_provider_credential_name_exists( - credential_name=credential_name, session=session - ): - raise ValueError(f"Credential with name '{credential_name}' already exists.") + if credential_name: + if self._check_provider_credential_name_exists(credential_name=credential_name, session=session): + raise ValueError(f"Credential with name '{credential_name}' already exists.") else: credential_name = self._generate_provider_credential_name(session) @@ -891,10 +890,11 @@ class ProviderConfiguration(BaseModel): :return: """ with Session(db.engine) as session: - if credential_name and self._check_custom_model_credential_name_exists( - model=model, model_type=model_type, credential_name=credential_name, session=session - ): - raise ValueError(f"Model credential with name '{credential_name}' already exists for {model}.") + if credential_name: + if self._check_custom_model_credential_name_exists( + model=model, model_type=model_type, credential_name=credential_name, session=session + ): + raise ValueError(f"Model credential with name '{credential_name}' already exists for {model}.") else: credential_name = self._generate_custom_model_credential_name( model=model, model_type=model_type, session=session diff --git a/api/core/helper/position_helper.py b/api/core/helper/position_helper.py index 8def6fe4ed..314f052832 100644 --- a/api/core/helper/position_helper.py +++ b/api/core/helper/position_helper.py @@ -1,7 +1,7 @@ import os from collections import OrderedDict from collections.abc import Callable -from typing import Any +from typing import TypeVar from configs import dify_config from core.tools.utils.yaml_utils import load_yaml_file @@ -72,11 +72,14 @@ def pin_position_map(original_position_map: dict[str, int], pin_list: list[str]) return position_map +T = TypeVar("T") + + def is_filtered( include_set: set[str], exclude_set: set[str], - data: Any, - name_func: Callable[[Any], str], + data: T, + name_func: Callable[[T], str], ) -> bool: """ Check if the object should be filtered out. @@ -103,9 +106,9 @@ def is_filtered( def sort_by_position_map( position_map: dict[str, int], - data: list[Any], - name_func: Callable[[Any], str], -) -> list[Any]: + data: list[T], + name_func: Callable[[T], str], +): """ Sort the objects by the position map. If the name of the object is not in the position map, it will be put at the end. @@ -122,9 +125,9 @@ def sort_by_position_map( def sort_to_dict_by_position_map( position_map: dict[str, int], - data: list[Any], - name_func: Callable[[Any], str], -) -> OrderedDict[str, Any]: + data: list[T], + name_func: Callable[[T], str], +): """ Sort the objects into a ordered dict by the position map. If the name of the object is not in the position map, it will be put at the end. @@ -134,4 +137,4 @@ def sort_to_dict_by_position_map( :return: an OrderedDict with the sorted pairs of name and object """ sorted_items = sort_by_position_map(position_map, data, name_func) - return OrderedDict([(name_func(item), item) for item in sorted_items]) + return OrderedDict((name_func(item), item) for item in sorted_items) diff --git a/api/core/mcp/client/streamable_client.py b/api/core/mcp/client/streamable_client.py index 14e346c2f3..a2b003e717 100644 --- a/api/core/mcp/client/streamable_client.py +++ b/api/core/mcp/client/streamable_client.py @@ -246,6 +246,10 @@ class StreamableHTTPTransport: logger.debug("Received 202 Accepted") return + if response.status_code == 204: + logger.debug("Received 204 No Content") + return + if response.status_code == 404: if isinstance(message.root, JSONRPCRequest): self._send_session_terminated_error( diff --git a/api/core/mcp/server/streamable_http.py b/api/core/mcp/server/streamable_http.py index 5851c6d406..3d51ac2333 100644 --- a/api/core/mcp/server/streamable_http.py +++ b/api/core/mcp/server/streamable_http.py @@ -258,5 +258,5 @@ def convert_input_form_to_parameters( parameters[item.variable]["type"] = "string" parameters[item.variable]["enum"] = item.options elif item.type == VariableEntityType.NUMBER: - parameters[item.variable]["type"] = "float" + parameters[item.variable]["type"] = "number" return parameters, required diff --git a/api/core/rag/datasource/vdb/myscale/myscale_vector.py b/api/core/rag/datasource/vdb/myscale/myscale_vector.py index 99f766a88a..d048f3b34e 100644 --- a/api/core/rag/datasource/vdb/myscale/myscale_vector.py +++ b/api/core/rag/datasource/vdb/myscale/myscale_vector.py @@ -152,8 +152,8 @@ class MyScaleVector(BaseVector): ) for r in self._client.query(sql).named_results() ] - except Exception as e: - logger.exception("\033[91m\033[1m%s\033[0m \033[95m%s\033[0m", type(e), str(e)) # noqa:TRY401 + except Exception: + logger.exception("Vector search operation failed") return [] def delete(self) -> None: diff --git a/api/extensions/storage/clickzetta_volume/file_lifecycle.py b/api/extensions/storage/clickzetta_volume/file_lifecycle.py index 2ef320bb9a..f5d6fd6f22 100644 --- a/api/extensions/storage/clickzetta_volume/file_lifecycle.py +++ b/api/extensions/storage/clickzetta_volume/file_lifecycle.py @@ -1,7 +1,8 @@ """ClickZetta Volume file lifecycle management -This module provides file lifecycle management features including version control, automatic cleanup, backup and restore -Supports complete lifecycle management for knowledge base files. +This module provides file lifecycle management features including version control, +automatic cleanup, backup and restore. Supports complete lifecycle management for +knowledge base files. """ import json diff --git a/api/pyproject.toml b/api/pyproject.toml index d85f3334c6..05737e546c 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "dify-api" -version = "1.8.0" +version = "1.8.1" requires-python = ">=3.11,<3.13" dependencies = [ diff --git a/api/tests/unit_tests/core/mcp/server/test_streamable_http.py b/api/tests/unit_tests/core/mcp/server/test_streamable_http.py index ccc5d42bcf..f1d741602a 100644 --- a/api/tests/unit_tests/core/mcp/server/test_streamable_http.py +++ b/api/tests/unit_tests/core/mcp/server/test_streamable_http.py @@ -1,6 +1,7 @@ import json from unittest.mock import Mock, patch +import jsonschema import pytest from core.app.app_config.entities import VariableEntity, VariableEntityType @@ -434,7 +435,7 @@ class TestUtilityFunctions: assert parameters["category"]["enum"] == ["A", "B", "C"] assert "count" in parameters - assert parameters["count"]["type"] == "float" + assert parameters["count"]["type"] == "number" # FILE type should be skipped - it creates empty dict but gets filtered later # Check that it doesn't have any meaningful content @@ -447,3 +448,65 @@ class TestUtilityFunctions: assert "category" not in required # Note: _get_request_id function has been removed as request_id is now passed as parameter + + def test_convert_input_form_to_parameters_jsonschema_validation_ok(self): + """Current schema uses 'number' for numeric fields; it should be a valid JSON Schema.""" + user_input_form = [ + VariableEntity( + type=VariableEntityType.NUMBER, + variable="count", + description="Count", + label="Count", + required=True, + ), + VariableEntity( + type=VariableEntityType.TEXT_INPUT, + variable="name", + description="User name", + label="Name", + required=False, + ), + ] + + parameters_dict = { + "count": "Enter count", + "name": "Enter your name", + } + + parameters, required = convert_input_form_to_parameters(user_input_form, parameters_dict) + + # Build a complete JSON Schema + schema = { + "type": "object", + "properties": parameters, + "required": required, + } + + # 1) The schema itself must be valid + jsonschema.Draft202012Validator.check_schema(schema) + + # 2) Both float and integer instances should pass validation + jsonschema.validate(instance={"count": 3.14, "name": "alice"}, schema=schema) + jsonschema.validate(instance={"count": 2, "name": "bob"}, schema=schema) + + def test_legacy_float_type_schema_is_invalid(self): + """Legacy/buggy behavior: using 'float' should produce an invalid JSON Schema.""" + # Manually construct a legacy/incorrect schema (simulating old behavior) + bad_schema = { + "type": "object", + "properties": { + "count": { + "type": "float", # Invalid type: JSON Schema does not support 'float' + "description": "Enter count", + } + }, + "required": ["count"], + } + + # The schema itself should raise a SchemaError + with pytest.raises(jsonschema.exceptions.SchemaError): + jsonschema.Draft202012Validator.check_schema(bad_schema) + + # Or validation should also raise SchemaError + with pytest.raises(jsonschema.exceptions.SchemaError): + jsonschema.validate(instance={"count": 1.23}, schema=bad_schema) diff --git a/api/uv.lock b/api/uv.lock index 6b7e7eebfa..1dda825295 100644 --- a/api/uv.lock +++ b/api/uv.lock @@ -1260,7 +1260,7 @@ wheels = [ [[package]] name = "dify-api" -version = "1.8.0" +version = "1.8.1" source = { virtual = "." } dependencies = [ { name = "arize-phoenix-otel" }, diff --git a/docker/docker-compose-template.yaml b/docker/docker-compose-template.yaml index a779999983..b479795c93 100644 --- a/docker/docker-compose-template.yaml +++ b/docker/docker-compose-template.yaml @@ -2,7 +2,7 @@ x-shared-env: &shared-api-worker-env services: # API service api: - image: langgenius/dify-api:1.8.0 + image: langgenius/dify-api:1.8.1 restart: always environment: # Use the shared environment variables. @@ -31,7 +31,7 @@ services: # worker service # The Celery worker for processing the queue. worker: - image: langgenius/dify-api:1.8.0 + image: langgenius/dify-api:1.8.1 restart: always environment: # Use the shared environment variables. @@ -58,7 +58,7 @@ services: # worker_beat service # Celery beat for scheduling periodic tasks. worker_beat: - image: langgenius/dify-api:1.8.0 + image: langgenius/dify-api:1.8.1 restart: always environment: # Use the shared environment variables. @@ -76,7 +76,7 @@ services: # Frontend web application. web: - image: langgenius/dify-web:1.8.0 + image: langgenius/dify-web:1.8.1 restart: always environment: CONSOLE_API_URL: ${CONSOLE_API_URL:-} @@ -118,7 +118,17 @@ services: volumes: - ./volumes/db/data:/var/lib/postgresql/data healthcheck: - test: [ 'CMD', 'pg_isready', '-h', 'db', '-U', '${PGUSER:-postgres}', '-d', '${POSTGRES_DB:-dify}' ] + test: + [ + "CMD", + "pg_isready", + "-h", + "db", + "-U", + "${PGUSER:-postgres}", + "-d", + "${POSTGRES_DB:-dify}", + ] interval: 1s timeout: 3s retries: 60 @@ -135,7 +145,11 @@ services: # Set the redis password when startup redis server. command: redis-server --requirepass ${REDIS_PASSWORD:-difyai123456} healthcheck: - test: [ 'CMD-SHELL', 'redis-cli -a ${REDIS_PASSWORD:-difyai123456} ping | grep -q PONG' ] + test: + [ + "CMD-SHELL", + "redis-cli -a ${REDIS_PASSWORD:-difyai123456} ping | grep -q PONG", + ] # The DifySandbox sandbox: @@ -157,7 +171,7 @@ services: - ./volumes/sandbox/dependencies:/dependencies - ./volumes/sandbox/conf:/conf healthcheck: - test: [ 'CMD', 'curl', '-f', 'http://localhost:8194/health' ] + test: ["CMD", "curl", "-f", "http://localhost:8194/health"] networks: - ssrf_proxy_network @@ -231,7 +245,12 @@ services: volumes: - ./ssrf_proxy/squid.conf.template:/etc/squid/squid.conf.template - ./ssrf_proxy/docker-entrypoint.sh:/docker-entrypoint-mount.sh - entrypoint: [ 'sh', '-c', "cp /docker-entrypoint-mount.sh /docker-entrypoint.sh && sed -i 's/\r$$//' /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh && /docker-entrypoint.sh" ] + entrypoint: + [ + "sh", + "-c", + "cp /docker-entrypoint-mount.sh /docker-entrypoint.sh && sed -i 's/\r$$//' /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh && /docker-entrypoint.sh", + ] environment: # pls clearly modify the squid env vars to fit your network environment. HTTP_PORT: ${SSRF_HTTP_PORT:-3128} @@ -260,8 +279,8 @@ services: - CERTBOT_EMAIL=${CERTBOT_EMAIL} - CERTBOT_DOMAIN=${CERTBOT_DOMAIN} - CERTBOT_OPTIONS=${CERTBOT_OPTIONS:-} - entrypoint: [ '/docker-entrypoint.sh' ] - command: [ 'tail', '-f', '/dev/null' ] + entrypoint: ["/docker-entrypoint.sh"] + command: ["tail", "-f", "/dev/null"] # The nginx reverse proxy. # used for reverse proxying the API service and Web service. @@ -278,7 +297,12 @@ services: - ./volumes/certbot/conf/live:/etc/letsencrypt/live # cert dir (with certbot container) - ./volumes/certbot/conf:/etc/letsencrypt - ./volumes/certbot/www:/var/www/html - entrypoint: [ 'sh', '-c', "cp /docker-entrypoint-mount.sh /docker-entrypoint.sh && sed -i 's/\r$$//' /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh && /docker-entrypoint.sh" ] + entrypoint: + [ + "sh", + "-c", + "cp /docker-entrypoint-mount.sh /docker-entrypoint.sh && sed -i 's/\r$$//' /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh && /docker-entrypoint.sh", + ] environment: NGINX_SERVER_NAME: ${NGINX_SERVER_NAME:-_} NGINX_HTTPS_ENABLED: ${NGINX_HTTPS_ENABLED:-false} @@ -300,14 +324,14 @@ services: - api - web ports: - - '${EXPOSE_NGINX_PORT:-80}:${NGINX_PORT:-80}' - - '${EXPOSE_NGINX_SSL_PORT:-443}:${NGINX_SSL_PORT:-443}' + - "${EXPOSE_NGINX_PORT:-80}:${NGINX_PORT:-80}" + - "${EXPOSE_NGINX_SSL_PORT:-443}:${NGINX_SSL_PORT:-443}" # The Weaviate vector store. weaviate: image: semitechnologies/weaviate:1.19.0 profiles: - - '' + - "" - weaviate restart: always volumes: @@ -360,13 +384,17 @@ services: working_dir: /opt/couchbase stdin_open: true tty: true - entrypoint: [ "" ] + entrypoint: [""] command: sh -c "/opt/couchbase/init/init-cbserver.sh" volumes: - ./volumes/couchbase/data:/opt/couchbase/var/lib/couchbase/data healthcheck: # ensure bucket was created before proceeding - test: [ "CMD-SHELL", "curl -s -f -u Administrator:password http://localhost:8091/pools/default/buckets | grep -q '\\[{' || exit 1" ] + test: + [ + "CMD-SHELL", + "curl -s -f -u Administrator:password http://localhost:8091/pools/default/buckets | grep -q '\\[{' || exit 1", + ] interval: 10s retries: 10 start_period: 30s @@ -392,9 +420,9 @@ services: volumes: - ./volumes/pgvector/data:/var/lib/postgresql/data - ./pgvector/docker-entrypoint.sh:/docker-entrypoint.sh - entrypoint: [ '/docker-entrypoint.sh' ] + entrypoint: ["/docker-entrypoint.sh"] healthcheck: - test: [ 'CMD', 'pg_isready' ] + test: ["CMD", "pg_isready"] interval: 1s timeout: 3s retries: 30 @@ -411,14 +439,14 @@ services: - VB_USERNAME=dify - VB_PASSWORD=Difyai123456 ports: - - '5434:5432' + - "5434:5432" volumes: - ./vastbase/lic:/home/vastbase/vastbase/lic - ./vastbase/data:/home/vastbase/data - ./vastbase/backup:/home/vastbase/backup - ./vastbase/backup_log:/home/vastbase/backup_log healthcheck: - test: [ 'CMD', 'pg_isready' ] + test: ["CMD", "pg_isready"] interval: 1s timeout: 3s retries: 30 @@ -440,7 +468,7 @@ services: volumes: - ./volumes/pgvecto_rs/data:/var/lib/postgresql/data healthcheck: - test: [ 'CMD', 'pg_isready' ] + test: ["CMD", "pg_isready"] interval: 1s timeout: 3s retries: 30 @@ -479,7 +507,11 @@ services: ports: - "${OCEANBASE_VECTOR_PORT:-2881}:2881" healthcheck: - test: [ 'CMD-SHELL', 'obclient -h127.0.0.1 -P2881 -uroot@test -p$${OB_TENANT_PASSWORD} -e "SELECT 1;"' ] + test: + [ + "CMD-SHELL", + 'obclient -h127.0.0.1 -P2881 -uroot@test -p$${OB_TENANT_PASSWORD} -e "SELECT 1;"', + ] interval: 10s retries: 30 start_period: 30s @@ -515,7 +547,7 @@ services: - ./volumes/milvus/etcd:/etcd command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd healthcheck: - test: [ 'CMD', 'etcdctl', 'endpoint', 'health' ] + test: ["CMD", "etcdctl", "endpoint", "health"] interval: 30s timeout: 20s retries: 3 @@ -534,7 +566,7 @@ services: - ./volumes/milvus/minio:/minio_data command: minio server /minio_data --console-address ":9001" healthcheck: - test: [ 'CMD', 'curl', '-f', 'http://localhost:9000/minio/health/live' ] + test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] interval: 30s timeout: 20s retries: 3 @@ -546,7 +578,7 @@ services: image: milvusdb/milvus:v2.5.15 profiles: - milvus - command: [ 'milvus', 'run', 'standalone' ] + command: ["milvus", "run", "standalone"] environment: ETCD_ENDPOINTS: ${ETCD_ENDPOINTS:-etcd:2379} MINIO_ADDRESS: ${MINIO_ADDRESS:-minio:9000} @@ -554,7 +586,7 @@ services: volumes: - ./volumes/milvus/milvus:/var/lib/milvus healthcheck: - test: [ 'CMD', 'curl', '-f', 'http://localhost:9091/healthz' ] + test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"] interval: 30s start_period: 90s timeout: 20s @@ -620,7 +652,7 @@ services: volumes: - ./volumes/opengauss/data:/var/lib/opengauss/data healthcheck: - test: [ "CMD-SHELL", "netstat -lntp | grep tcp6 > /dev/null 2>&1" ] + test: ["CMD-SHELL", "netstat -lntp | grep tcp6 > /dev/null 2>&1"] interval: 10s timeout: 10s retries: 10 @@ -673,18 +705,19 @@ services: node.name: dify-es0 discovery.type: single-node xpack.license.self_generated.type: basic - xpack.security.enabled: 'true' - xpack.security.enrollment.enabled: 'false' - xpack.security.http.ssl.enabled: 'false' + xpack.security.enabled: "true" + xpack.security.enrollment.enabled: "false" + xpack.security.http.ssl.enabled: "false" ports: - ${ELASTICSEARCH_PORT:-9200}:9200 deploy: resources: limits: memory: 2g - entrypoint: [ 'sh', '-c', "sh /docker-entrypoint-mount.sh" ] + entrypoint: ["sh", "-c", "sh /docker-entrypoint-mount.sh"] healthcheck: - test: [ 'CMD', 'curl', '-s', 'http://localhost:9200/_cluster/health?pretty' ] + test: + ["CMD", "curl", "-s", "http://localhost:9200/_cluster/health?pretty"] interval: 30s timeout: 10s retries: 50 @@ -702,17 +735,17 @@ services: environment: XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY: d1a66dfd-c4d3-4a0a-8290-2abcb83ab3aa NO_PROXY: localhost,127.0.0.1,elasticsearch,kibana - XPACK_SECURITY_ENABLED: 'true' - XPACK_SECURITY_ENROLLMENT_ENABLED: 'false' - XPACK_SECURITY_HTTP_SSL_ENABLED: 'false' - XPACK_FLEET_ISAIRGAPPED: 'true' + XPACK_SECURITY_ENABLED: "true" + XPACK_SECURITY_ENROLLMENT_ENABLED: "false" + XPACK_SECURITY_HTTP_SSL_ENABLED: "false" + XPACK_FLEET_ISAIRGAPPED: "true" I18N_LOCALE: zh-CN - SERVER_PORT: '5601' + SERVER_PORT: "5601" ELASTICSEARCH_HOSTS: http://elasticsearch:9200 ports: - ${KIBANA_PORT:-5601}:5601 healthcheck: - test: [ 'CMD-SHELL', 'curl -s http://localhost:5601 >/dev/null || exit 1' ] + test: ["CMD-SHELL", "curl -s http://localhost:5601 >/dev/null || exit 1"] interval: 30s timeout: 10s retries: 3 diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 5a78d42f98..69d75f1069 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -586,7 +586,7 @@ x-shared-env: &shared-api-worker-env services: # API service api: - image: langgenius/dify-api:1.8.0 + image: langgenius/dify-api:1.8.1 restart: always environment: # Use the shared environment variables. @@ -615,7 +615,7 @@ services: # worker service # The Celery worker for processing the queue. worker: - image: langgenius/dify-api:1.8.0 + image: langgenius/dify-api:1.8.1 restart: always environment: # Use the shared environment variables. @@ -642,7 +642,7 @@ services: # worker_beat service # Celery beat for scheduling periodic tasks. worker_beat: - image: langgenius/dify-api:1.8.0 + image: langgenius/dify-api:1.8.1 restart: always environment: # Use the shared environment variables. @@ -660,7 +660,7 @@ services: # Frontend web application. web: - image: langgenius/dify-web:1.8.0 + image: langgenius/dify-web:1.8.1 restart: always environment: CONSOLE_API_URL: ${CONSOLE_API_URL:-} @@ -702,7 +702,17 @@ services: volumes: - ./volumes/db/data:/var/lib/postgresql/data healthcheck: - test: [ 'CMD', 'pg_isready', '-h', 'db', '-U', '${PGUSER:-postgres}', '-d', '${POSTGRES_DB:-dify}' ] + test: + [ + "CMD", + "pg_isready", + "-h", + "db", + "-U", + "${PGUSER:-postgres}", + "-d", + "${POSTGRES_DB:-dify}", + ] interval: 1s timeout: 3s retries: 60 @@ -719,7 +729,11 @@ services: # Set the redis password when startup redis server. command: redis-server --requirepass ${REDIS_PASSWORD:-difyai123456} healthcheck: - test: [ 'CMD-SHELL', 'redis-cli -a ${REDIS_PASSWORD:-difyai123456} ping | grep -q PONG' ] + test: + [ + "CMD-SHELL", + "redis-cli -a ${REDIS_PASSWORD:-difyai123456} ping | grep -q PONG", + ] # The DifySandbox sandbox: @@ -741,7 +755,7 @@ services: - ./volumes/sandbox/dependencies:/dependencies - ./volumes/sandbox/conf:/conf healthcheck: - test: [ 'CMD', 'curl', '-f', 'http://localhost:8194/health' ] + test: ["CMD", "curl", "-f", "http://localhost:8194/health"] networks: - ssrf_proxy_network @@ -815,7 +829,12 @@ services: volumes: - ./ssrf_proxy/squid.conf.template:/etc/squid/squid.conf.template - ./ssrf_proxy/docker-entrypoint.sh:/docker-entrypoint-mount.sh - entrypoint: [ 'sh', '-c', "cp /docker-entrypoint-mount.sh /docker-entrypoint.sh && sed -i 's/\r$$//' /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh && /docker-entrypoint.sh" ] + entrypoint: + [ + "sh", + "-c", + "cp /docker-entrypoint-mount.sh /docker-entrypoint.sh && sed -i 's/\r$$//' /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh && /docker-entrypoint.sh", + ] environment: # pls clearly modify the squid env vars to fit your network environment. HTTP_PORT: ${SSRF_HTTP_PORT:-3128} @@ -844,8 +863,8 @@ services: - CERTBOT_EMAIL=${CERTBOT_EMAIL} - CERTBOT_DOMAIN=${CERTBOT_DOMAIN} - CERTBOT_OPTIONS=${CERTBOT_OPTIONS:-} - entrypoint: [ '/docker-entrypoint.sh' ] - command: [ 'tail', '-f', '/dev/null' ] + entrypoint: ["/docker-entrypoint.sh"] + command: ["tail", "-f", "/dev/null"] # The nginx reverse proxy. # used for reverse proxying the API service and Web service. @@ -862,7 +881,12 @@ services: - ./volumes/certbot/conf/live:/etc/letsencrypt/live # cert dir (with certbot container) - ./volumes/certbot/conf:/etc/letsencrypt - ./volumes/certbot/www:/var/www/html - entrypoint: [ 'sh', '-c', "cp /docker-entrypoint-mount.sh /docker-entrypoint.sh && sed -i 's/\r$$//' /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh && /docker-entrypoint.sh" ] + entrypoint: + [ + "sh", + "-c", + "cp /docker-entrypoint-mount.sh /docker-entrypoint.sh && sed -i 's/\r$$//' /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh && /docker-entrypoint.sh", + ] environment: NGINX_SERVER_NAME: ${NGINX_SERVER_NAME:-_} NGINX_HTTPS_ENABLED: ${NGINX_HTTPS_ENABLED:-false} @@ -884,14 +908,14 @@ services: - api - web ports: - - '${EXPOSE_NGINX_PORT:-80}:${NGINX_PORT:-80}' - - '${EXPOSE_NGINX_SSL_PORT:-443}:${NGINX_SSL_PORT:-443}' + - "${EXPOSE_NGINX_PORT:-80}:${NGINX_PORT:-80}" + - "${EXPOSE_NGINX_SSL_PORT:-443}:${NGINX_SSL_PORT:-443}" # The Weaviate vector store. weaviate: image: semitechnologies/weaviate:1.19.0 profiles: - - '' + - "" - weaviate restart: always volumes: @@ -944,13 +968,17 @@ services: working_dir: /opt/couchbase stdin_open: true tty: true - entrypoint: [ "" ] + entrypoint: [""] command: sh -c "/opt/couchbase/init/init-cbserver.sh" volumes: - ./volumes/couchbase/data:/opt/couchbase/var/lib/couchbase/data healthcheck: # ensure bucket was created before proceeding - test: [ "CMD-SHELL", "curl -s -f -u Administrator:password http://localhost:8091/pools/default/buckets | grep -q '\\[{' || exit 1" ] + test: + [ + "CMD-SHELL", + "curl -s -f -u Administrator:password http://localhost:8091/pools/default/buckets | grep -q '\\[{' || exit 1", + ] interval: 10s retries: 10 start_period: 30s @@ -976,9 +1004,9 @@ services: volumes: - ./volumes/pgvector/data:/var/lib/postgresql/data - ./pgvector/docker-entrypoint.sh:/docker-entrypoint.sh - entrypoint: [ '/docker-entrypoint.sh' ] + entrypoint: ["/docker-entrypoint.sh"] healthcheck: - test: [ 'CMD', 'pg_isready' ] + test: ["CMD", "pg_isready"] interval: 1s timeout: 3s retries: 30 @@ -995,14 +1023,14 @@ services: - VB_USERNAME=dify - VB_PASSWORD=Difyai123456 ports: - - '5434:5432' + - "5434:5432" volumes: - ./vastbase/lic:/home/vastbase/vastbase/lic - ./vastbase/data:/home/vastbase/data - ./vastbase/backup:/home/vastbase/backup - ./vastbase/backup_log:/home/vastbase/backup_log healthcheck: - test: [ 'CMD', 'pg_isready' ] + test: ["CMD", "pg_isready"] interval: 1s timeout: 3s retries: 30 @@ -1024,7 +1052,7 @@ services: volumes: - ./volumes/pgvecto_rs/data:/var/lib/postgresql/data healthcheck: - test: [ 'CMD', 'pg_isready' ] + test: ["CMD", "pg_isready"] interval: 1s timeout: 3s retries: 30 @@ -1063,7 +1091,11 @@ services: ports: - "${OCEANBASE_VECTOR_PORT:-2881}:2881" healthcheck: - test: [ 'CMD-SHELL', 'obclient -h127.0.0.1 -P2881 -uroot@test -p$${OB_TENANT_PASSWORD} -e "SELECT 1;"' ] + test: + [ + "CMD-SHELL", + 'obclient -h127.0.0.1 -P2881 -uroot@test -p$${OB_TENANT_PASSWORD} -e "SELECT 1;"', + ] interval: 10s retries: 30 start_period: 30s @@ -1099,7 +1131,7 @@ services: - ./volumes/milvus/etcd:/etcd command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd healthcheck: - test: [ 'CMD', 'etcdctl', 'endpoint', 'health' ] + test: ["CMD", "etcdctl", "endpoint", "health"] interval: 30s timeout: 20s retries: 3 @@ -1118,7 +1150,7 @@ services: - ./volumes/milvus/minio:/minio_data command: minio server /minio_data --console-address ":9001" healthcheck: - test: [ 'CMD', 'curl', '-f', 'http://localhost:9000/minio/health/live' ] + test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] interval: 30s timeout: 20s retries: 3 @@ -1130,7 +1162,7 @@ services: image: milvusdb/milvus:v2.5.15 profiles: - milvus - command: [ 'milvus', 'run', 'standalone' ] + command: ["milvus", "run", "standalone"] environment: ETCD_ENDPOINTS: ${ETCD_ENDPOINTS:-etcd:2379} MINIO_ADDRESS: ${MINIO_ADDRESS:-minio:9000} @@ -1138,7 +1170,7 @@ services: volumes: - ./volumes/milvus/milvus:/var/lib/milvus healthcheck: - test: [ 'CMD', 'curl', '-f', 'http://localhost:9091/healthz' ] + test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"] interval: 30s start_period: 90s timeout: 20s @@ -1204,7 +1236,7 @@ services: volumes: - ./volumes/opengauss/data:/var/lib/opengauss/data healthcheck: - test: [ "CMD-SHELL", "netstat -lntp | grep tcp6 > /dev/null 2>&1" ] + test: ["CMD-SHELL", "netstat -lntp | grep tcp6 > /dev/null 2>&1"] interval: 10s timeout: 10s retries: 10 @@ -1257,18 +1289,19 @@ services: node.name: dify-es0 discovery.type: single-node xpack.license.self_generated.type: basic - xpack.security.enabled: 'true' - xpack.security.enrollment.enabled: 'false' - xpack.security.http.ssl.enabled: 'false' + xpack.security.enabled: "true" + xpack.security.enrollment.enabled: "false" + xpack.security.http.ssl.enabled: "false" ports: - ${ELASTICSEARCH_PORT:-9200}:9200 deploy: resources: limits: memory: 2g - entrypoint: [ 'sh', '-c', "sh /docker-entrypoint-mount.sh" ] + entrypoint: ["sh", "-c", "sh /docker-entrypoint-mount.sh"] healthcheck: - test: [ 'CMD', 'curl', '-s', 'http://localhost:9200/_cluster/health?pretty' ] + test: + ["CMD", "curl", "-s", "http://localhost:9200/_cluster/health?pretty"] interval: 30s timeout: 10s retries: 50 @@ -1286,17 +1319,17 @@ services: environment: XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY: d1a66dfd-c4d3-4a0a-8290-2abcb83ab3aa NO_PROXY: localhost,127.0.0.1,elasticsearch,kibana - XPACK_SECURITY_ENABLED: 'true' - XPACK_SECURITY_ENROLLMENT_ENABLED: 'false' - XPACK_SECURITY_HTTP_SSL_ENABLED: 'false' - XPACK_FLEET_ISAIRGAPPED: 'true' + XPACK_SECURITY_ENABLED: "true" + XPACK_SECURITY_ENROLLMENT_ENABLED: "false" + XPACK_SECURITY_HTTP_SSL_ENABLED: "false" + XPACK_FLEET_ISAIRGAPPED: "true" I18N_LOCALE: zh-CN - SERVER_PORT: '5601' + SERVER_PORT: "5601" ELASTICSEARCH_HOSTS: http://elasticsearch:9200 ports: - ${KIBANA_PORT:-5601}:5601 healthcheck: - test: [ 'CMD-SHELL', 'curl -s http://localhost:5601 >/dev/null || exit 1' ] + test: ["CMD-SHELL", "curl -s http://localhost:5601 >/dev/null || exit 1"] interval: 30s timeout: 10s retries: 3 diff --git a/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx b/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx index e856e6a88a..cc5e46deeb 100644 --- a/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx +++ b/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx @@ -52,6 +52,10 @@ const ChatWrapper = () => { allInputsHidden, initUserVariables, } = useChatWithHistoryContext() + + // Semantic variable for better code readability + const isHistoryConversation = !!currentConversationId + const appConfig = useMemo(() => { const config = appParams || {} @@ -62,9 +66,9 @@ const ChatWrapper = () => { fileUploadConfig: (config as any).system_parameters, }, supportFeedback: true, - opening_statement: currentConversationId ? currentConversationItem?.introduction : (config as any).opening_statement, + opening_statement: isHistoryConversation ? currentConversationItem?.introduction : (config as any).opening_statement, } as ChatConfig - }, [appParams, currentConversationItem?.introduction, currentConversationId]) + }, [appParams, currentConversationItem?.introduction, isHistoryConversation]) const { chatList, setTargetMessageId, @@ -75,7 +79,7 @@ const ChatWrapper = () => { } = useChat( appConfig, { - inputs: (currentConversationId ? currentConversationInputs : newConversationInputs) as any, + inputs: (isHistoryConversation ? currentConversationInputs : newConversationInputs) as any, inputsForm: inputsForms, }, appPrevChatTree, @@ -83,7 +87,7 @@ const ChatWrapper = () => { clearChatList, setClearChatList, ) - const inputsFormValue = currentConversationId ? currentConversationInputs : newConversationInputsRef?.current + const inputsFormValue = isHistoryConversation ? currentConversationInputs : newConversationInputsRef?.current const inputDisabled = useMemo(() => { if (allInputsHidden) return false @@ -132,7 +136,7 @@ const ChatWrapper = () => { const data: any = { query: message, files, - inputs: formatBooleanInputs(inputsForms, currentConversationId ? currentConversationInputs : newConversationInputs), + inputs: formatBooleanInputs(inputsForms, isHistoryConversation ? currentConversationInputs : newConversationInputs), conversation_id: currentConversationId, parent_message_id: (isRegenerate ? parentAnswer?.id : getLastAnswer(chatList)?.id) || null, } @@ -142,11 +146,11 @@ const ChatWrapper = () => { data, { onGetSuggestedQuestions: responseItemId => fetchSuggestedQuestions(responseItemId, isInstalledApp, appId), - onConversationComplete: currentConversationId ? undefined : handleNewConversationCompleted, + onConversationComplete: isHistoryConversation ? undefined : handleNewConversationCompleted, isPublicAPI: !isInstalledApp, }, ) - }, [chatList, handleNewConversationCompleted, handleSend, currentConversationId, currentConversationInputs, newConversationInputs, isInstalledApp, appId]) + }, [chatList, handleNewConversationCompleted, handleSend, isHistoryConversation, currentConversationInputs, newConversationInputs, isInstalledApp, appId]) const doRegenerate = useCallback((chatItem: ChatItemInTree, editedQuestion?: { message: string, files?: FileEntity[] }) => { const question = editedQuestion ? chatItem : chatList.find(item => item.id === chatItem.parentMessageId)! @@ -159,31 +163,30 @@ const ChatWrapper = () => { }, [chatList, doSend]) const messageList = useMemo(() => { - if (currentConversationId) - return chatList + // Always filter out opening statement from message list as it's handled separately in welcome component return chatList.filter(item => !item.isOpeningStatement) - }, [chatList, currentConversationId]) + }, [chatList]) - const [collapsed, setCollapsed] = useState(!!currentConversationId) + const [collapsed, setCollapsed] = useState(isHistoryConversation) const chatNode = useMemo(() => { if (allInputsHidden || !inputsForms.length) return null if (isMobile) { - if (!currentConversationId) + if (!isHistoryConversation) return return null } else { return } - }, [inputsForms.length, isMobile, currentConversationId, collapsed, allInputsHidden]) + }, [inputsForms.length, isMobile, isHistoryConversation, collapsed, allInputsHidden]) const welcome = useMemo(() => { const welcomeMessage = chatList.find(item => item.isOpeningStatement) if (respondingState) return null - if (currentConversationId) + if (isHistoryConversation) return null if (!welcomeMessage) return null @@ -224,7 +227,7 @@ const ChatWrapper = () => { ) - }, [appData?.site.icon, appData?.site.icon_background, appData?.site.icon_type, appData?.site.icon_url, chatList, collapsed, currentConversationId, inputsForms.length, respondingState, allInputsHidden]) + }, [appData?.site.icon, appData?.site.icon_background, appData?.site.icon_type, appData?.site.icon_url, chatList, collapsed, isHistoryConversation, inputsForms.length, respondingState, allInputsHidden]) const answerIcon = (appData?.site && appData.site.use_icon_as_answer_icon) ? { chatFooterClassName='pb-4' chatFooterInnerClassName={`mx-auto w-full max-w-[768px] ${isMobile ? 'px-2' : 'px-4'}`} onSend={doSend} - inputs={currentConversationId ? currentConversationInputs as any : newConversationInputs} + inputs={isHistoryConversation ? currentConversationInputs as any : newConversationInputs} inputsForm={inputsForms} onRegenerate={doRegenerate} onStopResponding={handleStop} diff --git a/web/app/components/header/account-setting/model-provider-page/declarations.ts b/web/app/components/header/account-setting/model-provider-page/declarations.ts index 9fac34b21b..62cb1a96e9 100644 --- a/web/app/components/header/account-setting/model-provider-page/declarations.ts +++ b/web/app/components/header/account-setting/model-provider-page/declarations.ts @@ -14,7 +14,7 @@ export enum FormTypeEnum { secretInput = 'secret-input', select = 'select', radio = 'radio', - boolean = 'boolean', + boolean = 'checkbox', files = 'files', file = 'file', modelSelector = 'model-selector', diff --git a/web/app/components/header/account-setting/model-provider-page/model-modal/index.tsx b/web/app/components/header/account-setting/model-provider-page/model-modal/index.tsx index adf633831b..4ffbc8f191 100644 --- a/web/app/components/header/account-setting/model-provider-page/model-modal/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/model-modal/index.tsx @@ -115,7 +115,7 @@ const ModelModal: FC = ({ const [selectedCredential, setSelectedCredential] = useState() const formRef2 = useRef(null) const isEditMode = !!Object.keys(formValues).filter((key) => { - return key !== '__model_name' && key !== '__model_type' + return key !== '__model_name' && key !== '__model_type' && !!formValues[key] }).length && isCurrentWorkspaceManager const handleSave = useCallback(async () => { @@ -167,7 +167,7 @@ const ModelModal: FC = ({ __authorization_name__, ...rest } = values - if (__model_name && __model_type && __authorization_name__) { + if (__model_name && __model_type) { await handleSaveCredential({ credential_id: credential?.credential_id, credentials: rest, diff --git a/web/app/components/workflow/nodes/_base/components/form-input-item.tsx b/web/app/components/workflow/nodes/_base/components/form-input-item.tsx index d624130317..a7825145b4 100644 --- a/web/app/components/workflow/nodes/_base/components/form-input-item.tsx +++ b/web/app/components/workflow/nodes/_base/components/form-input-item.tsx @@ -90,8 +90,8 @@ const FormInputItem: FC = ({ // return VarType.appSelector // else if (isModelSelector) // return VarType.modelSelector - // else if (isBoolean) - // return VarType.boolean + else if (isBoolean) + return VarType.boolean else if (isObject) return VarType.object else if (isArray) @@ -183,7 +183,7 @@ const FormInputItem: FC = ({ return (
{showTypeSwitch && ( - + )} {isString && ( = ({ placeholder={placeholder?.[language] || placeholder?.en_US} /> )} - {isBoolean && ( + {isBoolean && isConstant && ( =v22.11.0" },