@props-labs/mesh-os 0.1.20 → 0.1.23

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.
@@ -1,5 +1,6 @@
1
1
  import { EdgeType, type AgentStatus, type EdgeMetadata, type MemoryMetadata, type TimestampFilter, EntityRelationshipType } from './taxonomy';
2
2
  import { EntityManager } from './entities';
3
+ import { WorkflowManager } from './workflows';
3
4
  /**
4
5
  * An agent in the system.
5
6
  */
@@ -76,6 +77,7 @@ export declare class MeshOS {
76
77
  private headers;
77
78
  private openai;
78
79
  entities: EntityManager;
80
+ workflows: WorkflowManager;
79
81
  constructor(config?: MeshOSConfig);
80
82
  private validateSlug;
81
83
  /**
@@ -117,7 +119,7 @@ export declare class MeshOS {
117
119
  /**
118
120
  * Create a link between two memories.
119
121
  */
120
- linkMemories(sourceMemoryId: string, targetMemoryId: string, relationship: EdgeType, weight?: number, metadata?: Partial<EdgeMetadata>): Promise<MemoryEdge>;
122
+ linkMemories(sourceMemoryId: string, targetMemoryId: string, relationship: EdgeType, weight?: number): Promise<MemoryEdge>;
121
123
  /**
122
124
  * Remove links between two memories.
123
125
  */
@@ -12,6 +12,7 @@ const chalk_1 = __importDefault(require("chalk"));
12
12
  const boxen_1 = __importDefault(require("boxen"));
13
13
  const taxonomy_1 = require("./taxonomy");
14
14
  const entities_1 = require("./entities");
15
+ const workflows_1 = require("./workflows");
15
16
  // Constants
16
17
  const SLUG_PATTERN = /^[a-zA-Z0-9_-]+$/;
17
18
  /**
@@ -61,8 +62,9 @@ class MeshOS {
61
62
  throw new Error('OpenAI API key is required');
62
63
  }
63
64
  this.openai = new openai_1.default({ apiKey: openaiApiKey });
64
- // Initialize entity manager
65
+ // Initialize managers
65
66
  this.entities = new entities_1.EntityManager(this.url, this.headers, this.createEmbedding.bind(this));
67
+ this.workflows = new workflows_1.WorkflowManager(this.url, this.headers);
66
68
  }
67
69
  validateSlug(slug) {
68
70
  return SLUG_PATTERN.test(slug);
@@ -339,19 +341,9 @@ class MeshOS {
339
341
  memories.push(memory);
340
342
  // Link chunks sequentially
341
343
  if (previousChunkId) {
342
- await this.linkMemories(previousChunkId, memory.id, taxonomy_1.EdgeType.FOLLOWS_UP, 1.0, {
343
- relationship: taxonomy_1.EdgeType.FOLLOWS_UP,
344
- weight: 1.0,
345
- bidirectional: false,
346
- additional: { is_chunk_link: true }
347
- });
344
+ await this.linkMemories(previousChunkId, memory.id, taxonomy_1.EdgeType.FOLLOWS_UP, 1.0);
348
345
  // Also add PART_OF relationship to show these are parts of the same content
349
- await this.linkMemories(memory.id, previousChunkId, taxonomy_1.EdgeType.PART_OF, 1.0, {
350
- relationship: taxonomy_1.EdgeType.PART_OF,
351
- weight: 1.0,
352
- bidirectional: true,
353
- additional: { is_chunk_link: true }
354
- });
346
+ await this.linkMemories(memory.id, previousChunkId, taxonomy_1.EdgeType.PART_OF, 1.0);
355
347
  }
356
348
  previousChunkId = memory.id;
357
349
  }
@@ -376,21 +368,19 @@ class MeshOS {
376
368
  /**
377
369
  * Create a link between two memories.
378
370
  */
379
- async linkMemories(sourceMemoryId, targetMemoryId, relationship, weight = 1.0, metadata) {
371
+ async linkMemories(sourceMemoryId, targetMemoryId, relationship, weight = 1.0) {
380
372
  const query = `
381
373
  mutation LinkMemories(
382
374
  $sourceMemory: uuid!,
383
375
  $targetMemory: uuid!,
384
376
  $relationship: String!,
385
- $weight: float8!,
386
- $metadata: jsonb!
377
+ $weight: float8!
387
378
  ) {
388
379
  insert_memory_edges_one(object: {
389
380
  source_memory: $sourceMemory,
390
381
  target_memory: $targetMemory,
391
382
  relationship: $relationship,
392
- weight: $weight,
393
- metadata: $metadata
383
+ weight: $weight
394
384
  }) {
395
385
  id
396
386
  source_memory
@@ -398,23 +388,14 @@ class MeshOS {
398
388
  relationship
399
389
  weight
400
390
  created_at
401
- metadata
402
391
  }
403
392
  }
404
393
  `;
405
- const fullMetadata = {
406
- relationship,
407
- weight,
408
- bidirectional: false,
409
- additional: {},
410
- ...metadata
411
- };
412
394
  const result = await this.executeQuery(query, {
413
395
  sourceMemory: sourceMemoryId,
414
396
  targetMemory: targetMemoryId,
415
397
  relationship,
416
- weight,
417
- metadata: fullMetadata
398
+ weight
418
399
  });
419
400
  // Convert snake_case to camelCase
420
401
  const { source_memory, target_memory, created_at, ...rest } = result.insert_memory_edges_one;
@@ -484,12 +465,7 @@ class MeshOS {
484
465
  if (createVersionEdge) {
485
466
  // If we got multiple memories (chunks), link the first one
486
467
  const firstNewMemory = Array.isArray(newMemories) ? newMemories[0] : newMemories;
487
- await this.linkMemories(oldMemory.id, firstNewMemory.id, taxonomy_1.EdgeType.VERSION_OF, 1.0, {
488
- relationship: taxonomy_1.EdgeType.VERSION_OF,
489
- weight: 1.0,
490
- bidirectional: false,
491
- additional: { version_increment: 1 }
492
- });
468
+ await this.linkMemories(oldMemory.id, firstNewMemory.id, taxonomy_1.EdgeType.VERSION_OF, 1.0);
493
469
  }
494
470
  return newMemories;
495
471
  }
@@ -168,6 +168,18 @@ export declare const CoreAgentStatus: {
168
168
  readonly PAUSED: "paused";
169
169
  };
170
170
  export type AgentStatus = typeof CoreAgentStatus[keyof typeof CoreAgentStatus] | string;
171
+ /**
172
+ * Core workflow status types.
173
+ * The type allows for both predefined and custom status strings.
174
+ */
175
+ export declare const CoreWorkflowStatus: {
176
+ readonly PENDING: "pending";
177
+ readonly RUNNING: "running";
178
+ readonly COMPLETED: "completed";
179
+ readonly FAILED: "failed";
180
+ readonly CANCELLED: "cancelled";
181
+ };
182
+ export type WorkflowStatus = typeof CoreWorkflowStatus[keyof typeof CoreWorkflowStatus] | string;
171
183
  /**
172
184
  * Version history entry.
173
185
  */
@@ -320,3 +332,35 @@ export interface TimestampFilter {
320
332
  _lte?: string;
321
333
  _eq?: string;
322
334
  }
335
+ /**
336
+ * Workflow schema definition.
337
+ */
338
+ export declare const workflowSchema: z.ZodObject<{
339
+ id: z.ZodOptional<z.ZodString>;
340
+ jobId: z.ZodString;
341
+ type: z.ZodString;
342
+ status: z.ZodDefault<z.ZodString>;
343
+ result: z.ZodOptional<z.ZodUnknown>;
344
+ metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
345
+ createdAt: z.ZodOptional<z.ZodString>;
346
+ updatedAt: z.ZodOptional<z.ZodString>;
347
+ }, "strip", z.ZodTypeAny, {
348
+ type: string;
349
+ status: string;
350
+ metadata: Record<string, unknown>;
351
+ jobId: string;
352
+ id?: string | undefined;
353
+ createdAt?: string | undefined;
354
+ updatedAt?: string | undefined;
355
+ result?: unknown;
356
+ }, {
357
+ type: string;
358
+ jobId: string;
359
+ id?: string | undefined;
360
+ status?: string | undefined;
361
+ metadata?: Record<string, unknown> | undefined;
362
+ createdAt?: string | undefined;
363
+ updatedAt?: string | undefined;
364
+ result?: unknown;
365
+ }>;
366
+ export type Workflow = z.infer<typeof workflowSchema>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.edgeMetadataSchema = exports.memoryMetadataSchema = exports.CoreAgentStatus = exports.RelevanceTag = exports.EdgeType = exports.MediaSubtype = exports.DecisionSubtype = exports.KnowledgeSubtype = exports.ActivitySubtype = exports.entityMemoryLinkSchema = exports.entitySchema = exports.EntityStatus = exports.EntityRelationshipType = exports.DataType = void 0;
3
+ exports.workflowSchema = exports.edgeMetadataSchema = exports.memoryMetadataSchema = exports.CoreWorkflowStatus = exports.CoreAgentStatus = exports.RelevanceTag = exports.EdgeType = exports.MediaSubtype = exports.DecisionSubtype = exports.KnowledgeSubtype = exports.ActivitySubtype = exports.entityMemoryLinkSchema = exports.entitySchema = exports.EntityStatus = exports.EntityRelationshipType = exports.DataType = void 0;
4
4
  /**
5
5
  * Taxonomy and classification models for MeshOS.
6
6
  */
@@ -143,6 +143,17 @@ exports.CoreAgentStatus = {
143
143
  ERROR: 'error',
144
144
  PAUSED: 'paused'
145
145
  };
146
+ /**
147
+ * Core workflow status types.
148
+ * The type allows for both predefined and custom status strings.
149
+ */
150
+ exports.CoreWorkflowStatus = {
151
+ PENDING: 'pending',
152
+ RUNNING: 'running',
153
+ COMPLETED: 'completed',
154
+ FAILED: 'failed',
155
+ CANCELLED: 'cancelled'
156
+ };
146
157
  /**
147
158
  * Standardized metadata structure for memories.
148
159
  */
@@ -187,3 +198,16 @@ exports.edgeMetadataSchema = zod_1.z.object({
187
198
  bidirectional: zod_1.z.boolean().default(false),
188
199
  additional: zod_1.z.record(zod_1.z.unknown()).default({}),
189
200
  });
201
+ /**
202
+ * Workflow schema definition.
203
+ */
204
+ exports.workflowSchema = zod_1.z.object({
205
+ id: zod_1.z.string().uuid().optional(),
206
+ jobId: zod_1.z.string(),
207
+ type: zod_1.z.string(),
208
+ status: zod_1.z.string().default(exports.CoreWorkflowStatus.PENDING),
209
+ result: zod_1.z.unknown().optional(),
210
+ metadata: zod_1.z.record(zod_1.z.unknown()).default({}),
211
+ createdAt: zod_1.z.string().optional(),
212
+ updatedAt: zod_1.z.string().optional(),
213
+ });
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Workflow management functionality for MeshOS.
3
+ */
4
+ import { Workflow } from './taxonomy';
5
+ export declare class WorkflowManager {
6
+ private url;
7
+ private headers;
8
+ constructor(url: string, headers: Record<string, string>);
9
+ /**
10
+ * Execute a GraphQL query.
11
+ */
12
+ private executeQuery;
13
+ /**
14
+ * Get a workflow by job ID.
15
+ */
16
+ getByJobId(jobId: string): Promise<Workflow | null>;
17
+ /**
18
+ * Create a new workflow.
19
+ */
20
+ create(workflow: Omit<Workflow, 'id' | 'createdAt' | 'updatedAt'>): Promise<Workflow>;
21
+ /**
22
+ * Get a workflow by ID.
23
+ */
24
+ get(id: string): Promise<Workflow | null>;
25
+ /**
26
+ * Get workflows with optional filtering and sorting.
27
+ */
28
+ list(options?: {
29
+ where?: Record<string, unknown>;
30
+ orderBy?: Array<{
31
+ column: string;
32
+ order: 'asc' | 'desc';
33
+ }>;
34
+ limit?: number;
35
+ offset?: number;
36
+ }): Promise<Workflow[]>;
37
+ /**
38
+ * Update a workflow.
39
+ */
40
+ update(id: string, updates: Partial<Omit<Workflow, 'id' | 'createdAt' | 'updatedAt'>>): Promise<Workflow>;
41
+ /**
42
+ * Delete a workflow.
43
+ */
44
+ delete(id: string): Promise<boolean>;
45
+ }
@@ -0,0 +1,243 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkflowManager = void 0;
4
+ /**
5
+ * Workflow management functionality for MeshOS.
6
+ */
7
+ const taxonomy_1 = require("./taxonomy");
8
+ class WorkflowManager {
9
+ constructor(url, headers) {
10
+ this.url = url;
11
+ this.headers = headers;
12
+ }
13
+ /**
14
+ * Execute a GraphQL query.
15
+ */
16
+ async executeQuery(query, variables) {
17
+ const response = await fetch(this.url, {
18
+ method: 'POST',
19
+ headers: this.headers,
20
+ body: JSON.stringify({
21
+ query,
22
+ variables: variables || {}
23
+ })
24
+ });
25
+ if (!response.ok) {
26
+ throw new Error(`HTTP error! status: ${response.status}`);
27
+ }
28
+ const result = await response.json();
29
+ if (result.errors) {
30
+ throw new Error(result.errors[0].message);
31
+ }
32
+ return result.data;
33
+ }
34
+ /**
35
+ * Get a workflow by job ID.
36
+ */
37
+ async getByJobId(jobId) {
38
+ const query = `
39
+ query GetWorkflowByJobId($jobId: String!) {
40
+ workflows(where: {job_id: {_eq: $jobId}}, limit: 1) {
41
+ id
42
+ job_id
43
+ type
44
+ status
45
+ result
46
+ metadata
47
+ created_at
48
+ updated_at
49
+ }
50
+ }
51
+ `;
52
+ const result = await this.executeQuery(query, { jobId });
53
+ if (!result.workflows[0]) {
54
+ return null;
55
+ }
56
+ // Convert snake_case to camelCase
57
+ const { job_id, created_at, updated_at, ...rest } = result.workflows[0];
58
+ return {
59
+ ...rest,
60
+ jobId: job_id,
61
+ createdAt: created_at,
62
+ updatedAt: updated_at,
63
+ };
64
+ }
65
+ /**
66
+ * Create a new workflow.
67
+ */
68
+ async create(workflow) {
69
+ // Validate workflow data
70
+ const validatedData = taxonomy_1.workflowSchema.omit({ id: true, createdAt: true, updatedAt: true }).parse(workflow);
71
+ const query = `
72
+ mutation CreateWorkflow($workflow: workflows_insert_input!) {
73
+ insert_workflows_one(object: $workflow) {
74
+ id
75
+ job_id
76
+ type
77
+ status
78
+ result
79
+ metadata
80
+ created_at
81
+ updated_at
82
+ }
83
+ }
84
+ `;
85
+ const result = await this.executeQuery(query, {
86
+ workflow: {
87
+ job_id: validatedData.jobId,
88
+ type: validatedData.type,
89
+ status: validatedData.status,
90
+ result: validatedData.result,
91
+ metadata: validatedData.metadata
92
+ }
93
+ });
94
+ // Convert snake_case to camelCase
95
+ const { job_id, created_at, updated_at, ...rest } = result.insert_workflows_one;
96
+ return {
97
+ ...rest,
98
+ jobId: job_id,
99
+ createdAt: created_at,
100
+ updatedAt: updated_at,
101
+ };
102
+ }
103
+ /**
104
+ * Get a workflow by ID.
105
+ */
106
+ async get(id) {
107
+ const query = `
108
+ query GetWorkflow($id: uuid!) {
109
+ workflows_by_pk(id: $id) {
110
+ id
111
+ job_id
112
+ type
113
+ status
114
+ result
115
+ metadata
116
+ created_at
117
+ updated_at
118
+ }
119
+ }
120
+ `;
121
+ const result = await this.executeQuery(query, { id });
122
+ if (!result.workflows_by_pk) {
123
+ return null;
124
+ }
125
+ // Convert snake_case to camelCase
126
+ const { job_id, created_at, updated_at, ...rest } = result.workflows_by_pk;
127
+ return {
128
+ ...rest,
129
+ jobId: job_id,
130
+ createdAt: created_at,
131
+ updatedAt: updated_at,
132
+ };
133
+ }
134
+ /**
135
+ * Get workflows with optional filtering and sorting.
136
+ */
137
+ async list(options = {}) {
138
+ const { where, orderBy = [{ column: 'createdAt', order: 'desc' }], limit, offset } = options;
139
+ // Convert orderBy to Hasura format
140
+ const hasuraOrderBy = orderBy.map(({ column, order }) => {
141
+ // Convert camelCase to snake_case for column names
142
+ const snakeCaseColumn = column.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
143
+ return { [snakeCaseColumn]: order };
144
+ });
145
+ const query = `
146
+ query GetWorkflows(
147
+ $where: workflows_bool_exp,
148
+ $orderBy: [workflows_order_by!],
149
+ $limit: Int,
150
+ $offset: Int
151
+ ) {
152
+ workflows(
153
+ where: $where,
154
+ order_by: $orderBy,
155
+ limit: $limit,
156
+ offset: $offset
157
+ ) {
158
+ id
159
+ job_id
160
+ type
161
+ status
162
+ result
163
+ metadata
164
+ created_at
165
+ updated_at
166
+ }
167
+ }
168
+ `;
169
+ const result = await this.executeQuery(query, {
170
+ where,
171
+ orderBy: hasuraOrderBy,
172
+ limit,
173
+ offset
174
+ });
175
+ return result.workflows.map(workflow => {
176
+ const { job_id, created_at, updated_at, ...rest } = workflow;
177
+ return {
178
+ ...rest,
179
+ jobId: job_id,
180
+ createdAt: created_at,
181
+ updatedAt: updated_at,
182
+ };
183
+ });
184
+ }
185
+ /**
186
+ * Update a workflow.
187
+ */
188
+ async update(id, updates) {
189
+ const query = `
190
+ mutation UpdateWorkflow($id: uuid!, $updates: workflows_set_input!) {
191
+ update_workflows_by_pk(pk_columns: {id: $id}, _set: $updates) {
192
+ id
193
+ job_id
194
+ type
195
+ status
196
+ result
197
+ metadata
198
+ created_at
199
+ updated_at
200
+ }
201
+ }
202
+ `;
203
+ // Convert camelCase to snake_case for update fields
204
+ const updateData = {};
205
+ if (updates.jobId !== undefined)
206
+ updateData.job_id = updates.jobId;
207
+ if (updates.type !== undefined)
208
+ updateData.type = updates.type;
209
+ if (updates.status !== undefined)
210
+ updateData.status = updates.status;
211
+ if (updates.result !== undefined)
212
+ updateData.result = updates.result;
213
+ if (updates.metadata !== undefined)
214
+ updateData.metadata = updates.metadata;
215
+ const result = await this.executeQuery(query, {
216
+ id,
217
+ updates: updateData
218
+ });
219
+ // Convert snake_case to camelCase
220
+ const { job_id, created_at, updated_at, ...rest } = result.update_workflows_by_pk;
221
+ return {
222
+ ...rest,
223
+ jobId: job_id,
224
+ createdAt: created_at,
225
+ updatedAt: updated_at,
226
+ };
227
+ }
228
+ /**
229
+ * Delete a workflow.
230
+ */
231
+ async delete(id) {
232
+ const query = `
233
+ mutation DeleteWorkflow($id: uuid!) {
234
+ delete_workflows_by_pk(id: $id) {
235
+ id
236
+ }
237
+ }
238
+ `;
239
+ const result = await this.executeQuery(query, { id });
240
+ return result.delete_workflows_by_pk !== null;
241
+ }
242
+ }
243
+ exports.WorkflowManager = WorkflowManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@props-labs/mesh-os",
3
- "version": "0.1.20",
3
+ "version": "0.1.23",
4
4
  "description": "MeshOS - A memory system for AI agents",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",