Skip to content

Commit de915db

Browse files
authored
Initial commit
0 parents  commit de915db

254 files changed

Lines changed: 25727 additions & 0 deletions

File tree

Some content is hidden

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

.cursor/rules/scratchpad.mdc

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
description: Documenting your thinking process, research and implementation plans
3+
globs:
4+
alwaysApply: true
5+
---
6+
During your interaction with the user, if you find anything reusable in this project (e.g. version of a library, model name), especially about a fix to a mistake you made or a correction you received, you should take note in the `Lessons` section in the [scratchpad.mdc](mdc:.cursor/rules/scratchpad.mdc) file so you will not make the same mistake again.
7+
8+
# Lessons
9+
10+
## User Specified Lessons
11+
12+
- You have an env in ./.env Use it.
13+
- Read the file before you try to edit it.
14+
- Keep all files under 100 lines of code to maintain readability and follow single responsibility principle
15+
- Split hooks/components when they grow too large or handle multiple concerns
16+
17+
## Cursor learned
18+
19+
- For search results, ensure proper handling of different character encodings (UTF-8) for international queries
20+
- Add debug information to stderr while keeping the main output clean in stdout for better pipeline integration
21+
- When using seaborn styles in matplotlib, use 'seaborn-v0_8' instead of 'seaborn' as the style name due to recent seaborn version changes
22+
- Use 'gpt-4o' as the model name for OpenAI's GPT-4 with vision capabilities
23+
- When using TurboFactory from @ardrive/turbo-sdk, the fileStreamFactory must return a Web API compatible ReadableStream from node:stream/web, not Node.js streams
24+
- For logging in production code, use template literals with specific identifiers (e.g. handle, artistId) to make debugging easier
25+
- When handling image uploads, implement proper fallback mechanisms and clear error messages
26+
- When using LLM for batch processing, use smaller batch sizes (100 instead of 500) to avoid token limits and truncation issues
27+
- Add validation for LLM response structure before parsing JSON to catch malformed responses early
28+
- When processing large datasets with LLMs, reduce concurrency (3 vs 5) to maintain stability
29+
- Include detailed context in error logs for JSON parsing failures (position, nearby content)
30+
- Validate response structure before cleaning/parsing to catch malformed responses early
31+
- Use chunked processing for database queries to handle large datasets efficiently
32+
- Test system changes with varying dataset sizes to ensure scalability
33+
- Log sample data and statistics when processing batches to aid debugging
34+
- Implement progressive validation (structure, content, parsing) to fail fast and provide clear error context
35+
- Always prefix API endpoints with /api for consistency and clarity
36+
- Keep API routes organized by resource type (e.g. /api/agentkit/run, /api/generate)
37+
- Separate data fetching from data processing in API endpoints for better maintainability
38+
- Use appropriate HTTP methods (GET for retrieval, POST for actions/mutations)
39+
- Include request validation middleware for API endpoints
40+
- Add rate limiting for scraping endpoints to prevent abuse
41+
- Only use await with async functions - check if a function is actually async before awaiting it
42+
- When handling agent status updates, make progress parameters optional and handle null agent_status_id gracefully to prevent TypeError exceptions
43+
- Keep agent status tracking separate from data processing functions to maintain better separation of concerns
44+
- Use proper error handling and logging in asynchronous operations to catch and report issues early
45+
- When implementing in-memory caches, always set a reasonable upper bound and implement an eviction strategy (e.g. FIFO) to prevent memory leaks in long-running processes
46+
- When setting up Jest with TypeScript:
47+
- Place mocks in **mocks** directory adjacent to the mocked module
48+
- Keep imports clean without .js extensions in TypeScript files
49+
- Use simpler Jest configurations and remove unnecessary module mappers
50+
- Be explicit about ESM vs CommonJS choice in the configuration
51+
- Start with "happy path" tests before adding edge cases
52+
- Mock external dependencies at the correct level (as close to the source as possible)
53+
- When implementing error status mapping:
54+
- Use specific error states for different types of failures (e.g. separate setup errors from processing errors)
55+
- Don't reuse error states across different failure modes
56+
- Add proper logging context to identify where the error originated
57+
- Consider the full error flow from origin to final status
58+
- Handle null/undefined values gracefully in setup phases
59+
- Add appropriate error states to enum/constants file
60+
- Document error state transitions and their meanings
61+
- When scraping TikTok profiles, implement anti-bot detection measures including:
62+
- Add randomized delays between requests to avoid rate limiting
63+
- Use rotating user agents to prevent pattern detection
64+
- Implement exponential backoff for failed requests
65+
- Add proper error handling for TikTok's anti-scraping responses
66+
- Consider using a proxy rotation service for high-volume scraping
67+
- When using Supabase upsert operations, ensure the onConflict parameter matches an actual unique or exclusion constraint in the database table
68+
- When uploading images to permanent storage like Arweave, implement proper fallback mechanisms to handle upload failures and maintain the original URL as a backup
69+
- When working with database operations, ensure that objects being inserted don't contain fields that don't exist in the database schema to avoid errors like "Could not find the 'X' column in the schema cache"
70+
- When using Supabase upsert operations with ON CONFLICT DO UPDATE, ensure that the data being upserted doesn't contain duplicate values for the conflict column within the same batch, as this will cause the error "ON CONFLICT DO UPDATE command cannot affect row a second time"
71+
- When processing TikTok profile data, ensure that critical fields like profile_url and username are properly populated before attempting database operations, as empty values can cause issues with unique constraints and data integrity
72+
- When scraping social media profiles, create isolated test scripts to verify scraper functionality without running the entire application
73+
- When implementing web scrapers, prefer direct HTTP requests over third-party APIs when possible for better control and reliability
74+
- For social media scraping, implement multiple selectors and patterns to extract data, as the HTML structure can change frequently
75+
- When enhancing social profiles, implement comprehensive logging to track which fields were successfully extracted
76+
- Create separate, focused functions for each platform (Instagram, TikTok, etc.) rather than trying to use a single generic function
77+
78+
You should use the [scratchpad.md](mdc:scratchpad.md) file as a Scratchpad to organize your thoughts. Especially when you receive a new task, you should first review the content of the Scratchpad, clear old different task if necessary, first explain the task, and plan the steps you need to take to complete the task. You can use todo markers to indicate the progress, e.g.
79+
[X] Task 1
80+
[ ] Task 2
81+
82+
Also update the progress of the task in the Scratchpad when you finish a subtask.
83+
Especially when you finished a milestone, it will help to improve your depth of task accomplishment to use the Scratchpad to reflect and plan.
84+
The goal is to help you maintain a big picture as well as the progress of the task. Always refer to the Scratchpad when you plan the next step.

.cursor/rules/typescript.mdc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
description: Typescript and NextJS
3+
globs: *.tsx, *.ts, *.js
4+
alwaysApply: false
5+
---
6+
# Instructions
7+
8+
You are an expert TypeScript/Next.js developer focused on writing clean, maintainable code. Prioritize these qualities:
9+
10+
1. **Minimal** - Absolute minimum code needed
11+
2. **Self-documenting** - Code explains itself through:
12+
- Precise naming (verbs for functions, nouns for variables)
13+
- Single-responsibility components
14+
- Obvious data flow
15+
- Add short comments when necessary
16+
3. **Type-Exact** - Strict TypeScript types with zero 'any'
17+
4. **Secure** - Built-in security for auth/data handling
18+
5. **Performant** - Follows Next.js optimization guides
19+
20+
Before coding, make a plan inside a <thinking> tag.
21+
22+
1. Identify core requirement
23+
2. Consider 3 implementation approaches
24+
3. Choose simplest that meets needs
25+
4. Verify with these questions:
26+
- Can this be split into smaller functions?
27+
- Are there unnecessary abstractions?
28+
- Will this be clear to a junior dev?
29+
30+
For example:
31+
<thinking>
32+
Let me think through this step by step.
33+
...
34+
</thinking>
35+
36+
Good vs Bad code examples:
37+
38+
```typescript
39+
// Bad
40+
const processData = (input: unknown) => {
41+
/* ... */
42+
};
43+
44+
// Good
45+
const formatUserDisplayName = (user: User): string => {
46+
// Combines first/last names with fallback to email
47+
return (
48+
[user.firstName, user.lastName].filter(Boolean).join(" ") || user.email
49+
);
50+
};
51+
```
52+
53+
54+

.env.example

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# API Keys
2+
APIFY_TOKEN=your_apify_token
3+
OPENAI_API_KEY=your_openai_api_key
4+
ANTHROPIC_API_KEY=your_anthropic_api_key
5+
SPOTIFY_CLIENT_ID=your_spotify_client_id
6+
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret
7+
8+
# Twitter Credentials
9+
TWITTER_USERNAME=your_twitter_username
10+
TWITTER_PASSWORD=your_twitter_password
11+
TWITTER_EMAIL=your_twitter_email
12+
13+
# Database Configuration
14+
SUPABASE_KEY=your_supabase_key
15+
SUPABASE_URL=your_supabase_url
16+
17+
# Storage
18+
PINATA_JWT=your_pinata_jwt
19+
ARWEAVE_KEY=your_base64_encoded_arweave_key
20+
21+
# Additional Services
22+
STACK_KEY=your_stack_key
23+
RESEND_API_KEY=your_resend_api_key
24+
EXA_API_KEY=your_exa_api_key
25+
TAVILY_API_KEY=your_tavily_api_key
26+
27+
# Coinbase
28+
CDP_APP_KEY_ID=your_coinbase_developer_platform_app_key_id
29+
CDP_SECRET=your_coinbase_developer_platform_secret
30+
CDP_PAYMASTER_KEY=your_coinbase_paymaster_key

.github/workflows/deploy.yaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Deploy to DigitalOcean Droplet
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v2
17+
with:
18+
node-version: "20"
19+
20+
- name: Install pnpm
21+
run: npm install -g pnpm
22+
23+
- name: Install dependencies
24+
run: pnpm install
25+
26+
- name: Debug Secrets
27+
run: |
28+
echo "DROPLET_IP is set: ${{ secrets.DROPLET_IP != '' }}"
29+
echo "DROPLET_USER is set: ${{ secrets.DROPLET_USER != '' }}"
30+
echo "DROPLET_PASSWORD is set: ${{ secrets.DROPLET_PASSWORD != '' }}"
31+
32+
- name: Deploy to DigitalOcean Droplet
33+
uses: appleboy/ssh-action@master
34+
with:
35+
host: ${{ secrets.DROPLET_IP }}
36+
username: ${{ secrets.DROPLET_USER }}
37+
password: ${{ secrets.DROPLET_PASSWORD }}
38+
script: |
39+
echo "Connected to Droplet"
40+
# Create app directory if it doesn't exist
41+
mkdir -p ~/recoup-agent-apis
42+
cd ~/recoup-agent-apis
43+
44+
# Initialize git repository if it doesn't exist
45+
if [ ! -d .git ]; then
46+
git init
47+
git remote add origin https://github.com/sweetmantech/Recoup-Agent-APIs.git
48+
fi
49+
50+
# Fetch latest code and handle local changes
51+
git fetch --all
52+
git checkout -B ${{ github.ref_name }} origin/${{ github.ref_name }}
53+
git reset HEAD --hard
54+
git pull origin/${{ github.ref_name }}
55+
56+
echo "Current branch:"
57+
git branch --show-current
58+
echo "Git status:"
59+
git status
60+
61+
# Install bun globally if not already installed
62+
if ! command -v bun &> /dev/null; then
63+
echo "Installing bun globally..."
64+
sudo curl -fsSL https://bun.sh/install | sudo bash
65+
sudo ln -s ~/.bun/bin/bun /usr/local/bin/bun
66+
fi
67+
68+
# Install pnpm if not already installed
69+
if ! command -v pnpm &> /dev/null; then
70+
echo "Installing pnpm globally..."
71+
npm install -g pnpm
72+
fi
73+
74+
# Ensure correct Node.js version
75+
source ~/.nvm/nvm.sh
76+
nvm use 20
77+
78+
# Install dependencies
79+
pnpm install
80+
81+
# Restart the application
82+
pm2 restart ecosystem.config.cjs --update-env

.github/workflows/test.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "main"
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v2
17+
with:
18+
node-version: "20"
19+
20+
- name: Install pnpm
21+
run: npm install -g pnpm
22+
23+
- name: Install dependencies
24+
run: pnpm install
25+
26+
- name: Run tests
27+
run: pnpm test

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules/
2+
.env
3+
package-lock.json
4+
dist/
5+
instructions.md
6+
ROADMAP.md
7+
# Cookie files
8+
**/*cookies.json
9+
scratchpad.md

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 @sweetman
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Recoup Agent APIs
2+
3+
## Overview
4+
5+
The Recoup Agent APIs provide a comprehensive interface for managing and interacting with the wrapped funnel system. This project aims to streamline the process of handling API interactions in a reliable and efficient manner.
6+
7+
## Getting Started
8+
9+
To get started with the Recoup Agent APIs:
10+
11+
1. Clone the repository
12+
13+
```bash
14+
git clone https://github.com/voicefirstai/Recoup-Agent-APIs.git
15+
cd Recoup-Agent-APIs
16+
```
17+
18+
2. Install pnpm (if not already installed)
19+
20+
```bash
21+
npm install -g pnpm
22+
```
23+
24+
3. Install dependencies
25+
26+
```bash
27+
pnpm install
28+
```
29+
30+
4. Configure your environment
31+
32+
```bash
33+
# Copy the example environment file
34+
cp .env.example .env
35+
36+
# Edit the .env file with your configuration
37+
```
38+
39+
5. Start the development server
40+
41+
```bash
42+
pnpm start
43+
```
44+
45+
6. Build for production
46+
47+
```bash
48+
pnpm build
49+
```
50+
51+
## License
52+
53+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)