Skip to content

Commit

Permalink
Merge pull request #4 from digidem/background-jobs
Browse files Browse the repository at this point in the history
feat: add basic background jobs #9
  • Loading branch information
luandro authored Nov 22, 2024
2 parents 0b4c35e + 88029bc commit d2651e5
Show file tree
Hide file tree
Showing 40 changed files with 1,320 additions and 67 deletions.
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
6 changes: 0 additions & 6 deletions apps/ai_api/hello.py

This file was deleted.

2 changes: 1 addition & 1 deletion apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "biome lint",
"format": "biome format --write .",
"start": "next start",
"typecheck": "tsc --noEmit"
"typecheck": "tsc-files --noEmit"
},
"dependencies": {
"@eda/analytics": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"clean": "git clean -xdf .next .turbo node_modules",
"lint": "biome lint src",
"format": "biome format --write .",
"typecheck": "tsc --noEmit"
"typecheck": "tsc-files --noEmit"
},
"dependencies": {
"@astrojs/check": "^0.9.4",
Expand Down
2 changes: 1 addition & 1 deletion apps/whatsapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"typescript": "^5.0.0"
},
"dependencies": {
"@trigger.dev/sdk": "3.1.0",
"@trigger.dev/sdk": "3.2.1",
"dotenv": "^16.4.5",
"mkdirp": "^3.0.1",
"mongoose": "^8.7.1",
Expand Down
6 changes: 3 additions & 3 deletions assets/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ cp deploy/langtrace-stack/.env.example deploy/langtrace-stack/.env

3. Before starting the development server, ensure you have the required environmental variables in place:

- Connect to Trigger instance by setting the correct `TRIGGER_PROJECT_ID` and `TRIGGER_API_URL` variables in the `packages/jobs/.env` file from [Local Trigger](http://localhost:3001/) or [Cloud Trigger](https://cloud.trigger.dev)
- Add the correct `TRIGGER_SECRET_KEY` to `apps/whatsapp/.env` and `packages/simulator/.env` from [Local Trigger](http://localhost:3001/) or [Cloud Trigger](https://cloud.trigger.dev) ([docs](https://trigger.dev/docs/apikeys))
- Connect to Trigger instance by setting the correct `TRIGGER_PROJECT_ID` and `TRIGGER_API_URL` variables in the `packages/jobs/.env` file from [Local Trigger](http://localhost:3040/) or [Cloud Trigger](https://cloud.trigger.dev)
- Add the correct `TRIGGER_SECRET_KEY` to `apps/whatsapp/.env` and `packages/simulator/.env` from [Local Trigger](http://localhost:3040/) or [Cloud Trigger](https://cloud.trigger.dev) ([docs](https://trigger.dev/docs/apikeys))
- Add the correct `SUPABASE_SERVICE_ROLE_KEY` to the `packages/jobs/.env` from [Local Supabase](http://localhost:54323/project/default/settings/api) or [Cloud Supabase](https://supabase.com/dashboard/)
- Add valid `CEREBRAS_API_KEY` or `OPENAI_API_KEY` to `apps/ai_api/.env` from [Cerebras](https://cloud.cerebras.ai/platform) or [OpenAI](https://platform.openai.com/api-keys)
- (optional) Add the correct `LANGTRACE_API_KEY` to the `.env` in `apps/ai_api/.env` and `packages/simulator/.env`
Expand Down Expand Up @@ -142,7 +142,7 @@ bun seed // run Supabase seed
- **Documentation**: Visit [http://localhost:8082](http://localhost:8082) to browse the documentation.
- **AI API**: Visit [http://localhost:8083/docs](http://localhost:8083/docs) to access the API documentation.
- **Supabase Studio**: Visit [http://localhost:54323](http://localhost:54323) to manage your database, view API documentation, and perform backend tasks.
- **Trigger.dev Dashboard**: Visit [http://localhost:3001](http://localhost:3001) to manage jobs. Use `docker logs -f trigger-webapp` to view the magic link in the logs.
- **Trigger.dev Dashboard**: Visit [http://localhost:3040](http://localhost:3040) to manage jobs. Use `docker logs -f trigger-webapp` to view the magic link in the logs.

Development should be done primarily through the simulator, which creates realistic scenarios of community members interacting with the system. The simulator enables testing conversations between two AI agents - one representing a community member and another representing the assistant.

Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion deploy/trigger-stack/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PORT=3001
PORT=3040
REMIX_APP_PORT=3030

NODE_ENV=production
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
"@biomejs/biome": "1.9.4",
"@t3-oss/env-nextjs": "^0.11.1",
"lefthook": "^1.8.2",
"tsc-files": "^1.1.4",
"turbo": "^2.2.3",
"typescript": "^5.6.3"
},
"packageManager": "[email protected].33",
"packageManager": "[email protected].34",
"private": true
}
2 changes: 1 addition & 1 deletion packages/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"clean": "rm -rf .turbo node_modules",
"lint": "biome check .",
"format": "biome --write .",
"typecheck": "tsc --noEmit"
"typecheck": "tsc-files --noEmit"
},
"dependencies": {
"@eda/logger": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/email/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"clean": "rm -rf .turbo node_modules",
"lint": "biome lint ./components ./emails",
"format": "biome lint --write --unsafe",
"typecheck": "tsc --noEmit",
"typecheck": "tsc-files --noEmit",
"dev": "email dev -p 8083",
"build": "email build",
"start": "email start"
Expand Down
10 changes: 6 additions & 4 deletions packages/jobs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
"lint": "biome lint ./trigger ./lib",
"dev": "bunx trigger.dev dev",
"format": "biome format --write .",
"typecheck": "tsc --noEmit"
"typecheck": "tsc-files --noEmit",
"test": "vitest"
},
"dependencies": {
"@eda/supabase": "workspace:*",
"@eda/types": "workspace:*",
"@getzep/zep-cloud": "^2.0.0",
"@trigger.dev/sdk": "3.1.0"
"@getzep/zep-cloud": "^2.1.1",
"@trigger.dev/sdk": "3.2.1"
},
"devDependencies": {
"@trigger.dev/build": "3.1.0"
"@trigger.dev/build": "3.2.1",
"vitest": "^2.1.5"
}
}
66 changes: 66 additions & 0 deletions packages/jobs/schemas/grant-calls.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { z } from "zod";

// Define specific types for meta values
const metaValueSchema = z.union([
z.string(),
z.number(),
z.boolean(),
z.null(),
z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])),
z.record(
z.string(),
z.union([z.string(), z.number(), z.boolean(), z.null()]),
),
]);

export const querySchema = z
.object({
userId: z.string().optional(),
limit: z.number().int().min(0).optional(),
offset: z.number().int().min(0).optional(),
status: z.enum(["open", "closed", "draft"]).optional(),
focusArea: z.string().optional(),
minAmount: z.number().min(0).optional(),
maxAmount: z.number().min(0).optional(),
})
.refine(
(data) =>
!data.minAmount || !data.maxAmount || data.maxAmount >= data.minAmount,
{ message: "maxAmount must be greater than or equal to minAmount" },
);

export const saveGrantCallSchema = z.object({
id: z.string().optional(),
title: z.string(),
description: z.string(),
organization: z.string(),
funding_amount: z.number().min(0),
deadline: z.string(),
focus_areas: z.array(z.string()),
eligibility_criteria: z.array(z.string()),
requirements: z.array(z.string()),
status: z.enum(["open", "closed", "draft"]),
meta: z.record(z.string(), metaValueSchema).optional(),
});

export type MetaValue =
| string
| number
| boolean
| null
| Array<string | number | boolean | null>
| Record<string, string | number | boolean | null>;

export type GrantCallResult = {
id: string;
title: string;
description: string;
organization: string;
funding_amount: number;
deadline: string;
focus_areas: string[];
eligibility_criteria: string[];
requirements: string[];
status: "open" | "closed" | "draft";
meta?: Record<string, MetaValue>;
};
55 changes: 55 additions & 0 deletions packages/jobs/schemas/profiles.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { z } from "zod";

// Define specific types for meta values
const metaValueSchema = z.union([
z.string(),
z.number(),
z.boolean(),
z.null(),
z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])),
z.record(
z.string(),
z.union([z.string(), z.number(), z.boolean(), z.null()]),
),
]);

// Query schema for getting profiles
export const querySchema = z.object({
userId: z.string().optional(),
biome: z.string().optional(),
ethnicGroup: z.string().optional(),
territory: z.string().optional(),
community: z.string().optional(),
limit: z.number().int().min(0).optional(),
offset: z.number().int().min(0).optional(),
});

// Schema for saving profiles
export const saveProfileSchema = z.object({
id: z.string().optional(),
userId: z.string().min(1),
biome: z.string().min(1),
ethnicGroup: z.string().min(1),
territory: z.string().min(1),
community: z.string().min(1),
meta: z.record(z.string(), metaValueSchema).optional(),
});

export type MetaValue =
| string
| number
| boolean
| null
| Array<string | number | boolean | null>
| Record<string, string | number | boolean | null>;

export type ProfileResult = {
id: string;
user_id: string;
biome: string;
ethnic_group: string;
territory: string;
community: string;
meta?: Record<string, MetaValue>;
created_at: string;
};
43 changes: 43 additions & 0 deletions packages/jobs/schemas/received-messages.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { z } from "zod";

export const querySchema = z
.object({
userId: z.string().optional(),
limit: z.number().int().min(0).optional(),
offset: z.number().int().min(0).optional(),
fromTimestamp: z.number().min(0).optional(),
toTimestamp: z.number().min(0).optional(),
})
.refine(
(data) =>
!data.fromTimestamp ||
!data.toTimestamp ||
data.toTimestamp >= data.fromTimestamp,
{ message: "toTimestamp must be greater than or equal to fromTimestamp" },
);

export const messageSchema = z.object({
id: z.string(),
_id: z.string(),
from: z.string(),
to: z.string(),
userId: z.string(),
data: z.object({
text: z.string(),
}),
timestamp: z.number(),
type: z.string(),
isGroupChat: z.boolean(),
chatId: z.string(),
created: z.string(),
});

export type MessageResult = {
id: string;
user_id: string;
text: string;
timestamp: number;
processed: boolean;
meta: Record<string, unknown>;
created_at: string;
};
47 changes: 47 additions & 0 deletions packages/jobs/schemas/tosend-messages.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { z } from "zod";

export const querySchema = z
.object({
userId: z.string().optional(),
limit: z.number().int().min(0).optional(),
offset: z.number().int().min(0).optional(),
fromTimestamp: z.number().min(0).optional(),
toTimestamp: z.number().min(0).optional(),
processed: z.boolean().optional(),
})
.refine(
(data) =>
!data.fromTimestamp ||
!data.toTimestamp ||
data.toTimestamp >= data.fromTimestamp,
{ message: "toTimestamp must be greater than or equal to fromTimestamp" },
);

const metaValueSchema = z.union([
z.string(),
z.number(),
z.boolean(),
z.null(),
z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])),
z.record(
z.string(),
z.union([z.string(), z.number(), z.boolean(), z.null()]),
),
]);

const messageSchema = z.object({
userId: z.string().min(1),
text: z.string().min(1),
timestamp: z.number(),
meta: z.record(z.string(), metaValueSchema).optional(),
});

export type MetaValue =
| string
| number
| boolean
| null
| Array<string | number | boolean | null>
| Record<string, string | number | boolean | null>;

export { messageSchema };
Loading

0 comments on commit d2651e5

Please sign in to comment.