chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动

演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wuzilongandCursor committed 2026-11-18 13:59:25 +08:00
1 parent 60158935f4
commit 6519682885
15831 files changed
+3063428

No files matched your search

+107
View File
@@ -0,0 +1,107 @@
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
REPO_ROOT="$SCRIPT_DIR/.."
cd "$REPO_ROOT"
EXCLUDES_FILE="api/pyrefly-local-excludes.txt"
UNIT_TESTS_CONFIG="tests/unit_tests/pyrefly.toml"
TEST_CONTAINERS_DIR="tests/e2e_tests/containers"
TEST_CONTAINERS_CONFIG="$TEST_CONTAINERS_DIR/pyrefly.toml"
target_paths=()
for target_path in "$@"; do
if [[ "$target_path" == api/* ]]; then
target_paths+=("${target_path#api/}")
else
target_paths+=("$target_path")
fi
done
pyrefly_args=(
"--summary=none"
"--use-ignore-files=false"
"--disable-project-excludes-heuristics=true"
"--project-excludes=.venv"
"--project-excludes=migrations/"
"--project-excludes=tests/"
)
if [[ "${PYREFLY_OUTPUT_FORMAT:-}" == "github" ]]; then
pyrefly_args+=("--output-format=github")
fi
if [[ -f "$EXCLUDES_FILE" ]]; then
while IFS= read -r exclude; do
[[ -z "$exclude" || "${exclude:0:1}" == "#" ]] && continue
pyrefly_args+=("--project-excludes=$exclude")
done < "$EXCLUDES_FILE"
fi
run_pyrefly() {
if [[ "${PYREFLY_OUTPUT_FORMAT:-}" == "github" ]]; then
set +e
"$@"
local pyrefly_status=$?
set -e
return "$pyrefly_status"
fi
local tmp_output
tmp_output="$(mktemp)"
set +e
"$@" >"$tmp_output" 2>&1
local pyrefly_status=$?
set -e
uv run --directory api python libs/pyrefly_diagnostics.py --status "$pyrefly_status" < "$tmp_output"
rm -f "$tmp_output"
return "$pyrefly_status"
}
status=0
pyrefly_command=(
uv run --directory api --dev pyrefly check
"${pyrefly_args[@]}"
)
if (( ${#target_paths[@]} > 0 )); then
pyrefly_command+=("${target_paths[@]}")
fi
run_pyrefly "${pyrefly_command[@]}" || status=$?
if (( ${#target_paths[@]} == 0 )); then
unit_tests_args=(
"--summary=none"
"--use-ignore-files=false"
"--disable-project-excludes-heuristics=true"
"--config=$UNIT_TESTS_CONFIG"
)
if [[ "${PYREFLY_OUTPUT_FORMAT:-}" == "github" ]]; then
unit_tests_args+=("--output-format=github")
fi
run_pyrefly \
uv run --directory api --dev pyrefly check \
"${unit_tests_args[@]}" \
|| status=$?
test_containers_args=(
"--summary=none"
"--use-ignore-files=false"
"--disable-project-excludes-heuristics=true"
"--config=$TEST_CONTAINERS_CONFIG"
)
if [[ "${PYREFLY_OUTPUT_FORMAT:-}" == "github" ]]; then
test_containers_args+=("--output-format=github")
fi
run_pyrefly \
uv run --directory api --dev pyrefly check \
"${test_containers_args[@]}" \
|| status=$?
fi
exit "$status"
+21
View File
@@ -0,0 +1,21 @@
#!/bin/bash
set -x
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
cd "$SCRIPT_DIR/.."
# Import linter
uv run --directory api --dev lint-imports
# run ruff linter
uv run --directory api --dev ruff check --fix ./
# run ruff formatter
uv run --directory api --dev ruff format ./
# run dotenv-linter linter
uv run --project api --dev dotenv-linter ./api/.env.example ./web/.env.example
# run pyrefly check
dev/pyrefly-check-local
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
ROOT="$(dirname "$SCRIPT_DIR")"
API_ENV_EXAMPLE="$ROOT/api/.env.example"
API_ENV="$ROOT/api/.env"
WEB_ENV_EXAMPLE="$ROOT/web/.env.example"
WEB_ENV="$ROOT/web/.env.local"
MIDDLEWARE_ENV_EXAMPLE="$ROOT/docker/envs/middleware.env.example"
MIDDLEWARE_ENV="$ROOT/docker/middleware.env"
# 1) Copy api/.env.example -> api/.env
cp "$API_ENV_EXAMPLE" "$API_ENV"
# 2) Copy web/.env.example -> web/.env.local
cp "$WEB_ENV_EXAMPLE" "$WEB_ENV"
# 3) Copy docker/envs/middleware.env.example -> docker/middleware.env
cp "$MIDDLEWARE_ENV_EXAMPLE" "$MIDDLEWARE_ENV"
# 4) Install deps
cd "$ROOT/api"
uv sync --group dev
pnpm --dir "$ROOT" install
+11
View File
@@ -0,0 +1,11 @@
#!/bin/bash
set -x
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
cd "$SCRIPT_DIR/../api" || exit 1
uv run flask db upgrade
uv run \
dotenv -f .env run --no-override -- python -m app
+60
View File
@@ -0,0 +1,60 @@
#!/bin/bash
set -x
# Help function
show_help() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --loglevel LEVEL Log level (default: INFO)"
echo " --scheduler SCHEDULER Scheduler class (default: celery.beat:PersistentScheduler)"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0"
echo " $0 --loglevel DEBUG"
echo " $0 --scheduler django_celery_beat.schedulers:DatabaseScheduler"
echo ""
echo "Description:"
echo " Starts Celery Beat scheduler for periodic task execution."
echo " Beat sends scheduled tasks to worker queues at specified intervals."
}
# Parse command line arguments
LOGLEVEL="INFO"
SCHEDULER="celery.beat:PersistentScheduler"
while [[ $# -gt 0 ]]; do
case $1 in
--loglevel)
LOGLEVEL="$2"
shift 2
;;
--scheduler)
SCHEDULER="$2"
shift 2
;;
-h|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1"
show_help
exit 1
;;
esac
done
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
cd "$SCRIPT_DIR/.."
echo "Starting Celery Beat with:"
echo " Log Level: ${LOGLEVEL}"
echo " Scheduler: ${SCHEDULER}"
uv --directory api run \
celery -A app.celery beat \
--loglevel ${LOGLEVEL} \
--scheduler ${SCHEDULER}
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
ROOT="$(dirname "$SCRIPT_DIR")"
cd "$ROOT/docker"
docker compose --env-file middleware.env -f docker-compose.middleware.yaml -p dify up -d
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
set -x
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
pnpm --dir "$ROOT_DIR" install && pnpm --dir "$ROOT_DIR/web" dev
+138
View File
@@ -0,0 +1,138 @@
#!/bin/bash
set -x
# Help function
show_help() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -q, --queues QUEUES Comma-separated list of queues to process"
echo " -c, --concurrency NUM Number of worker processes (default: 1)"
echo " -P, --pool POOL Pool implementation (default: gevent)"
echo " --loglevel LEVEL Log level (default: INFO)"
echo " -e, --env-file FILE Path to an env file to source before starting"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 --queues dataset,workflow"
echo " $0 --queues workflow_professional,workflow_team --concurrency 4"
echo " $0 --queues dataset --concurrency 2 --pool prefork"
echo ""
echo "Available queues:"
echo " dataset - RAG indexing and document processing"
echo " dataset_summary - LLM-heavy summary index generation (isolated from indexing)"
echo " workflow - Workflow triggers (community edition)"
echo " workflow_professional - Professional tier workflows (cloud edition)"
echo " workflow_team - Team tier workflows (cloud edition)"
echo " workflow_sandbox - Sandbox tier workflows (cloud edition)"
echo " schedule_poller - Schedule polling tasks"
echo " schedule_executor - Schedule execution tasks"
echo " mail - Email notifications"
echo " ops_trace_v2 - Operations tracing (override with OPS_TRACE_QUEUE)"
echo " app_deletion - Application cleanup"
echo " plugin - Plugin operations"
echo " workflow_storage - Workflow storage tasks"
echo " conversation - Conversation tasks"
echo " priority_pipeline - High priority pipeline tasks"
echo " pipeline - Standard pipeline tasks"
echo " triggered_workflow_dispatcher - Trigger dispatcher tasks"
echo " trigger_refresh_executor - Trigger refresh tasks"
echo " retention - Retention tasks"
echo " knowledge_fs_lifecycle - KnowledgeFS provisioning and deletion lifecycle"
}
# Parse command line arguments
QUEUES=""
CONCURRENCY=1
POOL="gevent"
LOGLEVEL="INFO"
ENV_FILE=""
while [[ $# -gt 0 ]]; do
case $1 in
-q|--queues)
QUEUES="$2"
shift 2
;;
-c|--concurrency)
CONCURRENCY="$2"
shift 2
;;
-P|--pool)
POOL="$2"
shift 2
;;
--loglevel)
LOGLEVEL="$2"
shift 2
;;
-e|--env-file)
ENV_FILE="$2"
shift 2
;;
-h|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1"
show_help
exit 1
;;
esac
done
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
cd "$SCRIPT_DIR/../api" || exit 1
if [[ -n "${ENV_FILE}" ]]; then
if [[ ! -f "${ENV_FILE}" ]]; then
echo "Env file ${ENV_FILE} not found"
exit 1
fi
echo "Loading environment variables from ${ENV_FILE}"
# Export everything sourced from the env file
set -a
# The env file is selected at runtime via --env-file.
# shellcheck source=/dev/null
source "${ENV_FILE}"
set +a
fi
# If no queues are specified, use product-edition defaults
if [[ -z "${QUEUES}" ]]; then
# Configure queues based on product edition
if [[ "${DEPLOYMENT_EDITION:-COMMUNITY}" == "CLOUD" ]]; then
# Cloud edition: separate queues for dataset and trigger tasks
QUEUES="dataset,dataset_summary,priority_dataset,priority_pipeline,pipeline,mail,${OPS_TRACE_QUEUE:-ops_trace_v2},app_deletion,plugin,workflow_storage,conversation,workflow_professional,workflow_team,workflow_sandbox,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor,retention,workflow_based_app_execution,knowledge_fs_lifecycle"
else
# Self-hosted editions: dataset and workflow have separate queues
QUEUES="dataset,dataset_summary,priority_dataset,priority_pipeline,pipeline,mail,${OPS_TRACE_QUEUE:-ops_trace_v2},app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor,retention,workflow_based_app_execution,knowledge_fs_lifecycle"
fi
echo "No queues specified, using edition-based defaults: ${QUEUES}"
else
echo "Using specified queues: ${QUEUES}"
fi
case ",${QUEUES}," in
*,knowledge_fs_upgrade,*)
if [[ "${POOL}" != "prefork" ]]; then
echo "KnowledgeFS upgrades require --pool prefork to enforce checkpoint time limits." >&2
exit 1
fi
;;
esac
echo "Starting Celery worker with:"
echo " Queues: ${QUEUES}"
echo " Concurrency: ${CONCURRENCY}"
echo " Pool: ${POOL}"
echo " Log Level: ${LOGLEVEL}"
uv run \
celery -A app.celery worker \
-P ${POOL} -c ${CONCURRENCY} --loglevel ${LOGLEVEL} -Q ${QUEUES}
+13
View File
@@ -0,0 +1,13 @@
#!/bin/bash
# rely on `uv` in path
if ! command -v uv &> /dev/null; then
echo "Installing uv ..."
pip install uv
fi
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
cd "$SCRIPT_DIR/.."
# check uv.lock in sync with pyproject.toml
uv lock --project api
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
set -x
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
cd "$SCRIPT_DIR/.."
# run ty checks
uv run --directory api --dev \
ty check
+22
View File
@@ -0,0 +1,22 @@
#!/bin/bash
# Update dependencies in dify/api project using uv
set -e
set -o pipefail
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
REPO_ROOT="$(dirname "${SCRIPT_DIR}")"
# rely on `poetry` in path
if ! command -v uv &> /dev/null; then
echo "Installing uv ..."
pip install uv
fi
cd "${REPO_ROOT}"
# refreshing lockfile, updating locked versions
uv lock --project api --upgrade
# check uv.lock in sync with pyproject.toml
uv lock --project api --check