Skip to content

Commit b70c28a

Browse files
committed
feat: upgraded react widget to be deployed
1 parent 76c65ac commit b70c28a

16 files changed

Lines changed: 1638 additions & 44508 deletions

File tree

.github/workflows/ci.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
env:
14+
NODE_VERSION: "20"
15+
16+
jobs:
17+
build:
18+
name: Build
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: ${{ env.NODE_VERSION }}
28+
cache: npm
29+
30+
- name: Install dependencies
31+
run: npm ci
32+
33+
- name: Type check
34+
run: npx tsc --noEmit
35+
36+
- name: Build
37+
run: npm run build
38+
39+
- name: Verify output
40+
run: |
41+
if [ ! -f dist/app.min.js ]; then
42+
echo "Build output missing: dist/app.min.js"
43+
exit 1
44+
fi
45+
SIZE=$(stat -f%z dist/app.min.js 2>/dev/null || stat -c%s dist/app.min.js)
46+
echo "Bundle size: ${SIZE} bytes ($(( SIZE / 1024 ))KB)"
47+
48+
- name: Upload artifact
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: widget-dist
52+
path: dist/app.min.js
53+
retention-days: 30
54+
55+
test:
56+
name: Test
57+
runs-on: ubuntu-latest
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@v4
61+
62+
- name: Set up Node.js
63+
uses: actions/setup-node@v4
64+
with:
65+
node-version: ${{ env.NODE_VERSION }}
66+
cache: npm
67+
68+
- name: Install dependencies
69+
run: npm ci
70+
71+
- name: Run tests
72+
run: npm test -- --passWithNoTests

.github/workflows/deploy.yml

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build, Deploy to S3, and Create Release
1+
name: Build, Deploy to S3, and Publish to npm
22

33
on:
44
push:
@@ -14,21 +14,22 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout main repository and submodules
17-
uses: actions/checkout@v3
17+
uses: actions/checkout@v4
1818
with:
1919
submodules: recursive
2020
token: ${{ secrets.GH_TOKEN }}
2121

2222
- name: Set up Node.js
23-
uses: actions/setup-node@v3
23+
uses: actions/setup-node@v4
2424
with:
2525
node-version: "20"
26+
registry-url: "https://registry.npmjs.org"
2627

2728
- name: Install dependencies
28-
run: yarn install
29+
run: npm ci
2930

3031
- name: Build the project
31-
run: yarn run build
32+
run: npm run build
3233

3334
- name: Upload to S3
3435
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
@@ -37,8 +38,16 @@ jobs:
3738
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
3839
AWS_REGION: ${{ secrets.AWS_REGION }}
3940
run: |
41+
# Latest — short cache
4042
aws s3 cp ./dist/app.min.js s3://${{ secrets.S3_BUCKET_NAME }}/public/scripts/app.min.js \
41-
--region $AWS_REGION --acl public-read
43+
--region $AWS_REGION --acl public-read \
44+
--cache-control "public,max-age=3600"
45+
46+
# Versioned — immutable cache for pinning
47+
VERSION=$(node -p "require('./package.json').version")
48+
aws s3 cp ./dist/app.min.js s3://${{ secrets.S3_BUCKET_NAME }}/public/scripts/v${VERSION}/app.min.js \
49+
--region $AWS_REGION --acl public-read \
50+
--cache-control "public,max-age=31536000,immutable"
4251
4352
- name: Invalidate CloudFront cache
4453
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
@@ -51,6 +60,20 @@ jobs:
5160
--distribution-id E3SJXANXL6IYCB \
5261
--paths "/public/scripts/*"
5362
63+
- name: Publish to npm
64+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
65+
run: |
66+
PKG=$(node -p "require('./package.json').name")
67+
VER=$(node -p "require('./package.json').version")
68+
if npm view "${PKG}@${VER}" version 2>/dev/null; then
69+
echo "npm: ${PKG}@${VER} already published — skipping"
70+
else
71+
npm publish --access public
72+
echo "npm: published ${PKG}@${VER}"
73+
fi
74+
env:
75+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
76+
5477
create_release:
5578
name: Create Release
5679
needs: build_and_deploy
@@ -67,7 +90,7 @@ jobs:
6790
- name: Get version and create tag
6891
id: version
6992
run: |
70-
VERSION="0.1.$(date +%Y%m%d)-$(git rev-parse --short HEAD)"
93+
VERSION=$(node -p "require('./package.json').version")
7194
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
7295
echo "TAG_NAME=v${VERSION}" >> $GITHUB_OUTPUT
7396
if git tag -l "v${VERSION}" | grep -q "v${VERSION}"; then
@@ -85,13 +108,23 @@ jobs:
85108
git push origin "${{ steps.version.outputs.TAG_NAME }}"
86109
87110
- name: Create GitHub Release
111+
if: steps.version.outputs.TAG_EXISTS == 'false'
88112
env:
89113
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90114
run: |
91-
echo "# Release ${{ steps.version.outputs.TAG_NAME }}" > release-notes.md
92-
echo "" >> release-notes.md
93-
echo "## Changes" >> release-notes.md
94-
echo "- Automated release from commit $(git rev-parse --short HEAD)" >> release-notes.md
115+
{
116+
echo "# Release ${{ steps.version.outputs.TAG_NAME }}"
117+
echo ""
118+
echo "## Deployment"
119+
echo "| Target | URL |"
120+
echo "|--------|-----|"
121+
echo "| CDN (latest) | \`https://cdn-01.rapida.ai/public/scripts/app.min.js\` |"
122+
echo "| CDN (pinned) | \`https://cdn-01.rapida.ai/public/scripts/v${{ steps.version.outputs.VERSION }}/app.min.js\` |"
123+
echo "| npm | \`npm i @rapidaai/web-widget@${{ steps.version.outputs.VERSION }}\` |"
124+
echo ""
125+
echo "## Changes"
126+
echo "- Commit: $(git rev-parse --short HEAD)"
127+
} > release-notes.md
95128
96129
gh release create "${{ steps.version.outputs.TAG_NAME }}" \
97130
--title "Release ${{ steps.version.outputs.TAG_NAME }}" \

index.html

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,56 @@
1-
<html>
2-
<title>avyan.global webchatbot demo</title>
3-
<header>
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Rapida Chat Widget Demo</title>
47
<style>
5-
#RPDContainer.RPDContainer .RPD_Wrapper {
6-
--cds-chat-BASE-border-radius-xsmall: 0px;
7-
--cds-chat-BASE-border-radius-small: 0px;
8-
--cds-chat-BASE-border-radius-med: 0px;
9-
--cds-chat-BASE-border-radius-large: 10px;
10-
--cds-chat-BASE-border-radius-xlarge: 10px;
11-
--cds-chat-BASE-width: 600px !important;
12-
--cds-chat-BASE-height: 100dvh !important;
13-
--cds-chat-BASE-bottom-position: 0px;
14-
--cds-chat-BASE-right-position: 0px;
8+
body {
9+
margin: 0;
10+
font-family: "IBM Plex Sans", sans-serif;
11+
background: #f4f4f4;
12+
min-height: 100vh;
13+
transition: margin 150ms cubic-bezier(0.2, 0, 0.38, 0.9);
1514
}
1615
</style>
17-
</header>
16+
</head>
1817
<body>
1918
<script>
2019
window.chatbotConfig = {
21-
theme: {
22-
color: "black",
23-
},
24-
// assistant_id: "2180932482075983872",
25-
assistant_id: "2139456643765633024",
20+
api_base: "http://localhost:8080",
21+
assistant_id: "2291436907428577280",
2622
token:
27-
"5e04b962dfd988ca0f4ac9e097f17841ebf34d7e38c50297e245c12bddce2117",
28-
// "05064a056f0a60f309ff1d5cc66cb6bb5ecd1d79238e048b2594b51bfb9d4610",
29-
//
23+
"e691ea71f5c99bf9e4a53bbd724436ca441d3bf5be1a45a7e7b840ae18d1dfbb",
24+
// assistant_id: "2139456643765633024",
25+
// token:
26+
// "5e04b962dfd988ca0f4ac9e097f17841ebf34d7e38c50297e245c12bddce2117",
3027
user: {
31-
id: "ayan-global-user",
28+
id: "demo-user",
3229
name: "Guest",
3330
},
31+
32+
// ---- Usage 1: Floating (default) ----
33+
// A floating panel with a launcher FAB button.
34+
layout: "docked-right",
35+
position: "bottom-right", // bottom-right | bottom-left | top-right | top-left
36+
showLauncher: true, // set false to use your own trigger button
37+
38+
// ---- Usage 2: Docked to side ----
39+
// Panel sticks to the side of the viewport and pushes page content.
40+
// layout: "docked-right", // docked-right | docked-left
41+
42+
// ---- Usage 3: Inline ----
43+
// Panel flows with page content, no fixed positioning.
44+
// layout: "inline",
45+
46+
name: "Rapida Assistant",
47+
logo_url:
48+
"https://rapida-assets-01.s3.ap-south-1.amazonaws.com/cdn/rapidaLogo.png",
49+
theme: {
50+
mode: "light", // light | dark
51+
},
3452
};
3553
</script>
3654
<script defer src="./dist/app.min.js"></script>
37-
38-
<!-- <script
39-
src="https://cdn-01.rapida.ai/public/scripts/app.min.js"
40-
defer
41-
></script> -->
4255
</body>
4356
</html>

package-lock.json

Lines changed: 23 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)