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
21 changes: 10 additions & 11 deletions .cursor/rules/convex_rules.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Note: `paginationOpts` is an object with the following properties:

## Schema guidelines
- Always define your schema in `convex/schema.ts`.
- Always import the schema definition functions from `convex/server`:
- Always import the schema definition functions from `convex/server`.
- 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 @@ -480,8 +480,8 @@ import OpenAI from "openai";
import { internal } from "./_generated/api";

/**
* Create a user with a given name.
*/
* Create a user with a given name.
*/
export const createUser = mutation({
args: {
name: v.string(),
Expand All @@ -493,8 +493,8 @@ export const createUser = mutation({
});

/**
* Create a channel with a given name.
*/
* Create a channel with a given name.
*/
export const createChannel = mutation({
args: {
name: v.string(),
Expand All @@ -506,8 +506,8 @@ export const createChannel = mutation({
});

/**
* List the 10 most recent messages from a channel in descending creation order.
*/
* List the 10 most recent messages from a channel in descending creation order.
*/
export const listMessages = query({
args: {
channelId: v.id("channels"),
Expand All @@ -532,8 +532,8 @@ export const listMessages = query({
});

/**
* Send a message to a channel and schedule a response from the AI.
*/
* Send a message to a channel and schedule a response from the AI.
*/
export const sendMessage = mutation({
args: {
channelId: v.id("channels"),
Expand Down Expand Up @@ -672,5 +672,4 @@ export default defineSchema({
export default function App() {
return <div>Hello World</div>;
}
```

```
90 changes: 90 additions & 0 deletions example/convex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Welcome to your Convex functions directory!

Write your Convex functions here.
See https://docs.convex.dev/functions for more.

A query function that takes two arguments looks like:

```ts
// convex/myFunctions.ts
import { query } from "./_generated/server";
import { v } from "convex/values";

export const myQueryFunction = query({
// Validators for arguments.
args: {
first: v.number(),
second: v.string(),
},

// Function implementation.
handler: async (ctx, args) => {
// Read the database as many times as you need here.
// See https://docs.convex.dev/database/reading-data.
const documents = await ctx.db.query("tablename").collect();

// Arguments passed from the client are properties of the args object.
console.log(args.first, args.second);

// Write arbitrary JavaScript here: filter, aggregate, build derived data,
// remove non-public properties, or create new objects.
return documents;
},
});
```

Using this query function in a React component looks like:

```ts
const data = useQuery(api.myFunctions.myQueryFunction, {
first: 10,
second: "hello",
});
```

A mutation function looks like:

```ts
// convex/myFunctions.ts
import { mutation } from "./_generated/server";
import { v } from "convex/values";

export const myMutationFunction = mutation({
// Validators for arguments.
args: {
first: v.string(),
second: v.string(),
},

// Function implementation.
handler: async (ctx, args) => {
// Insert or modify documents in the database here.
// Mutations can also read from the database like queries.
// See https://docs.convex.dev/database/writing-data.
const message = { body: args.first, author: args.second };
const id = await ctx.db.insert("messages", message);

// Optionally, return a value from your mutation.
return await ctx.db.get(id);
},
});
```

Using this mutation function in a React component looks like:

```ts
const mutation = useMutation(api.myFunctions.myMutationFunction);
function handleButtonPress() {
// fire and forget, the most common way to use mutations
mutation({ first: "Hello!", second: "me" });
// OR
// use the result once the mutation has completed
mutation({ first: "Hello!", second: "me" }).then((result) =>
console.log(result),
);
}
```

Use the Convex CLI to push your functions to a deployment. See everything
the Convex CLI can do by running `npx convex -h` in your project root
directory. To learn more, launch the docs with `npx convex docs`.
20 changes: 20 additions & 0 deletions example/convex/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
* @module
*/

import type * as agents_analyst from "../agents/analyst.js";
import type * as agents_config from "../agents/config.js";
import type * as agents_creative from "../agents/creative.js";
import type * as agents_fashion from "../agents/fashion.js";
import type * as agents_judge from "../agents/judge.js";
import type * as agents_pragmatist from "../agents/pragmatist.js";
import type * as agents_researcher from "../agents/researcher.js";
import type * as agents_simple from "../agents/simple.js";
import type * as agents_story from "../agents/story.js";
import type * as agents_synthesizer from "../agents/synthesizer.js";
import type * as agents_weather from "../agents/weather.js";
import type * as chat_basic from "../chat/basic.js";
import type * as chat_human from "../chat/human.js";
Expand Down Expand Up @@ -46,7 +52,11 @@ import type * as usage_tracking_invoicing from "../usage_tracking/invoicing.js";
import type * as usage_tracking_tables from "../usage_tracking/tables.js";
import type * as usage_tracking_usageHandler from "../usage_tracking/usageHandler.js";
import type * as utils from "../utils.js";
import type * as workflows_actor_critique from "../workflows/actor_critique.js";
import type * as workflows_batching from "../workflows/batching.js";
import type * as workflows_chaining from "../workflows/chaining.js";
import type * as workflows_council_of_agents from "../workflows/council_of_agents.js";
import type * as workflows_deep_agent from "../workflows/deep_agent.js";
import type * as workflows_human_in_the_loop from "../workflows/human_in_the_loop.js";
import type * as workflows_orchestrator from "../workflows/orchestrator.js";
import type * as workflows_parallel from "../workflows/parallel.js";
Expand All @@ -62,10 +72,16 @@ import type {
} from "convex/server";

declare const fullApi: ApiFromModules<{
"agents/analyst": typeof agents_analyst;
"agents/config": typeof agents_config;
"agents/creative": typeof agents_creative;
"agents/fashion": typeof agents_fashion;
"agents/judge": typeof agents_judge;
"agents/pragmatist": typeof agents_pragmatist;
"agents/researcher": typeof agents_researcher;
"agents/simple": typeof agents_simple;
"agents/story": typeof agents_story;
"agents/synthesizer": typeof agents_synthesizer;
"agents/weather": typeof agents_weather;
"chat/basic": typeof chat_basic;
"chat/human": typeof chat_human;
Expand Down Expand Up @@ -100,7 +116,11 @@ declare const fullApi: ApiFromModules<{
"usage_tracking/tables": typeof usage_tracking_tables;
"usage_tracking/usageHandler": typeof usage_tracking_usageHandler;
utils: typeof utils;
"workflows/actor_critique": typeof workflows_actor_critique;
"workflows/batching": typeof workflows_batching;
"workflows/chaining": typeof workflows_chaining;
"workflows/council_of_agents": typeof workflows_council_of_agents;
"workflows/deep_agent": typeof workflows_deep_agent;
"workflows/human_in_the_loop": typeof workflows_human_in_the_loop;
"workflows/orchestrator": typeof workflows_orchestrator;
"workflows/parallel": typeof workflows_parallel;
Expand Down
Loading
Loading