Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
node_modules
sources
sources

# Git
.git
.gitignore

# Documentation (not needed in runtime)
*.md
README*
CONTRIBUTING*
LICENSE*

# Build artifacts (built in Docker)
dist

# Lock files for other package managers
pnpm-lock.yaml
package-lock.json
yarn.lock

# Tests
tests

# IDE/Editor
.vscode
.idea
*.swp
*.swo
*~

# Logs
*.log
*.log*

.env
.env.*

.DS_Store
Thumbs.db

.github

# Docker
.dockerignore
Dockerfile*
docker-compose*.yml
10 changes: 5 additions & 5 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
node-version: '18'
bun-version: latest

- name: Install dependencies
run: npm install
run: bun install

- name: Format
run: npm run format
run: bun run format
10 changes: 5 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
node-version: '18'
bun-version: latest

- name: Install dependencies
run: npm install
run: bun install

- name: Lint
run: npm run lint
run: bun run lint
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ If you are worried about or don’t know where to start, check out the next sect
git clone https://github.com/appwrite/assistant.git appwrite-assistant
```

### 2. Install dependencies with pnpm
### 2. Install dependencies with bun

Navigate to the Appwrite Assistant repository and install dependencies.

```bash
cd appwrite-assistant && pnpm install
cd appwrite-assistant && bun install
```

### 3. Setup environment variables
Expand All @@ -29,7 +29,7 @@ Add a `.env` file by copying the `.env.example` file as a template in the projec
Finally, start a development server:

```bash
pnpm run dev
bun run dev
```

### 4. Testing the changes
Expand All @@ -41,7 +41,7 @@ We use a set of benchmark questions to test your changes:
- What's the difference between Server and Client SDKs?
- How do I use the users API to create a new user with Dart?

You can execute the [pnpm run test](./scripts/test-prompts.js) script to write snapshots of the answers to these questions to the tests folder.
You can execute the [bun run test](./scripts/test-prompts.js) script to write snapshots of the answers to these questions to the tests folder.

### 5. Running docker compose

Expand All @@ -62,8 +62,8 @@ docker compose up -d
We use [Prettier](https://prettier.io/) and [ESLint](https://eslint.org/) to lint and format our code.

```bash
pnpm format
pnpm lint
bun run format
bun run lint
```

## Submit a Pull Request 🚀
Expand Down
51 changes: 27 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18-alpine AS base
FROM oven/bun:alpine AS base

RUN apk add --no-cache \
python3 \
Expand All @@ -7,49 +7,52 @@ RUN apk add --no-cache \
build-base \
git

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
RUN corepack prepare pnpm@10.13.1 --activate

FROM base AS builder

WORKDIR /usr/src/app

COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --prod
COPY package.json bun.lock* ./

RUN bun install --frozen-lockfile --production

COPY . .
COPY src ./src
COPY scripts ./scripts

ARG _BUILD_GIT_URL
ARG _BUILD_GIT_BRANCH
ARG _BUILD_WEBSITE_URL
ARG _BUILD_WEBSITE_VERSION
ARG _BUILD_GIT_BRANCH=main
ARG _BUILD_WEBSITE_VERSION=cloud
ARG _BUILD_WEBSITE_URL=https://appwrite.io
ARG _BUILD_GIT_URL=https://github.com/appwrite/website.git

ENV _BUILD_GIT_URL=${_BUILD_GIT_URL}
ENV _BUILD_GIT_BRANCH=${_BUILD_GIT_BRANCH}
ENV _BUILD_WEBSITE_URL=${_BUILD_WEBSITE_URL}
ENV _BUILD_WEBSITE_VERSION=${_BUILD_WEBSITE_VERSION}

RUN pnpm run fetch-sources
RUN bun run fetch-sources

FROM node:18-alpine AS prod
ARG _APP_ASSISTANT_OPENAI_API_KEY
ENV _APP_ASSISTANT_OPENAI_API_KEY=${_APP_ASSISTANT_OPENAI_API_KEY}
Comment on lines +33 to +34
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

echo "=== Checking OPENAI_API_KEY usage in scripts ==="
rg -n "OPENAI_API_KEY" --max-count=20

echo -e "\n=== Checking Dockerfile context around lines 30-35 ==="
head -n 50 Dockerfile | tail -n +25

echo -e "\n=== Checking prod stage (around line 54) ==="
tail -n +45 Dockerfile | head -n 20

echo -e "\n=== Checking fetch-sources script ==="
if [ -f "scripts/fetch-sources.sh" ]; then
  cat scripts/fetch-sources.sh
elif [ -f "scripts/fetch-sources.js" ]; then
  head -n 50 scripts/fetch-sources.js
else
  find . -name "*fetch-sources*" -type f 2>/dev/null | head -5
fi

echo -e "\n=== Checking for build-embeddings references ==="
rg -n "build-embeddings" --max-count=20

Repository: appwrite/assistant

Length of output: 2130


🏁 Script executed:

#!/bin/bash

echo "=== Checking if fetch-sources uses API key ==="
find . -name "fetch-sources*" -type f 2>/dev/null | xargs cat 2>/dev/null | head -50

echo -e "\n=== Checking if API key is actually used in runtime ==="
cat -n src/embeddings.js | head -40

echo -e "\n=== Checking package.json build scripts ==="
grep -A 5 "scripts" package.json | head -20

Repository: appwrite/assistant

Length of output: 2083


Remove the OpenAI API key from build arguments—it's only needed at runtime.

The API key is passed as a build ARG and then set as an ENV, but it's never actually consumed during the build process. Embeddings are generated at runtime in src/embeddings.js, not during Docker image build. The build-time ARG is unnecessary and could expose the key in build history.

Recommendation: Remove lines 33-34 and rely only on the API key being provided at container runtime (which is how it's already reset in the prod stage on line 54).

🤖 Prompt for AI Agents
In Dockerfile around lines 33-34, remove the build ARG and ENV for
_APP_ASSISTANT_OPENAI_API_KEY because the key is not used during image build and
should only be provided at runtime; delete the two lines declaring ARG
_APP_ASSISTANT_OPENAI_API_KEY and ENV
_APP_ASSISTANT_OPENAI_API_KEY=${_APP_ASSISTANT_OPENAI_API_KEY} so the secret is
not leaked into build history and rely on the existing runtime provision (as
done in the prod stage at line 54).


ENV NODE_ENV=production
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN bun build src/main.js \
--outdir ./dist \
--target bun \
--minify \
--sourcemap=none \
--external hnswlib-node

RUN corepack enable
RUN corepack prepare pnpm@10.13.1 --activate
FROM oven/bun:alpine AS prod

ENV NODE_ENV=production

WORKDIR /usr/src/app

COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/sources ./sources
COPY --from=builder /usr/src/app/package.json ./
COPY --from=builder /usr/src/app/src ./src
COPY --from=builder /usr/src/app/package.json ./package.json
COPY --from=builder /usr/src/app/node_modules ./node_modules

ENV _APP_ASSISTANT_OPENAI_API_KEY=''
ENV _APP_ASSISTANT_OPENAI_MODEL='gpt-4o'

EXPOSE 3003
CMD [ "node", "src/main.js" ]
CMD [ "bun", "dist/main.js" ]
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ Appwrite Assistant is an AI-powered API that helps you with Appwrite-related tas

## Installation

Make sure you have [pnpm](https://pnpm.io/) installed.
Make sure you have [Bun](https://bun.sh) installed.

To install, run the following command.

```bash
pnpm i
bun install
```

Next, fetch the Appwrite-specific sources used by the assistant. This will download the sources from the Appwrite documentation and store them in the `./sources` directory.

```bash
pnpm run fetch-sources
bun run fetch-sources
```

The scripts will pull the latest documentation from the `main` branch of the [website repository](https://github.com/appwrite/website), and the latest API reference from live [Appwrite documentation](https://appwrite.io/docs).
The scripts will pull the latest documentation from the `main` branch of the [website repository](https://github.com/appwrite/website), and the latest API reference from live [Appwrite documentation](https://appwrite.io/docs).

If you want to pull from a different branch or repository, you can set the `_BUILD_GIT_URL` and `_BUILD_WEBSITE_URL` environment variables.

## Usage

First, retrieve an API key from OpenAI. You can sign up for an API key at [OpenAI](https://beta.openai.com/signup/). Once you have an API key, set it as the `_APP_ASSISTANT_OPENAI_API_KEY` environment variable.
First, retrieve an API key from OpenAI. You can sign up for an API key at [OpenAI](https://beta.openai.com/signup/). Once you have an API key, set it as the `_APP_ASSISTANT_OPENAI_API_KEY` environment variable. Optionally, you can set `_APP_ASSISTANT_OPENAI_MODEL` (defaults to `gpt-4o`).

To run the server, execute the `dev` command. By default, the server will be available at `http://localhost:3003`
To run the server, execute the `dev` command. By default, the server will be available at `http://localhost:3003`

```bash
pnpm run dev
bun run dev
```

The server exposes a POST endpoint at `/`. The endpoint expects a raw text body containing the query for the assistant. The answer to the query will be streamed back to the client as raw text.
Expand Down
Loading