@yamo/memory-mesh 3.0.0 → 3.0.2
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 +9 -3
- package/bin/memory_mesh.js +95 -8
- package/lib/llm/client.d.ts +23 -48
- package/lib/llm/client.js +1 -0
- package/lib/llm/client.ts +298 -377
- package/lib/llm/index.js +1 -0
- package/lib/llm/index.ts +1 -2
- package/lib/memory/adapters/client.d.ts +22 -85
- package/lib/memory/adapters/client.js +1 -0
- package/lib/memory/adapters/client.ts +474 -633
- package/lib/memory/adapters/config.d.ts +82 -89
- package/lib/memory/adapters/config.js +1 -0
- package/lib/memory/adapters/config.ts +156 -225
- package/lib/memory/adapters/errors.d.ts +28 -20
- package/lib/memory/adapters/errors.js +1 -0
- package/lib/memory/adapters/errors.ts +83 -120
- package/lib/memory/context-manager.d.ts +15 -18
- package/lib/memory/context-manager.js +1 -0
- package/lib/memory/context-manager.ts +314 -401
- package/lib/memory/embeddings/factory.d.ts +18 -20
- package/lib/memory/embeddings/factory.js +1 -0
- package/lib/memory/embeddings/factory.ts +130 -173
- package/lib/memory/embeddings/index.js +1 -0
- package/lib/memory/embeddings/index.ts +1 -0
- package/lib/memory/embeddings/service.d.ts +36 -66
- package/lib/memory/embeddings/service.js +1 -0
- package/lib/memory/embeddings/service.ts +479 -616
- package/lib/memory/index.d.ts +2 -2
- package/lib/memory/index.js +1 -0
- package/lib/memory/index.ts +3 -13
- package/lib/memory/memory-mesh.d.ts +151 -93
- package/lib/memory/memory-mesh.js +1 -0
- package/lib/memory/memory-mesh.ts +1406 -1692
- package/lib/memory/memory-translator.d.ts +1 -6
- package/lib/memory/memory-translator.js +1 -0
- package/lib/memory/memory-translator.ts +96 -128
- package/lib/memory/schema.d.ts +29 -10
- package/lib/memory/schema.js +1 -0
- package/lib/memory/schema.ts +102 -185
- package/lib/memory/scorer.d.ts +3 -4
- package/lib/memory/scorer.js +1 -0
- package/lib/memory/scorer.ts +69 -86
- package/lib/memory/search/index.js +1 -0
- package/lib/memory/search/index.ts +1 -0
- package/lib/memory/search/keyword-search.d.ts +10 -26
- package/lib/memory/search/keyword-search.js +1 -0
- package/lib/memory/search/keyword-search.ts +123 -161
- package/lib/scrubber/config/defaults.d.ts +39 -46
- package/lib/scrubber/config/defaults.js +1 -0
- package/lib/scrubber/config/defaults.ts +50 -112
- package/lib/scrubber/errors/scrubber-error.d.ts +22 -0
- package/lib/scrubber/errors/scrubber-error.js +39 -0
- package/lib/scrubber/errors/scrubber-error.ts +44 -0
- package/lib/scrubber/index.d.ts +0 -1
- package/lib/scrubber/index.js +1 -0
- package/lib/scrubber/index.ts +1 -2
- package/lib/scrubber/scrubber.d.ts +14 -31
- package/lib/scrubber/scrubber.js +1 -0
- package/lib/scrubber/scrubber.ts +93 -152
- package/lib/scrubber/stages/chunker.d.ts +22 -10
- package/lib/scrubber/stages/chunker.js +86 -0
- package/lib/scrubber/stages/chunker.ts +104 -0
- package/lib/scrubber/stages/metadata-annotator.d.ts +14 -15
- package/lib/scrubber/stages/metadata-annotator.js +64 -0
- package/lib/scrubber/stages/metadata-annotator.ts +75 -0
- package/lib/scrubber/stages/normalizer.d.ts +13 -10
- package/lib/scrubber/stages/normalizer.js +51 -0
- package/lib/scrubber/stages/normalizer.ts +60 -0
- package/lib/scrubber/stages/semantic-filter.d.ts +13 -10
- package/lib/scrubber/stages/semantic-filter.js +51 -0
- package/lib/scrubber/stages/semantic-filter.ts +62 -0
- package/lib/scrubber/stages/structural-cleaner.d.ts +15 -10
- package/lib/scrubber/stages/structural-cleaner.js +73 -0
- package/lib/scrubber/stages/structural-cleaner.ts +83 -0
- package/lib/scrubber/stages/validator.d.ts +14 -15
- package/lib/scrubber/stages/validator.js +56 -0
- package/lib/scrubber/stages/validator.ts +67 -0
- package/lib/scrubber/telemetry.d.ts +20 -27
- package/lib/scrubber/telemetry.js +1 -0
- package/lib/scrubber/telemetry.ts +53 -90
- package/lib/scrubber/utils/hash.d.ts +14 -0
- package/lib/scrubber/utils/hash.js +37 -0
- package/lib/scrubber/utils/hash.ts +40 -0
- package/lib/scrubber/utils/html-parser.d.ts +14 -0
- package/lib/scrubber/utils/html-parser.js +38 -0
- package/lib/scrubber/utils/html-parser.ts +46 -0
- package/lib/scrubber/utils/pattern-matcher.d.ts +12 -0
- package/lib/scrubber/utils/pattern-matcher.js +54 -0
- package/lib/scrubber/utils/pattern-matcher.ts +64 -0
- package/lib/scrubber/utils/token-counter.d.ts +18 -0
- package/lib/scrubber/utils/token-counter.js +30 -0
- package/lib/scrubber/utils/token-counter.ts +32 -0
- package/lib/utils/logger.d.ts +1 -11
- package/lib/utils/logger.js +1 -0
- package/lib/utils/logger.ts +43 -63
- package/lib/utils/skill-metadata.d.ts +6 -14
- package/lib/utils/skill-metadata.js +1 -0
- package/lib/utils/skill-metadata.ts +89 -103
- package/lib/yamo/emitter.d.ts +8 -35
- package/lib/yamo/emitter.js +1 -0
- package/lib/yamo/emitter.ts +77 -155
- package/lib/yamo/index.d.ts +14 -0
- package/lib/yamo/index.js +14 -0
- package/lib/yamo/index.ts +16 -0
- package/lib/yamo/schema.d.ts +8 -10
- package/lib/yamo/schema.js +1 -0
- package/lib/yamo/schema.ts +82 -114
- package/package.json +5 -2
package/lib/yamo/emitter.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
/**
|
|
2
3
|
* YAMO Emitter - Constructs structured YAMO blocks for auditability
|
|
3
4
|
*
|
|
@@ -8,64 +9,20 @@
|
|
|
8
9
|
*
|
|
9
10
|
* Reference: Hindsight project's yamo_integration.py
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
-
export interface ReflectBlockParams {
|
|
13
|
-
topic?: string;
|
|
14
|
-
memoryCount: number;
|
|
15
|
-
agentId?: string;
|
|
16
|
-
reflection: string;
|
|
17
|
-
confidence?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface RetainBlockParams {
|
|
21
|
-
content: string;
|
|
22
|
-
metadata?: any;
|
|
23
|
-
id: string;
|
|
24
|
-
agentId?: string;
|
|
25
|
-
memoryType?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface RecallBlockParams {
|
|
29
|
-
query: string;
|
|
30
|
-
resultCount: number;
|
|
31
|
-
limit?: number;
|
|
32
|
-
agentId?: string;
|
|
33
|
-
searchType?: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface DeleteBlockParams {
|
|
37
|
-
id: string;
|
|
38
|
-
agentId?: string;
|
|
39
|
-
reason?: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface ValidationResult {
|
|
43
|
-
valid: boolean;
|
|
44
|
-
errors: string[];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
12
|
/**
|
|
48
13
|
* YamoEmitter class for building YAMO protocol blocks
|
|
49
14
|
* YAMO (Yet Another Multi-agent Orchestration) blocks provide
|
|
50
15
|
* structured reasoning traces for AI agent operations.
|
|
51
16
|
*/
|
|
52
17
|
export class YamoEmitter {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
agentId = "default",
|
|
62
|
-
reflection,
|
|
63
|
-
confidence = 0.8,
|
|
64
|
-
} = params;
|
|
65
|
-
|
|
66
|
-
const timestamp = new Date().toISOString();
|
|
67
|
-
|
|
68
|
-
return `agent: MemoryMesh_${agentId};
|
|
18
|
+
/**
|
|
19
|
+
* Build a YAMO block for reflect operation
|
|
20
|
+
* Reflect operations synthesize insights from existing memories
|
|
21
|
+
*/
|
|
22
|
+
static buildReflectBlock(params) {
|
|
23
|
+
const { topic, memoryCount, agentId = "default", reflection, confidence = 0.8, } = params;
|
|
24
|
+
const timestamp = new Date().toISOString();
|
|
25
|
+
return `agent: MemoryMesh_${agentId};
|
|
69
26
|
intent: synthesize_insights_from_context;
|
|
70
27
|
context:
|
|
71
28
|
topic;${topic || "general"};
|
|
@@ -84,29 +41,18 @@ meta:
|
|
|
84
41
|
log: reflection_generated;timestamp;${timestamp};memories;${memoryCount};
|
|
85
42
|
handoff: End;
|
|
86
43
|
`;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
memoryType = "event",
|
|
100
|
-
} = params;
|
|
101
|
-
|
|
102
|
-
const timestamp = new Date().toISOString();
|
|
103
|
-
const contentPreview =
|
|
104
|
-
content.length > 100 ? `${content.substring(0, 100)}...` : content;
|
|
105
|
-
|
|
106
|
-
// Escape semicolons in content for YAMO format
|
|
107
|
-
const escapedContent = contentPreview.replace(/;/g, ",");
|
|
108
|
-
|
|
109
|
-
return `agent: MemoryMesh_${agentId};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build a YAMO block for retain (add) operation
|
|
47
|
+
* Retain operations store new memories into the system
|
|
48
|
+
*/
|
|
49
|
+
static buildRetainBlock(params) {
|
|
50
|
+
const { content, metadata: _metadata = {}, id, agentId = "default", memoryType = "event", } = params;
|
|
51
|
+
const timestamp = new Date().toISOString();
|
|
52
|
+
const contentPreview = content.length > 100 ? `${content.substring(0, 100)}...` : content;
|
|
53
|
+
// Escape semicolons in content for YAMO format
|
|
54
|
+
const escapedContent = contentPreview.replace(/;/g, ",");
|
|
55
|
+
return `agent: MemoryMesh_${agentId};
|
|
110
56
|
intent: store_memory_for_future_retrieval;
|
|
111
57
|
context:
|
|
112
58
|
memory_id;${id};
|
|
@@ -126,26 +72,16 @@ meta:
|
|
|
126
72
|
log: memory_retained;timestamp;${timestamp};id;${id};type;${memoryType};
|
|
127
73
|
handoff: End;
|
|
128
74
|
`;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
limit = 10,
|
|
140
|
-
agentId = "default",
|
|
141
|
-
searchType = "semantic",
|
|
142
|
-
} = params;
|
|
143
|
-
|
|
144
|
-
const timestamp = new Date().toISOString();
|
|
145
|
-
const recallRatio =
|
|
146
|
-
resultCount > 0 ? (resultCount / limit).toFixed(2) : "0.00";
|
|
147
|
-
|
|
148
|
-
return `agent: MemoryMesh_${agentId};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Build a YAMO block for recall (search) operation
|
|
78
|
+
* Recall operations retrieve memories based on semantic similarity
|
|
79
|
+
*/
|
|
80
|
+
static buildRecallBlock(params) {
|
|
81
|
+
const { query, resultCount, limit = 10, agentId = "default", searchType = "semantic", } = params;
|
|
82
|
+
const timestamp = new Date().toISOString();
|
|
83
|
+
const recallRatio = resultCount > 0 ? (resultCount / limit).toFixed(2) : "0.00";
|
|
84
|
+
return `agent: MemoryMesh_${agentId};
|
|
149
85
|
intent: retrieve_relevant_memories;
|
|
150
86
|
context:
|
|
151
87
|
query;${query};
|
|
@@ -165,18 +101,15 @@ meta:
|
|
|
165
101
|
log: memory_recalled;timestamp;${timestamp};results;${resultCount};query;${query};
|
|
166
102
|
handoff: End;
|
|
167
103
|
`;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const timestamp = new Date().toISOString();
|
|
178
|
-
|
|
179
|
-
return `agent: MemoryMesh_${agentId};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Build a YAMO block for delete operation (optional)
|
|
107
|
+
* Delete operations remove memories from the system
|
|
108
|
+
*/
|
|
109
|
+
static buildDeleteBlock(params) {
|
|
110
|
+
const { id, agentId = "default", reason = "user_request" } = params;
|
|
111
|
+
const timestamp = new Date().toISOString();
|
|
112
|
+
return `agent: MemoryMesh_${agentId};
|
|
180
113
|
intent: remove_memory_from_storage;
|
|
181
114
|
context:
|
|
182
115
|
memory_id;${id};
|
|
@@ -194,56 +127,45 @@ meta:
|
|
|
194
127
|
log: memory_deleted;timestamp;${timestamp};id;${id};
|
|
195
128
|
handoff: End;
|
|
196
129
|
`;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Validate a YAMO block structure
|
|
201
|
-
* Checks for required sections and proper formatting
|
|
202
|
-
*/
|
|
203
|
-
static validateBlock(yamoBlock: string): ValidationResult {
|
|
204
|
-
const errors: string[] = [];
|
|
205
|
-
|
|
206
|
-
// Check for required sections
|
|
207
|
-
const requiredSections = [
|
|
208
|
-
"agent:",
|
|
209
|
-
"intent:",
|
|
210
|
-
"context:",
|
|
211
|
-
"output:",
|
|
212
|
-
"log:",
|
|
213
|
-
];
|
|
214
|
-
for (const section of requiredSections) {
|
|
215
|
-
if (!yamoBlock.includes(section)) {
|
|
216
|
-
errors.push(`Missing required section: ${section}`);
|
|
217
|
-
}
|
|
218
130
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Validate a YAMO block structure
|
|
133
|
+
* Checks for required sections and proper formatting
|
|
134
|
+
*/
|
|
135
|
+
static validateBlock(yamoBlock) {
|
|
136
|
+
const errors = [];
|
|
137
|
+
// Check for required sections
|
|
138
|
+
const requiredSections = [
|
|
139
|
+
"agent:",
|
|
140
|
+
"intent:",
|
|
141
|
+
"context:",
|
|
142
|
+
"output:",
|
|
143
|
+
"log:",
|
|
144
|
+
];
|
|
145
|
+
for (const section of requiredSections) {
|
|
146
|
+
if (!yamoBlock.includes(section)) {
|
|
147
|
+
errors.push(`Missing required section: ${section}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Check for semicolon termination
|
|
151
|
+
const lines = yamoBlock.split("\n");
|
|
152
|
+
for (const line of lines) {
|
|
153
|
+
const trimmed = line.trim();
|
|
154
|
+
if (trimmed.length > 0 &&
|
|
155
|
+
!trimmed.startsWith("//") &&
|
|
156
|
+
!trimmed.endsWith(";")) {
|
|
157
|
+
// Allow empty lines and comments
|
|
158
|
+
if (trimmed &&
|
|
159
|
+
!trimmed.startsWith("agent:") &&
|
|
160
|
+
!trimmed.startsWith("handoff:")) {
|
|
161
|
+
errors.push(`Line not semicolon-terminated: ${trimmed.substring(0, 50)}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
238
164
|
}
|
|
239
|
-
|
|
165
|
+
return {
|
|
166
|
+
valid: errors.length === 0,
|
|
167
|
+
errors,
|
|
168
|
+
};
|
|
240
169
|
}
|
|
241
|
-
|
|
242
|
-
return {
|
|
243
|
-
valid: errors.length === 0,
|
|
244
|
-
errors,
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
170
|
}
|
|
248
|
-
|
|
249
171
|
export default YamoEmitter;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAMO Module - YAMO Protocol support for yamo-memory-mesh
|
|
3
|
+
* Exports YAMO block construction, validation, and schema utilities
|
|
4
|
+
*/
|
|
5
|
+
export { YamoEmitter } from './emitter.js';
|
|
6
|
+
export * from './schema.js';
|
|
7
|
+
declare const _default: {
|
|
8
|
+
YamoEmitter: typeof import("./emitter.js").YamoEmitter;
|
|
9
|
+
createYamoSchema: typeof import("./schema.js").createYamoSchema;
|
|
10
|
+
createYamoTable: typeof import("./schema.js").createYamoTable;
|
|
11
|
+
validateYamoRecord: typeof import("./schema.js").validateYamoRecord;
|
|
12
|
+
generateYamoId: typeof import("./schema.js").generateYamoId;
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* YAMO Module - YAMO Protocol support for yamo-memory-mesh
|
|
4
|
+
* Exports YAMO block construction, validation, and schema utilities
|
|
5
|
+
*/
|
|
6
|
+
export { YamoEmitter } from './emitter.js';
|
|
7
|
+
export * from './schema.js';
|
|
8
|
+
export default {
|
|
9
|
+
YamoEmitter: (await import('./emitter.js')).YamoEmitter,
|
|
10
|
+
createYamoSchema: (await import('./schema.js')).createYamoSchema,
|
|
11
|
+
createYamoTable: (await import('./schema.js')).createYamoTable,
|
|
12
|
+
validateYamoRecord: (await import('./schema.js')).validateYamoRecord,
|
|
13
|
+
generateYamoId: (await import('./schema.js')).generateYamoId
|
|
14
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* YAMO Module - YAMO Protocol support for yamo-memory-mesh
|
|
4
|
+
* Exports YAMO block construction, validation, and schema utilities
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export { YamoEmitter } from './emitter.js';
|
|
8
|
+
export * from './schema.js';
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
YamoEmitter: (await import('./emitter.js')).YamoEmitter,
|
|
12
|
+
createYamoSchema: (await import('./schema.js')).createYamoSchema,
|
|
13
|
+
createYamoTable: (await import('./schema.js')).createYamoTable,
|
|
14
|
+
validateYamoRecord: (await import('./schema.js')).validateYamoRecord,
|
|
15
|
+
generateYamoId: (await import('./schema.js')).generateYamoId
|
|
16
|
+
};
|
package/lib/yamo/schema.d.ts
CHANGED
|
@@ -6,13 +6,12 @@
|
|
|
6
6
|
* YAMO blocks provide audit trail for all memory operations.
|
|
7
7
|
*/
|
|
8
8
|
import * as arrow from "apache-arrow";
|
|
9
|
-
import * as lancedb from "@lancedb/lancedb";
|
|
10
9
|
/**
|
|
11
10
|
* Create YAMO blocks table schema
|
|
12
11
|
* Defines the structure for storing YAMO protocol blocks
|
|
13
12
|
* @returns {arrow.Schema} Arrow schema for YAMO blocks
|
|
14
13
|
*/
|
|
15
|
-
export declare function createYamoSchema(): arrow.Schema
|
|
14
|
+
export declare function createYamoSchema(): arrow.Schema<any>;
|
|
16
15
|
/**
|
|
17
16
|
* Create YAMO blocks table in LanceDB
|
|
18
17
|
* Creates the table if it doesn't exist, opens it if it does
|
|
@@ -22,16 +21,15 @@ export declare function createYamoSchema(): arrow.Schema;
|
|
|
22
21
|
* @returns {Promise<lancedb.Table>} The created or opened table
|
|
23
22
|
* @throws {Error} If table creation fails
|
|
24
23
|
*/
|
|
25
|
-
export declare function createYamoTable(db:
|
|
26
|
-
export interface YamoRecordValidationResult {
|
|
27
|
-
valid: boolean;
|
|
28
|
-
errors: string[];
|
|
29
|
-
}
|
|
24
|
+
export declare function createYamoTable(db: any, tableName?: string): Promise<any>;
|
|
30
25
|
/**
|
|
31
26
|
* Validate a YAMO block record before insertion
|
|
32
27
|
* Checks for required fields and valid values
|
|
33
28
|
*/
|
|
34
|
-
export declare function validateYamoRecord(record: any):
|
|
29
|
+
export declare function validateYamoRecord(record: any): {
|
|
30
|
+
valid: boolean;
|
|
31
|
+
errors: any[];
|
|
32
|
+
};
|
|
35
33
|
/**
|
|
36
34
|
* Generate a YAMO block ID
|
|
37
35
|
* Creates a unique ID for a YAMO block
|
|
@@ -39,7 +37,7 @@ export declare function validateYamoRecord(record: any): YamoRecordValidationRes
|
|
|
39
37
|
* @param {string} operationType - Type of operation
|
|
40
38
|
* @returns {string} Generated YAMO block ID
|
|
41
39
|
*/
|
|
42
|
-
export declare function generateYamoId(operationType:
|
|
40
|
+
export declare function generateYamoId(operationType: any): string;
|
|
43
41
|
/**
|
|
44
42
|
* Check if a table uses YAMO schema
|
|
45
43
|
* Detects if a table has the YAMO block schema structure
|
|
@@ -47,7 +45,7 @@ export declare function generateYamoId(operationType: string): string;
|
|
|
47
45
|
* @param {arrow.Schema} schema - Table schema to check
|
|
48
46
|
* @returns {boolean} True if YAMO schema detected
|
|
49
47
|
*/
|
|
50
|
-
export declare function isYamoSchema(schema:
|
|
48
|
+
export declare function isYamoSchema(schema: any): any;
|
|
51
49
|
declare const _default: {
|
|
52
50
|
createYamoSchema: typeof createYamoSchema;
|
|
53
51
|
createYamoTable: typeof createYamoTable;
|
package/lib/yamo/schema.js
CHANGED
package/lib/yamo/schema.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
/**
|
|
2
3
|
* YAMO Block Schema Definitions for yamo-memory-mesh
|
|
3
4
|
* Uses Apache Arrow Schema format for LanceDB JavaScript SDK
|
|
@@ -5,41 +6,29 @@
|
|
|
5
6
|
* Provides schema and table creation for YAMO block persistence.
|
|
6
7
|
* YAMO blocks provide audit trail for all memory operations.
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
9
|
import * as arrow from "apache-arrow";
|
|
10
|
-
import * as lancedb from "@lancedb/lancedb";
|
|
11
|
-
|
|
12
10
|
/**
|
|
13
11
|
* Create YAMO blocks table schema
|
|
14
12
|
* Defines the structure for storing YAMO protocol blocks
|
|
15
13
|
* @returns {arrow.Schema} Arrow schema for YAMO blocks
|
|
16
14
|
*/
|
|
17
|
-
export function createYamoSchema()
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
// Blockchain fields (optional, nullable) - for future anchoring
|
|
35
|
-
new arrow.Field("block_hash", new arrow.Utf8(), true), // Hash of this block
|
|
36
|
-
new arrow.Field("prev_hash", new arrow.Utf8(), true), // Hash of previous block (for chain)
|
|
37
|
-
|
|
38
|
-
// Metadata (JSON string for flexibility)
|
|
39
|
-
new arrow.Field("metadata", new arrow.Utf8(), true), // Additional metadata as JSON
|
|
40
|
-
]);
|
|
15
|
+
export function createYamoSchema() {
|
|
16
|
+
return new arrow.Schema([
|
|
17
|
+
// Core identifiers
|
|
18
|
+
new arrow.Field("id", new arrow.Utf8(), false),
|
|
19
|
+
new arrow.Field("agent_id", new arrow.Utf8(), true),
|
|
20
|
+
// Operation tracking
|
|
21
|
+
new arrow.Field("operation_type", new arrow.Utf8(), false), // 'retain', 'recall', 'reflect'
|
|
22
|
+
new arrow.Field("yamo_text", new arrow.Utf8(), false), // Full YAMO block content
|
|
23
|
+
// Temporal
|
|
24
|
+
new arrow.Field("timestamp", new arrow.Timestamp(arrow.TimeUnit.MILLISECOND), false),
|
|
25
|
+
// Blockchain fields (optional, nullable) - for future anchoring
|
|
26
|
+
new arrow.Field("block_hash", new arrow.Utf8(), true), // Hash of this block
|
|
27
|
+
new arrow.Field("prev_hash", new arrow.Utf8(), true), // Hash of previous block (for chain)
|
|
28
|
+
// Metadata (JSON string for flexibility)
|
|
29
|
+
new arrow.Field("metadata", new arrow.Utf8(), true), // Additional metadata as JSON
|
|
30
|
+
]);
|
|
41
31
|
}
|
|
42
|
-
|
|
43
32
|
/**
|
|
44
33
|
* Create YAMO blocks table in LanceDB
|
|
45
34
|
* Creates the table if it doesn't exist, opens it if it does
|
|
@@ -49,83 +38,67 @@ export function createYamoSchema(): arrow.Schema {
|
|
|
49
38
|
* @returns {Promise<lancedb.Table>} The created or opened table
|
|
50
39
|
* @throws {Error} If table creation fails
|
|
51
40
|
*/
|
|
52
|
-
export async function createYamoTable(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
41
|
+
export async function createYamoTable(db, tableName = "yamo_blocks") {
|
|
42
|
+
try {
|
|
43
|
+
// Check if table already exists
|
|
44
|
+
const existingTables = await db.tableNames();
|
|
45
|
+
if (existingTables.includes(tableName)) {
|
|
46
|
+
// Table exists, open it
|
|
47
|
+
return await db.openTable(tableName);
|
|
48
|
+
}
|
|
49
|
+
// Create new table with YAMO schema
|
|
50
|
+
const schema = createYamoSchema();
|
|
51
|
+
const table = await db.createTable(tableName, [], { schema });
|
|
52
|
+
return table;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
56
|
+
throw new Error(`Failed to create YAMO table '${tableName}': ${message}`);
|
|
63
57
|
}
|
|
64
|
-
|
|
65
|
-
// Create new table with YAMO schema
|
|
66
|
-
const schema = createYamoSchema();
|
|
67
|
-
const table = await db.createTable(tableName, [], { schema } as any);
|
|
68
|
-
|
|
69
|
-
return table;
|
|
70
|
-
} catch (error) {
|
|
71
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
72
|
-
throw new Error(`Failed to create YAMO table '${tableName}': ${message}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface YamoRecordValidationResult {
|
|
77
|
-
valid: boolean;
|
|
78
|
-
errors: string[];
|
|
79
58
|
}
|
|
80
|
-
|
|
81
59
|
/**
|
|
82
60
|
* Validate a YAMO block record before insertion
|
|
83
61
|
* Checks for required fields and valid values
|
|
84
62
|
*/
|
|
85
|
-
export function validateYamoRecord(record
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
63
|
+
export function validateYamoRecord(record) {
|
|
64
|
+
const errors = [];
|
|
65
|
+
// Check required fields
|
|
66
|
+
if (!record.id) {
|
|
67
|
+
errors.push("Missing required field: id");
|
|
68
|
+
}
|
|
69
|
+
if (!record.operation_type) {
|
|
70
|
+
errors.push("Missing required field: operation_type");
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// Validate operation_type is one of the allowed values
|
|
74
|
+
const validTypes = ["retain", "recall", "reflect"];
|
|
75
|
+
if (!validTypes.includes(record.operation_type)) {
|
|
76
|
+
errors.push(`Invalid operation_type: ${record.operation_type}. Must be one of: ${validTypes.join(", ")}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!record.yamo_text) {
|
|
80
|
+
errors.push("Missing required field: yamo_text");
|
|
102
81
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (!record.yamo_text.includes(section)) {
|
|
118
|
-
errors.push(`YAMO block missing required section: ${section}`);
|
|
119
|
-
}
|
|
82
|
+
else {
|
|
83
|
+
// Validate YAMO block format
|
|
84
|
+
const requiredSections = [
|
|
85
|
+
"agent:",
|
|
86
|
+
"intent:",
|
|
87
|
+
"context:",
|
|
88
|
+
"output:",
|
|
89
|
+
"log:",
|
|
90
|
+
];
|
|
91
|
+
for (const section of requiredSections) {
|
|
92
|
+
if (!record.yamo_text.includes(section)) {
|
|
93
|
+
errors.push(`YAMO block missing required section: ${section}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
120
96
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
errors,
|
|
126
|
-
};
|
|
97
|
+
return {
|
|
98
|
+
valid: errors.length === 0,
|
|
99
|
+
errors,
|
|
100
|
+
};
|
|
127
101
|
}
|
|
128
|
-
|
|
129
102
|
/**
|
|
130
103
|
* Generate a YAMO block ID
|
|
131
104
|
* Creates a unique ID for a YAMO block
|
|
@@ -133,12 +106,11 @@ export function validateYamoRecord(record: any): YamoRecordValidationResult {
|
|
|
133
106
|
* @param {string} operationType - Type of operation
|
|
134
107
|
* @returns {string} Generated YAMO block ID
|
|
135
108
|
*/
|
|
136
|
-
export function generateYamoId(operationType
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
109
|
+
export function generateYamoId(operationType) {
|
|
110
|
+
const timestamp = Date.now();
|
|
111
|
+
const random = Math.random().toString(36).substring(2, 10);
|
|
112
|
+
return `yamo_${operationType}_${timestamp}_${random}`;
|
|
140
113
|
}
|
|
141
|
-
|
|
142
114
|
/**
|
|
143
115
|
* Check if a table uses YAMO schema
|
|
144
116
|
* Detects if a table has the YAMO block schema structure
|
|
@@ -146,20 +118,16 @@ export function generateYamoId(operationType: string): string {
|
|
|
146
118
|
* @param {arrow.Schema} schema - Table schema to check
|
|
147
119
|
* @returns {boolean} True if YAMO schema detected
|
|
148
120
|
*/
|
|
149
|
-
export function isYamoSchema(schema
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
return hasYamoFields;
|
|
121
|
+
export function isYamoSchema(schema) {
|
|
122
|
+
// Check for unique YAMO fields
|
|
123
|
+
const hasYamoFields = schema.fields.some((f) => f.name === "operation_type" || f.name === "yamo_text");
|
|
124
|
+
return hasYamoFields;
|
|
156
125
|
}
|
|
157
|
-
|
|
158
126
|
// Export schema function as default for consistency with lancedb/schema.js
|
|
159
127
|
export default {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
128
|
+
createYamoSchema,
|
|
129
|
+
createYamoTable,
|
|
130
|
+
validateYamoRecord,
|
|
131
|
+
generateYamoId,
|
|
132
|
+
isYamoSchema,
|
|
165
133
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yamo/memory-mesh",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "Portable semantic memory system with Layer 0 Scrubber for YAMO agents (v3 Singularity Edition)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/memory/index.js",
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "tsc",
|
|
19
|
-
"test": "npm run build &&
|
|
19
|
+
"test": "npm run build && npx tsx --test test/**/*.test.ts",
|
|
20
|
+
"test:unit": "npx tsx --test test/unit/*.test.ts",
|
|
21
|
+
"test:e2e": "npm run build && npx tsx --test test/e2e/*.test.ts",
|
|
20
22
|
"type-check": "tsc --noEmit",
|
|
21
23
|
"prepublishOnly": "npm run build"
|
|
22
24
|
},
|
|
@@ -24,6 +26,7 @@
|
|
|
24
26
|
"@lancedb/lancedb": "^0.23.0",
|
|
25
27
|
"@xenova/transformers": "^2.17.0",
|
|
26
28
|
"apache-arrow": "^17.0.0",
|
|
29
|
+
"commander": "^14.0.3",
|
|
27
30
|
"onnxruntime-node": "^1.18.0",
|
|
28
31
|
"pino": "^10.3.1",
|
|
29
32
|
"pino-pretty": "^13.1.3"
|