voyageai-cli 1.28.0 → 1.30.0
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/README.md +82 -8
- package/package.json +2 -1
- package/src/commands/app.js +15 -0
- package/src/commands/benchmark.js +22 -8
- package/src/commands/chat.js +18 -0
- package/src/commands/chunk.js +10 -0
- package/src/commands/demo.js +4 -0
- package/src/commands/embed.js +13 -0
- package/src/commands/estimate.js +3 -0
- package/src/commands/eval.js +6 -0
- package/src/commands/explain.js +2 -0
- package/src/commands/generate.js +2 -0
- package/src/commands/ingest.js +4 -0
- package/src/commands/init.js +2 -0
- package/src/commands/mcp-server.js +2 -0
- package/src/commands/models.js +2 -0
- package/src/commands/ping.js +7 -0
- package/src/commands/pipeline.js +15 -0
- package/src/commands/playground.js +685 -8
- package/src/commands/query.js +16 -0
- package/src/commands/rerank.js +12 -0
- package/src/commands/scaffold.js +2 -0
- package/src/commands/search.js +11 -0
- package/src/commands/similarity.js +9 -0
- package/src/commands/store.js +4 -0
- package/src/commands/workflow.js +702 -13
- package/src/lib/capability-report.js +134 -0
- package/src/lib/chat.js +32 -1
- package/src/lib/config.js +2 -0
- package/src/lib/cost-display.js +107 -0
- package/src/lib/explanations.js +94 -0
- package/src/lib/llm.js +125 -18
- package/src/lib/npm-utils.js +265 -0
- package/src/lib/quality-audit.js +71 -0
- package/src/lib/security/blocked-domains.json +17 -0
- package/src/lib/security-audit.js +198 -0
- package/src/lib/telemetry.js +23 -1
- package/src/lib/workflow-registry.js +416 -0
- package/src/lib/workflow-scaffold.js +380 -0
- package/src/lib/workflow-test-runner.js +208 -0
- package/src/lib/workflow.js +559 -7
- package/src/playground/announcements.md +80 -0
- package/src/playground/assets/announcements/appstore.jpg +0 -0
- package/src/playground/assets/announcements/circuits.jpg +0 -0
- package/src/playground/assets/announcements/csvingest.jpg +0 -0
- package/src/playground/assets/announcements/green-wave.jpg +0 -0
- package/src/playground/help/workflow-nodes.js +472 -0
- package/src/playground/icons/V.png +0 -0
- package/src/playground/index.html +3634 -226
- package/src/workflows/consistency-check.json +4 -0
- package/src/workflows/cost-analysis.json +4 -0
- package/src/workflows/enrich-and-ingest.json +56 -0
- package/src/workflows/intelligent-ingest.json +66 -0
- package/src/workflows/kb-health-report.json +45 -0
- package/src/workflows/multi-collection-search.json +4 -0
- package/src/workflows/research-and-summarize.json +4 -0
- package/src/workflows/search-with-fallback.json +66 -0
- package/src/workflows/smart-ingest.json +4 -0
package/src/lib/llm.js
CHANGED
|
@@ -147,15 +147,24 @@ class AnthropicProvider {
|
|
|
147
147
|
const json = await res.json();
|
|
148
148
|
const text = json.content?.[0]?.text || '';
|
|
149
149
|
yield text;
|
|
150
|
+
// Yield usage sentinel
|
|
151
|
+
const usage = json.usage || {};
|
|
152
|
+
yield { __usage: { inputTokens: usage.input_tokens || 0, outputTokens: usage.output_tokens || 0 } };
|
|
150
153
|
return;
|
|
151
154
|
}
|
|
152
155
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
+
// Manual SSE loop to capture usage from streaming events
|
|
157
|
+
const usage = { inputTokens: 0, outputTokens: 0 };
|
|
158
|
+
for await (const chunk of parseSSEWithMeta(res.body)) {
|
|
159
|
+
if (chunk.__event === 'message_start' && chunk.__data?.message?.usage) {
|
|
160
|
+
usage.inputTokens = chunk.__data.message.usage.input_tokens || 0;
|
|
161
|
+
} else if (chunk.__event === 'message_delta' && chunk.__data?.usage) {
|
|
162
|
+
usage.outputTokens = chunk.__data.usage.output_tokens || 0;
|
|
163
|
+
} else if (chunk.__event === 'content_block_delta' && chunk.__data?.delta?.text) {
|
|
164
|
+
yield chunk.__data.delta.text;
|
|
156
165
|
}
|
|
157
|
-
|
|
158
|
-
}
|
|
166
|
+
}
|
|
167
|
+
yield { __usage: usage };
|
|
159
168
|
}
|
|
160
169
|
|
|
161
170
|
/**
|
|
@@ -163,7 +172,7 @@ class AnthropicProvider {
|
|
|
163
172
|
* @param {Array} messages - Conversation messages
|
|
164
173
|
* @param {Array} tools - Tool definitions in Anthropic format
|
|
165
174
|
* @param {object} [options]
|
|
166
|
-
* @returns {Promise<{type: 'text'|'tool_calls', content?: string, calls?: Array, stopReason: string}>}
|
|
175
|
+
* @returns {Promise<{type: 'text'|'tool_calls', content?: string, calls?: Array, stopReason: string, usage: object}>}
|
|
167
176
|
*/
|
|
168
177
|
async chatWithTools(messages, tools, options = {}) {
|
|
169
178
|
const model = options.model || this.model;
|
|
@@ -200,6 +209,8 @@ class AnthropicProvider {
|
|
|
200
209
|
|
|
201
210
|
const json = await res.json();
|
|
202
211
|
const stopReason = json.stop_reason || 'end_turn';
|
|
212
|
+
const apiUsage = json.usage || {};
|
|
213
|
+
const usage = { inputTokens: apiUsage.input_tokens || 0, outputTokens: apiUsage.output_tokens || 0 };
|
|
203
214
|
|
|
204
215
|
// Check for tool_use blocks
|
|
205
216
|
const toolBlocks = (json.content || []).filter(b => b.type === 'tool_use');
|
|
@@ -212,6 +223,7 @@ class AnthropicProvider {
|
|
|
212
223
|
arguments: b.input,
|
|
213
224
|
})),
|
|
214
225
|
stopReason,
|
|
226
|
+
usage,
|
|
215
227
|
_raw: json.content,
|
|
216
228
|
};
|
|
217
229
|
}
|
|
@@ -222,6 +234,7 @@ class AnthropicProvider {
|
|
|
222
234
|
type: 'text',
|
|
223
235
|
content: textBlocks.map(b => b.text).join(''),
|
|
224
236
|
stopReason,
|
|
237
|
+
usage,
|
|
225
238
|
};
|
|
226
239
|
}
|
|
227
240
|
|
|
@@ -324,6 +337,11 @@ class OpenAIProvider {
|
|
|
324
337
|
messages,
|
|
325
338
|
};
|
|
326
339
|
|
|
340
|
+
// Request usage data in streaming mode
|
|
341
|
+
if (stream) {
|
|
342
|
+
body.stream_options = { include_usage: true };
|
|
343
|
+
}
|
|
344
|
+
|
|
327
345
|
const res = await fetch(`${this.baseUrl}/v1/chat/completions`, {
|
|
328
346
|
method: 'POST',
|
|
329
347
|
headers: {
|
|
@@ -342,14 +360,25 @@ class OpenAIProvider {
|
|
|
342
360
|
const json = await res.json();
|
|
343
361
|
const text = json.choices?.[0]?.message?.content || '';
|
|
344
362
|
yield text;
|
|
363
|
+
const apiUsage = json.usage || {};
|
|
364
|
+
yield { __usage: { inputTokens: apiUsage.prompt_tokens || 0, outputTokens: apiUsage.completion_tokens || 0 } };
|
|
345
365
|
return;
|
|
346
366
|
}
|
|
347
367
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
368
|
+
// Manual SSE loop to capture usage from final streaming chunk
|
|
369
|
+
const usage = { inputTokens: 0, outputTokens: 0 };
|
|
370
|
+
for await (const chunk of parseSSEWithMeta(res.body)) {
|
|
371
|
+
const data = chunk.__data;
|
|
372
|
+
if (data === '[DONE]') continue;
|
|
373
|
+
// Final chunk with usage stats (stream_options: include_usage)
|
|
374
|
+
if (data?.usage) {
|
|
375
|
+
usage.inputTokens = data.usage.prompt_tokens || 0;
|
|
376
|
+
usage.outputTokens = data.usage.completion_tokens || 0;
|
|
377
|
+
}
|
|
378
|
+
const content = data?.choices?.[0]?.delta?.content;
|
|
379
|
+
if (content) yield content;
|
|
380
|
+
}
|
|
381
|
+
yield { __usage: usage };
|
|
353
382
|
}
|
|
354
383
|
|
|
355
384
|
/**
|
|
@@ -357,7 +386,7 @@ class OpenAIProvider {
|
|
|
357
386
|
* @param {Array} messages - Conversation messages
|
|
358
387
|
* @param {Array} tools - Tool definitions in OpenAI format
|
|
359
388
|
* @param {object} [options]
|
|
360
|
-
* @returns {Promise<{type: 'text'|'tool_calls', content?: string, calls?: Array, stopReason: string}>}
|
|
389
|
+
* @returns {Promise<{type: 'text'|'tool_calls', content?: string, calls?: Array, stopReason: string, usage: object}>}
|
|
361
390
|
*/
|
|
362
391
|
async chatWithTools(messages, tools, options = {}) {
|
|
363
392
|
const model = options.model || this.model;
|
|
@@ -389,6 +418,8 @@ class OpenAIProvider {
|
|
|
389
418
|
const choice = json.choices?.[0] || {};
|
|
390
419
|
const msg = choice.message || {};
|
|
391
420
|
const stopReason = choice.finish_reason || 'stop';
|
|
421
|
+
const apiUsage = json.usage || {};
|
|
422
|
+
const usage = { inputTokens: apiUsage.prompt_tokens || 0, outputTokens: apiUsage.completion_tokens || 0 };
|
|
392
423
|
|
|
393
424
|
if (msg.tool_calls && msg.tool_calls.length > 0) {
|
|
394
425
|
return {
|
|
@@ -401,6 +432,7 @@ class OpenAIProvider {
|
|
|
401
432
|
: tc.function.arguments,
|
|
402
433
|
})),
|
|
403
434
|
stopReason,
|
|
435
|
+
usage,
|
|
404
436
|
_raw: msg,
|
|
405
437
|
};
|
|
406
438
|
}
|
|
@@ -409,6 +441,7 @@ class OpenAIProvider {
|
|
|
409
441
|
type: 'text',
|
|
410
442
|
content: msg.content || '',
|
|
411
443
|
stopReason,
|
|
444
|
+
usage,
|
|
412
445
|
};
|
|
413
446
|
}
|
|
414
447
|
|
|
@@ -502,14 +535,25 @@ class OllamaProvider {
|
|
|
502
535
|
const json = await res.json();
|
|
503
536
|
const text = json.choices?.[0]?.message?.content || '';
|
|
504
537
|
yield text;
|
|
538
|
+
// Ollama may not return usage, default to 0
|
|
539
|
+
const apiUsage = json.usage || {};
|
|
540
|
+
yield { __usage: { inputTokens: apiUsage.prompt_tokens || 0, outputTokens: apiUsage.completion_tokens || 0 } };
|
|
505
541
|
return;
|
|
506
542
|
}
|
|
507
543
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
544
|
+
// Manual SSE loop (Ollama may not support stream_options)
|
|
545
|
+
const usage = { inputTokens: 0, outputTokens: 0 };
|
|
546
|
+
for await (const chunk of parseSSEWithMeta(res.body)) {
|
|
547
|
+
const data = chunk.__data;
|
|
548
|
+
if (data === '[DONE]') continue;
|
|
549
|
+
if (data?.usage) {
|
|
550
|
+
usage.inputTokens = data.usage.prompt_tokens || 0;
|
|
551
|
+
usage.outputTokens = data.usage.completion_tokens || 0;
|
|
552
|
+
}
|
|
553
|
+
const content = data?.choices?.[0]?.delta?.content;
|
|
554
|
+
if (content) yield content;
|
|
555
|
+
}
|
|
556
|
+
yield { __usage: usage };
|
|
513
557
|
}
|
|
514
558
|
|
|
515
559
|
/**
|
|
@@ -517,7 +561,7 @@ class OllamaProvider {
|
|
|
517
561
|
* @param {Array} messages - Conversation messages
|
|
518
562
|
* @param {Array} tools - Tool definitions in OpenAI format
|
|
519
563
|
* @param {object} [options]
|
|
520
|
-
* @returns {Promise<{type: 'text'|'tool_calls', content?: string, calls?: Array, stopReason: string}>}
|
|
564
|
+
* @returns {Promise<{type: 'text'|'tool_calls', content?: string, calls?: Array, stopReason: string, usage: object}>}
|
|
521
565
|
*/
|
|
522
566
|
async chatWithTools(messages, tools, options = {}) {
|
|
523
567
|
const model = options.model || this.model;
|
|
@@ -544,6 +588,9 @@ class OllamaProvider {
|
|
|
544
588
|
const choice = json.choices?.[0] || {};
|
|
545
589
|
const msg = choice.message || {};
|
|
546
590
|
const stopReason = choice.finish_reason || 'stop';
|
|
591
|
+
// Ollama may not return usage, default to 0
|
|
592
|
+
const apiUsage = json.usage || {};
|
|
593
|
+
const usage = { inputTokens: apiUsage.prompt_tokens || 0, outputTokens: apiUsage.completion_tokens || 0 };
|
|
547
594
|
|
|
548
595
|
if (msg.tool_calls && msg.tool_calls.length > 0) {
|
|
549
596
|
return {
|
|
@@ -556,6 +603,7 @@ class OllamaProvider {
|
|
|
556
603
|
: tc.function.arguments,
|
|
557
604
|
})),
|
|
558
605
|
stopReason,
|
|
606
|
+
usage,
|
|
559
607
|
_raw: msg,
|
|
560
608
|
};
|
|
561
609
|
}
|
|
@@ -564,6 +612,7 @@ class OllamaProvider {
|
|
|
564
612
|
type: 'text',
|
|
565
613
|
content: msg.content || '',
|
|
566
614
|
stopReason,
|
|
615
|
+
usage,
|
|
567
616
|
};
|
|
568
617
|
}
|
|
569
618
|
|
|
@@ -622,6 +671,64 @@ class OllamaProvider {
|
|
|
622
671
|
// SSE Stream Parser
|
|
623
672
|
// ============================================
|
|
624
673
|
|
|
674
|
+
/**
|
|
675
|
+
* Parse a Server-Sent Events stream, yielding raw event+data pairs.
|
|
676
|
+
* Unlike parseSSE, this preserves event types and full data objects
|
|
677
|
+
* so callers can extract both content and metadata (e.g. usage stats).
|
|
678
|
+
*
|
|
679
|
+
* @param {ReadableStream} body - Response body stream
|
|
680
|
+
* @yields {{ __event: string|null, __data: object|string }} Parsed SSE events
|
|
681
|
+
*/
|
|
682
|
+
async function* parseSSEWithMeta(body) {
|
|
683
|
+
const decoder = new TextDecoder();
|
|
684
|
+
let buffer = '';
|
|
685
|
+
let currentEvent = null;
|
|
686
|
+
|
|
687
|
+
for await (const chunk of body) {
|
|
688
|
+
buffer += decoder.decode(chunk, { stream: true });
|
|
689
|
+
|
|
690
|
+
const lines = buffer.split('\n');
|
|
691
|
+
buffer = lines.pop() || '';
|
|
692
|
+
|
|
693
|
+
for (const line of lines) {
|
|
694
|
+
if (line.startsWith('event: ')) {
|
|
695
|
+
currentEvent = line.slice(7).trim();
|
|
696
|
+
continue;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
if (line.startsWith('data: ')) {
|
|
700
|
+
const rawData = line.slice(6);
|
|
701
|
+
|
|
702
|
+
if (rawData === '[DONE]') {
|
|
703
|
+
yield { __event: currentEvent, __data: '[DONE]' };
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
let parsed;
|
|
708
|
+
try {
|
|
709
|
+
parsed = JSON.parse(rawData);
|
|
710
|
+
} catch {
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
yield { __event: currentEvent, __data: parsed };
|
|
715
|
+
currentEvent = null;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// Process remaining buffer
|
|
721
|
+
if (buffer.trim() && buffer.startsWith('data: ')) {
|
|
722
|
+
const rawData = buffer.slice(6);
|
|
723
|
+
if (rawData !== '[DONE]') {
|
|
724
|
+
try {
|
|
725
|
+
const parsed = JSON.parse(rawData);
|
|
726
|
+
yield { __event: currentEvent, __data: parsed };
|
|
727
|
+
} catch { /* skip */ }
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
625
732
|
/**
|
|
626
733
|
* Parse a Server-Sent Events stream.
|
|
627
734
|
* @param {ReadableStream} body - Response body stream
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { execSync } = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
|
|
7
|
+
const WORKFLOW_PREFIX = 'vai-workflow-';
|
|
8
|
+
const VAICLI_SCOPE = '@vaicli/';
|
|
9
|
+
const VAICLI_WORKFLOW_PREFIX = '@vaicli/vai-workflow-';
|
|
10
|
+
const NPM_SEARCH_URL = 'https://registry.npmjs.org/-/v1/search';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Check if a package name is an official @vaicli scoped package.
|
|
14
|
+
* @param {string} name
|
|
15
|
+
* @returns {boolean}
|
|
16
|
+
*/
|
|
17
|
+
function isOfficialPackage(name) {
|
|
18
|
+
return name.startsWith(VAICLI_WORKFLOW_PREFIX);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Check if a package name is a valid vai workflow package (scoped or unscoped).
|
|
23
|
+
* @param {string} name
|
|
24
|
+
* @returns {boolean}
|
|
25
|
+
*/
|
|
26
|
+
function isWorkflowPackage(name) {
|
|
27
|
+
return name.startsWith(VAICLI_WORKFLOW_PREFIX) || name.startsWith(WORKFLOW_PREFIX);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Search the npm registry for vai workflow packages.
|
|
32
|
+
* @param {string} query - Search terms
|
|
33
|
+
* @param {{ limit?: number }} options
|
|
34
|
+
* @returns {Promise<Array<{ name: string, version: string, description: string, author: string, date: string, keywords: string[], official: boolean }>>}
|
|
35
|
+
*/
|
|
36
|
+
async function searchNpm(query, options = {}) {
|
|
37
|
+
const limit = options.limit || 10;
|
|
38
|
+
// Search for both scoped and unscoped packages
|
|
39
|
+
const searchText = query
|
|
40
|
+
? `keywords:vai-workflow ${query}`
|
|
41
|
+
: `keywords:vai-workflow`;
|
|
42
|
+
const url = `${NPM_SEARCH_URL}?text=${encodeURIComponent(searchText)}&size=${limit * 3}`;
|
|
43
|
+
|
|
44
|
+
const res = await fetch(url, {
|
|
45
|
+
headers: { 'Accept': 'application/json' },
|
|
46
|
+
signal: AbortSignal.timeout(15000),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (!res.ok) {
|
|
50
|
+
throw new Error(`npm search failed: ${res.status} ${res.statusText}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const data = await res.json();
|
|
54
|
+
let results = (data.objects || [])
|
|
55
|
+
.filter(obj => isWorkflowPackage(obj.package.name))
|
|
56
|
+
.map(obj => ({
|
|
57
|
+
name: obj.package.name,
|
|
58
|
+
version: obj.package.version,
|
|
59
|
+
description: obj.package.description || '',
|
|
60
|
+
author: obj.package.author?.name || obj.package.publisher?.username || 'unknown',
|
|
61
|
+
date: obj.package.date,
|
|
62
|
+
keywords: obj.package.keywords || [],
|
|
63
|
+
official: isOfficialPackage(obj.package.name),
|
|
64
|
+
}));
|
|
65
|
+
|
|
66
|
+
// Client-side filtering: npm keyword search returns all vai-workflow packages,
|
|
67
|
+
// so we filter locally by matching query against name, description, and keywords
|
|
68
|
+
if (query) {
|
|
69
|
+
const q = query.toLowerCase();
|
|
70
|
+
const terms = q.split(/\s+/).filter(Boolean);
|
|
71
|
+
results = results.filter(pkg => {
|
|
72
|
+
const haystack = [
|
|
73
|
+
pkg.name,
|
|
74
|
+
pkg.description,
|
|
75
|
+
...pkg.keywords,
|
|
76
|
+
].join(' ').toLowerCase();
|
|
77
|
+
return terms.every(term => haystack.includes(term));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
results = results.slice(0, options.limit || limit);
|
|
82
|
+
|
|
83
|
+
// Sort: official first, then by name
|
|
84
|
+
results.sort((a, b) => {
|
|
85
|
+
if (a.official !== b.official) return a.official ? -1 : 1;
|
|
86
|
+
return a.name.localeCompare(b.name);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return results;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Install a workflow package via npm.
|
|
94
|
+
* @param {string} packageName
|
|
95
|
+
* @param {{ global?: boolean }} options
|
|
96
|
+
* @returns {{ success: boolean, version: string, path: string, official: boolean }}
|
|
97
|
+
*/
|
|
98
|
+
function installPackage(packageName, options = {}) {
|
|
99
|
+
if (!isWorkflowPackage(packageName)) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Package name must start with "${WORKFLOW_PREFIX}" or "${VAICLI_WORKFLOW_PREFIX}". Did you mean ${WORKFLOW_PREFIX}${packageName}?`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Determine install location: use global if explicitly requested,
|
|
106
|
+
// or if there's no local package.json (e.g. running inside Electron app)
|
|
107
|
+
const hasLocalPkg = !options.global && (() => {
|
|
108
|
+
try { return require('fs').existsSync(require('path').join(process.cwd(), 'package.json')); }
|
|
109
|
+
catch { return false; }
|
|
110
|
+
})();
|
|
111
|
+
const useGlobal = options.global || !hasLocalPkg;
|
|
112
|
+
const globalFlag = useGlobal ? '-g' : '';
|
|
113
|
+
const cmd = `npm install ${packageName} ${globalFlag} ${useGlobal ? '' : '--save'} --ignore-scripts 2>&1`;
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
const output = execSync(cmd, {
|
|
117
|
+
encoding: 'utf8',
|
|
118
|
+
timeout: 60000,
|
|
119
|
+
cwd: useGlobal ? undefined : process.cwd(),
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Find installed version from node_modules
|
|
123
|
+
const pkgPath = resolvePackagePath(packageName, useGlobal);
|
|
124
|
+
let version = 'unknown';
|
|
125
|
+
if (pkgPath) {
|
|
126
|
+
try {
|
|
127
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(pkgPath, 'package.json'), 'utf8'));
|
|
128
|
+
version = pkg.version;
|
|
129
|
+
} catch { /* ignore */ }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return { success: true, version, path: pkgPath || '', official: isOfficialPackage(packageName) };
|
|
133
|
+
} catch (err) {
|
|
134
|
+
const msg = err.stderr || err.stdout || err.message;
|
|
135
|
+
if (msg.includes('404') || msg.includes('E404')) {
|
|
136
|
+
throw new Error(`Package ${packageName} not found on npm`);
|
|
137
|
+
}
|
|
138
|
+
throw new Error(`npm install failed: ${msg}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Uninstall a workflow package via npm.
|
|
144
|
+
* @param {string} packageName
|
|
145
|
+
* @param {{ global?: boolean }} options
|
|
146
|
+
* @returns {{ success: boolean }}
|
|
147
|
+
*/
|
|
148
|
+
function uninstallPackage(packageName, options = {}) {
|
|
149
|
+
const globalFlag = options.global ? '-g' : '';
|
|
150
|
+
const cmd = `npm uninstall ${packageName} ${globalFlag} 2>&1`;
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
execSync(cmd, { encoding: 'utf8', timeout: 30000 });
|
|
154
|
+
return { success: true };
|
|
155
|
+
} catch (err) {
|
|
156
|
+
throw new Error(`npm uninstall failed: ${err.message}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Get metadata for a package from the npm registry (without installing).
|
|
162
|
+
* @param {string} packageName
|
|
163
|
+
* @returns {Promise<{ name: string, version: string, description: string, author: string, vai: object|null, official: boolean }>}
|
|
164
|
+
*/
|
|
165
|
+
async function getPackageInfo(packageName) {
|
|
166
|
+
// Scoped packages need proper encoding: @vaicli/vai-workflow-foo -> @vaicli%2fvai-workflow-foo
|
|
167
|
+
const encodedName = packageName.startsWith('@')
|
|
168
|
+
? `@${encodeURIComponent(packageName.slice(1))}`
|
|
169
|
+
: encodeURIComponent(packageName);
|
|
170
|
+
const url = `https://registry.npmjs.org/${encodedName}/latest`;
|
|
171
|
+
const res = await fetch(url, {
|
|
172
|
+
headers: { 'Accept': 'application/json' },
|
|
173
|
+
signal: AbortSignal.timeout(10000),
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
if (!res.ok) {
|
|
177
|
+
if (res.status === 404) throw new Error(`Package ${packageName} not found on npm`);
|
|
178
|
+
throw new Error(`npm registry error: ${res.status}`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const data = await res.json();
|
|
182
|
+
return {
|
|
183
|
+
name: data.name,
|
|
184
|
+
version: data.version,
|
|
185
|
+
description: data.description || '',
|
|
186
|
+
author: typeof data.author === 'string' ? data.author : data.author?.name || 'unknown',
|
|
187
|
+
license: data.license || 'unknown',
|
|
188
|
+
vai: data.vai || null,
|
|
189
|
+
keywords: data.keywords || [],
|
|
190
|
+
repository: data.repository,
|
|
191
|
+
official: isOfficialPackage(data.name),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Resolve the filesystem path of an installed package.
|
|
197
|
+
* Handles both scoped (@vaicli/vai-workflow-*) and unscoped (vai-workflow-*) packages.
|
|
198
|
+
* @param {string} packageName
|
|
199
|
+
* @param {boolean} [global]
|
|
200
|
+
* @returns {string|null}
|
|
201
|
+
*/
|
|
202
|
+
function resolvePackagePath(packageName, global) {
|
|
203
|
+
// Scoped packages live at node_modules/@scope/package-name
|
|
204
|
+
// path.join handles this correctly since packageName includes the scope
|
|
205
|
+
if (!global) {
|
|
206
|
+
let dir = process.cwd();
|
|
207
|
+
while (dir !== path.dirname(dir)) {
|
|
208
|
+
const candidate = path.join(dir, 'node_modules', packageName);
|
|
209
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
210
|
+
dir = path.dirname(dir);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Try global
|
|
215
|
+
try {
|
|
216
|
+
const globalRoot = execSync('npm root -g', { encoding: 'utf8' }).trim();
|
|
217
|
+
const candidate = path.join(globalRoot, packageName);
|
|
218
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
219
|
+
} catch { /* ignore */ }
|
|
220
|
+
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Find the nearest node_modules directory.
|
|
226
|
+
* @returns {string|null}
|
|
227
|
+
*/
|
|
228
|
+
function findLocalNodeModules() {
|
|
229
|
+
let dir = process.cwd();
|
|
230
|
+
while (dir !== path.dirname(dir)) {
|
|
231
|
+
const candidate = path.join(dir, 'node_modules');
|
|
232
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isDirectory()) {
|
|
233
|
+
return candidate;
|
|
234
|
+
}
|
|
235
|
+
dir = path.dirname(dir);
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Find the global node_modules directory.
|
|
242
|
+
* @returns {string|null}
|
|
243
|
+
*/
|
|
244
|
+
function findGlobalNodeModules() {
|
|
245
|
+
try {
|
|
246
|
+
return execSync('npm root -g', { encoding: 'utf8' }).trim();
|
|
247
|
+
} catch {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
module.exports = {
|
|
253
|
+
searchNpm,
|
|
254
|
+
installPackage,
|
|
255
|
+
uninstallPackage,
|
|
256
|
+
getPackageInfo,
|
|
257
|
+
resolvePackagePath,
|
|
258
|
+
findLocalNodeModules,
|
|
259
|
+
findGlobalNodeModules,
|
|
260
|
+
isOfficialPackage,
|
|
261
|
+
isWorkflowPackage,
|
|
262
|
+
WORKFLOW_PREFIX,
|
|
263
|
+
VAICLI_SCOPE,
|
|
264
|
+
VAICLI_WORKFLOW_PREFIX,
|
|
265
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const CATEGORIES = ['retrieval', 'analysis', 'ingestion', 'domain-specific', 'utility', 'integration'];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Run quality audit on a workflow definition and its package.
|
|
10
|
+
* @param {object} definition - Parsed workflow JSON
|
|
11
|
+
* @param {object} pkg - Parsed package.json
|
|
12
|
+
* @param {string} [packagePath] - Path to the package directory
|
|
13
|
+
* @returns {Array<{level: string, message: string}>}
|
|
14
|
+
*/
|
|
15
|
+
function qualityAudit(definition, pkg, packagePath) {
|
|
16
|
+
const issues = [];
|
|
17
|
+
|
|
18
|
+
// Package metadata checks
|
|
19
|
+
if (!pkg.description || pkg.description.length < 20) {
|
|
20
|
+
issues.push({ level: 'error', message: 'Package description too short (min 20 chars)' });
|
|
21
|
+
}
|
|
22
|
+
if (!pkg.author) {
|
|
23
|
+
issues.push({ level: 'error', message: 'Package must have an author' });
|
|
24
|
+
}
|
|
25
|
+
if (!pkg.license) {
|
|
26
|
+
issues.push({ level: 'warning', message: 'No license specified' });
|
|
27
|
+
}
|
|
28
|
+
if (!pkg.vai?.category || !CATEGORIES.includes(pkg.vai.category)) {
|
|
29
|
+
issues.push({ level: 'error', message: 'Invalid or missing vai.category' });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// README checks
|
|
33
|
+
if (packagePath) {
|
|
34
|
+
const readmePath = path.join(packagePath, 'README.md');
|
|
35
|
+
if (!fs.existsSync(readmePath)) {
|
|
36
|
+
issues.push({ level: 'error', message: 'Missing README.md' });
|
|
37
|
+
} else {
|
|
38
|
+
const readme = fs.readFileSync(readmePath, 'utf8');
|
|
39
|
+
if (readme.length < 200) {
|
|
40
|
+
issues.push({ level: 'warning', message: 'README is very short (< 200 chars)' });
|
|
41
|
+
}
|
|
42
|
+
if (!readme.includes('## Usage') && !readme.includes('## Install')) {
|
|
43
|
+
issues.push({ level: 'warning', message: 'README should include Usage or Install section' });
|
|
44
|
+
}
|
|
45
|
+
if (readme.includes('TODO')) {
|
|
46
|
+
issues.push({ level: 'warning', message: 'README contains TODO placeholders' });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Workflow definition quality
|
|
52
|
+
if (definition && Array.isArray(definition.steps)) {
|
|
53
|
+
if (definition.steps.length === 1) {
|
|
54
|
+
issues.push({ level: 'suggestion', message: 'Single-step workflows may not warrant a package — consider documenting as a CLI example instead' });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Branding
|
|
59
|
+
if (!definition?.branding?.icon) {
|
|
60
|
+
issues.push({ level: 'suggestion', message: 'Consider adding branding.icon for store display' });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Naming — should be descriptive, not generic
|
|
64
|
+
if (definition?.name && /^(test|my|workflow|demo|example)/i.test(definition.name)) {
|
|
65
|
+
issues.push({ level: 'warning', message: `Workflow name "${definition.name}" is too generic` });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return issues;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = { qualityAudit, CATEGORIES };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[
|
|
2
|
+
"evil.com",
|
|
3
|
+
"malware.com",
|
|
4
|
+
"requestbin.com",
|
|
5
|
+
"webhook.site",
|
|
6
|
+
"pipedream.net",
|
|
7
|
+
"hookbin.com",
|
|
8
|
+
"requestcatcher.com",
|
|
9
|
+
"canarytokens.com",
|
|
10
|
+
"burpcollaborator.net",
|
|
11
|
+
"interact.sh",
|
|
12
|
+
"oastify.com",
|
|
13
|
+
"dnslog.cn",
|
|
14
|
+
"ceye.io",
|
|
15
|
+
"bxss.me",
|
|
16
|
+
"xss.ht"
|
|
17
|
+
]
|