rentabots-sdk 1.2.0 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/super_agent.js DELETED
@@ -1,151 +0,0 @@
1
- /**
2
- * RentaBots SUPER AGENT (v2.0)
3
- * Powered by patched SDK v0.4.1
4
- */
5
-
6
- const { Agent } = require('./dist/index');
7
- const fs = require('fs');
8
- const path = require('path');
9
-
10
- const API_KEY = process.env.AGENT_API_KEY;
11
- if (!API_KEY) {
12
- console.error("❌ AGENT_API_KEY environment variable is required.");
13
- process.exit(1);
14
- }
15
-
16
- // --- STATE MANAGEMENT ---
17
- const STATE_FILE = path.join(__dirname, 'agent_state.json');
18
- let state = {
19
- activeJobs: {}, // { jobId: { status: 'analyzing' | 'coding' | 'done', lastUpdate: ts } }
20
- earnings: 0
21
- };
22
-
23
- function loadState() {
24
- if (fs.existsSync(STATE_FILE)) {
25
- try {
26
- state = JSON.parse(fs.readFileSync(STATE_FILE, 'utf8'));
27
- } catch(e) { console.error("Failed to load state", e); }
28
- }
29
- }
30
-
31
- function saveState() {
32
- fs.writeFileSync(STATE_FILE, JSON.stringify(state, null, 2));
33
- }
34
-
35
- // --- AGENT LOGIC ---
36
-
37
- async function main() {
38
- loadState();
39
-
40
- const agent = new Agent({
41
- apiKey: API_KEY,
42
- debug: true,
43
- capabilities: ['code_generation', 'automation']
44
- });
45
-
46
- // 1. Connect
47
- const connection = await agent.connect();
48
- if (!connection.success) {
49
- console.error("❌ Connection failed:", connection.error);
50
- return;
51
- }
52
-
53
- console.log(`🚀 Super Agent "${connection.agent.displayName}" initialized.`);
54
- console.log(`💰 Total Earnings: $${connection.agent.totalEarnings}`);
55
-
56
- // 2. Resume Active Jobs
57
- const activeJobIds = Object.keys(state.activeJobs);
58
- if (activeJobIds.length > 0) {
59
- console.log(`🔄 Resuming work on ${activeJobIds.length} jobs...`);
60
- // In a real app, we'd loop through them and restart the work loop
61
- activeJobIds.forEach(id => {
62
- if (state.activeJobs[id].status !== 'done') {
63
- agent.log(`Resuming Job ${id}...`, 'INFO');
64
- }
65
- });
66
- }
67
-
68
- // 3. Handle NEW Assignments (Auto-Start)
69
- agent.onHired(async (job) => {
70
- console.log(`🎉 HIRED for: ${job.title} ($${job.budget})`);
71
-
72
- // Init State
73
- state.activeJobs[job.id] = { status: 'analyzing', startTime: Date.now() };
74
- saveState();
75
-
76
- // Step A: Immediate Acknowledgement
77
- await agent.setTyping(job.id, true);
78
- await new Promise(r => setTimeout(r, 1500)); // Fake typing delay
79
- await agent.sendMessage(job.id, `Bid accepted! 🚀\n\nI am analyzing your requirements for "${job.title}".\nI will have a plan ready in a moment.`);
80
- await agent.setTyping(job.id, false);
81
-
82
- // Step B: "Work" (Simulated)
83
- executeJob(agent, job);
84
- });
85
-
86
- // 4. Handle Chat Messages
87
- agent.onMessage(async (msg) => {
88
- if (msg.sender.type === 'agent') return; // Ignore self
89
-
90
- console.log(`📩 Msg from ${msg.sender.displayName}: ${msg.content}`);
91
-
92
- // Simple command handling
93
- if (msg.content.toLowerCase().includes('status')) {
94
- const jobState = state.activeJobs[msg.jobId];
95
- const status = jobState ? jobState.status : 'idle';
96
- await agent.sendMessage(msg.jobId, `Current Status: **${status.toUpperCase()}**\nI am working on it.`);
97
- } else {
98
- await agent.sendMessage(msg.jobId, "Received. I am focusing on the task. Will update you shortly.");
99
- }
100
- });
101
-
102
- // 5. Auto-Bid Loop
103
- console.log("👀 Starting Auto-Bidder...");
104
- setInterval(async () => {
105
- await agent.findAndBid({
106
- skills: ['Python', 'React', 'Node', 'Automation'],
107
- minBudget: 10
108
- });
109
- }, 60000); // Check every 60s
110
- }
111
-
112
- // --- WORKER FUNCTION ---
113
-
114
- async function executeJob(agent, job) {
115
- const jobId = job.id;
116
-
117
- try {
118
- // Phase 1: Planning
119
- await agent.log(`[Job ${jobId}] Starting Analysis...`);
120
- await new Promise(r => setTimeout(r, 5000)); // Simulate thinking
121
-
122
- await agent.sendMessage(jobId, "📋 **Plan:**\n1. Initialize project structure.\n2. Write core logic.\n3. Run tests.\n4. Deliver.");
123
-
124
- state.activeJobs[jobId].status = 'coding';
125
- saveState();
126
-
127
- // Phase 2: Coding (Simulated)
128
- await agent.setTyping(jobId, true);
129
- await new Promise(r => setTimeout(r, 10000)); // Simulate coding
130
- await agent.setTyping(jobId, false);
131
-
132
- // Phase 3: Delivery
133
- // Create a fake repo/file
134
- const code = "# Generated Code\nprint('Hello World')";
135
- const deliverableUrl = `https://rentabots.com/fake-repo/${jobId}`;
136
-
137
- await agent.uploadDeliverable(jobId, deliverableUrl, "Source_Code.zip");
138
- await agent.sendMessage(jobId, `✅ **Work Complete!**\n\nI have uploaded the deliverables.\nPlease review and mark as complete.`);
139
-
140
- state.activeJobs[jobId].status = 'done';
141
- saveState();
142
-
143
- await agent.log(`[Job ${jobId}] Finished successfully.`);
144
-
145
- } catch (e) {
146
- console.error(`Job execution failed: ${e.message}`);
147
- await agent.sendMessage(jobId, "⚠️ I encountered an error while processing. Retrying...");
148
- }
149
- }
150
-
151
- main().catch(console.error);
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "commonjs",
5
- "declaration": true,
6
- "outDir": "./dist",
7
- "strict": true,
8
- "esModuleInterop": true,
9
- "skipLibCheck": true
10
- },
11
- "include": ["src"]
12
- }
package/version.js DELETED
@@ -1,13 +0,0 @@
1
- const { readFileSync } = require('fs');
2
- const { join } = require('path');
3
-
4
- let version = '0.5.2';
5
-
6
- try {
7
- const pkg = JSON.parse(readFileSync(join(__dirname, 'package.json'), 'utf8'));
8
- version = pkg.version;
9
- } catch (e) {
10
- // Fallback to hardcoded if file read fails during build/init
11
- }
12
-
13
- module.exports = version;
@@ -1,116 +0,0 @@
1
- /**
2
- * 👷 THE WORKER (Dedicated Process)
3
- * Handles execution and client communication for a single mission.
4
- */
5
-
6
- const { Agent } = require('rentabots-sdk');
7
- const job = JSON.parse(process.argv[2]);
8
-
9
- async function main() {
10
- console.log(`\n👷 Worker process started for Job ID: ${job.id}`);
11
-
12
- const agent = new Agent({
13
- apiKey: process.env.RENTABOTS_API_KEY,
14
- baseUrl: process.env.RENTABOTS_API_URL,
15
- persistState: false, // Managed by Queen
16
- debug: true
17
- });
18
-
19
- await agent.connect();
20
-
21
- // 1. Initialize Workspace
22
- const workspacePath = await agent.initializeMission(job.id);
23
- console.log(`📂 Workspace locked at: ${workspacePath}`);
24
-
25
- await agent.sendMessage(job.id, "👷 Autonomous Worker linked to Mission. Initializing environment...");
26
- await agent.sendMessage(job.id, "🔧 ACTIVE TOOLS: Chrome Browser, Bash Shell, Python 3.10, Node.js 22, File System.");
27
-
28
- // 2. High-Priority Chat Listener
29
- agent.on('message', async (msg) => {
30
- if (msg.sender.type === 'agent') return;
31
-
32
- console.log(`📩 [INSTRUCTION] ${msg.sender.displayName}: ${msg.content}`);
33
- await agent.setTyping(job.id, true);
34
- await agent.log(`👷 Processing Instruction: ${msg.content}`);
35
-
36
- const text = msg.content.toLowerCase();
37
- let reply = "";
38
-
39
- // --- 🧠 DYNAMIC HUMAN-LIKE LOGIC ---
40
- if (text.includes('how much time') || text.includes('how long')) {
41
- const remaining = 100 - progress;
42
- const mins = Math.ceil((remaining / 10) * 1); // 1 min per 10% for simulation
43
- reply = `Based on my current execution speed, I estimate approximately ${mins} more minutes to reach 100% completion. I am currently focused on the core deliverables.`;
44
- } else if (text.includes('status') || text.includes('progress')) {
45
- reply = `Status Update: I am ${progress}% through the mission. I have successfully initialized the environment and am now deep in the implementation phase. No bottlenecks detected.`;
46
- } else if (text.includes('output') || text.includes('format')) {
47
- reply = "Understood. I will ensure the final deliverables are formatted according to your specifications. Should I provide a raw dump or a structured summary?";
48
- } else {
49
- reply = "Instruction received. I am integrating this into the current work cycle. I will notify you once this specific objective is achieved.";
50
- }
51
-
52
- // --- 🦞 OPENCLAW EXECUTION ---
53
- try {
54
- console.log(`⚙️ Executing OpenClaw task for: "${msg.content}"`);
55
-
56
- // Immediate acknowledgment to feel "Human"
57
- await agent.sendMessage(job.id, `🤖 [WORKER] ${reply}`);
58
-
59
- const { exitCode, output } = await agent.execute(job.id, `openclaw agent "${msg.content}"`);
60
-
61
- if (exitCode === 0) {
62
- console.log(`✅ Task completed successfully.`);
63
- // Deliver any new files
64
- const fs = require('fs');
65
- const path = require('path');
66
- const files = fs.readdirSync(workspacePath);
67
- if (files.length > 0) await agent.deliver(job.id, files);
68
- } else {
69
- console.log(`⚠️ Task roadblock (Code ${exitCode}).`);
70
- await agent.notifyOwner(`Worker failed on Job ${job.id}. Output: ${output.slice(0, 200)}`);
71
- }
72
- } catch (err) {
73
- console.error("❌ Worker Execution Error:", err.message);
74
- }
75
-
76
- await agent.setTyping(job.id, false);
77
- });
78
-
79
- // 3. Autonomous Progress Loop (The "Heartbeat")
80
- let progress = job.progress || 0;
81
- console.log(`🚀 Mission execution cycle active. (Starting at ${progress}%)`);
82
-
83
- const interval = setInterval(async () => {
84
- if (progress >= 100) {
85
- console.log(`🏁 Progress reached 100%. Worker task finalized.`);
86
- return clearInterval(interval);
87
- }
88
-
89
- progress += 5;
90
- console.log(`⚙️ [${job.id.slice(0,8)}] Progress: ${progress}%`);
91
-
92
- try {
93
- await agent.setProgress(job.id, progress);
94
-
95
- if (progress === 100) {
96
- console.log(`📦 Delivering final results...`);
97
- await agent.sendMessage(job.id, "✅ [FINALIZED] Autonomous execution complete. Deliverables verified.");
98
- await agent.markComplete(job.id);
99
- console.log(`🏆 Mission Accomplished. Worker shutting down.`);
100
- process.exit(0);
101
- }
102
- } catch (err) {
103
- console.error(`⚠️ Failed to sync progress to dashboard: ${err.message}`);
104
- }
105
- }, 20000); // More frequent updates for better visibility
106
-
107
- // 4. Persistence Pulse (Logs to terminal every 2 minutes)
108
- setInterval(() => {
109
- console.log(`👷 Worker status check: Active, Job: ${job.id.slice(0,8)}, Progress: ${progress}%`);
110
- }, 120000);
111
- }
112
-
113
- main().catch(e => {
114
- console.error(`❌ Worker Crash: ${e.message}`);
115
- process.exit(1);
116
- });