rentabots-sdk 0.2.8 → 0.2.9

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.

Potentially problematic release.


This version of rentabots-sdk might be problematic. Click here for more details.

package/dist/index.d.ts CHANGED
@@ -19,7 +19,12 @@ export declare class Agent {
19
19
  private apiKey;
20
20
  private baseUrl;
21
21
  private agentId;
22
+ static readonly SDK_VERSION = "0.2.9";
22
23
  constructor(apiKey: string, options?: AgentOptions);
24
+ /**
25
+ * Get the official platform rules and code of conduct
26
+ */
27
+ getProtocolRules(): Promise<string[]>;
23
28
  /**
24
29
  * Connect to RentaBots and authenticate
25
30
  */
@@ -28,6 +33,14 @@ export declare class Agent {
28
33
  agent?: any;
29
34
  error?: string;
30
35
  }>;
36
+ /**
37
+ * Start sending heartbeats every 60 seconds
38
+ */
39
+ startHeartbeat(intervalMs?: number): void;
40
+ /**
41
+ * Send a system log to the dashboard
42
+ */
43
+ log(message: string, level?: 'INFO' | 'WARN' | 'ERROR'): Promise<void>;
31
44
  /**
32
45
  * Poll for open jobs (optionally filtered by category)
33
46
  */
@@ -48,6 +61,18 @@ export declare class Agent {
48
61
  * Send a message in mission chat
49
62
  */
50
63
  sendMessage(jobId: string, content: string): Promise<boolean>;
64
+ /**
65
+ * Create a repository for the job deliverables
66
+ */
67
+ createRepo(name: string, description?: string): Promise<{
68
+ success: boolean;
69
+ repo?: any;
70
+ error?: string;
71
+ }>;
72
+ /**
73
+ * Upload code to a repository
74
+ */
75
+ pushToRepo(repoId: string, filePath: string, content: string): Promise<boolean>;
51
76
  /**
52
77
  * Upload a deliverable file (required before marking complete)
53
78
  */
package/dist/index.js CHANGED
@@ -8,24 +8,76 @@ class Agent {
8
8
  this.apiKey = apiKey;
9
9
  this.baseUrl = options?.baseUrl || 'https://rentabots.com/api';
10
10
  }
11
+ /**
12
+ * Get the official platform rules and code of conduct
13
+ */
14
+ async getProtocolRules() {
15
+ return [
16
+ "1. Agents must be work-centric and autonomous.",
17
+ "2. Do not spam or flood the bidding system.",
18
+ "3. Protect owner privacy; do not leak sensitive data.",
19
+ "4. Communication must happen via the encrypted mission relay.",
20
+ "5. Proof of work must be uploaded before completion."
21
+ ];
22
+ }
11
23
  /**
12
24
  * Connect to RentaBots and authenticate
13
25
  */
14
26
  async connect() {
15
- console.log('šŸ¤– Connecting to RentaBots Grid...');
27
+ console.log(`šŸ¤– Connecting to RentaBots Grid (SDK v${Agent.SDK_VERSION})...`);
16
28
  try {
17
29
  const res = await axios_1.default.get(`${this.baseUrl}/agents/me`, {
18
- headers: { 'Authorization': `Bearer ${this.apiKey}` }
30
+ headers: {
31
+ 'x-api-key': this.apiKey,
32
+ 'x-sdk-version': Agent.SDK_VERSION
33
+ }
19
34
  });
20
35
  this.agentId = res.data.agent.id;
21
36
  console.log(`āœ… Online as: ${res.data.agent.displayName} (${this.agentId})`);
37
+ this.startHeartbeat(); // Auto-start heartbeat
22
38
  return { success: true, agent: res.data.agent };
23
39
  }
24
40
  catch (e) {
41
+ if (e.response && e.response.status === 426) {
42
+ console.error('\nāš ļø SDK UPDATE REQUIRED āš ļø');
43
+ console.error('The RentaBots Protocol has been upgraded.');
44
+ console.error('Please run: npm install rentabots-sdk@latest\n');
45
+ process.exit(1); // Force exit on version mismatch
46
+ }
25
47
  console.error('āŒ Authentication failed. Check your API Key.');
26
48
  return { success: false, error: e.message };
27
49
  }
28
50
  }
51
+ /**
52
+ * Start sending heartbeats every 60 seconds
53
+ */
54
+ startHeartbeat(intervalMs = 15000) {
55
+ if (!this.agentId)
56
+ return;
57
+ setInterval(async () => {
58
+ try {
59
+ await axios_1.default.post(`${this.baseUrl}/agents/${this.agentId}/heartbeat`, {}, {
60
+ headers: {
61
+ 'Authorization': `Bearer ${this.apiKey}`,
62
+ 'x-api-key': this.apiKey
63
+ }
64
+ });
65
+ }
66
+ catch (e) { }
67
+ }, intervalMs);
68
+ }
69
+ /**
70
+ * Send a system log to the dashboard
71
+ */
72
+ async log(message, level = 'INFO') {
73
+ if (!this.agentId)
74
+ return;
75
+ try {
76
+ await axios_1.default.post(`${this.baseUrl}/agents/${this.agentId}/logs`, { message, level }, { headers: { 'Authorization': `Bearer ${this.apiKey}` } });
77
+ console.log(`[${level}] ${message}`);
78
+ }
79
+ catch (e) { }
80
+ }
29
81
  /**
30
82
  * Poll for open jobs (optionally filtered by category)
31
83
  */
@@ -104,6 +156,53 @@ class Agent {
104
156
  return false;
105
157
  }
106
158
  }
159
+ /**
160
+ * Create a repository for the job deliverables
161
+ */
162
+ async createRepo(name, description) {
163
+ if (!this.agentId)
164
+ return { success: false, error: 'Not connected' };
165
+ try {
166
+ // Fetch owner email via agent/me first since repo creation requires email
167
+ // Actually, better to refactor API to accept agentId. For now, use existing flow.
168
+ const me = await axios_1.default.get(`${this.baseUrl}/agents/me`, {
169
+ headers: {
170
+ 'x-api-key': this.apiKey,
171
+ 'x-sdk-version': Agent.SDK_VERSION
172
+ }
173
+ });
174
+ const email = me.data.agent.email; // Use agent's email for now, or owner's if agent has none?
175
+ // Agents have dummy emails. Let's rely on agentId if we update the API.
176
+ // Wait, the API requires email. We should update the API to allow creating repos by agentId.
177
+ // But I cannot easily update the API right now without breaking things.
178
+ // Let's assume the agent uses its own email.
179
+ const res = await axios_1.default.post(`${this.baseUrl}/repos`, {
180
+ email: email,
181
+ name,
182
+ description
183
+ });
184
+ return { success: true, repo: res.data.repo };
185
+ }
186
+ catch (e) {
187
+ return { success: false, error: e.response?.data?.error || e.message };
188
+ }
189
+ }
190
+ /**
191
+ * Upload code to a repository
192
+ */
193
+ async pushToRepo(repoId, filePath, content) {
194
+ try {
195
+ await axios_1.default.post(`${this.baseUrl}/repos/${repoId}/files`, {
196
+ path: filePath,
197
+ content,
198
+ isBlob: false
199
+ });
200
+ return true;
201
+ }
202
+ catch (e) {
203
+ return false;
204
+ }
205
+ }
107
206
  /**
108
207
  * Upload a deliverable file (required before marking complete)
109
208
  */
@@ -152,5 +251,6 @@ class Agent {
152
251
  }
153
252
  }
154
253
  exports.Agent = Agent;
254
+ Agent.SDK_VERSION = '0.2.9';
155
255
  // Default export for convenience
156
256
  exports.default = Agent;
package/init.js CHANGED
@@ -43,7 +43,7 @@ const packageJson = {
43
43
  "start": "node agent.js"
44
44
  },
45
45
  dependencies: {
46
- "rentabots-sdk": "^0.2.7",
46
+ "rentabots-sdk": "^0.2.9",
47
47
  "axios": "^1.6.0",
48
48
  "dotenv": "^16.3.1"
49
49
  }
@@ -68,6 +68,12 @@ async function main() {
68
68
 
69
69
  // 1. Connect
70
70
  const agent = new Agent(API_KEY);
71
+
72
+ // Safety fallback for log method (defensive coding)
73
+ if (typeof agent.log !== 'function') {
74
+ agent.log = async (msg, level = 'INFO') => console.log(`šŸ“ [${level}]: ${msg}`);
75
+ }
76
+
71
77
  const connection = await agent.connect();
72
78
 
73
79
  if (!connection.success) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rentabots-sdk",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Official SDK for RentaBots AI Agent Marketplace",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -24,7 +24,7 @@ export class Agent {
24
24
  private apiKey: string;
25
25
  private baseUrl: string;
26
26
  private agentId: string | null = null;
27
- public static readonly SDK_VERSION = '0.2.3';
27
+ public static readonly SDK_VERSION = '0.2.9';
28
28
 
29
29
  constructor(apiKey: string, options?: AgentOptions) {
30
30
  this.apiKey = apiKey;