Skip to content

Ian/playground UI #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 87 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
4bb24a1
expose functions for playground
ianmacartney May 9, 2025
cc4cf8a
allow mapping user names
ianmacartney May 9, 2025
a4ac8b5
add playground to package route
ianmacartney May 9, 2025
149c757
expose playground in example
ianmacartney May 9, 2025
7c5f781
update convex rules.mdc
ianmacartney May 9, 2025
945522f
add playground-chef
ianmacartney May 9, 2025
321f673
wire up chef UI
ianmacartney May 9, 2025
2d91c35
Fix#38: Ensures proper pairing of tool messages
apostolisCodpal May 12, 2025
88b9690
document threads and improve naming
ianmacartney May 12, 2025
748db1c
rename isTool to includeToolMessages
ianmacartney May 12, 2025
053106e
document MessageDoc
ianmacartney May 12, 2025
4ce3205
use excludeToolMessages on the internal fn but keep excluding by default
ianmacartney May 12, 2025
f2f7795
rename to excludeToolMessages on top level too
ianmacartney May 12, 2025
d91d697
Change back to asc and simplify orphaned check
apostolisCodpal May 12, 2025
9df5ce6
reverse original fetch
ianmacartney May 13, 2025
b17e409
test
ianmacartney May 13, 2025
b8daffd
0.0.16
ianmacartney May 13, 2025
2095520
run-p for example dev
ianmacartney May 13, 2025
05315ad
update package lock
ianmacartney May 13, 2025
0b2a6d5
fix deleting vectors by batch
ianmacartney May 13, 2025
2e4bf28
0.0.16-alpha.0
ianmacartney May 14, 2025
34bf30a
doc on avoiding type cycles
ianmacartney May 15, 2025
304c31c
metadata
ianmacartney May 15, 2025
052f0a8
increment the step order
ianmacartney May 15, 2025
f6c005e
assign stepOrder from existing tool calls
ianmacartney May 15, 2025
b52ef45
organize schema for messages
ianmacartney May 15, 2025
21dc977
add loveable playground
ianmacartney May 15, 2025
64ef461
test for maxMessage
ianmacartney May 15, 2025
98c31ef
clean up data model
ianmacartney May 15, 2025
d47c229
playground uses convex instead of tanstack query
ianmacartney May 16, 2025
e5f051e
package for agent & audit fixes
ianmacartney May 17, 2025
22a5aad
update chef variable names to ids where applicable
ianmacartney May 17, 2025
52c5a79
add message -> ui message helper
ianmacartney May 18, 2025
c320049
files has data not bytes
ianmacartney May 18, 2025
8ca3a97
user id -> _id
ianmacartney May 18, 2025
0fc5429
get playground working with data model
ianmacartney May 18, 2025
6ffc504
lints
ianmacartney May 18, 2025
228e1f2
fix touimessages
ianmacartney May 18, 2025
07c24bd
always set an id - use message id if not provided
ianmacartney May 18, 2025
4104200
unique index in message item
ianmacartney May 18, 2025
feefa36
pass through contextOptions and storageOptions
ianmacartney May 18, 2025
deb29c0
add saveAny to vStorageOptions
ianmacartney May 18, 2025
fed8027
return messagedoc from fetch context messages
ianmacartney May 19, 2025
6704fe1
readme
ianmacartney May 19, 2025
3fbf9e1
UI is working to send & fetch context messages
ianmacartney May 19, 2025
0250466
fix opt defaulting for searching other threads
ianmacartney May 19, 2025
549caf5
Merge branch 'main' into ian/playground-ui
ianmacartney May 19, 2025
a1c1007
.
ianmacartney May 19, 2025
4168433
fix toUIMessages
ianmacartney May 19, 2025
2286d35
do vector result ranks later
ianmacartney May 19, 2025
22ede92
prompt for api key if it isn't there
ianmacartney May 19, 2025
ea70c63
canonical url update
ianmacartney May 19, 2025
58faa4a
better API key entry
ianmacartney May 19, 2025
8b3adb3
comment
ianmacartney May 19, 2025
19dda33
make it warn you about the wrong api path
ianmacartney May 19, 2025
a0694c7
factor out apikeygate into own file
ianmacartney May 19, 2025
1feda70
factor out code
ianmacartney May 19, 2025
0669cb1
start making the playground a standalone package
ianmacartney May 19, 2025
5522e6c
get npx command working
ianmacartney May 19, 2025
4fb8790
fix getMaxMessage test
ianmacartney May 19, 2025
898de3e
peer deps
ianmacartney May 19, 2025
1b974e0
factor so playground could be in own package
ianmacartney May 19, 2025
2caa4f3
0.0.17-alpha.1
ianmacartney May 19, 2025
7c2ff3d
move playground api generation into package
ianmacartney May 19, 2025
ac79504
remove mock data
ianmacartney May 19, 2025
5e10773
prompt for the convex url if it isn't in env variables
ianmacartney May 19, 2025
5bdad52
save password on submit
ianmacartney May 19, 2025
ac1ad7b
v0.0.2-alpha.0
ianmacartney May 19, 2025
061fdde
v0.0.2
ianmacartney May 19, 2025
e33029f
screenshot in readme
ianmacartney May 19, 2025
608503f
move things into dependencies
ianmacartney May 19, 2025
1ea0b67
use the encoded backend url as the path instead of env variables
ianmacartney May 19, 2025
6ce1e56
store in localStorage
ianmacartney May 19, 2025
f62e594
try to default the path to the env variable
ianmacartney May 19, 2025
a9f81ab
poll for backend status
ianmacartney May 19, 2025
292f482
v0.0.3
ianmacartney May 19, 2025
b0d81ef
deploy to github pages
ianmacartney May 19, 2025
0b254d5
remove playground-chef
ianmacartney May 19, 2025
389d5c9
add dev dependencies for github pages build
ianmacartney May 19, 2025
29ffec5
try with more permissions
ianmacartney May 19, 2025
44ee456
try with regular pages deploy
ianmacartney May 19, 2025
2f0636b
try with other pages config
ianmacartney May 19, 2025
8a4a35d
fix gh pages routing
ianmacartney May 19, 2025
24283b3
add to top level readme
ianmacartney May 19, 2025
cf4f73b
readme
ianmacartney May 19, 2025
488fd39
0.0.17-alpha.1
ianmacartney May 19, 2025
a2a6105
0.0.17-alpha.2
ianmacartney May 19, 2025
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
33 changes: 25 additions & 8 deletions .cursor/rules/convex_rules.mdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
description: Guidelines and best practices for building Convex projects, including database schema design, queries, mutations, and real-world examples
globs: **/*.{ts,tsx,js,jsx}
globs: **/*.ts,**/*.tsx,**/*.js,**/*.jsx
alwaysApply: false
---

# Convex guidelines
Expand Down Expand Up @@ -85,6 +86,19 @@ globs: **/*.{ts,tsx,js,jsx}
},
});
```
- Here are the valid Convex types along with their respective validators:
Convex Type | TS/JS type | Example Usage | Validator for argument validation and schemas | Notes |
| ----------- | ------------| -----------------------| -----------------------------------------------| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Id | string | `doc._id` | `v.id(tableName)` | |
| Null | null | `null` | `v.null()` | JavaScript's `undefined` is not a valid Convex value. Functions the return `undefined` or do not return will return `null` when called from a client. Use `null` instead. |
| Int64 | bigint | `3n` | `v.int64()` | Int64s only support BigInts between -2^63 and 2^63-1. Convex supports `bigint`s in most modern browsers. |
| Float64 | number | `3.1` | `v.number()` | Convex supports all IEEE-754 double-precision floating point numbers (such as NaNs). Inf and NaN are JSON serialized as strings. |
| Boolean | boolean | `true` | `v.boolean()` |
| String | string | `"abc"` | `v.string()` | Strings are stored as UTF-8 and must be valid Unicode sequences. Strings must be smaller than the 1MB total size limit when encoded as UTF-8. |
| Bytes | ArrayBuffer | `new ArrayBuffer(8)` | `v.bytes()` | Convex supports first class bytestrings, passed in as `ArrayBuffer`s. Bytestrings must be smaller than the 1MB total size limit for Convex types. |
| Array | Array] | `[1, 3.2, "abc"]` | `v.array(values)` | Arrays can have at most 8192 values. |
| Object | Object | `{a: "abc"}` | `v.object({property: value})` | Convex only supports "plain old JavaScript objects" (objects that do not have a custom prototype). Objects can have at most 1024 entries. Field names must be nonempty and not start with "$" or "_". |
| Record | Record | `{"a": "1", "b": "2"}` | `v.record(keys, values)` | Records are objects at runtime, but can have dynamic keys. Keys must be only ASCII characters, nonempty, and not start with "$" or "_". |

### Function registration
- Use `internalQuery`, `internalMutation`, and `internalAction` to register internal functions. These functions are private and aren't part of an app's API. They can only be called by other Convex functions. These functions are always imported from `./_generated/server`.
Expand Down Expand Up @@ -152,6 +166,9 @@ globs: **/*.{ts,tsx,js,jsx}
},
});
```
Note: `paginationOpts` is an object with the following properties:
- `numItems`: the maximum number of documents to return (the validator is `v.number()`)
- `cursor`: the cursor to use to fetch the next page of documents (the validator is `v.union(v.string(), v.null())`)
- A query that ends in `.paginate()` returns an object that has the following properties:
- page (contains an array of documents that you fetches)
- isDone (a boolean that represents whether or not this is the last page of documents)
Expand All @@ -165,7 +182,7 @@ globs: **/*.{ts,tsx,js,jsx}
## Schema guidelines
- Always define your schema in `convex/schema.ts`.
- Always import the schema definition functions from `convex/server`:
- System fields are automatically added to all documents and are prefixed with an underscore.
- System fields are automatically added to all documents and are prefixed with an underscore. The two system fields that are automatically added to all documents are `_creationTime` which has the validator `v.number()` and `_id` which has the validator `v.id(tableName)`.
- Always include all index fields in the index name. For example, if an index is defined as `["field1", "field2"]`, the index name should be "by_field1_and_field2".
- Index fields must be queried in the same order they are defined. If you want to be able to query by "field1" then "field2" and by "field2" then "field1", you must create separate indexes.

Expand Down Expand Up @@ -301,13 +318,13 @@ const messages = await ctx.db


# Examples:
## Example: thread-app
## Example: chat-app

### Task
```
Create a real-time thread application backend with AI responses. The app should:
Create a real-time chat application backend with AI responses. The app should:
- Allow creating users with names
- Support multiple thread channels
- Support multiple chat channels
- Enable users to send messages to channels
- Automatically generate AI responses to user messages
- Show recent message history
Expand All @@ -325,7 +342,7 @@ and limit history display to the 10 most recent messages per channel.

### Analysis
1. Task Requirements Summary:
- Build a real-time thread backend with AI integration
- Build a real-time chat backend with AI integration
- Support user creation
- Enable channel-based conversations
- Store and retrieve messages with proper ordering
Expand Down Expand Up @@ -414,8 +431,8 @@ Internal Functions:
#### package.json
```typescript
{
"name": "thread-app",
"description": "This example shows how to build a thread app without authentication.",
"name": "chat-app",
"description": "This example shows how to build a chat app without authentication.",
"version": "1.0.0",
"dependencies": {
"convex": "^1.17.4",
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Deploy Playground to GitHub Pages

on:
push:
branches:
- main
- ian/playground-ui

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: 'pages'
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- name: Install root dependencies
run: npm ci

- name: Install playground dependencies
run: cd playground && npm ci

- name: Build Vite project
run: cd playground && VITE_BASE=/agent/ npm run build

- name: Configure Pages
uses: actions/configure-pages@v5

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: playground/dist

deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
33 changes: 29 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

## 0.0.17 alpha

- UI Playground, to host locally or embed into your app.
- On the left panel it has a dropdown to select a users, then lists the user's treads
- In the middle you can see the thread's messages and tool calls
- On the right you can see the selected message's details, as well as:
- Fetch context messages with different ContextOptions
- Send a message in the thread - optionally saving it to the thread.
- Run it with `npx @convex-dev/agent-playground` - uses Vite internally for now.
- Add a function to turn MessageDoc[] into UIMessage[].
- API key management (to authenticate into the UI Playground)
- The README is a better resource.
- Fixes a bug to increment stepOrder correctly.

### Breaking

- `agent.fetchContextMessages` now returns `MessageDoc` instead of a `CoreMessage` objects.
- `isTool` configuration for context has been changed to `excludeToolMessages` - where `false`/`undefined` is the default and includes tool messages, and `true` will only return user/assistant messages.
- Reorganization of API (split `agent.messages.*` into `agent.threads.*`, `agent.messages.*`, `agent.files.*`, and `agent.users.*`.
- Parameters like `parentMessageId` have generally been renamed to `beforeMessageId` to better clarify their use for things like looking up context. The `generate*` / `stream*` functions do not take a parentMessageId.
- Calls to steps and objects now take a parentMessageId instead of messageId parameter, as this is the true meaning of parent message (the message being responded to).

## 0.0.16

- Fixes a bug with providing out-of-order tool messages in the prompt context. (author: @apostolisCodpal)

## 0.0.15

- You can pass tools at the agent definition, thread definition, or per-message call, making it easier to define tools at runtime with runtime context.
Expand All @@ -13,9 +39,9 @@
### Deprecated

- Passing `ConfigOptions` and `StorageOptions` should now be passed as separate parameters via `configOptions` and `storageOptions`.
e.g. for `generateText`
`{ prompt }, { contextOptions: { recentMessages: 10 } }` instead of
`{ prompt, recentMessages: 10 }`
e.g. for `generateText`
`{ prompt }, { contextOptions: { recentMessages: 10 } }` instead of
`{ prompt, recentMessages: 10 }`

## 0.0.14

Expand All @@ -30,4 +56,3 @@ e.g. for `generateText`
### Deprecated

- parentThreadIds is deprecated, as it wasn't merging histories and the desire to do so should have a message as its parent to make the history behavior clear.

Loading
Loading