agentic-flow 1.8.11 → 1.8.14
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/CHANGELOG.md +58 -0
- package/dist/agents/claudeAgentDirect.js +168 -0
- package/dist/cli/federation-cli.d.ts +53 -0
- package/dist/cli/federation-cli.js +431 -0
- package/dist/cli-proxy.js +32 -4
- package/dist/federation/EphemeralAgent.js +258 -0
- package/dist/federation/FederationHub.js +283 -0
- package/dist/federation/FederationHubClient.js +212 -0
- package/dist/federation/FederationHubServer.js +436 -0
- package/dist/federation/SecurityManager.js +191 -0
- package/dist/federation/debug/agent-debug-stream.js +474 -0
- package/dist/federation/debug/debug-stream.js +419 -0
- package/dist/federation/index.js +12 -0
- package/dist/federation/integrations/realtime-federation.js +404 -0
- package/dist/federation/integrations/supabase-adapter-debug.js +400 -0
- package/dist/federation/integrations/supabase-adapter.js +258 -0
- package/dist/utils/cli.js +5 -0
- package/docs/architecture/FEDERATION-DATA-LIFECYCLE.md +520 -0
- package/docs/federation/AGENT-DEBUG-STREAMING.md +403 -0
- package/docs/federation/DEBUG-STREAMING-COMPLETE.md +432 -0
- package/docs/federation/DEBUG-STREAMING.md +537 -0
- package/docs/federation/DEPLOYMENT-VALIDATION-SUCCESS.md +394 -0
- package/docs/federation/DOCKER-FEDERATION-DEEP-REVIEW.md +478 -0
- package/docs/issues/ISSUE-SUPABASE-INTEGRATION.md +536 -0
- package/docs/releases/RELEASE-v1.8.13.md +426 -0
- package/docs/supabase/IMPLEMENTATION-SUMMARY.md +498 -0
- package/docs/supabase/INDEX.md +358 -0
- package/docs/supabase/QUICKSTART.md +365 -0
- package/docs/supabase/README.md +318 -0
- package/docs/supabase/SUPABASE-REALTIME-FEDERATION.md +575 -0
- package/docs/supabase/TEST-REPORT.md +446 -0
- package/docs/supabase/migrations/001_create_federation_tables.sql +339 -0
- package/docs/validation/reports/REGRESSION-TEST-V1.8.11.md +456 -0
- package/package.json +4 -1
- package/wasm/reasoningbank/reasoningbank_wasm_bg.js +2 -2
- package/wasm/reasoningbank/reasoningbank_wasm_bg.wasm +0 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
-- Federation Hub Schema for Supabase
|
|
2
|
+
-- Version: 1.0.0
|
|
3
|
+
-- Date: 2025-10-31
|
|
4
|
+
|
|
5
|
+
-- Enable required extensions
|
|
6
|
+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
7
|
+
CREATE EXTENSION IF NOT EXISTS "vector";
|
|
8
|
+
|
|
9
|
+
-- =====================================================
|
|
10
|
+
-- Agent Sessions Table
|
|
11
|
+
-- =====================================================
|
|
12
|
+
CREATE TABLE IF NOT EXISTS agent_sessions (
|
|
13
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
14
|
+
session_id TEXT UNIQUE NOT NULL,
|
|
15
|
+
tenant_id TEXT NOT NULL,
|
|
16
|
+
agent_id TEXT NOT NULL,
|
|
17
|
+
status TEXT NOT NULL CHECK (status IN ('active', 'completed', 'failed')),
|
|
18
|
+
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
19
|
+
ended_at TIMESTAMPTZ,
|
|
20
|
+
metadata JSONB DEFAULT '{}',
|
|
21
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
22
|
+
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
-- Indexes for agent_sessions
|
|
26
|
+
CREATE INDEX idx_agent_sessions_tenant ON agent_sessions(tenant_id);
|
|
27
|
+
CREATE INDEX idx_agent_sessions_agent ON agent_sessions(agent_id);
|
|
28
|
+
CREATE INDEX idx_agent_sessions_status ON agent_sessions(status);
|
|
29
|
+
CREATE INDEX idx_agent_sessions_started ON agent_sessions(started_at DESC);
|
|
30
|
+
|
|
31
|
+
-- =====================================================
|
|
32
|
+
-- Agent Memories Table
|
|
33
|
+
-- =====================================================
|
|
34
|
+
CREATE TABLE IF NOT EXISTS agent_memories (
|
|
35
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
36
|
+
tenant_id TEXT NOT NULL,
|
|
37
|
+
agent_id TEXT NOT NULL,
|
|
38
|
+
session_id TEXT NOT NULL,
|
|
39
|
+
content TEXT NOT NULL,
|
|
40
|
+
embedding vector(1536), -- OpenAI ada-002 dimension
|
|
41
|
+
metadata JSONB DEFAULT '{}',
|
|
42
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
43
|
+
expires_at TIMESTAMPTZ,
|
|
44
|
+
|
|
45
|
+
-- Foreign key to session
|
|
46
|
+
CONSTRAINT fk_session FOREIGN KEY (session_id)
|
|
47
|
+
REFERENCES agent_sessions(session_id)
|
|
48
|
+
ON DELETE CASCADE
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
-- Indexes for agent_memories
|
|
52
|
+
CREATE INDEX idx_agent_memories_tenant ON agent_memories(tenant_id);
|
|
53
|
+
CREATE INDEX idx_agent_memories_agent ON agent_memories(agent_id);
|
|
54
|
+
CREATE INDEX idx_agent_memories_session ON agent_memories(session_id);
|
|
55
|
+
CREATE INDEX idx_agent_memories_created ON agent_memories(created_at DESC);
|
|
56
|
+
CREATE INDEX idx_agent_memories_expires ON agent_memories(expires_at)
|
|
57
|
+
WHERE expires_at IS NOT NULL;
|
|
58
|
+
|
|
59
|
+
-- HNSW vector index for semantic search
|
|
60
|
+
CREATE INDEX idx_agent_memories_embedding ON agent_memories
|
|
61
|
+
USING hnsw (embedding vector_cosine_ops)
|
|
62
|
+
WITH (m = 16, ef_construction = 64);
|
|
63
|
+
|
|
64
|
+
-- =====================================================
|
|
65
|
+
-- Agent Tasks Table
|
|
66
|
+
-- =====================================================
|
|
67
|
+
CREATE TABLE IF NOT EXISTS agent_tasks (
|
|
68
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
69
|
+
task_id TEXT UNIQUE NOT NULL,
|
|
70
|
+
tenant_id TEXT NOT NULL,
|
|
71
|
+
assigned_to TEXT NOT NULL,
|
|
72
|
+
assigned_by TEXT,
|
|
73
|
+
description TEXT NOT NULL,
|
|
74
|
+
priority TEXT NOT NULL CHECK (priority IN ('low', 'medium', 'high', 'critical')),
|
|
75
|
+
status TEXT NOT NULL CHECK (status IN ('pending', 'assigned', 'in_progress', 'completed', 'failed')),
|
|
76
|
+
result JSONB,
|
|
77
|
+
dependencies TEXT[] DEFAULT '{}',
|
|
78
|
+
deadline TIMESTAMPTZ,
|
|
79
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
80
|
+
started_at TIMESTAMPTZ,
|
|
81
|
+
completed_at TIMESTAMPTZ,
|
|
82
|
+
metadata JSONB DEFAULT '{}'
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
-- Indexes for agent_tasks
|
|
86
|
+
CREATE INDEX idx_agent_tasks_tenant ON agent_tasks(tenant_id);
|
|
87
|
+
CREATE INDEX idx_agent_tasks_assigned_to ON agent_tasks(assigned_to);
|
|
88
|
+
CREATE INDEX idx_agent_tasks_status ON agent_tasks(status);
|
|
89
|
+
CREATE INDEX idx_agent_tasks_priority ON agent_tasks(priority);
|
|
90
|
+
CREATE INDEX idx_agent_tasks_created ON agent_tasks(created_at DESC);
|
|
91
|
+
|
|
92
|
+
-- =====================================================
|
|
93
|
+
-- Agent Events Table (Audit Log)
|
|
94
|
+
-- =====================================================
|
|
95
|
+
CREATE TABLE IF NOT EXISTS agent_events (
|
|
96
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
97
|
+
tenant_id TEXT NOT NULL,
|
|
98
|
+
agent_id TEXT NOT NULL,
|
|
99
|
+
event_type TEXT NOT NULL,
|
|
100
|
+
payload JSONB NOT NULL DEFAULT '{}',
|
|
101
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
-- Indexes for agent_events
|
|
105
|
+
CREATE INDEX idx_agent_events_tenant ON agent_events(tenant_id);
|
|
106
|
+
CREATE INDEX idx_agent_events_agent ON agent_events(agent_id);
|
|
107
|
+
CREATE INDEX idx_agent_events_type ON agent_events(event_type);
|
|
108
|
+
CREATE INDEX idx_agent_events_created ON agent_events(created_at DESC);
|
|
109
|
+
|
|
110
|
+
-- Partition by month for efficient archival
|
|
111
|
+
-- CREATE TABLE agent_events_2025_11 PARTITION OF agent_events
|
|
112
|
+
-- FOR VALUES FROM ('2025-11-01') TO ('2025-12-01');
|
|
113
|
+
|
|
114
|
+
-- =====================================================
|
|
115
|
+
-- Row Level Security (RLS)
|
|
116
|
+
-- =====================================================
|
|
117
|
+
|
|
118
|
+
-- Enable RLS on all tables
|
|
119
|
+
ALTER TABLE agent_sessions ENABLE ROW LEVEL SECURITY;
|
|
120
|
+
ALTER TABLE agent_memories ENABLE ROW LEVEL SECURITY;
|
|
121
|
+
ALTER TABLE agent_tasks ENABLE ROW LEVEL SECURITY;
|
|
122
|
+
ALTER TABLE agent_events ENABLE ROW LEVEL SECURITY;
|
|
123
|
+
|
|
124
|
+
-- Policies for agent_sessions
|
|
125
|
+
CREATE POLICY tenant_isolation_sessions ON agent_sessions
|
|
126
|
+
FOR ALL
|
|
127
|
+
USING (tenant_id = current_setting('app.current_tenant', TRUE));
|
|
128
|
+
|
|
129
|
+
-- Policies for agent_memories
|
|
130
|
+
CREATE POLICY tenant_isolation_memories ON agent_memories
|
|
131
|
+
FOR ALL
|
|
132
|
+
USING (tenant_id = current_setting('app.current_tenant', TRUE));
|
|
133
|
+
|
|
134
|
+
-- Policies for agent_tasks
|
|
135
|
+
CREATE POLICY tenant_isolation_tasks ON agent_tasks
|
|
136
|
+
FOR ALL
|
|
137
|
+
USING (tenant_id = current_setting('app.current_tenant', TRUE));
|
|
138
|
+
|
|
139
|
+
-- Policies for agent_events
|
|
140
|
+
CREATE POLICY tenant_isolation_events ON agent_events
|
|
141
|
+
FOR ALL
|
|
142
|
+
USING (tenant_id = current_setting('app.current_tenant', TRUE));
|
|
143
|
+
|
|
144
|
+
-- Service role bypass (for server-side operations)
|
|
145
|
+
CREATE POLICY service_role_bypass_sessions ON agent_sessions
|
|
146
|
+
FOR ALL
|
|
147
|
+
TO service_role
|
|
148
|
+
USING (TRUE);
|
|
149
|
+
|
|
150
|
+
CREATE POLICY service_role_bypass_memories ON agent_memories
|
|
151
|
+
FOR ALL
|
|
152
|
+
TO service_role
|
|
153
|
+
USING (TRUE);
|
|
154
|
+
|
|
155
|
+
CREATE POLICY service_role_bypass_tasks ON agent_tasks
|
|
156
|
+
FOR ALL
|
|
157
|
+
TO service_role
|
|
158
|
+
USING (TRUE);
|
|
159
|
+
|
|
160
|
+
CREATE POLICY service_role_bypass_events ON agent_events
|
|
161
|
+
FOR ALL
|
|
162
|
+
TO service_role
|
|
163
|
+
USING (TRUE);
|
|
164
|
+
|
|
165
|
+
-- =====================================================
|
|
166
|
+
-- Functions
|
|
167
|
+
-- =====================================================
|
|
168
|
+
|
|
169
|
+
-- Semantic search function using pgvector
|
|
170
|
+
CREATE OR REPLACE FUNCTION search_memories(
|
|
171
|
+
query_embedding vector(1536),
|
|
172
|
+
query_tenant_id TEXT,
|
|
173
|
+
match_count INT DEFAULT 10,
|
|
174
|
+
similarity_threshold FLOAT DEFAULT 0.7
|
|
175
|
+
)
|
|
176
|
+
RETURNS TABLE (
|
|
177
|
+
id UUID,
|
|
178
|
+
tenant_id TEXT,
|
|
179
|
+
agent_id TEXT,
|
|
180
|
+
session_id TEXT,
|
|
181
|
+
content TEXT,
|
|
182
|
+
metadata JSONB,
|
|
183
|
+
created_at TIMESTAMPTZ,
|
|
184
|
+
similarity FLOAT
|
|
185
|
+
)
|
|
186
|
+
LANGUAGE plpgsql
|
|
187
|
+
AS $$
|
|
188
|
+
BEGIN
|
|
189
|
+
RETURN QUERY
|
|
190
|
+
SELECT
|
|
191
|
+
m.id,
|
|
192
|
+
m.tenant_id,
|
|
193
|
+
m.agent_id,
|
|
194
|
+
m.session_id,
|
|
195
|
+
m.content,
|
|
196
|
+
m.metadata,
|
|
197
|
+
m.created_at,
|
|
198
|
+
1 - (m.embedding <=> query_embedding) AS similarity
|
|
199
|
+
FROM agent_memories m
|
|
200
|
+
WHERE m.tenant_id = query_tenant_id
|
|
201
|
+
AND m.embedding IS NOT NULL
|
|
202
|
+
AND 1 - (m.embedding <=> query_embedding) > similarity_threshold
|
|
203
|
+
ORDER BY m.embedding <=> query_embedding
|
|
204
|
+
LIMIT match_count;
|
|
205
|
+
END;
|
|
206
|
+
$$;
|
|
207
|
+
|
|
208
|
+
-- Update updated_at timestamp automatically
|
|
209
|
+
CREATE OR REPLACE FUNCTION update_updated_at()
|
|
210
|
+
RETURNS TRIGGER AS $$
|
|
211
|
+
BEGIN
|
|
212
|
+
NEW.updated_at = NOW();
|
|
213
|
+
RETURN NEW;
|
|
214
|
+
END;
|
|
215
|
+
$$ LANGUAGE plpgsql;
|
|
216
|
+
|
|
217
|
+
CREATE TRIGGER update_agent_sessions_updated_at
|
|
218
|
+
BEFORE UPDATE ON agent_sessions
|
|
219
|
+
FOR EACH ROW
|
|
220
|
+
EXECUTE FUNCTION update_updated_at();
|
|
221
|
+
|
|
222
|
+
-- Auto-delete expired memories
|
|
223
|
+
CREATE OR REPLACE FUNCTION delete_expired_memories()
|
|
224
|
+
RETURNS void AS $$
|
|
225
|
+
BEGIN
|
|
226
|
+
DELETE FROM agent_memories
|
|
227
|
+
WHERE expires_at IS NOT NULL
|
|
228
|
+
AND expires_at < NOW();
|
|
229
|
+
END;
|
|
230
|
+
$$ LANGUAGE plpgsql;
|
|
231
|
+
|
|
232
|
+
-- Schedule periodic cleanup (requires pg_cron extension)
|
|
233
|
+
-- SELECT cron.schedule('cleanup-expired-memories', '0 * * * *', 'SELECT delete_expired_memories()');
|
|
234
|
+
|
|
235
|
+
-- =====================================================
|
|
236
|
+
-- Views
|
|
237
|
+
-- =====================================================
|
|
238
|
+
|
|
239
|
+
-- Active sessions view
|
|
240
|
+
CREATE OR REPLACE VIEW active_sessions AS
|
|
241
|
+
SELECT
|
|
242
|
+
s.tenant_id,
|
|
243
|
+
s.agent_id,
|
|
244
|
+
s.session_id,
|
|
245
|
+
s.started_at,
|
|
246
|
+
s.metadata,
|
|
247
|
+
COUNT(m.id) AS memory_count,
|
|
248
|
+
MAX(m.created_at) AS last_memory_at
|
|
249
|
+
FROM agent_sessions s
|
|
250
|
+
LEFT JOIN agent_memories m ON s.session_id = m.session_id
|
|
251
|
+
WHERE s.status = 'active'
|
|
252
|
+
GROUP BY s.tenant_id, s.agent_id, s.session_id, s.started_at, s.metadata;
|
|
253
|
+
|
|
254
|
+
-- Hub statistics view
|
|
255
|
+
CREATE OR REPLACE VIEW hub_statistics AS
|
|
256
|
+
SELECT
|
|
257
|
+
tenant_id,
|
|
258
|
+
COUNT(DISTINCT agent_id) AS total_agents,
|
|
259
|
+
COUNT(DISTINCT session_id) AS total_sessions,
|
|
260
|
+
COUNT(*) AS total_memories,
|
|
261
|
+
MIN(created_at) AS first_memory_at,
|
|
262
|
+
MAX(created_at) AS last_memory_at
|
|
263
|
+
FROM agent_memories
|
|
264
|
+
GROUP BY tenant_id;
|
|
265
|
+
|
|
266
|
+
-- Task status view
|
|
267
|
+
CREATE OR REPLACE VIEW task_status_summary AS
|
|
268
|
+
SELECT
|
|
269
|
+
tenant_id,
|
|
270
|
+
status,
|
|
271
|
+
priority,
|
|
272
|
+
COUNT(*) AS task_count,
|
|
273
|
+
AVG(EXTRACT(EPOCH FROM (completed_at - started_at))) AS avg_duration_seconds
|
|
274
|
+
FROM agent_tasks
|
|
275
|
+
GROUP BY tenant_id, status, priority;
|
|
276
|
+
|
|
277
|
+
-- =====================================================
|
|
278
|
+
-- Sample Data (Optional - for testing)
|
|
279
|
+
-- =====================================================
|
|
280
|
+
|
|
281
|
+
-- Uncomment to insert sample data:
|
|
282
|
+
/*
|
|
283
|
+
INSERT INTO agent_sessions (session_id, tenant_id, agent_id, status, metadata)
|
|
284
|
+
VALUES
|
|
285
|
+
('session-001', 'demo-tenant', 'agent-001', 'active', '{"type": "researcher"}'),
|
|
286
|
+
('session-002', 'demo-tenant', 'agent-002', 'active', '{"type": "analyst"}');
|
|
287
|
+
|
|
288
|
+
INSERT INTO agent_memories (tenant_id, agent_id, session_id, content, metadata)
|
|
289
|
+
VALUES
|
|
290
|
+
('demo-tenant', 'agent-001', 'session-001', 'Research finding: AI safety is critical', '{"topic": "AI safety"}'),
|
|
291
|
+
('demo-tenant', 'agent-002', 'session-002', 'Analysis: High confidence in results', '{"confidence": 0.95}');
|
|
292
|
+
|
|
293
|
+
INSERT INTO agent_tasks (task_id, tenant_id, assigned_to, description, priority, status)
|
|
294
|
+
VALUES
|
|
295
|
+
('task-001', 'demo-tenant', 'agent-001', 'Research AI safety frameworks', 'high', 'in_progress'),
|
|
296
|
+
('task-002', 'demo-tenant', 'agent-002', 'Analyze research findings', 'medium', 'pending');
|
|
297
|
+
*/
|
|
298
|
+
|
|
299
|
+
-- =====================================================
|
|
300
|
+
-- Grants
|
|
301
|
+
-- =====================================================
|
|
302
|
+
|
|
303
|
+
-- Grant necessary permissions
|
|
304
|
+
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO authenticated;
|
|
305
|
+
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO service_role;
|
|
306
|
+
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO authenticated;
|
|
307
|
+
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO service_role;
|
|
308
|
+
|
|
309
|
+
-- =====================================================
|
|
310
|
+
-- Comments
|
|
311
|
+
-- =====================================================
|
|
312
|
+
|
|
313
|
+
COMMENT ON TABLE agent_sessions IS 'Tracks active and historical agent sessions';
|
|
314
|
+
COMMENT ON TABLE agent_memories IS 'Stores agent memories with vector embeddings for semantic search';
|
|
315
|
+
COMMENT ON TABLE agent_tasks IS 'Manages task assignments and coordination between agents';
|
|
316
|
+
COMMENT ON TABLE agent_events IS 'Audit log for all agent events and actions';
|
|
317
|
+
|
|
318
|
+
COMMENT ON FUNCTION search_memories IS 'Performs semantic search using pgvector cosine similarity';
|
|
319
|
+
COMMENT ON FUNCTION delete_expired_memories IS 'Removes memories that have passed their expiration time';
|
|
320
|
+
|
|
321
|
+
-- =====================================================
|
|
322
|
+
-- Completion Message
|
|
323
|
+
-- =====================================================
|
|
324
|
+
|
|
325
|
+
DO $$
|
|
326
|
+
BEGIN
|
|
327
|
+
RAISE NOTICE '✅ Federation Hub schema created successfully!';
|
|
328
|
+
RAISE NOTICE '';
|
|
329
|
+
RAISE NOTICE 'Next steps:';
|
|
330
|
+
RAISE NOTICE '1. Enable Realtime for tables in Supabase dashboard:';
|
|
331
|
+
RAISE NOTICE ' - agent_sessions';
|
|
332
|
+
RAISE NOTICE ' - agent_memories';
|
|
333
|
+
RAISE NOTICE ' - agent_tasks';
|
|
334
|
+
RAISE NOTICE ' - agent_events';
|
|
335
|
+
RAISE NOTICE '';
|
|
336
|
+
RAISE NOTICE '2. Configure RLS policies for your application';
|
|
337
|
+
RAISE NOTICE '3. Set up pg_cron for automatic memory cleanup (optional)';
|
|
338
|
+
RAISE NOTICE '4. Update your .env file with Supabase credentials';
|
|
339
|
+
END $$;
|