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
28 changes: 28 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ packages:
- 'templates/chat-react-ts'
- 'templates/react-ts'
- 'templates/basic-ts'
- 'templates/llm-chat-ts'
- 'templates/vue-ts'
- 'templates/tanstack-ts'
- 'templates/browser-ts'
Expand Down
5 changes: 5 additions & 0 deletions templates/llm-chat-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist
node_modules
tsconfig.tsbuildinfo
.env
.env.local
14 changes: 14 additions & 0 deletions templates/llm-chat-ts/.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"description": "Simple TypeScript chat app that calls an LLM API from a SpacetimeDB module",
"client_framework": "React",
"client_lang": "typescript",
"server_lang": "typescript",
"builtWith": [
"react",
"react-dom",
"vitejs",
"typescript",
"vite",
"spacetimedb"
]
}
83 changes: 83 additions & 0 deletions templates/llm-chat-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Get a SpacetimeDB-backed LLM chat app running in under 5 minutes.

## Prerequisites

- [Node.js](https://nodejs.org/) 18+ installed
- [SpacetimeDB CLI](https://spacetimedb.com/install) installed
- An OpenRouter or OpenAI API key

Install the [SpacetimeDB CLI](https://spacetimedb.com/install) before continuing.

---

## Create your project

Run the `spacetime dev` command to create a new project with a SpacetimeDB
module and React client.

This will start the local SpacetimeDB server, publish your module, generate
TypeScript bindings, and start the React development server.

```bash
spacetime dev --template llm-chat-ts
```

## Open your app

Navigate to [http://localhost:5173](http://localhost:5173) to see your app
running.

Open the provider config modal, choose OpenRouter or OpenAI, enter an API key
and model, then start a new chat.

## Explore the project structure

Your project contains both server and client code.

Edit `spacetimedb/src/index.ts` to change tables, views, reducers, and
procedures. Edit `src/App.tsx` to build the chat UI.

```
my-spacetime-app/
├── spacetimedb/ # Your SpacetimeDB module
│ └── src/
│ ├── index.ts # Server-side tables, views, and reducers
│ └── llm.ts # LLM provider request helpers
├── src/
│ ├── App.tsx # React chat UI
│ └── module_bindings/ # Auto-generated types
└── package.json
```

## Understand the module

The module stores private chat threads, private chat messages, and private LLM
configuration for each SpacetimeDB identity.

The public `chat` and `message` views only expose rows owned by the connected
identity. The `llm_config` table is private, and the API key is never returned
through subscriptions or config status calls.

The API key is still stored as module data. This template is not a secret
manager: database operators can inspect module data, so use keys that are
appropriate for your local or hackathon environment.

## Configure models

Defaults:

- Provider: `openrouter`
- Model: `openai/gpt-4o-mini`
- Local database name: `llm-chat-ts`
- New chats start with a clean context.

Leaving the API key field blank keeps the saved key when editing the same
provider. Switching providers requires entering a new key.

Set `VITE_SPACETIMEDB_HOST` or `VITE_SPACETIMEDB_DB_NAME` if you publish to a
different host or database name.

## Next steps

- See the [Chat App Tutorial](https://spacetimedb.com/docs/intro/tutorials/chat-app) for a complete example
- Read the [TypeScript SDK Reference](https://spacetimedb.com/docs/intro/core-concepts/clients/typescript-reference) for detailed API docs
12 changes: 12 additions & 0 deletions templates/llm-chat-ts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SpacetimeDB LLM Chat</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions templates/llm-chat-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@clockworklabs/llm-chat-ts",
"private": true,
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"preview": "vite preview",
"spacetime:generate": "spacetime generate --lang typescript --out-dir src/module_bindings --module-path spacetimedb",
"spacetime:publish:local": "spacetime publish --module-path spacetimedb --server local",
"spacetime:publish": "spacetime publish --module-path spacetimedb --server maincloud"
},
"dependencies": {
"spacetimedb": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
"@vitejs/plugin-react": "^5.0.2",
"typescript": "~5.6.2",
"vite": "^7.1.5"
}
}
19 changes: 19 additions & 0 deletions templates/llm-chat-ts/spacetimedb/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "spacetime-module",
"version": "1.0.0",
"description": "",
"scripts": {
"build": "spacetime build",
"publish": "spacetime publish"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"spacetimedb": "workspace:*"
},
"devDependencies": {
"typescript": "~5.6.2"
}
}

Loading
Loading