diff --git a/.github/deploy-stg.sh b/.github/deploy-stg.sh new file mode 100644 index 000000000..bd5498d4c --- /dev/null +++ b/.github/deploy-stg.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +ssh ci@$@ "sh deploy-stg.sh" \ No newline at end of file diff --git a/.github/dev-deploy.sh b/.github/dev-deploy.sh deleted file mode 100644 index 1cc7cf3c9..000000000 --- a/.github/dev-deploy.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -ssh ci@$@ "docker stack deploy -c /home/ci/dev-agn.docker-compose.yml dev-agnai" \ No newline at end of file diff --git a/.github/workflows/stg-deploy-stack.yml b/.github/workflows/stg-deploy-stack.yml new file mode 100644 index 000000000..fbd18df34 --- /dev/null +++ b/.github/workflows/stg-deploy-stack.yml @@ -0,0 +1,64 @@ +name: Deploy to STG (Web + API) + +on: workflow_dispatch + +env: + IMAGE_NAME: agnaistic + node-version: '18.4.0' + pnpm-version: 8.6.0 + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Get cached dependencies + # cache is automatically saved after this job completes. jobs depending on this one will get the latest cached files + id: cache-step + uses: actions/cache@v3 + with: + path: '**/node_modules' + key: ${{ runner.os }}-modules-${{ hashFiles('**/pnpm-lock.yaml') }} + + - name: Install SSH Key + uses: shimataro/ssh-key-action@v2 + with: + key: ${{ secrets.SSH_KEY }} + known_hosts: 'none' + + - name: Add known host + run: | + ssh-keyscan -H ${{ secrets.SSH_SERVER }} >> ~/.ssh/known_hosts + + - name: Install project dependencies + if: steps.cache-step.outputs.cache-hit != 'true' + run: | + ls -la + echo $NODE_ENV + pnpm install --frozen-lockfile + + - name: Build frontend + env: + INJECT_SCRIPT: ${{ secrets.INJECT_SCRIPT }} + run: | + pnpm run build:prod + cp dist/index.html dist/original.html + node .github/inject.js + + - name: Update Backend + run: | + sh .github/deploy.sh ${{ secrets.SSH_SERVER }} + + - name: Update Frontend + uses: shallwefootball/s3-upload-action@master + with: + aws_key_id: ${{ secrets.S3_ASSET_ACCESS_KEY }} + aws_secret_access_key: ${{ secrets.S3_ASSET_SECRET_KEY }} + aws_bucket: ${{ secrets.S3_DEV_ASSET_BUCKET }} + source_dir: 'dist' + destination_dir: '' diff --git a/srv/api/chat/message.ts b/srv/api/chat/message.ts index b5bb64cca..c5eb3ab6e 100644 --- a/srv/api/chat/message.ts +++ b/srv/api/chat/message.ts @@ -23,6 +23,7 @@ const sendValidator = { ], text: 'string', impersonate: 'any?', + parent: 'string?', } as const const genValidator = { @@ -95,6 +96,7 @@ export const createMessage = handle(async (req) => { characterId: impersonate?._id, ooc: body.kind === 'ooc' || body.kind === 'send-event:ooc', event: getScenarioEventType(body.kind), + parent: body.parent, }) sendGuest(guest, { type: 'message-created', msg: newMsg, chatId }) } else { @@ -111,8 +113,11 @@ export const createMessage = handle(async (req) => { senderId: userId, ooc: body.kind === 'ooc' || body.kind === 'send-event:ooc', event: getScenarioEventType(body.kind), + parent: body.parent, }) + await store.chats.update(chatId, { treeLeafId: userMsg._id }) + sendMany(members, { type: 'message-created', msg: userMsg, chatId }) } diff --git a/web/store/data/messages.ts b/web/store/data/messages.ts index 1f72ad901..0d1d1d3da 100644 --- a/web/store/data/messages.ts +++ b/web/store/data/messages.ts @@ -542,6 +542,9 @@ async function getGenerateProps( const index = entities.messages.findIndex((msg) => msg._id === opts.messageId) const replacing = entities.messages[index] + const replaceParent = entities.messages[index - 1] + props.parent = replaceParent + // Retrying an impersonated message - We'll use the "auto-reply as" or the "main character" if (replacing?.userId) { props.replyAs = getBot(active.replyAs || active.char._id) @@ -651,6 +654,7 @@ async function createMessage( text: text.parsed, kind: opts.kind, impersonate, + parent: getMessageParent(opts.kind, props.messages)?._id, }) }