Skip to content

Commit 1470907

Browse files
committed
chore: split from supabase/supabase monorepo into own repo
0 parents  commit 1470907

File tree

87 files changed

+25669
-0
lines changed

Some content is hidden

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

87 files changed

+25669
-0
lines changed

.eslintrc.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.yarn/install-state.gz
8+
9+
# testing
10+
/coverage
11+
12+
# next.js
13+
/.next/
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
# or
14+
bun dev
15+
```
16+
17+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18+
19+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20+
21+
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
22+
23+
## Learn More
24+
25+
To learn more about Next.js, take a look at the following resources:
26+
27+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29+
30+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
31+
32+
## Deploy on Vercel
33+
34+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35+
36+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

app/api/chat/route.ts

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { openai } from '@ai-sdk/openai'
2+
import { ToolInvocation, convertToCoreMessages, streamText } from 'ai'
3+
import { codeBlock } from 'common-tags'
4+
import { convertToCoreTools, tools } from '~/lib/tools'
5+
6+
// Allow streaming responses up to 30 seconds
7+
export const maxDuration = 30
8+
9+
type Message = {
10+
role: 'user' | 'assistant'
11+
content: string
12+
toolInvocations?: (ToolInvocation & { result: any })[]
13+
}
14+
15+
export async function POST(req: Request) {
16+
const { messages }: { messages: Message[] } = await req.json()
17+
18+
const result = await streamText({
19+
system: codeBlock`
20+
You are a helpful database assistant. Under the hood you have access to an in-browser Postgres database called PGlite (https://github.com/electric-sql/pglite).
21+
Some special notes about this database:
22+
- foreign data wrappers are not supported
23+
- the following extensions are available:
24+
- plpgsql [pre-enabled]
25+
- vector (https://github.com/pgvector/pgvector) [pre-enabled]
26+
- use <=> for cosine distance (default to this)
27+
- use <#> for negative inner product
28+
- use <-> for L2 distance
29+
- use <+> for L1 distance
30+
- note queried vectors will be truncated/redacted due to their size - export as CSV if the full vector is required
31+
32+
When generating tables, do the following:
33+
- For primary keys, always use "id bigint primary key generated always as identity" (not serial)
34+
- Prefer 'text' over 'varchar'
35+
- Keep explanations brief but helpful
36+
37+
When creating sample data:
38+
- Make the data realistic, including joined data
39+
- Check for existing records/conflicts in the table
40+
41+
When querying data, limit to 5 by default.
42+
43+
You also know math. All math equations and expressions must be written in KaTex and must be wrapped in double dollar \`$$\`:
44+
- Inline: $$\\sqrt{26}$$
45+
- Multiline:
46+
$$
47+
\\sqrt{26}
48+
$$
49+
50+
No images are allowed. Do not try to generate or link images, including base64 data URLs.
51+
52+
Err on the side of caution. Ask the user to confirm before any mutating operations.
53+
54+
If you're just querying schema, data, or showing charts, go ahead and do it without asking.
55+
56+
Feel free to suggest corrections for suspected typos.
57+
`,
58+
model: openai('gpt-4o-2024-05-13'),
59+
messages: convertToCoreMessages(messages),
60+
tools: convertToCoreTools(tools),
61+
})
62+
63+
return result.toAIStreamResponse()
64+
}

app/d/[id]/page.tsx

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use client'
2+
3+
import { useRouter } from 'next/navigation'
4+
import { useEffect } from 'react'
5+
import Workspace from '~/components/workspace'
6+
import { getDb } from '~/lib/db'
7+
8+
export default function Page({ params }: { params: { id: string } }) {
9+
const databaseId = params.id
10+
const router = useRouter()
11+
12+
useEffect(() => {
13+
async function run() {
14+
try {
15+
await getDb(databaseId)
16+
} catch (err) {
17+
router.push('/')
18+
}
19+
}
20+
run()
21+
}, [databaseId, router])
22+
23+
return <Workspace databaseId={databaseId} />
24+
}

app/favicon.ico

25.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)