prior-cli 1.7.8 → 1.7.10
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/lib/agent.js +11 -1
- package/lib/tools.js +30 -2
- package/package.json +3 -3
package/lib/agent.js
CHANGED
|
@@ -300,7 +300,7 @@ async function runAgent({ messages, model, uncensored, cwd, projectContext, imag
|
|
|
300
300
|
const approved = await confirm({ name: call.name, args: call.args });
|
|
301
301
|
if (!approved) {
|
|
302
302
|
send({ type: 'tool_skip', name: call.name });
|
|
303
|
-
resultParts.push(`<tool_result name="${call.name}">\
|
|
303
|
+
resultParts.push(`<tool_result name="${call.name}">\nThe user declined this action. Do NOT retry it, rephrase it, or attempt a workaround — that would go against their explicit choice. Simply acknowledge and move on, or ask what they'd like to do instead.\n</tool_result>`);
|
|
304
304
|
continue;
|
|
305
305
|
}
|
|
306
306
|
}
|
|
@@ -310,6 +310,16 @@ async function runAgent({ messages, model, uncensored, cwd, projectContext, imag
|
|
|
310
310
|
// Pass output snippet so the CLI can show a rich preview
|
|
311
311
|
send({ type: 'tool_done', name: call.name, summary: toolResult.summary, preview: toolResult.output, weather: toolResult.weather });
|
|
312
312
|
resultParts.push(`<tool_result name="${call.name}">\n${toolResult.output}\n</tool_result>`);
|
|
313
|
+
|
|
314
|
+
// generate_image pre-generates its caption before queuing (queuing kills Ollama
|
|
315
|
+
// for VRAM) — emit it directly as the final response instead of looping back
|
|
316
|
+
// into infer(), which would race the ~65-70s restart+prewarm cycle
|
|
317
|
+
if (call.name === 'generate_image' && toolResult.preDescription && call === calls[calls.length - 1]) {
|
|
318
|
+
await trackTokenUsage(token, totalPromptTokens, totalCompletionTokens);
|
|
319
|
+
send({ type: 'text', content: toolResult.preDescription });
|
|
320
|
+
send({ type: 'done', promptTokens: totalPromptTokens, completionTokens: totalCompletionTokens });
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
313
323
|
} catch (err) {
|
|
314
324
|
send({ type: 'tool_error', name: call.name, error: err.message });
|
|
315
325
|
resultParts.push(`<tool_result name="${call.name}">\nERROR: ${err.message}\n</tool_result>`);
|
package/lib/tools.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
4
5
|
const path = require('path');
|
|
5
6
|
const { exec } = require('child_process');
|
|
6
7
|
const fetch = require('node-fetch');
|
|
@@ -269,6 +270,22 @@ const TOOLS = {
|
|
|
269
270
|
const totalSteps = steps || 20;
|
|
270
271
|
const authHdr = token ? { Authorization: `Bearer ${token}` } : {};
|
|
271
272
|
|
|
273
|
+
// Pre-generate the caption BEFORE queuing — queuing kills Ollama for VRAM right
|
|
274
|
+
// after, and the restart+prewarm cycle outlasts a normal post-gen inference call
|
|
275
|
+
let preDescription = null;
|
|
276
|
+
try {
|
|
277
|
+
const descRes = await fetch(`${CLI_BASE}/api/describe-image`, {
|
|
278
|
+
method: 'POST',
|
|
279
|
+
headers: { 'Content-Type': 'application/json' },
|
|
280
|
+
body: JSON.stringify({ prompt, token }),
|
|
281
|
+
timeout: 30000,
|
|
282
|
+
});
|
|
283
|
+
if (descRes.ok) {
|
|
284
|
+
const d = await descRes.json();
|
|
285
|
+
preDescription = (d.description || '').trim() || null;
|
|
286
|
+
}
|
|
287
|
+
} catch { /* non-fatal — falls back to a normal post-gen description */ }
|
|
288
|
+
|
|
272
289
|
// Step 1: Queue
|
|
273
290
|
const queueRes = await fetch(`${CLI_BASE}/api/generate-image/queue`, {
|
|
274
291
|
method: 'POST',
|
|
@@ -319,11 +336,22 @@ const TOOLS = {
|
|
|
319
336
|
}
|
|
320
337
|
const data = await wmRes.json();
|
|
321
338
|
if (!data.filename || !data.data) throw new Error('Invalid response from image generation service');
|
|
322
|
-
const
|
|
323
|
-
|
|
339
|
+
const buffer = Buffer.from(data.data, 'base64');
|
|
340
|
+
let savePath = path.join(cwd, data.filename);
|
|
341
|
+
try {
|
|
342
|
+
fs.writeFileSync(savePath, buffer);
|
|
343
|
+
} catch (err) {
|
|
344
|
+
if (err.code !== 'EPERM' && err.code !== 'EACCES') throw err;
|
|
345
|
+
// cwd requires elevated permissions (e.g. C:\Windows\System32) — fall back to Downloads
|
|
346
|
+
const downloads = path.join(os.homedir(), 'Downloads');
|
|
347
|
+
if (!fs.existsSync(downloads)) fs.mkdirSync(downloads, { recursive: true });
|
|
348
|
+
savePath = path.join(downloads, data.filename);
|
|
349
|
+
fs.writeFileSync(savePath, buffer);
|
|
350
|
+
}
|
|
324
351
|
return {
|
|
325
352
|
output: `Image saved to: ${savePath}`,
|
|
326
353
|
summary: savePath,
|
|
354
|
+
preDescription,
|
|
327
355
|
};
|
|
328
356
|
},
|
|
329
357
|
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prior-cli",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.10",
|
|
4
4
|
"description": "Prior Network AI — command-line interface",
|
|
5
5
|
"author": "Prior Network",
|
|
6
6
|
"homepage": "https://priornetwork.com",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/
|
|
9
|
+
"url": "git+https://github.com/PriorNetwork/prior-cli.git"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/
|
|
12
|
+
"url": "https://github.com/PriorNetwork/prior-cli/issues"
|
|
13
13
|
},
|
|
14
14
|
"bin": {
|
|
15
15
|
"prior": "bin/prior.js"
|