diff --git a/.github/workflows/deploy_preview.yml b/.github/workflows/deploy_preview.yml new file mode 100644 index 000000000..02ee0f192 --- /dev/null +++ b/.github/workflows/deploy_preview.yml @@ -0,0 +1,83 @@ +name: VercelPreviewDeployment + +on: + pull_request_target: + types: + - opened + - synchronize + +env: + VERCEL_TEAM: ${{ secrets.VERCEL_TEAM }} + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + VERCEL_PR_DOMAIN_SUFFIX: ${{ secrets.VERCEL_PR_DOMAIN_SUFFIX }} + +permissions: + contents: read + statuses: write + pull-requests: write + +jobs: + deploy-preview: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Extract branch name + shell: bash + run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_OUTPUT" + id: extract_branch + + - name: Hash branch name + uses: pplanel/hash-calculator-action@v1.3.1 + id: hash_branch + with: + input: ${{ steps.extract_branch.outputs.branch }} + method: MD5 + + - name: Set Environment Variables + id: set_env + if: github.event_name == 'pull_request_target' + run: | + echo "VERCEL_ALIAS_DOMAIN=${{ github.event.pull_request.number }}-${{ github.workflow }}.${VERCEL_PR_DOMAIN_SUFFIX}" >> $GITHUB_OUTPUT + + - name: Install Vercel CLI + run: npm install --global vercel@latest + + - name: Cache dependencies + uses: actions/cache@v2 + id: cache-npm + with: + path: ~/.npm + key: npm-${{ hashFiles('package-lock.json') }} + restore-keys: npm- + + - name: Pull Vercel Environment Information + run: vercel pull --yes --environment=preview --token=${VERCEL_TOKEN} + + - name: Deploy Project Artifacts to Vercel + id: vercel + env: + META_TAG: ${{ steps.hash_branch.outputs.digest }}-${{ github.run_number }}-${{ github.run_attempt}} + run: | + set -e + vercel pull --yes --environment=preview --token=${VERCEL_TOKEN} + vercel build --token=${VERCEL_TOKEN} + vercel deploy --prebuilt --archive=tgz --token=${VERCEL_TOKEN} --meta base_hash=${{ env.META_TAG }} + + DEFAULT_URL=$(vercel ls --token=${VERCEL_TOKEN} --meta base_hash=${{ env.META_TAG }}) + ALIAS_URL=$(vercel alias set ${DEFAULT_URL} ${{ steps.set_env.outputs.VERCEL_ALIAS_DOMAIN }} --token=${VERCEL_TOKEN} --scope ${VERCEL_TEAM}| awk '{print $3}') + + echo "New preview URL: ${DEFAULT_URL}" + echo "New alias URL: ${ALIAS_URL}" + echo "VERCEL_URL=${ALIAS_URL}" >> "$GITHUB_OUTPUT" + + - uses: mshick/add-pr-comment@v2 + with: + message: | + Your build has completed! + + [Preview deployment](${{ steps.vercel.outputs.VERCEL_URL }}) diff --git a/.github/workflows/remove_deploy_preview.yml b/.github/workflows/remove_deploy_preview.yml new file mode 100644 index 000000000..4846cda2d --- /dev/null +++ b/.github/workflows/remove_deploy_preview.yml @@ -0,0 +1,40 @@ +name: Removedeploypreview + +permissions: + contents: read + statuses: write + pull-requests: write + +env: + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + +on: + pull_request_target: + types: + - closed + +jobs: + delete-deployments: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Extract branch name + shell: bash + run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT + id: extract_branch + + - name: Hash branch name + uses: pplanel/hash-calculator-action@v1.3.1 + id: hash_branch + with: + input: ${{ steps.extract_branch.outputs.branch }} + method: MD5 + + - name: Call the delete-deployment-preview.sh script + env: + META_TAG: ${{ steps.hash_branch.outputs.digest }} + run: | + bash ./scripts/delete-deployment-preview.sh diff --git a/app/api/cors/[...path]/route.ts b/app/api/cors/[...path]/route.ts index 0217b12b0..1f70d6630 100644 --- a/app/api/cors/[...path]/route.ts +++ b/app/api/cors/[...path]/route.ts @@ -40,4 +40,4 @@ export const POST = handle; export const GET = handle; export const OPTIONS = handle; -export const runtime = "nodejs"; +export const runtime = "edge"; diff --git a/app/api/google/[...path]/route.ts b/app/api/google/[...path]/route.ts index 869bd5076..ebd192891 100644 --- a/app/api/google/[...path]/route.ts +++ b/app/api/google/[...path]/route.ts @@ -101,19 +101,14 @@ export const POST = handle; export const runtime = "edge"; export const preferredRegion = [ - "arn1", "bom1", - "cdg1", "cle1", "cpt1", - "dub1", - "fra1", "gru1", "hnd1", "iad1", "icn1", "kix1", - "lhr1", "pdx1", "sfo1", "sin1", diff --git a/app/config/server.ts b/app/config/server.ts index 0329792aa..b6f32a410 100644 --- a/app/config/server.ts +++ b/app/config/server.ts @@ -95,6 +95,8 @@ export const getServerSideConfig = () => { googleApiKey: process.env.GOOGLE_API_KEY, googleUrl: process.env.GOOGLE_URL, + gtmId: process.env.GTM_ID, + needCode: ACCESS_CODES.size > 0, code: process.env.CODE, codes: ACCESS_CODES, diff --git a/app/constant.ts b/app/constant.ts index 2d88992f6..7d79f1b4e 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -111,7 +111,9 @@ export const SUMMARIZE_MODEL = "gpt-3.5-turbo-1106"; export const KnowledgeCutOffDate: Record = { default: "2021-09", + "gpt-4-turbo-preview": "2023-04", "gpt-4-1106-preview": "2023-04", + "gpt-4-0125-preview": "2023-04", "gpt-4-vision-preview": "2023-04", "gemini-pro": "2021-04", }; diff --git a/app/layout.tsx b/app/layout.tsx index 82b46d915..dd9b5d69b 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -6,7 +6,7 @@ import { getClientConfig } from "./config/client"; import { type Metadata } from "next"; import { SpeedInsights } from "@vercel/speed-insights/next"; import { getServerSideConfig } from "./config/server"; - +import { GoogleTagManager } from "@next/third-parties/google"; const serverConfig = getServerSideConfig(); import { Providers } from "@/app/providers"; import { Viewport } from "next"; @@ -49,6 +49,11 @@ export default function RootLayout({ )} + {serverConfig?.gtmId && ( + <> + + + )} ); diff --git a/app/store/config.ts b/app/store/config.ts index e9c757e04..1146b8368 100644 --- a/app/store/config.ts +++ b/app/store/config.ts @@ -28,9 +28,9 @@ export enum Theme { } export const DEFAULT_CONFIG = { - submitKey: SubmitKey.Enter as SubmitKey, lastUpdate: Date.now(), // timestamp, to merge state + submitKey: SubmitKey.Enter, // submitKey: isMacOS() ? SubmitKey.MetaEnter : SubmitKey.CtrlEnter, avatar: "1f603", fontSize: 14, @@ -137,7 +137,7 @@ export const useAppConfig = createPersistStore( }), { name: StoreKey.Config, - version: 3.893, + version: 3.894, migrate(persistedState, version) { const state = persistedState as ChatConfig; @@ -168,7 +168,7 @@ export const useAppConfig = createPersistStore( if (version < 3.8) { state.lastUpdate = Date.now(); } - if (version < 3.893) { + if (version < 3.894) { state.lastUpdate = Date.now(); return { ...DEFAULT_CONFIG }; } diff --git a/package.json b/package.json index 352a6dd60..d38d6d55a 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "dependencies": { "@fortaine/fetch-event-source": "^3.0.6", "@hello-pangea/dnd": "^16.5.0", + "@next/third-parties": "^14.1.0", "@next-auth/prisma-adapter": "^1.0.7", "@prisma/client": "^5.7.0", "@svgr/webpack": "^8.1.0", diff --git a/scripts/delete-deployment-preview.sh b/scripts/delete-deployment-preview.sh new file mode 100755 index 000000000..4f2bb3495 --- /dev/null +++ b/scripts/delete-deployment-preview.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Set the pipefail option. +set -o pipefail + +# Get the Vercel API endpoints. +GET_DEPLOYMENTS_ENDPOINT="https://api.vercel.com/v6/deployments" +DELETE_DEPLOYMENTS_ENDPOINT="https://api.vercel.com/v13/deployments" + +# Create a list of deployments. +deployments=$(curl -s -X GET "$GET_DEPLOYMENTS_ENDPOINT/?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID" -H "Authorization: Bearer $VERCEL_TOKEN ") +#deployments=$(curl -s -X GET "$GET_DEPLOYMENTS_ENDPOINT/?projectId=$VERCEL_PROJECT_ID" -H "Authorization: Bearer $VERCEL_TOKEN ") + +# Filter the deployments list by meta.base_hash === meta tag. +filtered_deployments=$(echo -E $deployments | jq --arg META_TAG "$META_TAG" '[.deployments[] | select(.meta.base_hash | type == "string" and contains($META_TAG)) | .uid] | join(",")') +filtered_deployments="${filtered_deployments//\"/}" # Remove double quotes + +# Clears the values from filtered_deployments +IFS=',' read -ra values <<<"$filtered_deployments" + +echo "META_TAG ${META_TAG}" +echo "Filtered deployments ${filtered_deployments}" + +# Iterate over the filtered deployments list. +for uid in "${values[@]}"; do + echo "Deleting ${uid}" + + delete_url="${DELETE_DEPLOYMENTS_ENDPOINT}/${uid}?teamId=${VERCEL_ORG_ID}" + echo $delete_url + + # Make DELETE a request to the /v13/deployments/{id} endpoint. + curl -X DELETE $delete_url -H "Authorization: Bearer $VERCEL_TOKEN" + + echo "Deleted!" +done diff --git a/start.sh b/start.sh index 2ec65196e..88210b22e 100755 --- a/start.sh +++ b/start.sh @@ -20,4 +20,4 @@ rsync -az --delete ./.next/server/ ${OUT_DIR}/.next/server rsync -az --delete ./.next/server/ ${OUT_DIR}/.next/server rsync -az --delete "./node_modules/tiktoken/" ${OUT_DIR}/node_modules/tiktoken -docker network create chatgpt-ns > /dev/null 2>&1 \ No newline at end of file +docker network create chatgpt-ns &> /dev/null \ No newline at end of file