prior-cli 1.2.6 → 1.2.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.
Files changed (3) hide show
  1. package/bin/prior.js +11 -37
  2. package/lib/tools.js +50 -13
  3. package/package.json +1 -1
package/bin/prior.js CHANGED
@@ -457,44 +457,18 @@ async function loginViaBrowser() {
457
457
 
458
458
  // ── Inline login flow ──────────────────────────────────────────
459
459
  async function doLoginFlow() {
460
- console.log(c.bold(' Sign in\n'));
461
- console.log(` ${c.brand('[1]')} Login manually`);
462
- console.log(` ${c.brand('[2]')} Login in browser`);
463
- console.log('');
464
-
465
- const choiceRl = readline.createInterface({ input: process.stdin, output: process.stdout });
466
- const choice = await ask(choiceRl, c.muted(' Choice [1/2] : '));
467
- choiceRl.close();
468
- console.log('');
469
-
470
- if (choice === '2') {
471
- process.stdout.write(c.dim(' Opening browser…'));
472
- try {
473
- const { token, username } = await loginViaBrowser();
474
- saveAuth(token, username);
475
- clearLine();
476
- console.log(c.ok(' ✓ Logged in as ') + c.bold(username));
477
- console.log('');
478
- return username;
479
- } catch (err) {
480
- clearLine();
481
- throw err;
482
- }
460
+ process.stdout.write(c.dim(' Opening browser…'));
461
+ try {
462
+ const { token, username } = await loginViaBrowser();
463
+ saveAuth(token, username);
464
+ clearLine();
465
+ console.log(c.ok(' Logged in as ') + c.bold(username));
466
+ console.log('');
467
+ return username;
468
+ } catch (err) {
469
+ clearLine();
470
+ throw err;
483
471
  }
484
-
485
- // Default: manual
486
- const manualRl = readline.createInterface({ input: process.stdin, output: process.stdout });
487
- const username = await ask(manualRl, c.muted(' Username : '));
488
- manualRl.close();
489
- const password = await promptPassword(c.muted(' Password : '));
490
- console.log('');
491
- process.stdout.write(c.dim(' Authenticating…'));
492
- const data = await api.login(username, password);
493
- saveAuth(data.token, username);
494
- clearLine();
495
- console.log(c.ok(' ✓ Logged in as ') + c.bold(username));
496
- console.log('');
497
- return username;
498
472
  }
499
473
 
500
474
  // ── Organization ToS flow ──────────────────────────────────────
package/lib/tools.js CHANGED
@@ -225,23 +225,60 @@ const TOOLS = {
225
225
  };
226
226
  },
227
227
 
228
- async generate_image({ prompt, width, height, steps }, { cwd, token }) {
228
+ async generate_image({ prompt, width, height, steps }, { cwd, token, send }) {
229
229
  if (!prompt) throw new Error('"prompt" is required');
230
- // Server handles queuing, polling, and watermarking — returns base64
231
- const res = await fetch(`${CLI_BASE}/api/generate-image`, {
230
+ const totalSteps = steps || 20;
231
+ const authHdr = token ? { Authorization: `Bearer ${token}` } : {};
232
+
233
+ // Step 1: Queue
234
+ const queueRes = await fetch(`${CLI_BASE}/api/generate-image/queue`, {
232
235
  method: 'POST',
233
- headers: {
234
- 'Content-Type': 'application/json',
235
- ...(token ? { Authorization: `Bearer ${token}` } : {}),
236
- },
237
- body: JSON.stringify({ prompt, width: width || 896, height: height || 896, steps: steps || 20 }),
238
- timeout: 360000,
236
+ headers: { 'Content-Type': 'application/json', ...authHdr },
237
+ body: JSON.stringify({ prompt, width: width || 896, height: height || 896, steps: totalSteps }),
238
+ timeout: 15000,
239
239
  });
240
- if (!res.ok) {
241
- const err = await res.json().catch(() => ({}));
242
- throw new Error(err.error || err.message || `HTTP ${res.status}`);
240
+ if (!queueRes.ok) {
241
+ const err = await queueRes.json().catch(() => ({}));
242
+ throw new Error(err.error || err.message || `HTTP ${queueRes.status}`);
243
243
  }
244
- const data = await res.json();
244
+ const { promptId } = await queueRes.json();
245
+ if (!promptId) throw new Error('No promptId returned from image queue');
246
+
247
+ // Step 2: Poll with progress
248
+ let job = null;
249
+ for (let i = 0; i < 240; i++) {
250
+ await new Promise(r => setTimeout(r, 1500));
251
+ try {
252
+ const pr = await fetch(`${CLI_BASE}/api/generate-image/progress/${promptId}`, {
253
+ headers: authHdr, timeout: 5000,
254
+ });
255
+ if (pr.ok) {
256
+ job = await pr.json();
257
+ if (job && send && job.step !== undefined) {
258
+ const pct = job.percent || Math.round((job.step / (job.total || totalSteps)) * 100);
259
+ send({ type: 'tool_progress', step: job.step, total: job.total || totalSteps, percent: pct });
260
+ }
261
+ if (job && (job.status === 'done' || job.status === 'error')) break;
262
+ }
263
+ } catch { /* keep polling */ }
264
+ }
265
+
266
+ if (!job || job.status === 'error') {
267
+ throw new Error(job?.error || 'Image generation failed or timed out');
268
+ }
269
+
270
+ // Step 3: Watermark
271
+ const wmRes = await fetch(`${CLI_BASE}/api/generate-image/watermark`, {
272
+ method: 'POST',
273
+ headers: { 'Content-Type': 'application/json', ...authHdr },
274
+ body: JSON.stringify({ filename: job.filename }),
275
+ timeout: 30000,
276
+ });
277
+ if (!wmRes.ok) {
278
+ const err = await wmRes.json().catch(() => ({}));
279
+ throw new Error(err.error || `Watermark failed: HTTP ${wmRes.status}`);
280
+ }
281
+ const data = await wmRes.json();
245
282
  if (!data.filename || !data.data) throw new Error('Invalid response from image generation service');
246
283
  const savePath = path.join(cwd, data.filename);
247
284
  fs.writeFileSync(savePath, Buffer.from(data.data, 'base64'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prior-cli",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "Prior Network AI — command-line interface",
5
5
  "bin": {
6
6
  "prior": "bin/prior.js"