Skip to content

Commit dcd6fe3

Browse files
authored
Add Beak.js server (#14)
1 parent d0b6e9f commit dcd6fe3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+16759
-146
lines changed

.github/workflows/release.yml

+20
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,23 @@ jobs:
3636
yarn workspace @beakjs/react publish --access public
3737
env:
3838
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
39+
- name: Publish (server)
40+
run: |
41+
yarn workspace @beakjs/server publish --access public
42+
env:
43+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
44+
- name: Publish (next)
45+
run: |
46+
yarn workspace @beakjs/next publish --access public
47+
env:
48+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
49+
- name: Publish (next)
50+
run: |
51+
yarn workspace @beakjs/remix publish --access public
52+
env:
53+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
54+
- name: Publish (express)
55+
run: |
56+
yarn workspace @beakjs/express publish --access public
57+
env:
58+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.vscode/cspell.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
"chatcmpl",
1515
"uuidv4",
1616
"Hola",
17-
"Mundo"
17+
"Mundo",
18+
"OpenAIAPIKey",
19+
"nextjs",
20+
"typecheck",
21+
"isbot"
1822
]
1923
}

README.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 🐦 Beak.js [![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/mme_xyz?style=flat&logo=x)](https://twitter.com/mme_xyz) [![npm (scoped)](https://img.shields.io/npm/v/%40beakjs/react)](https://www.npmjs.com/package/@beakjs/react)
22

3-
Beak.js lets you integrate custom conversational assistants into your React applications.
3+
Beak.js contains everything you need to create custom AI-powered assistants for your React app.
44

55
**Key Features:**
66

@@ -32,7 +32,7 @@ import { Beak } from "@beakjs/react";
3232

3333
const App = () => (
3434
<Beak
35-
openAIApiKey="sk-..."
35+
__unsafeOpenAIApiKey__="sk-..."
3636
instructions="Assistant is running in a web app and helps the user with XYZ."
3737
>
3838
<MyApp />
@@ -43,7 +43,7 @@ const App = () => (
4343

4444
Now, you've got a chat window ready in the bottom right corner of your website. Give it a try!
4545

46-
**Note:** Don't expose your API key in public-facing apps. We will be adding a solution for securely using your API key soon.
46+
**Note:** Don't expose your API key in public-facing apps - this is for development only. See [Deployment](#deployment) for information on how to securely deploy your app without compromising your API key.
4747

4848
### Making Beak.js work with your app
4949

@@ -94,6 +94,18 @@ const MyApp = () => {
9494

9595
By using `useBeakFunction` together with `useBeakInfo`, your assistant can see what's happening on the screen and take action within your app depending on the current context.
9696

97+
## Deployment
98+
99+
To keep your API keys safe, we set up a server that forwards your assistant's requests to OpenAI.
100+
101+
Currently, we support the following deployment options:
102+
103+
- [Next.js](/docs/deployment/next.md)
104+
- [Remix](/docs/deployment/remix.md)
105+
- [Express](/docs/deployment/express.md)
106+
107+
Read more by clicking the links above.
108+
97109
## Run the Demo
98110

99111
To run the demo, build the project and start the demo app:

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.5
1+
0.0.6

demo/backend/express/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.env
3+
dist

demo/backend/express/package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "demo-backend-express",
3+
"version": "0.0.6",
4+
"main": "dist/index.js",
5+
"repository": "https://github.com/mme/beakjs.git",
6+
"type": "module",
7+
"scripts": {
8+
"build": "tsc",
9+
"clean": "rm -rf node_modules && rm -rf .next && rm -rf dist",
10+
"start": "node dist/index.js"
11+
},
12+
"author": "Markus Ecker",
13+
"license": "MIT",
14+
"private": true,
15+
"dependencies": {
16+
"@beakjs/express": "0.0.6",
17+
"dotenv": "^16.3.1",
18+
"express": "^4.18.2"
19+
},
20+
"devDependencies": {
21+
"@types/express": "^4.17.21",
22+
"typescript": "^5.0.4"
23+
}
24+
}

demo/backend/express/src/index.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import express from "express";
2+
import { beakHandler } from "@beakjs/express";
3+
import dotenv from "dotenv";
4+
dotenv.config();
5+
6+
const app = express();
7+
const port = 3000;
8+
9+
app.use(express.json());
10+
app.use("/beak", beakHandler());
11+
12+
app.listen(port, () => {
13+
console.log(`Server running on http://localhost:${port}`);
14+
});

demo/backend/express/tsconfig.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2019",
4+
"module": "ESNext",
5+
"declaration": true,
6+
"strict": true,
7+
"esModuleInterop": true,
8+
"skipLibCheck": true,
9+
"forceConsistentCasingInFileNames": true,
10+
"outDir": "dist",
11+
"lib": ["es2019"],
12+
"allowJs": true,
13+
"allowSyntheticDefaultImports": true,
14+
"moduleResolution": "node",
15+
"resolveJsonModule": true,
16+
"isolatedModules": true,
17+
"noEmit": false,
18+
"types": ["node"]
19+
},
20+
"include": ["src"],
21+
"exclude": ["node_modules", "dist"]
22+
}

0 commit comments

Comments
 (0)