@props-labs/mesh-os 0.1.23 → 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 +337 -0
- package/dist/core/__fixtures__/mock_responses.js +355 -0
- package/dist/core/__fixtures__/sample_embeddings.d.ts +33 -0
- package/dist/core/__fixtures__/sample_embeddings.js +12355 -0
- package/dist/core/agents.d.ts +51 -0
- package/dist/core/agents.js +170 -0
- package/dist/core/client.d.ts +5 -7
- package/dist/core/client.js +5 -16
- package/dist/core/memories.d.ts +138 -0
- package/dist/core/memories.js +417 -0
- package/dist/core/workflows.d.ts +88 -25
- package/dist/core/workflows.js +247 -133
- package/package.json +3 -3
- package/src/templates/hasura/metadata/actions.yaml +6 -0
- package/src/templates/hasura/metadata/cron_triggers.yaml +1 -0
- package/src/templates/hasura/metadata/databases/databases.yaml +1 -1
- package/src/templates/hasura/metadata/databases/default/functions/functions.yaml +80 -0
- package/src/templates/hasura/metadata/databases/default/tables/tables.yaml +274 -9
- package/src/templates/hasura/metadata/query_collections.yaml +1 -0
- package/src/templates/hasura/metadata/rest_endpoints.yaml +1 -0
- package/src/templates/hasura/migrations/default/0_cleanup/down.sql +2 -0
- package/src/templates/hasura/migrations/default/0_cleanup/up.sql +59 -0
- package/src/templates/hasura/migrations/default/1_init/down.sql +27 -21
- package/src/templates/hasura/migrations/default/1_init/up.sql +446 -174
- package/src/templates/hasura/migrations/default/2_sample_data/down.sql +3 -0
- package/src/templates/hasura/migrations/default/2_sample_data/up.sql +288 -0
- package/src/templates/hasura/migrations/default/3_agent_relations/down.sql +76 -0
- package/src/templates/hasura/migrations/default/3_agent_relations/up.sql +469 -0
- package/dist/core/entities.d.ts +0 -58
- package/dist/core/entities.js +0 -347
- package/src/templates/hasura/metadata/config.yaml +0 -1
- package/src/templates/hasura/metadata/databases/default/tables/public_agents.yaml +0 -14
- package/src/templates/hasura/metadata/databases/default/tables/public_memories.yaml +0 -23
- package/src/templates/hasura/metadata/databases/default/tables/public_memory_edges.yaml +0 -57
- package/src/templates/hasura/metadata/databases/default/tables/track_tables.yaml +0 -14
- package/src/templates/hasura/metadata/metadata.json +0 -80
- package/src/templates/hasura/migrations/default/2_metadata_filtering/down.sql +0 -4
- package/src/templates/hasura/migrations/default/2_metadata_filtering/up.sql +0 -44
- package/src/templates/hasura/migrations/default/3_memory_expiry/down.sql +0 -55
- package/src/templates/hasura/migrations/default/3_memory_expiry/up.sql +0 -108
- package/src/templates/hasura/migrations/default/4_remove_slug_validation/down.sql +0 -20
- package/src/templates/hasura/migrations/default/4_remove_slug_validation/up.sql +0 -5
- package/src/templates/hasura/migrations/default/5_entities/down.sql +0 -13
- package/src/templates/hasura/migrations/default/5_entities/up.sql +0 -155
@@ -1,108 +0,0 @@
|
|
1
|
-
-- Add expires_at column to memories table
|
2
|
-
ALTER TABLE public.memories ADD COLUMN expires_at TIMESTAMPTZ;
|
3
|
-
|
4
|
-
-- Create a view for memories with similarity that includes all fields
|
5
|
-
DROP VIEW IF EXISTS public.memories_with_similarity;
|
6
|
-
CREATE OR REPLACE VIEW public.memories_with_similarity AS
|
7
|
-
SELECT
|
8
|
-
m.*,
|
9
|
-
0::float8 as similarity -- Default similarity, will be replaced in search
|
10
|
-
FROM memories m;
|
11
|
-
|
12
|
-
-- Drop the existing search_memories function
|
13
|
-
DROP FUNCTION IF EXISTS public.search_memories;
|
14
|
-
|
15
|
-
-- Create the updated search_memories function with standard Hasura filtering
|
16
|
-
CREATE OR REPLACE FUNCTION public.search_memories(
|
17
|
-
query_embedding vector(1536),
|
18
|
-
match_threshold float8,
|
19
|
-
match_count integer,
|
20
|
-
filter_agent_id uuid DEFAULT NULL,
|
21
|
-
metadata_filter jsonb DEFAULT NULL,
|
22
|
-
created_at_filter jsonb DEFAULT NULL,
|
23
|
-
expires_at_filter jsonb DEFAULT NULL
|
24
|
-
)
|
25
|
-
RETURNS SETOF public.memories_with_similarity
|
26
|
-
LANGUAGE sql
|
27
|
-
STABLE
|
28
|
-
AS $$
|
29
|
-
WITH normalized_query AS (
|
30
|
-
SELECT l2_normalize(query_embedding) AS normalized_vector
|
31
|
-
)
|
32
|
-
SELECT
|
33
|
-
m.id,
|
34
|
-
m.agent_id,
|
35
|
-
m.content,
|
36
|
-
m.metadata,
|
37
|
-
m.embedding,
|
38
|
-
m.created_at,
|
39
|
-
m.updated_at,
|
40
|
-
m.expires_at,
|
41
|
-
-(m.embedding <#> (SELECT normalized_vector FROM normalized_query)) as similarity
|
42
|
-
FROM memories m
|
43
|
-
WHERE
|
44
|
-
CASE
|
45
|
-
WHEN filter_agent_id IS NOT NULL THEN m.agent_id = filter_agent_id
|
46
|
-
ELSE TRUE
|
47
|
-
END
|
48
|
-
AND CASE
|
49
|
-
WHEN metadata_filter IS NOT NULL THEN m.metadata @> metadata_filter
|
50
|
-
ELSE TRUE
|
51
|
-
END
|
52
|
-
AND CASE
|
53
|
-
WHEN created_at_filter IS NOT NULL THEN (
|
54
|
-
CASE
|
55
|
-
WHEN created_at_filter ? '_gt' THEN m.created_at > (created_at_filter->>'_gt')::timestamptz
|
56
|
-
ELSE TRUE
|
57
|
-
END
|
58
|
-
AND CASE
|
59
|
-
WHEN created_at_filter ? '_gte' THEN m.created_at >= (created_at_filter->>'_gte')::timestamptz
|
60
|
-
ELSE TRUE
|
61
|
-
END
|
62
|
-
AND CASE
|
63
|
-
WHEN created_at_filter ? '_lt' THEN m.created_at < (created_at_filter->>'_lt')::timestamptz
|
64
|
-
ELSE TRUE
|
65
|
-
END
|
66
|
-
AND CASE
|
67
|
-
WHEN created_at_filter ? '_lte' THEN m.created_at <= (created_at_filter->>'_lte')::timestamptz
|
68
|
-
ELSE TRUE
|
69
|
-
END
|
70
|
-
AND CASE
|
71
|
-
WHEN created_at_filter ? '_eq' THEN m.created_at = (created_at_filter->>'_eq')::timestamptz
|
72
|
-
ELSE TRUE
|
73
|
-
END
|
74
|
-
)
|
75
|
-
ELSE TRUE
|
76
|
-
END
|
77
|
-
AND CASE
|
78
|
-
WHEN expires_at_filter IS NOT NULL THEN (
|
79
|
-
CASE
|
80
|
-
WHEN expires_at_filter ? '_gt' THEN m.expires_at > (expires_at_filter->>'_gt')::timestamptz
|
81
|
-
ELSE TRUE
|
82
|
-
END
|
83
|
-
AND CASE
|
84
|
-
WHEN expires_at_filter ? '_gte' THEN m.expires_at >= (expires_at_filter->>'_gte')::timestamptz
|
85
|
-
ELSE TRUE
|
86
|
-
END
|
87
|
-
AND CASE
|
88
|
-
WHEN expires_at_filter ? '_lt' THEN m.expires_at < (expires_at_filter->>'_lt')::timestamptz
|
89
|
-
ELSE TRUE
|
90
|
-
END
|
91
|
-
AND CASE
|
92
|
-
WHEN expires_at_filter ? '_lte' THEN m.expires_at <= (expires_at_filter->>'_lte')::timestamptz
|
93
|
-
ELSE TRUE
|
94
|
-
END
|
95
|
-
AND CASE
|
96
|
-
WHEN expires_at_filter ? '_eq' THEN m.expires_at = (expires_at_filter->>'_eq')::timestamptz
|
97
|
-
ELSE TRUE
|
98
|
-
END
|
99
|
-
)
|
100
|
-
ELSE TRUE
|
101
|
-
END
|
102
|
-
AND -(m.embedding <#> (SELECT normalized_vector FROM normalized_query)) >= match_threshold
|
103
|
-
ORDER BY -(m.embedding <#> (SELECT normalized_vector FROM normalized_query)) DESC
|
104
|
-
LIMIT match_count;
|
105
|
-
$$;
|
106
|
-
|
107
|
-
-- Track the function in Hasura
|
108
|
-
COMMENT ON FUNCTION public.search_memories IS E'@graphql({"type": "Query"})';
|
@@ -1,20 +0,0 @@
|
|
1
|
-
-- First drop the constraint since it depends on the function
|
2
|
-
ALTER TABLE public.agents DROP CONSTRAINT IF EXISTS valid_slug;
|
3
|
-
|
4
|
-
-- Now we can safely drop and recreate the function
|
5
|
-
DROP FUNCTION IF EXISTS validate_slug(text);
|
6
|
-
CREATE OR REPLACE FUNCTION validate_slug(slug text)
|
7
|
-
RETURNS boolean AS $$
|
8
|
-
BEGIN
|
9
|
-
RETURN slug ~ '^[a-z][a-z0-9_-]*[a-z0-9]$';
|
10
|
-
END;
|
11
|
-
$$ LANGUAGE plpgsql IMMUTABLE;
|
12
|
-
|
13
|
-
-- Update any existing invalid slugs to NULL
|
14
|
-
UPDATE public.agents
|
15
|
-
SET slug = NULL
|
16
|
-
WHERE slug IS NOT NULL AND NOT validate_slug(slug);
|
17
|
-
|
18
|
-
-- Finally add back the constraint
|
19
|
-
ALTER TABLE public.agents
|
20
|
-
ADD CONSTRAINT valid_slug CHECK (slug IS NULL OR validate_slug(slug));
|
@@ -1,13 +0,0 @@
|
|
1
|
-
-- Drop the combined search function
|
2
|
-
DROP FUNCTION IF EXISTS search_memories_and_entities;
|
3
|
-
|
4
|
-
-- Drop the combined search results view
|
5
|
-
DROP VIEW IF EXISTS public.search_results_with_similarity;
|
6
|
-
|
7
|
-
-- Drop triggers
|
8
|
-
DROP TRIGGER IF EXISTS update_entities_updated_at ON public.entities;
|
9
|
-
DROP TRIGGER IF EXISTS normalize_entity_embedding ON public.entities;
|
10
|
-
|
11
|
-
-- Drop tables (order matters due to foreign key constraints)
|
12
|
-
DROP TABLE IF EXISTS public.entity_memory_links;
|
13
|
-
DROP TABLE IF EXISTS public.entities;
|
@@ -1,155 +0,0 @@
|
|
1
|
-
-- Create entities table with embedding support
|
2
|
-
CREATE TABLE IF NOT EXISTS public.entities (
|
3
|
-
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
4
|
-
ref_id TEXT UNIQUE,
|
5
|
-
type TEXT NOT NULL,
|
6
|
-
name TEXT NOT NULL,
|
7
|
-
description TEXT,
|
8
|
-
metadata JSONB,
|
9
|
-
embedding vector(1536),
|
10
|
-
status TEXT NOT NULL DEFAULT 'active',
|
11
|
-
created_at TIMESTAMPTZ DEFAULT NOW(),
|
12
|
-
updated_at TIMESTAMPTZ DEFAULT NOW()
|
13
|
-
);
|
14
|
-
|
15
|
-
-- Create entity-memory links table
|
16
|
-
CREATE TABLE IF NOT EXISTS public.entity_memory_links (
|
17
|
-
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
18
|
-
entity_id UUID NOT NULL REFERENCES public.entities(id) ON DELETE CASCADE,
|
19
|
-
memory_id UUID NOT NULL REFERENCES public.memories(id) ON DELETE CASCADE,
|
20
|
-
relationship TEXT NOT NULL,
|
21
|
-
confidence FLOAT DEFAULT 1.0,
|
22
|
-
metadata JSONB,
|
23
|
-
created_at TIMESTAMPTZ DEFAULT NOW(),
|
24
|
-
UNIQUE(entity_id, memory_id, relationship)
|
25
|
-
);
|
26
|
-
|
27
|
-
-- Create index for vector similarity search
|
28
|
-
CREATE INDEX IF NOT EXISTS idx_entities_embedding
|
29
|
-
ON public.entities USING ivfflat (embedding vector_cosine_ops)
|
30
|
-
WITH (lists = 100);
|
31
|
-
|
32
|
-
-- Create trigger for updated_at
|
33
|
-
CREATE TRIGGER update_entities_updated_at
|
34
|
-
BEFORE UPDATE ON public.entities
|
35
|
-
FOR EACH ROW
|
36
|
-
EXECUTE FUNCTION update_updated_at_column();
|
37
|
-
|
38
|
-
-- Add normalization trigger for entities
|
39
|
-
CREATE TRIGGER normalize_entity_embedding
|
40
|
-
BEFORE INSERT OR UPDATE OF embedding ON public.entities
|
41
|
-
FOR EACH ROW
|
42
|
-
EXECUTE FUNCTION normalize_embedding();
|
43
|
-
|
44
|
-
-- Create a view for combined search results
|
45
|
-
CREATE OR REPLACE VIEW public.search_results_with_similarity AS
|
46
|
-
SELECT
|
47
|
-
id,
|
48
|
-
'memory'::text as type,
|
49
|
-
content,
|
50
|
-
metadata,
|
51
|
-
0::float8 as similarity
|
52
|
-
FROM memories
|
53
|
-
UNION ALL
|
54
|
-
SELECT
|
55
|
-
id,
|
56
|
-
'entity'::text as type,
|
57
|
-
name as content,
|
58
|
-
metadata,
|
59
|
-
0::float8 as similarity
|
60
|
-
FROM entities;
|
61
|
-
|
62
|
-
-- Create combined search function
|
63
|
-
CREATE OR REPLACE FUNCTION search_memories_and_entities(
|
64
|
-
query_embedding vector(1536),
|
65
|
-
match_threshold float8,
|
66
|
-
match_count integer,
|
67
|
-
include_entities boolean DEFAULT true,
|
68
|
-
include_memories boolean DEFAULT true,
|
69
|
-
metadata_filter jsonb DEFAULT NULL,
|
70
|
-
created_at_filter jsonb DEFAULT NULL
|
71
|
-
)
|
72
|
-
RETURNS SETOF public.search_results_with_similarity
|
73
|
-
LANGUAGE sql STABLE AS $$
|
74
|
-
WITH normalized_query AS (
|
75
|
-
SELECT l2_normalize(query_embedding) AS normalized_vector
|
76
|
-
)
|
77
|
-
(
|
78
|
-
SELECT
|
79
|
-
m.id,
|
80
|
-
'memory'::text as type,
|
81
|
-
m.content,
|
82
|
-
m.metadata,
|
83
|
-
-(m.embedding <#> (SELECT normalized_vector FROM normalized_query)) as similarity
|
84
|
-
FROM memories m
|
85
|
-
WHERE include_memories = true
|
86
|
-
AND CASE
|
87
|
-
WHEN metadata_filter IS NOT NULL THEN m.metadata @> metadata_filter
|
88
|
-
ELSE TRUE
|
89
|
-
END
|
90
|
-
AND CASE
|
91
|
-
WHEN created_at_filter IS NOT NULL THEN (
|
92
|
-
CASE
|
93
|
-
WHEN created_at_filter ? '_gt' THEN m.created_at > (created_at_filter->>'_gt')::timestamptz
|
94
|
-
ELSE TRUE
|
95
|
-
END
|
96
|
-
AND CASE
|
97
|
-
WHEN created_at_filter ? '_gte' THEN m.created_at >= (created_at_filter->>'_gte')::timestamptz
|
98
|
-
ELSE TRUE
|
99
|
-
END
|
100
|
-
AND CASE
|
101
|
-
WHEN created_at_filter ? '_lt' THEN m.created_at < (created_at_filter->>'_lt')::timestamptz
|
102
|
-
ELSE TRUE
|
103
|
-
END
|
104
|
-
AND CASE
|
105
|
-
WHEN created_at_filter ? '_lte' THEN m.created_at <= (created_at_filter->>'_lte')::timestamptz
|
106
|
-
ELSE TRUE
|
107
|
-
END
|
108
|
-
)
|
109
|
-
ELSE TRUE
|
110
|
-
END
|
111
|
-
AND -(m.embedding <#> (SELECT normalized_vector FROM normalized_query)) >= match_threshold
|
112
|
-
)
|
113
|
-
UNION ALL
|
114
|
-
(
|
115
|
-
SELECT
|
116
|
-
e.id,
|
117
|
-
'entity'::text as type,
|
118
|
-
e.name as content,
|
119
|
-
e.metadata,
|
120
|
-
-(e.embedding <#> (SELECT normalized_vector FROM normalized_query)) as similarity
|
121
|
-
FROM entities e
|
122
|
-
WHERE include_entities = true
|
123
|
-
AND CASE
|
124
|
-
WHEN metadata_filter IS NOT NULL THEN e.metadata @> metadata_filter
|
125
|
-
ELSE TRUE
|
126
|
-
END
|
127
|
-
AND CASE
|
128
|
-
WHEN created_at_filter IS NOT NULL THEN (
|
129
|
-
CASE
|
130
|
-
WHEN created_at_filter ? '_gt' THEN e.created_at > (created_at_filter->>'_gt')::timestamptz
|
131
|
-
ELSE TRUE
|
132
|
-
END
|
133
|
-
AND CASE
|
134
|
-
WHEN created_at_filter ? '_gte' THEN e.created_at >= (created_at_filter->>'_gte')::timestamptz
|
135
|
-
ELSE TRUE
|
136
|
-
END
|
137
|
-
AND CASE
|
138
|
-
WHEN created_at_filter ? '_lt' THEN e.created_at < (created_at_filter->>'_lt')::timestamptz
|
139
|
-
ELSE TRUE
|
140
|
-
END
|
141
|
-
AND CASE
|
142
|
-
WHEN created_at_filter ? '_lte' THEN e.created_at <= (created_at_filter->>'_lte')::timestamptz
|
143
|
-
ELSE TRUE
|
144
|
-
END
|
145
|
-
)
|
146
|
-
ELSE TRUE
|
147
|
-
END
|
148
|
-
AND -(e.embedding <#> (SELECT normalized_vector FROM normalized_query)) >= match_threshold
|
149
|
-
)
|
150
|
-
ORDER BY similarity DESC
|
151
|
-
LIMIT match_count;
|
152
|
-
$$;
|
153
|
-
|
154
|
-
-- Track the function in Hasura
|
155
|
-
COMMENT ON FUNCTION search_memories_and_entities IS E'@graphql({"type": "Query"})';
|