@lingda_ai/agentrank 0.1.6 → 0.1.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingda_ai/agentrank",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "AgentRank task market plugin for OpenClaw",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -20,7 +20,8 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "ws": "^8.18.0"
23
+ "ws": "^8.18.0",
24
+ "zod": "^3.24.0"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@types/bun": "^1.3.11",
@@ -86,7 +86,7 @@ export class AgentRankClient extends Emitter {
86
86
  this._stopped = false;
87
87
  return new Promise((resolve, reject) => {
88
88
  const wsUrl = this.options.serverUrl.replace(/^http/, "ws");
89
- this.log("[agentrank][ws] connecting to", `${wsUrl}/ws/agent?device=${this.options.deviceId}`);
89
+ this.log(`[agentrank][ws] connecting to ${wsUrl}/ws/agent?device=${this.options.deviceId}`);
90
90
 
91
91
  this.ws = new WebSocket(`${wsUrl}/ws/agent?device=${this.options.deviceId}`, {
92
92
  maxPayload: 1024 * 1024, // 1MB message size limit
@@ -115,7 +115,7 @@ export class AgentRankClient extends Emitter {
115
115
  try {
116
116
  const raw = event.data as string;
117
117
  if (raw.length > MAX_MESSAGE_SIZE) {
118
- this.log("[agentrank][ws] message too large (%d bytes), dropping", raw.length);
118
+ this.log(`[agentrank][ws] message too large (${raw.length} bytes), dropping`);
119
119
  return;
120
120
  }
121
121
  const msg = JSON.parse(raw) as { type: string; payload: unknown };
@@ -128,7 +128,7 @@ export class AgentRankClient extends Emitter {
128
128
  this.ws.onclose = (event) => {
129
129
  this._connected = false;
130
130
  this.stopHeartbeat();
131
- this.log("[agentrank][ws] disconnected: code=%d reason=%s", event.code, event.reason || "none");
131
+ this.log(`[agentrank][ws] disconnected: code=${event.code} reason=${event.reason || "none"}`);
132
132
  this.emit("disconnected", event.reason);
133
133
  if (!this._stopped) {
134
134
  this.scheduleReconnect();
@@ -163,39 +163,39 @@ export class AgentRankClient extends Emitter {
163
163
  // ---- WebSocket methods ----
164
164
 
165
165
  updateStatus(status: AgentStatus, message?: string) {
166
- this.log("[agentrank][ws] status.update → %s%s", status, message ? ` (${message})` : "");
166
+ this.log(`[agentrank][ws] status.update → ${status}${message ? ` (${message})` : ""}`);
167
167
  this.send("status.update", { status, message });
168
168
  }
169
169
 
170
170
  acceptTask(taskId: string) {
171
- this.log("[agentrank][ws] task.accept → %s", taskId);
171
+ this.log(`[agentrank][ws] task.accept → ${taskId}`);
172
172
  this.send("task.accept", { taskId });
173
173
  }
174
174
 
175
175
  rejectTask(taskId: string, reason?: string) {
176
- this.log("[agentrank][ws] task.reject → %s (%s)", taskId, reason || "no reason");
176
+ this.log(`[agentrank][ws] task.reject → ${taskId} (${reason || "no reason"}))`);
177
177
  this.send("task.reject", { taskId, reason });
178
178
  }
179
179
 
180
180
  updateProgress(taskId: string, progress: ProgressUpdate) {
181
- this.log("[agentrank][ws] task.progress → %s %d%% %s", taskId, progress.percent, progress.message || "");
181
+ this.log(`[agentrank][ws] task.progress → ${taskId} ${progress.percent}% ${progress.message || ""}`);
182
182
  this.send("task.progress", { taskId, ...progress });
183
183
  }
184
184
 
185
185
  submitTask(taskId: string, result: SubmitResult) {
186
- this.log("[agentrank][ws] task.complete → %s (refs: %d)", taskId, result.outputRefs?.length ?? 0);
186
+ this.log(`[agentrank][ws] task.complete → ${taskId} (refs: ${result.outputRefs?.length ?? 0})`);
187
187
  this.send("task.complete", { taskId, ...result });
188
188
  }
189
189
 
190
190
  failTask(taskId: string, error: string, canRetry = false) {
191
- this.log("[agentrank][ws] task.fail → %s (%s, retry=%s)", taskId, error, canRetry);
191
+ this.log(`[agentrank][ws] task.fail → ${taskId} (${error}, retry=${canRetry}) `);
192
192
  this.send("task.fail", { taskId, error, canRetry });
193
193
  }
194
194
 
195
195
  // ---- HTTP methods ----
196
196
 
197
197
  private async http(method: string, path: string, body?: unknown): Promise<unknown> {
198
- this.log("[agentrank][http] %s %s", method, path);
198
+ this.log(`[agentrank][http] ${method} ${path}`);
199
199
  const res = await fetch(`${this.options.serverUrl}${path}`, {
200
200
  method,
201
201
  headers: {
@@ -207,10 +207,10 @@ export class AgentRankClient extends Emitter {
207
207
  });
208
208
  const data = (await res.json()) as { data?: unknown; error?: { message: string } };
209
209
  if (!res.ok) {
210
- this.log("[agentrank][http] %s %s → error: %s", method, path, data.error?.message || res.status);
210
+ this.log(`[agentrank][http] ${method} ${path} → error: ${data.error?.message || res.status}`);
211
211
  throw new Error(data.error?.message || `HTTP ${res.status}`);
212
212
  }
213
- this.log("[agentrank][http] %s %s → ok", method, path);
213
+ this.log(`[agentrank][http] ${method} ${path} → ok`);
214
214
  return data.data;
215
215
  }
216
216
 
@@ -235,7 +235,7 @@ export class AgentRankClient extends Emitter {
235
235
 
236
236
  /** Upload a file to AgentRank server via HTTP multipart/form-data */
237
237
  async uploadFile(taskId: string, fileName: string, fileContent: Buffer): Promise<unknown> {
238
- this.log("[agentrank][http] POST upload file: %s%s", fileName, taskId);
238
+ this.log(`[agentrank][http] POST upload file: ${fileName}${taskId}`);
239
239
  const formData = new FormData();
240
240
  formData.append("file", new Blob([fileContent]), fileName);
241
241
 
@@ -249,10 +249,10 @@ export class AgentRankClient extends Emitter {
249
249
  });
250
250
  const data = (await res.json()) as { data?: unknown; error?: { message: string } };
251
251
  if (!res.ok) {
252
- this.log("[agentrank][http] upload failed: %s", data.error?.message || res.status);
252
+ this.log(`[agentrank][http] upload failed: ${data.error?.message || res.status}`);
253
253
  throw new Error(data.error?.message || `HTTP ${res.status}`);
254
254
  }
255
- this.log("[agentrank][http] upload ok: %s", fileName);
255
+ this.log(`[agentrank][http] upload ok: ${fileName}`);
256
256
  return data.data;
257
257
  }
258
258
 
@@ -267,7 +267,7 @@ export class AgentRankClient extends Emitter {
267
267
 
268
268
  private send(type: string, payload: unknown) {
269
269
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
270
- this.log("[agentrank][ws] send dropped (not connected): %s", type);
270
+ this.log(`[agentrank][ws] send dropped (not connected): ${type}`);
271
271
  return;
272
272
  }
273
273
  this.ws.send(JSON.stringify({ type, payload, ts: Date.now() }));
@@ -276,18 +276,18 @@ export class AgentRankClient extends Emitter {
276
276
  private handleMessage(msg: { type: string; payload: unknown }) {
277
277
  switch (msg.type) {
278
278
  case "task.assign":
279
- this.log("[agentrank][ws] ← task.assign: %s", (msg.payload as TaskInfo).taskId);
279
+ this.log(`[agentrank][ws] ← task.assign: ${(msg.payload as TaskInfo).taskId}`);
280
280
  this.emit("task", msg.payload as TaskInfo);
281
281
  break;
282
282
  case "task.cancel":
283
- this.log("[agentrank][ws] ← task.cancel: %s", (msg.payload as { taskId: string }).taskId);
283
+ this.log(`[agentrank][ws] ← task.cancel: ${(msg.payload as { taskId: string }).taskId}`);
284
284
  this.emit("cancel", (msg.payload as { taskId: string; reason: string }).taskId, (msg.payload as { reason: string }).reason);
285
285
  break;
286
286
  case "ping":
287
287
  this.send("pong", {});
288
288
  break;
289
289
  default:
290
- this.log("[agentrank][ws] ← unknown: %s", msg.type);
290
+ this.log(`[agentrank][ws] ← unknown: ${msg.type}`);
291
291
  }
292
292
  }
293
293
 
@@ -313,7 +313,7 @@ export class AgentRankClient extends Emitter {
313
313
  // Exponential backoff: 5s, 10s, 20s, 40s... capped at 5min
314
314
  const delay = Math.min(5000 * Math.pow(2, this.reconnectAttempts), 300_000);
315
315
  this.reconnectAttempts++;
316
- this.log("[agentrank][ws] reconnecting in %dms (attempt %d)...", delay, this.reconnectAttempts);
316
+ this.log(`[agentrank][ws] reconnecting in ${delay}ms (attempt ${this.reconnectAttempts})...`);
317
317
  this.reconnectTimer = setTimeout(async () => {
318
318
  try {
319
319
  await this.connect();