@props-labs/mesh-os 0.2.0 → 0.2.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/dist/core/__fixtures__/mock_responses.d.ts +19 -0
- package/dist/core/__fixtures__/mock_responses.js +22 -0
- package/dist/core/client.d.ts +5 -7
- package/dist/core/client.js +5 -16
- package/dist/core/workflows.d.ts +4 -0
- package/dist/core/workflows.js +25 -0
- package/package.json +1 -1
- package/dist/core/entities.d.ts +0 -58
- package/dist/core/entities.js +0 -347
@@ -311,6 +311,25 @@ export declare const WORKFLOW_MOCKS: {
|
|
311
311
|
};
|
312
312
|
};
|
313
313
|
};
|
314
|
+
getLastResult: {
|
315
|
+
data: {
|
316
|
+
workflow_results: {
|
317
|
+
id: string;
|
318
|
+
workflow_id: "c4d5e6f7-3456-7890-12cd-ef3456789012";
|
319
|
+
type: string;
|
320
|
+
result: {
|
321
|
+
summary: string;
|
322
|
+
confidence: number;
|
323
|
+
};
|
324
|
+
metadata: {
|
325
|
+
stage: string;
|
326
|
+
};
|
327
|
+
created_at: string;
|
328
|
+
updated_at: string;
|
329
|
+
agent_id: "d7f3668d-5ebf-4f95-9b5c-07301f5d4c62";
|
330
|
+
}[];
|
331
|
+
};
|
332
|
+
};
|
314
333
|
};
|
315
334
|
export declare const createMockFetch: (mocks: Record<string, any>) => (url: string, init?: RequestInit) => Promise<{
|
316
335
|
ok: boolean;
|
@@ -288,6 +288,25 @@ exports.WORKFLOW_MOCKS = {
|
|
288
288
|
agent_id: exports.SAMPLE_IDS.AGENT
|
289
289
|
}
|
290
290
|
}
|
291
|
+
},
|
292
|
+
getLastResult: {
|
293
|
+
data: {
|
294
|
+
workflow_results: [{
|
295
|
+
id: 'd5e6f7f8-4567-8901-23de-f45678901235',
|
296
|
+
workflow_id: exports.SAMPLE_IDS.WORKFLOW,
|
297
|
+
type: 'final',
|
298
|
+
result: {
|
299
|
+
summary: 'This is the document summary',
|
300
|
+
confidence: 0.95
|
301
|
+
},
|
302
|
+
metadata: {
|
303
|
+
stage: 'complete'
|
304
|
+
},
|
305
|
+
created_at: '2025-02-18T00:00:00Z',
|
306
|
+
updated_at: '2025-02-18T00:00:00Z',
|
307
|
+
agent_id: exports.SAMPLE_IDS.AGENT
|
308
|
+
}]
|
309
|
+
}
|
291
310
|
}
|
292
311
|
};
|
293
312
|
// Mock fetch function for testing
|
@@ -321,6 +340,9 @@ const createMockFetch = (mocks) => {
|
|
321
340
|
else if (query.includes('CreateWorkflowRun')) {
|
322
341
|
mockResponse = mocks.createRun;
|
323
342
|
}
|
343
|
+
else if (query.includes('GetLastWorkflowResult')) {
|
344
|
+
mockResponse = mocks.getLastResult;
|
345
|
+
}
|
324
346
|
if (!mockResponse) {
|
325
347
|
throw new Error(`No mock response found for query: ${query}`);
|
326
348
|
}
|
package/dist/core/client.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
import { EdgeType, type AgentStatus, type EdgeMetadata, type MemoryMetadata, type TimestampFilter
|
2
|
-
import { EntityManager } from './entities';
|
1
|
+
import { EdgeType, type AgentStatus, type EdgeMetadata, type MemoryMetadata, type TimestampFilter } from './taxonomy';
|
3
2
|
import { WorkflowManager } from './workflows';
|
3
|
+
import { MemoryManager } from './memories';
|
4
|
+
import { AgentManager } from './agents';
|
4
5
|
/**
|
5
6
|
* An agent in the system.
|
6
7
|
*/
|
@@ -66,8 +67,6 @@ export interface RememberOptions {
|
|
66
67
|
agentId: string;
|
67
68
|
metadata?: Partial<MemoryMetadata>;
|
68
69
|
expiresAt?: string;
|
69
|
-
entityId?: string;
|
70
|
-
entityRelationship?: EntityRelationshipType;
|
71
70
|
}
|
72
71
|
/**
|
73
72
|
* MeshOS client for interacting with the system.
|
@@ -76,8 +75,9 @@ export declare class MeshOS {
|
|
76
75
|
private url;
|
77
76
|
private headers;
|
78
77
|
private openai;
|
79
|
-
entities: EntityManager;
|
80
78
|
workflows: WorkflowManager;
|
79
|
+
memories: MemoryManager;
|
80
|
+
agents: AgentManager;
|
81
81
|
constructor(config?: MeshOSConfig);
|
82
82
|
private validateSlug;
|
83
83
|
/**
|
@@ -156,8 +156,6 @@ export declare class MeshOS {
|
|
156
156
|
filters?: Record<string, unknown>;
|
157
157
|
createdAtFilter?: TimestampFilter;
|
158
158
|
expiresAtFilter?: TimestampFilter;
|
159
|
-
entityId?: string;
|
160
|
-
entityRelationship?: EntityRelationshipType;
|
161
159
|
}): Promise<Memory[]>;
|
162
160
|
/**
|
163
161
|
* Internal method to perform recall with a specific threshold.
|
package/dist/core/client.js
CHANGED
@@ -11,8 +11,9 @@ const openai_1 = __importDefault(require("openai"));
|
|
11
11
|
const chalk_1 = __importDefault(require("chalk"));
|
12
12
|
const boxen_1 = __importDefault(require("boxen"));
|
13
13
|
const taxonomy_1 = require("./taxonomy");
|
14
|
-
const entities_1 = require("./entities");
|
15
14
|
const workflows_1 = require("./workflows");
|
15
|
+
const memories_1 = require("./memories");
|
16
|
+
const agents_1 = require("./agents");
|
16
17
|
// Constants
|
17
18
|
const SLUG_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
18
19
|
/**
|
@@ -63,8 +64,9 @@ class MeshOS {
|
|
63
64
|
}
|
64
65
|
this.openai = new openai_1.default({ apiKey: openaiApiKey });
|
65
66
|
// Initialize managers
|
66
|
-
this.entities = new entities_1.EntityManager(this.url, this.headers, this.createEmbedding.bind(this));
|
67
67
|
this.workflows = new workflows_1.WorkflowManager(this.url, this.headers);
|
68
|
+
this.memories = new memories_1.MemoryManager(this.url, this.headers, this.createEmbedding.bind(this));
|
69
|
+
this.agents = new agents_1.AgentManager(this.url, this.headers);
|
68
70
|
}
|
69
71
|
validateSlug(slug) {
|
70
72
|
return SLUG_PATTERN.test(slug);
|
@@ -203,7 +205,7 @@ class MeshOS {
|
|
203
205
|
* Store a new memory with optional entity linking.
|
204
206
|
*/
|
205
207
|
async remember(options, agentId, metadata, expiresAt) {
|
206
|
-
//
|
208
|
+
// Convert string input to options object
|
207
209
|
if (typeof options === 'string') {
|
208
210
|
options = {
|
209
211
|
content: options,
|
@@ -212,14 +214,7 @@ class MeshOS {
|
|
212
214
|
expiresAt
|
213
215
|
};
|
214
216
|
}
|
215
|
-
// Create the memory
|
216
217
|
const result = await this._remember(options.content, options.agentId, options.metadata, options.expiresAt);
|
217
|
-
// If entity linking is requested, create the link
|
218
|
-
if (options.entityId) {
|
219
|
-
const memories = Array.isArray(result) ? result : [result];
|
220
|
-
const firstMemory = memories[0];
|
221
|
-
await this.entities.linkMemory(options.entityId, firstMemory.id, options.entityRelationship || taxonomy_1.EntityRelationshipType.ASSOCIATED);
|
222
|
-
}
|
223
218
|
return result;
|
224
219
|
}
|
225
220
|
/**
|
@@ -543,12 +538,6 @@ class MeshOS {
|
|
543
538
|
createdAtFilter: options.createdAtFilter,
|
544
539
|
expiresAtFilter: options.expiresAtFilter
|
545
540
|
});
|
546
|
-
// If entity filtering is requested, filter results
|
547
|
-
if (options.entityId) {
|
548
|
-
const linkedMemories = await this.entities.getLinkedMemories(options.entityId, options.entityRelationship);
|
549
|
-
const linkedMemoryIds = new Set(linkedMemories.map(m => m.id));
|
550
|
-
results = results.filter(memory => linkedMemoryIds.has(memory.id));
|
551
|
-
}
|
552
541
|
// First try: Direct search with initial threshold
|
553
542
|
if (results.length >= minResults) {
|
554
543
|
return results.slice(0, options.limit || 5);
|
package/dist/core/workflows.d.ts
CHANGED
@@ -101,4 +101,8 @@ export declare class WorkflowManager {
|
|
101
101
|
* List workflow runs with optional filtering and sorting
|
102
102
|
*/
|
103
103
|
listRuns(options?: ListWorkflowRunsOptions): Promise<WorkflowRun[]>;
|
104
|
+
/**
|
105
|
+
* Get the last result for a workflow run, regardless of type
|
106
|
+
*/
|
107
|
+
getLastResult(workflowId: string): Promise<WorkflowResult | null>;
|
104
108
|
}
|
package/dist/core/workflows.js
CHANGED
@@ -328,5 +328,30 @@ class WorkflowManager {
|
|
328
328
|
});
|
329
329
|
return result.workflow_runs.map(run => workflowRunSchema.parse(run));
|
330
330
|
}
|
331
|
+
/**
|
332
|
+
* Get the last result for a workflow run, regardless of type
|
333
|
+
*/
|
334
|
+
async getLastResult(workflowId) {
|
335
|
+
const query = `
|
336
|
+
query GetLastWorkflowResult($workflow_id: uuid!) {
|
337
|
+
workflow_results(
|
338
|
+
where: {workflow_id: {_eq: $workflow_id}}
|
339
|
+
order_by: {created_at: desc}
|
340
|
+
limit: 1
|
341
|
+
) {
|
342
|
+
id
|
343
|
+
workflow_id
|
344
|
+
type
|
345
|
+
result
|
346
|
+
metadata
|
347
|
+
created_at
|
348
|
+
updated_at
|
349
|
+
agent_id
|
350
|
+
}
|
351
|
+
}
|
352
|
+
`;
|
353
|
+
const result = await this.executeQuery(query, { workflow_id: workflowId });
|
354
|
+
return result.workflow_results[0] ? workflowResultSchema.parse(result.workflow_results[0]) : null;
|
355
|
+
}
|
331
356
|
}
|
332
357
|
exports.WorkflowManager = WorkflowManager;
|
package/package.json
CHANGED
package/dist/core/entities.d.ts
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Entity management functionality for MeshOS.
|
3
|
-
*/
|
4
|
-
import { Entity, EntityStatus, EntityRelationshipType, EntityMemoryLink } from './taxonomy';
|
5
|
-
import type { Memory } from './client';
|
6
|
-
export declare class EntityManager {
|
7
|
-
private url;
|
8
|
-
private headers;
|
9
|
-
private createEmbedding;
|
10
|
-
constructor(url: string, headers: Record<string, string>, createEmbedding: (text: string) => Promise<number[]>);
|
11
|
-
/**
|
12
|
-
* Execute a GraphQL query.
|
13
|
-
*/
|
14
|
-
private executeQuery;
|
15
|
-
/**
|
16
|
-
* Add a new entity.
|
17
|
-
*/
|
18
|
-
add(entity: Omit<Entity, 'id' | 'createdAt' | 'updatedAt'>): Promise<Entity>;
|
19
|
-
/**
|
20
|
-
* Get an entity by ID.
|
21
|
-
*/
|
22
|
-
get(id: string): Promise<Entity | null>;
|
23
|
-
/**
|
24
|
-
* Get an entity by reference ID.
|
25
|
-
*/
|
26
|
-
getByRefId(refId: string): Promise<Entity | null>;
|
27
|
-
/**
|
28
|
-
* Update an entity.
|
29
|
-
*/
|
30
|
-
update(id: string, updates: Partial<Omit<Entity, 'id' | 'createdAt' | 'updatedAt'>>): Promise<Entity>;
|
31
|
-
/**
|
32
|
-
* Delete an entity.
|
33
|
-
*/
|
34
|
-
delete(id: string): Promise<boolean>;
|
35
|
-
/**
|
36
|
-
* Search entities by semantic similarity.
|
37
|
-
*/
|
38
|
-
search(options: {
|
39
|
-
query: string;
|
40
|
-
threshold?: number;
|
41
|
-
limit?: number;
|
42
|
-
type?: string;
|
43
|
-
status?: EntityStatus;
|
44
|
-
}): Promise<(Entity & {
|
45
|
-
similarity?: number;
|
46
|
-
})[]>;
|
47
|
-
/**
|
48
|
-
* Link an entity to a memory.
|
49
|
-
*/
|
50
|
-
linkMemory(entityId: string, memoryId: string, relationship: EntityRelationshipType, confidence?: number): Promise<EntityMemoryLink>;
|
51
|
-
/**
|
52
|
-
* Get all memories linked to an entity.
|
53
|
-
*/
|
54
|
-
getLinkedMemories(entityId: string, relationship?: EntityRelationshipType): Promise<Array<Memory & {
|
55
|
-
relationship: EntityRelationshipType;
|
56
|
-
confidence: number;
|
57
|
-
}>>;
|
58
|
-
}
|
package/dist/core/entities.js
DELETED
@@ -1,347 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.EntityManager = void 0;
|
4
|
-
/**
|
5
|
-
* Entity management functionality for MeshOS.
|
6
|
-
*/
|
7
|
-
const taxonomy_1 = require("./taxonomy");
|
8
|
-
class EntityManager {
|
9
|
-
constructor(url, headers, createEmbedding) {
|
10
|
-
this.url = url;
|
11
|
-
this.headers = headers;
|
12
|
-
this.createEmbedding = createEmbedding;
|
13
|
-
}
|
14
|
-
/**
|
15
|
-
* Execute a GraphQL query.
|
16
|
-
*/
|
17
|
-
async executeQuery(query, variables) {
|
18
|
-
const response = await fetch(this.url, {
|
19
|
-
method: 'POST',
|
20
|
-
headers: this.headers,
|
21
|
-
body: JSON.stringify({
|
22
|
-
query,
|
23
|
-
variables: variables || {}
|
24
|
-
})
|
25
|
-
});
|
26
|
-
if (!response.ok) {
|
27
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
28
|
-
}
|
29
|
-
const result = await response.json();
|
30
|
-
if (result.errors) {
|
31
|
-
throw new Error(result.errors[0].message);
|
32
|
-
}
|
33
|
-
return result.data;
|
34
|
-
}
|
35
|
-
/**
|
36
|
-
* Add a new entity.
|
37
|
-
*/
|
38
|
-
async add(entity) {
|
39
|
-
// Validate entity data
|
40
|
-
const validatedData = taxonomy_1.entitySchema.omit({ id: true, createdAt: true, updatedAt: true }).parse(entity);
|
41
|
-
// Create embedding from name and description
|
42
|
-
const embeddingText = `${validatedData.name} ${validatedData.description || ''}`.trim();
|
43
|
-
const embedding = await this.createEmbedding(embeddingText);
|
44
|
-
const embeddingStr = `[${embedding.join(',')}]`;
|
45
|
-
const query = `
|
46
|
-
mutation AddEntity($entity: entities_insert_input!) {
|
47
|
-
insert_entities_one(object: $entity) {
|
48
|
-
id
|
49
|
-
ref_id
|
50
|
-
type
|
51
|
-
name
|
52
|
-
description
|
53
|
-
metadata
|
54
|
-
status
|
55
|
-
created_at
|
56
|
-
updated_at
|
57
|
-
}
|
58
|
-
}
|
59
|
-
`;
|
60
|
-
const result = await this.executeQuery(query, {
|
61
|
-
entity: {
|
62
|
-
ref_id: validatedData.refId,
|
63
|
-
type: validatedData.type,
|
64
|
-
name: validatedData.name,
|
65
|
-
description: validatedData.description,
|
66
|
-
metadata: validatedData.metadata,
|
67
|
-
status: validatedData.status,
|
68
|
-
embedding: embeddingStr
|
69
|
-
}
|
70
|
-
});
|
71
|
-
// Convert snake_case to camelCase
|
72
|
-
const { ref_id, created_at, updated_at, ...rest } = result.insert_entities_one;
|
73
|
-
return {
|
74
|
-
...rest,
|
75
|
-
refId: ref_id,
|
76
|
-
createdAt: created_at,
|
77
|
-
updatedAt: updated_at,
|
78
|
-
};
|
79
|
-
}
|
80
|
-
/**
|
81
|
-
* Get an entity by ID.
|
82
|
-
*/
|
83
|
-
async get(id) {
|
84
|
-
const query = `
|
85
|
-
query GetEntity($id: uuid!) {
|
86
|
-
entities_by_pk(id: $id) {
|
87
|
-
id
|
88
|
-
ref_id
|
89
|
-
type
|
90
|
-
name
|
91
|
-
description
|
92
|
-
metadata
|
93
|
-
status
|
94
|
-
created_at
|
95
|
-
updated_at
|
96
|
-
}
|
97
|
-
}
|
98
|
-
`;
|
99
|
-
const result = await this.executeQuery(query, { id });
|
100
|
-
if (!result.entities_by_pk) {
|
101
|
-
return null;
|
102
|
-
}
|
103
|
-
// Convert snake_case to camelCase
|
104
|
-
const { ref_id, created_at, updated_at, ...rest } = result.entities_by_pk;
|
105
|
-
return {
|
106
|
-
...rest,
|
107
|
-
refId: ref_id,
|
108
|
-
createdAt: created_at,
|
109
|
-
updatedAt: updated_at,
|
110
|
-
};
|
111
|
-
}
|
112
|
-
/**
|
113
|
-
* Get an entity by reference ID.
|
114
|
-
*/
|
115
|
-
async getByRefId(refId) {
|
116
|
-
const query = `
|
117
|
-
query GetEntityByRefId($refId: String!) {
|
118
|
-
entities(where: {ref_id: {_eq: $refId}}, limit: 1) {
|
119
|
-
id
|
120
|
-
ref_id
|
121
|
-
type
|
122
|
-
name
|
123
|
-
description
|
124
|
-
metadata
|
125
|
-
status
|
126
|
-
created_at
|
127
|
-
updated_at
|
128
|
-
}
|
129
|
-
}
|
130
|
-
`;
|
131
|
-
const result = await this.executeQuery(query, { refId });
|
132
|
-
if (!result.entities[0]) {
|
133
|
-
return null;
|
134
|
-
}
|
135
|
-
// Convert snake_case to camelCase
|
136
|
-
const { ref_id, created_at, updated_at, ...rest } = result.entities[0];
|
137
|
-
return {
|
138
|
-
...rest,
|
139
|
-
refId: ref_id,
|
140
|
-
createdAt: created_at,
|
141
|
-
updatedAt: updated_at,
|
142
|
-
};
|
143
|
-
}
|
144
|
-
/**
|
145
|
-
* Update an entity.
|
146
|
-
*/
|
147
|
-
async update(id, updates) {
|
148
|
-
// If name or description is updated, update embedding
|
149
|
-
let embedding;
|
150
|
-
if (updates.name || updates.description) {
|
151
|
-
const entity = await this.get(id);
|
152
|
-
if (!entity) {
|
153
|
-
throw new Error(`Entity ${id} not found`);
|
154
|
-
}
|
155
|
-
const embeddingText = `${updates.name || entity.name} ${updates.description || entity.description || ''}`.trim();
|
156
|
-
embedding = await this.createEmbedding(embeddingText);
|
157
|
-
}
|
158
|
-
const query = `
|
159
|
-
mutation UpdateEntity($id: uuid!, $updates: entities_set_input!) {
|
160
|
-
update_entities_by_pk(pk_columns: {id: $id}, _set: $updates) {
|
161
|
-
id
|
162
|
-
ref_id
|
163
|
-
type
|
164
|
-
name
|
165
|
-
description
|
166
|
-
metadata
|
167
|
-
status
|
168
|
-
created_at
|
169
|
-
updated_at
|
170
|
-
}
|
171
|
-
}
|
172
|
-
`;
|
173
|
-
const updateData = {
|
174
|
-
ref_id: updates.refId,
|
175
|
-
type: updates.type,
|
176
|
-
name: updates.name,
|
177
|
-
description: updates.description,
|
178
|
-
metadata: updates.metadata,
|
179
|
-
status: updates.status,
|
180
|
-
};
|
181
|
-
if (embedding) {
|
182
|
-
updateData.embedding = `[${embedding.join(',')}]`;
|
183
|
-
}
|
184
|
-
// Remove undefined values
|
185
|
-
Object.keys(updateData).forEach(key => updateData[key] === undefined && delete updateData[key]);
|
186
|
-
const result = await this.executeQuery(query, {
|
187
|
-
id,
|
188
|
-
updates: updateData
|
189
|
-
});
|
190
|
-
// Convert snake_case to camelCase
|
191
|
-
const { ref_id, created_at, updated_at, ...rest } = result.update_entities_by_pk;
|
192
|
-
return {
|
193
|
-
...rest,
|
194
|
-
refId: ref_id,
|
195
|
-
createdAt: created_at,
|
196
|
-
updatedAt: updated_at,
|
197
|
-
};
|
198
|
-
}
|
199
|
-
/**
|
200
|
-
* Delete an entity.
|
201
|
-
*/
|
202
|
-
async delete(id) {
|
203
|
-
const query = `
|
204
|
-
mutation DeleteEntity($id: uuid!) {
|
205
|
-
delete_entities_by_pk(id: $id) {
|
206
|
-
id
|
207
|
-
}
|
208
|
-
}
|
209
|
-
`;
|
210
|
-
const result = await this.executeQuery(query, { id });
|
211
|
-
return result.delete_entities_by_pk !== null;
|
212
|
-
}
|
213
|
-
/**
|
214
|
-
* Search entities by semantic similarity.
|
215
|
-
*/
|
216
|
-
async search(options) {
|
217
|
-
const { query, threshold = 0.7, limit = 10, type, status } = options;
|
218
|
-
// Create embedding for search query
|
219
|
-
const embedding = await this.createEmbedding(query);
|
220
|
-
const embeddingStr = `[${embedding.join(',')}]`;
|
221
|
-
const searchQuery = `
|
222
|
-
query SearchEntities(
|
223
|
-
$embedding: vector!,
|
224
|
-
$threshold: float8!,
|
225
|
-
$limit: Int!,
|
226
|
-
$type: String,
|
227
|
-
$status: String
|
228
|
-
) {
|
229
|
-
entities(
|
230
|
-
where: {
|
231
|
-
_and: [
|
232
|
-
{type: {_eq: $type}},
|
233
|
-
{status: {_eq: $status}}
|
234
|
-
]
|
235
|
-
},
|
236
|
-
order_by: {embedding: {_cosine_distance: $embedding}},
|
237
|
-
limit: $limit
|
238
|
-
) {
|
239
|
-
id
|
240
|
-
ref_id
|
241
|
-
type
|
242
|
-
name
|
243
|
-
description
|
244
|
-
metadata
|
245
|
-
status
|
246
|
-
created_at
|
247
|
-
updated_at
|
248
|
-
similarity: _cosine_similarity_embedding_with($embedding)
|
249
|
-
}
|
250
|
-
}
|
251
|
-
`;
|
252
|
-
const result = await this.executeQuery(searchQuery, {
|
253
|
-
embedding: embeddingStr,
|
254
|
-
threshold,
|
255
|
-
limit,
|
256
|
-
type,
|
257
|
-
status
|
258
|
-
});
|
259
|
-
return result.entities.map(entity => {
|
260
|
-
const { ref_id, created_at, updated_at, ...rest } = entity;
|
261
|
-
return {
|
262
|
-
...rest,
|
263
|
-
refId: ref_id,
|
264
|
-
createdAt: created_at,
|
265
|
-
updatedAt: updated_at,
|
266
|
-
};
|
267
|
-
}).filter(entity => (entity.similarity || 0) >= threshold);
|
268
|
-
}
|
269
|
-
/**
|
270
|
-
* Link an entity to a memory.
|
271
|
-
*/
|
272
|
-
async linkMemory(entityId, memoryId, relationship, confidence) {
|
273
|
-
const query = `
|
274
|
-
mutation LinkEntityMemory($link: entity_memory_links_insert_input!) {
|
275
|
-
insert_entity_memory_links_one(object: $link) {
|
276
|
-
id
|
277
|
-
entity_id
|
278
|
-
memory_id
|
279
|
-
relationship
|
280
|
-
confidence
|
281
|
-
created_at
|
282
|
-
}
|
283
|
-
}
|
284
|
-
`;
|
285
|
-
const result = await this.executeQuery(query, {
|
286
|
-
link: {
|
287
|
-
entity_id: entityId,
|
288
|
-
memory_id: memoryId,
|
289
|
-
relationship,
|
290
|
-
confidence: confidence || 1.0
|
291
|
-
}
|
292
|
-
});
|
293
|
-
// Convert snake_case to camelCase
|
294
|
-
const { entity_id, memory_id, created_at, ...rest } = result.insert_entity_memory_links_one;
|
295
|
-
return {
|
296
|
-
...rest,
|
297
|
-
entityId: entity_id,
|
298
|
-
memoryId: memory_id,
|
299
|
-
createdAt: created_at,
|
300
|
-
};
|
301
|
-
}
|
302
|
-
/**
|
303
|
-
* Get all memories linked to an entity.
|
304
|
-
*/
|
305
|
-
async getLinkedMemories(entityId, relationship) {
|
306
|
-
const query = `
|
307
|
-
query GetLinkedMemories($entityId: uuid!, $relationship: String) {
|
308
|
-
entity_memory_links(
|
309
|
-
where: {
|
310
|
-
entity_id: {_eq: $entityId},
|
311
|
-
relationship: {_eq: $relationship}
|
312
|
-
}
|
313
|
-
) {
|
314
|
-
memory {
|
315
|
-
id
|
316
|
-
agent_id
|
317
|
-
content
|
318
|
-
metadata
|
319
|
-
created_at
|
320
|
-
updated_at
|
321
|
-
expires_at
|
322
|
-
}
|
323
|
-
relationship
|
324
|
-
confidence
|
325
|
-
}
|
326
|
-
}
|
327
|
-
`;
|
328
|
-
const result = await this.executeQuery(query, {
|
329
|
-
entityId,
|
330
|
-
relationship
|
331
|
-
});
|
332
|
-
return result.entity_memory_links.map(link => {
|
333
|
-
const { memory, relationship, confidence } = link;
|
334
|
-
const { agent_id, created_at, updated_at, expires_at, ...rest } = memory;
|
335
|
-
return {
|
336
|
-
...rest,
|
337
|
-
agentId: agent_id,
|
338
|
-
createdAt: created_at,
|
339
|
-
updatedAt: updated_at,
|
340
|
-
expiresAt: expires_at,
|
341
|
-
relationship,
|
342
|
-
confidence
|
343
|
-
};
|
344
|
-
});
|
345
|
-
}
|
346
|
-
}
|
347
|
-
exports.EntityManager = EntityManager;
|