uda-cli 0.2.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.
@@ -0,0 +1,77 @@
1
+ import * as lancedb from '@lancedb/lancedb';
2
+
3
+ export class VectorStore {
4
+ constructor(dbPath) {
5
+ this.dbPath = dbPath;
6
+ this.db = null;
7
+ this.table = null;
8
+ this.tableName = 'knowledge';
9
+ }
10
+
11
+ async init() {
12
+ this.db = await lancedb.connect(this.dbPath);
13
+
14
+ try {
15
+ this.table = await this.db.openTable(this.tableName);
16
+ } catch (err) {
17
+ // Table doesn't exist yet — will be created on first add
18
+ this.table = null;
19
+ if (err.message && !err.message.includes('does not exist') && !err.message.includes('not found') && !err.message.includes('was not found')) {
20
+ console.error(`Warning: Unexpected error opening table "${this.tableName}": ${err.message}`);
21
+ }
22
+ }
23
+ }
24
+
25
+ async add(documents) {
26
+ const rows = documents.map((doc) => ({
27
+ id: doc.id,
28
+ content: doc.content,
29
+ vector: doc.vector,
30
+ source: doc.metadata?.source || '',
31
+ engine: doc.metadata?.engine || '',
32
+ type: doc.metadata?.type || 'knowledge',
33
+ tags: JSON.stringify(doc.metadata?.tags || []),
34
+ date: doc.metadata?.date || new Date().toISOString().split('T')[0],
35
+ }));
36
+
37
+ if (!this.table) {
38
+ this.table = await this.db.createTable(this.tableName, rows);
39
+ } else {
40
+ await this.table.add(rows);
41
+ }
42
+ }
43
+
44
+ async search(queryVector, limit = 5) {
45
+ if (!this.table) return [];
46
+
47
+ const results = await this.table
48
+ .vectorSearch(queryVector)
49
+ .limit(limit)
50
+ .toArray();
51
+
52
+ return results.map((row) => ({
53
+ id: row.id,
54
+ content: row.content,
55
+ source: row.source,
56
+ engine: row.engine,
57
+ type: row.type,
58
+ tags: parseTags(row.tags),
59
+ score: row._distance,
60
+ }));
61
+ }
62
+
63
+ async count() {
64
+ if (!this.table) return 0;
65
+ return await this.table.countRows();
66
+ }
67
+ }
68
+
69
+ function parseTags(value) {
70
+ if (!value) return [];
71
+ try {
72
+ const parsed = JSON.parse(value);
73
+ return Array.isArray(parsed) ? parsed : [];
74
+ } catch {
75
+ return [];
76
+ }
77
+ }
@@ -0,0 +1,49 @@
1
+ // src/workflows/parser.js
2
+ import YAML from 'yaml';
3
+
4
+ export function parseWorkflow(yamlString) {
5
+ return YAML.parse(yamlString);
6
+ }
7
+
8
+ export function workflowToSkillMd(workflow) {
9
+ const lines = [
10
+ '---',
11
+ `description: ${workflow.description}`,
12
+ '---',
13
+ '',
14
+ `# ${workflow.name}`,
15
+ '',
16
+ ];
17
+
18
+ for (const step of workflow.steps || []) {
19
+ lines.push(`## ${step.name || step.id}`);
20
+
21
+ if (step.type === 'ask' && step.questions) {
22
+ lines.push('Ask the user:');
23
+ for (const q of step.questions) {
24
+ lines.push(`- "${q}"`);
25
+ }
26
+ }
27
+
28
+ if (step.type === 'auto' && step.actions) {
29
+ lines.push('Actions:');
30
+ for (const action of step.actions) {
31
+ if (typeof action === 'string') {
32
+ lines.push(`- ${action}`);
33
+ } else {
34
+ const key = Object.keys(action)[0];
35
+ lines.push(`- ${key}: ${JSON.stringify(action[key])}`);
36
+ }
37
+ }
38
+ }
39
+
40
+ if (step.type === 'agent') {
41
+ lines.push(`Delegate to agent: **${step.agent}**`);
42
+ if (step.output) lines.push(`Expected output: ${step.output}`);
43
+ }
44
+
45
+ lines.push('');
46
+ }
47
+
48
+ return lines.join('\n');
49
+ }