chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2025 coze-dev Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
|
||||
# Script for updating user password
|
||||
# Usage: ./change_user_password.sh <email> [password]
|
||||
# Parameters:
|
||||
# email: User email (required)
|
||||
# password: New password (optional, default is 123456)
|
||||
|
||||
set -e
|
||||
|
||||
# Check parameters
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: $0 <email> [password]"
|
||||
echo "Parameters:"
|
||||
echo " email: User email (required)"
|
||||
echo " password: New password (optional, default is 123456)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
EMAIL="$1"
|
||||
PASSWORD="${2:-123456}"
|
||||
|
||||
# Read MySQL configuration from docker-compose.yml
|
||||
MYSQL_USER="${MYSQL_USER:-coze}"
|
||||
MYSQL_PASSWORD="${MYSQL_PASSWORD:-coze123}"
|
||||
MYSQL_DATABASE="${MYSQL_DATABASE:-opencoze}"
|
||||
MYSQL_CONTAINER="coze-mysql"
|
||||
|
||||
echo "Updating password for user $EMAIL..."
|
||||
|
||||
# Python script to generate Argon2id hashed password
|
||||
# Reference implementation from hashPassword function in user_impl.go
|
||||
PYTHON_SCRIPT=$(cat << 'EOF'
|
||||
import argon2
|
||||
import base64
|
||||
import sys
|
||||
|
||||
def hash_password(password):
|
||||
# Default Argon2id parameters, consistent with Go code parameters
|
||||
memory = 64 * 1024 # 64MB
|
||||
iterations = 3
|
||||
parallelism = 4
|
||||
salt_length = 16
|
||||
key_length = 32
|
||||
|
||||
# Create Argon2 hasher
|
||||
hasher = argon2.PasswordHasher(
|
||||
memory_cost=memory,
|
||||
time_cost=iterations,
|
||||
parallelism=parallelism,
|
||||
hash_len=key_length,
|
||||
salt_len=salt_length
|
||||
)
|
||||
|
||||
# Generate hash
|
||||
hashed = hasher.hash(password)
|
||||
return hashed
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python script.py <password>")
|
||||
sys.exit(1)
|
||||
|
||||
password = sys.argv[1]
|
||||
hashed_password = hash_password(password)
|
||||
print(hashed_password)
|
||||
EOF
|
||||
)
|
||||
|
||||
# Check if argon2-cffi is installed
|
||||
if ! python -c "import argon2" 2>/dev/null; then
|
||||
echo "Error: argon2-cffi library is required"
|
||||
echo "If your version of python is python2"
|
||||
echo " Please run: pip install argon2"
|
||||
echo "If your version of python is python3"
|
||||
echo " Please run: pip install argon2-cffi"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Generate hashed password
|
||||
echo "Generating password hash..."
|
||||
HASHED_PASSWORD=$(echo "$PYTHON_SCRIPT" | python - "$PASSWORD")
|
||||
|
||||
if [ -z "$HASHED_PASSWORD" ]; then
|
||||
echo "Error: Password hash generation failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Password hash generated successfully"
|
||||
|
||||
# Check if MySQL container is running
|
||||
if ! docker ps | grep -q "$MYSQL_CONTAINER"; then
|
||||
echo "Error: MySQL container '$MYSQL_CONTAINER' is not running"
|
||||
echo "Please start MySQL container first: docker-compose up -d mysql"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Build SQL update statement
|
||||
SQL="UPDATE user SET password = '$HASHED_PASSWORD' WHERE email = '$EMAIL';"
|
||||
|
||||
echo "Executing SQL update..."
|
||||
|
||||
# Execute SQL statement through Docker and capture both stdout and stderr
|
||||
# Use --verbose flag to get detailed output including row count information
|
||||
RESULT=$(docker exec -it "$MYSQL_CONTAINER" mysql -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" --verbose -e "$SQL" 2>&1)
|
||||
EXIT_CODE=$?
|
||||
# Check if command executed successfully
|
||||
if [ $EXIT_CODE -eq 0 ]; then
|
||||
echo "The SQL query executed successfully"
|
||||
else
|
||||
echo "❌ Error: SQL execution failed (exit code: $EXIT_CODE)"
|
||||
echo "$RESULT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Operation completed"
|
||||
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
DOCKER_DIR="$(cd "$SCRIPT_DIR/../../docker" && pwd)"
|
||||
BACKEND_DIR="$(cd "$SCRIPT_DIR/../../backend" && pwd)"
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[0;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m'
|
||||
|
||||
cd "$DOCKER_DIR/atlas"
|
||||
|
||||
source "$DOCKER_DIR/.env"
|
||||
echo "ATLAS_URL: $ATLAS_URL"
|
||||
|
||||
# Check if ATLAS_URL is set
|
||||
if [ -z "$ATLAS_URL" ]; then
|
||||
echo -e "${RED}Error: ATLAS_URL is not set. Please set the ATLAS_URL environment variable.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# check if atlas is installed
|
||||
OS=$(uname -s)
|
||||
|
||||
if command -v atlas &>/dev/null; then
|
||||
echo -e "${GREEN}Atlas is installed.${NC}"
|
||||
else
|
||||
if [ "$OS" = "Darwin" ]; then
|
||||
# macOS prompt
|
||||
echo -e "${RED}Atlas is not installed. Please execute the following command to install:${NC}"
|
||||
echo -e "${RED}brew install ariga/tap/atlas${NC}"
|
||||
exit 1
|
||||
else
|
||||
# Linux prompt
|
||||
echo -e "${RED}Atlas is not installed. Please execute the following command to install:${NC}"
|
||||
echo -e "${RED}curl -sSf https://atlasgo.sh | sh -s -- --community${NC}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
cd "$DOCKER_DIR/atlas"
|
||||
|
||||
atlas schema apply -u $ATLAS_URL --to file://opencoze_latest_schema.hcl --exclude "atlas_schema_revisions,table_*" --auto-approve
|
||||
echo -e "${GREEN}✅ apply mysql schema successfully${NC}"
|
||||
|
||||
# if [ "$OS" = "Darwin" ]; then
|
||||
# atlas schema apply -u $ATLAS_URL --to file://opencoze_latest_schema.hcl --auto-approve --exclude "table_*"
|
||||
# echo -e "${GREEN}✅ apply mysql schema successfully${NC}"
|
||||
# elif [ "$OS" = "Linux" ]; then
|
||||
# atlas migrate apply \
|
||||
# --url "$ATLAS_URL" \
|
||||
# --dir "file://migrations" \
|
||||
# --revisions-schema opencoze \
|
||||
# --baseline "20250703095335"
|
||||
# echo -e "${GREEN}✅ migrate mysql successfully${NC}"
|
||||
# elif [ "$OS" = "Windows" ]; then
|
||||
# echo -e "${RED}Windows is not supported. Please install Atlas manually.${NC}"
|
||||
# exit 1
|
||||
# fi
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
BASE_DIR="$(cd "$SCRIPT_DIR/../../" && pwd)"
|
||||
ATLAS_DIR="$BASE_DIR/docker/atlas"
|
||||
DOCKER_DIR="$(cd "$SCRIPT_DIR/../../docker" && pwd)"
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[0;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Check if ATLAS_URL is set
|
||||
if [ -z "$ATLAS_URL" ]; then
|
||||
echo -e "${RED}Error: ATLAS_URL is not set. Please set the ATLAS_URL environment variable.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
echo "ATLAS_URL: $ATLAS_URL"
|
||||
|
||||
# check if atlas is installed
|
||||
OS=$(uname -s)
|
||||
|
||||
if command -v atlas &>/dev/null; then
|
||||
echo -e "${GREEN}Atlas is installed.${NC}"
|
||||
else
|
||||
if [ "$OS" = "Darwin" ]; then
|
||||
# macOS prompt
|
||||
echo -e "${RED}Atlas is not installed. Please execute the following command to install:${NC}"
|
||||
echo -e "${RED}brew install ariga/tap/atlas${NC}"
|
||||
exit 1
|
||||
else
|
||||
# Linux prompt
|
||||
echo -e "${RED}Atlas is not installed. Please execute the following command to install:${NC}"
|
||||
echo -e "${RED}curl -sSf https://atlasgo.sh | sh -s -- --community${NC}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
cd $ATLAS_DIR
|
||||
|
||||
atlas migrate diff update --env local --to $ATLAS_URL
|
||||
|
||||
atlas schema inspect -u $ATLAS_URL --exclude "atlas_schema_revisions,table_*" >opencoze_latest_schema.hcl
|
||||
@@ -0,0 +1,88 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2025 coze-dev Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
|
||||
# OceanBase Environment Configuration Script
|
||||
# Dynamically modify vector store type in environment files
|
||||
|
||||
set -e
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Script directory
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
DOCKER_DIR="$PROJECT_ROOT/../docker"
|
||||
|
||||
# Environment type
|
||||
ENV_TYPE="${1:-debug}"
|
||||
|
||||
# Validate environment type
|
||||
if [[ "$ENV_TYPE" != "debug" && "$ENV_TYPE" != "env" ]]; then
|
||||
echo -e "${RED}Error: Invalid environment type '$ENV_TYPE'${NC}"
|
||||
echo "Usage: $0 [debug|env]"
|
||||
echo " debug - Test environment (.env.debug)"
|
||||
echo " env - Production environment (.env)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Determine target environment file
|
||||
if [[ "$ENV_TYPE" == "debug" ]]; then
|
||||
TARGET_ENV_FILE="$DOCKER_DIR/.env.debug"
|
||||
else
|
||||
TARGET_ENV_FILE="$DOCKER_DIR/.env"
|
||||
fi
|
||||
|
||||
# Check if target environment file exists
|
||||
if [[ ! -f "$TARGET_ENV_FILE" ]]; then
|
||||
if [[ "$ENV_TYPE" == "debug" ]]; then
|
||||
cp "$DOCKER_DIR/.env.debug.example" "$TARGET_ENV_FILE"
|
||||
else
|
||||
cp "$DOCKER_DIR/.env.example" "$TARGET_ENV_FILE"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check if already configured for OceanBase
|
||||
if grep -q "VECTOR_STORE_TYPE.*oceanbase" "$TARGET_ENV_FILE"; then
|
||||
echo -e "${YELLOW}Already configured for OceanBase${NC}"
|
||||
else
|
||||
echo -e "${GREEN}Configuring OceanBase...${NC}"
|
||||
|
||||
# Use sed to replace VECTOR_STORE_TYPE
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS requires special handling - use temporary file to avoid .bak creation
|
||||
sed "s/export VECTOR_STORE_TYPE=\"milvus\"/export VECTOR_STORE_TYPE=\"oceanbase\"/g" "$TARGET_ENV_FILE" > "$TARGET_ENV_FILE.tmp"
|
||||
sed "s/export VECTOR_STORE_TYPE=\"vikingdb\"/export VECTOR_STORE_TYPE=\"oceanbase\"/g" "$TARGET_ENV_FILE.tmp" > "$TARGET_ENV_FILE"
|
||||
rm -f "$TARGET_ENV_FILE.tmp"
|
||||
else
|
||||
# Linux systems
|
||||
sed -i "s/export VECTOR_STORE_TYPE=\"milvus\"/export VECTOR_STORE_TYPE=\"oceanbase\"/g" "$TARGET_ENV_FILE"
|
||||
sed -i "s/export VECTOR_STORE_TYPE=\"vikingdb\"/export VECTOR_STORE_TYPE=\"oceanbase\"/g" "$TARGET_ENV_FILE"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Verify configuration
|
||||
if grep -q "VECTOR_STORE_TYPE.*oceanbase" "$TARGET_ENV_FILE"; then
|
||||
echo -e "${GREEN}✅ OceanBase configured successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Failed to configure OceanBase${NC}"
|
||||
exit 1
|
||||
fi
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SETUP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SCRIPT_DIR="$(dirname "$SETUP_DIR")"
|
||||
BASE_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
BACKEND_DIR="$BASE_DIR/backend"
|
||||
BIN_DIR="$BASE_DIR/bin"
|
||||
VENV_DIR="$BIN_DIR/.venv"
|
||||
|
||||
echo "Checking for Python virtual environment under $BIN_DIR"
|
||||
|
||||
if [ ! -f "$VENV_DIR/bin/activate" ]; then
|
||||
echo "Virtual environment not found or incomplete. Re-creating..."
|
||||
rm -rf "$VENV_DIR"
|
||||
python3 -m venv "$VENV_DIR"
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to create virtual environment - aborting startup"
|
||||
exit 1
|
||||
fi
|
||||
echo "Virtual environment created successfully!"
|
||||
else
|
||||
echo "Virtual environment already exists. Skipping creation."
|
||||
fi
|
||||
|
||||
|
||||
echo "Installing required Python packages"
|
||||
source "$VENV_DIR/bin/activate"
|
||||
pip install --upgrade pip
|
||||
# If you want to use other third-party libraries, you can install them here.
|
||||
pip install urllib3==1.26.16
|
||||
pip install h11==0.16.0 httpx==0.28.1 pillow==11.2.1 pdfplumber==0.11.7 python-docx==1.2.0 numpy==2.3.1
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to install Python packages - aborting startup"
|
||||
deactivate
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Python packages installed successfully!"
|
||||
deactivate
|
||||
|
||||
PARSER_SCRIPT_ROOT="$BACKEND_DIR/infra/document/parser/impl/builtin"
|
||||
PDF_PARSER="$PARSER_SCRIPT_ROOT/parse_pdf.py"
|
||||
DOCX_PARSER="$PARSER_SCRIPT_ROOT/parse_docx.py"
|
||||
WORKFLOW_SANBOX="$BACKEND_DIR/infra/coderunner/impl/script/sandbox.py"
|
||||
|
||||
if [ -f "$PDF_PARSER" ]; then
|
||||
cp "$PDF_PARSER" "$BIN_DIR/parse_pdf.py"
|
||||
else
|
||||
echo "❌ $PDF_PARSER file not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "$DOCX_PARSER" ]; then
|
||||
cp "$DOCX_PARSER" "$BIN_DIR/parse_docx.py"
|
||||
else
|
||||
echo "❌ $DOCX_PARSER file not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "$WORKFLOW_SANBOX" ]; then
|
||||
cp "$WORKFLOW_SANBOX" "$BIN_DIR/sandbox.py"
|
||||
else
|
||||
echo "❌ $WORKFLOW_SANBOX file not found"
|
||||
exit 1
|
||||
fi
|
||||
@@ -0,0 +1,98 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2025 coze-dev Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
BASE_DIR="$(cd "$SCRIPT_DIR/../../" && pwd)"
|
||||
BACKEND_DIR="$BASE_DIR/backend"
|
||||
BIN_DIR="$BASE_DIR/bin"
|
||||
CONFIG_DIR="$BIN_DIR/resources/conf"
|
||||
RESOURCES_DIR="$BIN_DIR/resources/"
|
||||
DOCKER_DIR="$BASE_DIR/docker"
|
||||
# source "$DOCKER_DIR/.env"
|
||||
ENV_FILE="$DOCKER_DIR/.env"
|
||||
|
||||
if [[ "$APP_ENV" == "debug" ]]; then
|
||||
ENV_FILE="$DOCKER_DIR/.env.debug"
|
||||
elif [[ "$APP_ENV" == "oceanbase" ]]; then
|
||||
ENV_FILE="$DOCKER_DIR/.env"
|
||||
fi
|
||||
|
||||
source "$ENV_FILE"
|
||||
|
||||
if [[ "$CODE_RUNNER_TYPE" == "sandbox" ]] && ! command -v deno &> /dev/null; then
|
||||
echo "deno is not installed, installing now..."
|
||||
curl -fsSL https://deno.land/install.sh | sh
|
||||
export PATH="$HOME/.deno/bin:$PATH"
|
||||
fi
|
||||
|
||||
echo "🧹 Checking for sandbox availability..."
|
||||
|
||||
echo "🧹 Checking for goimports availability..."
|
||||
|
||||
if command -v goimports >/dev/null 2>&1; then
|
||||
echo "🧹 Formatting Go files with goimports..."
|
||||
find "$BACKEND_DIR" \
|
||||
-path "$BACKEND_DIR/api/model" -prune -o \
|
||||
-path "$BACKEND_DIR/api/router" -prune -o \
|
||||
-path "*/dal/query*" -prune -o \
|
||||
-path "*/mock/*" -prune -o \
|
||||
-path "*_mock.go" -prune -o \
|
||||
-path "*/dal/model*" -prune -o \
|
||||
-name "*.go" -exec goimports -w -local "github.com/coze-dev/coze-studio" {} \;
|
||||
else
|
||||
echo "⚠️ goimports not found, skipping Go file formatting."
|
||||
fi
|
||||
|
||||
echo "🛠 Building Go project..."
|
||||
rm -rf "$BIN_DIR/opencoze"
|
||||
cd $BACKEND_DIR &&
|
||||
go build -ldflags="-s -w" -o "$BIN_DIR/opencoze" main.go
|
||||
|
||||
# 添加构建失败检查
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "❌ Go build failed - aborting startup"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ Build completed successfully!"
|
||||
|
||||
echo "📑 Copying environment file..."
|
||||
if [ -f "$ENV_FILE" ]; then
|
||||
cp "$ENV_FILE" "$BIN_DIR"
|
||||
else
|
||||
echo "❌ .env file not found in $DOCKER_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
echo "📑 Cleaning configuration files..."
|
||||
rm -rf "$CONFIG_DIR"
|
||||
mkdir -p "$CONFIG_DIR"
|
||||
|
||||
echo "📑 Copying plugin configuration files..."
|
||||
|
||||
cp -r "$BACKEND_DIR/conf" "$RESOURCES_DIR"
|
||||
cp -r "$BACKEND_DIR/static" "$RESOURCES_DIR"
|
||||
|
||||
for arg in "$@"; do
|
||||
if [[ "$arg" == "-start" ]]; then
|
||||
echo "🚀 Starting Go service..."
|
||||
cd $BIN_DIR && ./opencoze "$@"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user