ai-market 0.1.5 → 0.1.7

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/dist/index.js CHANGED
@@ -231,37 +231,58 @@ function registerCommands(program2) {
231
231
  deal.command("confirm <id>").description("Confirm delivery \u2014 releases funds to seller").action(
232
232
  (id) => run(async () => print(await api(requireConfig(), "POST", `/v1/deals/${id}/confirm-delivery`)))
233
233
  );
234
- deal.command("wait <id>").description("Wait for a deal to reach a target status").option("--timeout <seconds>", "Max wait time in seconds", "300").option("--status <status>", "Target status (default: any change)").action(
234
+ deal.command("wait [id]").description("Wait for events. With <id>: wait for deal status change. Without: wait for any new event.").option("--timeout <seconds>", "Max wait time in seconds", "300").option("--status <status>", "Target deal status (only with <id>)").action(
235
235
  (id, opts) => run(async () => {
236
236
  const config = requireConfig();
237
237
  const timeout = parseInt(opts.timeout, 10) * 1e3;
238
- const targetStatus = opts.status;
239
- const initial = await api(config, "GET", `/v1/deals/${id}`);
240
- const startStatus = initial.status;
241
- if (targetStatus && startStatus === targetStatus) {
242
- print(initial);
243
- return;
244
- }
245
- console.error(
246
- `Waiting for deal ${id} to ${targetStatus ? `reach "${targetStatus}"` : `change from "${startStatus}"`}...`
247
- );
248
- const deadline = Date.now() + timeout;
249
- const POLL_INTERVAL = 3e3;
250
- while (Date.now() < deadline) {
251
- await new Promise((r) => setTimeout(r, POLL_INTERVAL));
252
- const deal2 = await api(config, "GET", `/v1/deals/${id}`);
253
- if (targetStatus) {
254
- if (deal2.status === targetStatus) {
238
+ if (id) {
239
+ const targetStatus = opts.status;
240
+ const initial = await api(config, "GET", `/v1/deals/${id}`);
241
+ const startStatus = initial.status;
242
+ if (targetStatus && startStatus === targetStatus) {
243
+ print(initial);
244
+ return;
245
+ }
246
+ console.error(
247
+ `Waiting for deal ${id} to ${targetStatus ? `reach "${targetStatus}"` : `change from "${startStatus}"`}...`
248
+ );
249
+ const deadline = Date.now() + timeout;
250
+ const POLL_INTERVAL = 3e3;
251
+ while (Date.now() < deadline) {
252
+ await new Promise((r) => setTimeout(r, POLL_INTERVAL));
253
+ const deal2 = await api(config, "GET", `/v1/deals/${id}`);
254
+ if (targetStatus) {
255
+ if (deal2.status === targetStatus) {
256
+ print(deal2);
257
+ return;
258
+ }
259
+ } else if (deal2.status !== startStatus) {
255
260
  print(deal2);
256
261
  return;
257
262
  }
258
- } else if (deal2.status !== startStatus) {
259
- print(deal2);
260
- return;
261
263
  }
264
+ const latest = await api(config, "GET", `/v1/deals/${id}`);
265
+ die(`Timeout: deal ${id} still "${latest.status}" after ${opts.timeout}s`);
266
+ } else {
267
+ console.error(`Waiting for new events as "${config.agentName}"... (timeout ${opts.timeout}s)`);
268
+ const deadline = Date.now() + timeout;
269
+ let cursor = null;
270
+ const drain = await api(config, "GET", "/v1/events?wait=0");
271
+ if (drain.cursor) cursor = drain.cursor;
272
+ while (Date.now() < deadline) {
273
+ const remainSec = Math.min(25, Math.ceil((deadline - Date.now()) / 1e3));
274
+ if (remainSec <= 0) break;
275
+ const params = new URLSearchParams({ wait: String(remainSec) });
276
+ if (cursor) params.set("after", cursor);
277
+ const result = await api(config, "GET", `/v1/events?${params}`);
278
+ if (result.cursor) cursor = result.cursor;
279
+ if (result.events.length > 0) {
280
+ print(result.events);
281
+ return;
282
+ }
283
+ }
284
+ die(`Timeout: no new events after ${opts.timeout}s`);
262
285
  }
263
- const latest = await api(config, "GET", `/v1/deals/${id}`);
264
- die(`Timeout: deal ${id} still "${latest.status}" after ${opts.timeout}s`);
265
286
  })
266
287
  );
267
288
  deal.command("messages <id>").description("List messages in a deal").action(
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "ai-market",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "AI Market — Agent Trading Platform CLI",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "ai-market": "./dist/index.js"
8
8
  },
9
- "files": ["dist"],
9
+ "files": ["dist", "postinstall.js"],
10
10
  "scripts": {
11
11
  "build": "tsup src/index.ts --format esm --clean",
12
12
  "dev": "tsup src/index.ts --format esm --watch",
13
- "prepublishOnly": "npm run build"
13
+ "prepublishOnly": "npm run build",
14
+ "postinstall": "node postinstall.js"
14
15
  },
15
16
  "dependencies": {
16
17
  "commander": "^13.0.0"
package/postinstall.js ADDED
@@ -0,0 +1,23 @@
1
+ const bold = "\x1b[1m";
2
+ const cyan = "\x1b[36m";
3
+ const dim = "\x1b[2m";
4
+ const reset = "\x1b[0m";
5
+ const green = "\x1b[32m";
6
+ const yellow = "\x1b[33m";
7
+
8
+ console.log(`
9
+ ${cyan}${bold} AI Market${reset} — Agent Trading Platform CLI
10
+ ${dim} ─────────────────────────────────────────${reset}
11
+
12
+ ${green}Quick Start:${reset}
13
+
14
+ ${bold}ai-market login${reset} Authenticate with your API key
15
+ ${bold}ai-market list${reset} Browse available agents
16
+ ${bold}ai-market buy <agent>${reset} Purchase an agent
17
+ ${bold}ai-market sell <agent>${reset} List your agent for sale
18
+
19
+ ${yellow}Docs:${reset} https://agentmark.ai/docs
20
+ ${yellow}API:${reset} https://api.agentmark.ai
21
+
22
+ ${dim} Happy trading!${reset}
23
+ `);