remdb 0.3.157__py3-none-any.whl → 0.3.180__py3-none-any.whl

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.
Files changed (37) hide show
  1. rem/agentic/agents/agent_manager.py +2 -1
  2. rem/agentic/context.py +81 -3
  3. rem/agentic/context_builder.py +31 -6
  4. rem/agentic/mcp/tool_wrapper.py +43 -14
  5. rem/agentic/providers/pydantic_ai.py +76 -34
  6. rem/agentic/schema.py +4 -3
  7. rem/agentic/tools/rem_tools.py +11 -0
  8. rem/api/deps.py +1 -3
  9. rem/api/main.py +21 -2
  10. rem/api/mcp_router/resources.py +75 -14
  11. rem/api/mcp_router/server.py +27 -24
  12. rem/api/mcp_router/tools.py +83 -2
  13. rem/api/middleware/tracking.py +5 -5
  14. rem/api/routers/auth.py +152 -10
  15. rem/api/routers/chat/completions.py +5 -3
  16. rem/api/routers/chat/streaming.py +18 -0
  17. rem/api/routers/messages.py +24 -15
  18. rem/auth/jwt.py +352 -0
  19. rem/auth/middleware.py +70 -30
  20. rem/cli/commands/ask.py +1 -1
  21. rem/cli/commands/db.py +98 -44
  22. rem/models/entities/ontology.py +93 -101
  23. rem/schemas/agents/core/agent-builder.yaml +143 -42
  24. rem/services/email/service.py +72 -9
  25. rem/services/postgres/register_type.py +1 -1
  26. rem/services/postgres/repository.py +5 -4
  27. rem/services/user_service.py +41 -9
  28. rem/settings.py +15 -1
  29. rem/sql/background_indexes.sql +5 -0
  30. rem/sql/migrations/001_install.sql +33 -4
  31. rem/sql/migrations/002_install_models.sql +186 -168
  32. rem/utils/model_helpers.py +101 -0
  33. rem/utils/schema_loader.py +45 -7
  34. {remdb-0.3.157.dist-info → remdb-0.3.180.dist-info}/METADATA +1 -1
  35. {remdb-0.3.157.dist-info → remdb-0.3.180.dist-info}/RECORD +37 -36
  36. {remdb-0.3.157.dist-info → remdb-0.3.180.dist-info}/WHEEL +0 -0
  37. {remdb-0.3.157.dist-info → remdb-0.3.180.dist-info}/entry_points.txt +0 -0
@@ -44,6 +44,33 @@ BEGIN
44
44
  RAISE NOTICE '✓ All required extensions installed successfully';
45
45
  END $$;
46
46
 
47
+ -- ============================================================================
48
+ -- NORMALIZATION HELPER
49
+ -- ============================================================================
50
+
51
+ -- Normalize entity keys to lower-kebab-case for consistent lookups
52
+ -- "Mood Disorder" -> "mood-disorder"
53
+ -- "mood_disorder" -> "mood-disorder"
54
+ -- "MoodDisorder" -> "mood-disorder"
55
+ CREATE OR REPLACE FUNCTION normalize_key(input TEXT)
56
+ RETURNS TEXT AS $$
57
+ BEGIN
58
+ RETURN lower(
59
+ regexp_replace(
60
+ regexp_replace(
61
+ regexp_replace(input, '([a-z])([A-Z])', '\1-\2', 'g'), -- camelCase -> kebab
62
+ '[_\s]+', '-', 'g' -- underscores/spaces -> hyphens
63
+ ),
64
+ '-+', '-', 'g' -- collapse multiple hyphens
65
+ )
66
+ );
67
+ END;
68
+ $$ LANGUAGE plpgsql IMMUTABLE;
69
+
70
+ COMMENT ON FUNCTION normalize_key IS
71
+ 'Normalizes entity keys to lower-kebab-case for consistent lookups.
72
+ Examples: "Mood Disorder" -> "mood-disorder", "mood_disorder" -> "mood-disorder"';
73
+
47
74
  -- ============================================================================
48
75
  -- MIGRATION TRACKING
49
76
  -- ============================================================================
@@ -237,10 +264,11 @@ BEGIN
237
264
 
238
265
  -- First lookup in KV store to get entity_type (table name)
239
266
  -- Include user-owned AND public (NULL user_id) entries
267
+ -- Normalize input key for consistent matching
240
268
  SELECT kv.entity_type INTO entity_table
241
269
  FROM kv_store kv
242
270
  WHERE (kv.user_id = effective_user_id OR kv.user_id IS NULL)
243
- AND kv.entity_key = p_entity_key
271
+ AND kv.entity_key = normalize_key(p_entity_key)
244
272
  LIMIT 1;
245
273
 
246
274
  -- If not found, return empty
@@ -414,6 +442,7 @@ BEGIN
414
442
  FOR graph_keys IN
415
443
  WITH RECURSIVE graph_traversal AS (
416
444
  -- Base case: Find starting entity (user-owned OR public)
445
+ -- Normalize input key for consistent matching
417
446
  SELECT
418
447
  0 AS depth,
419
448
  kv.entity_key,
@@ -424,7 +453,7 @@ BEGIN
424
453
  ARRAY[kv.entity_key]::TEXT[] AS path
425
454
  FROM kv_store kv
426
455
  WHERE (kv.user_id = effective_user_id OR kv.user_id IS NULL)
427
- AND kv.entity_key = p_entity_key
456
+ AND kv.entity_key = normalize_key(p_entity_key)
428
457
 
429
458
  UNION ALL
430
459
 
@@ -441,7 +470,7 @@ BEGIN
441
470
  JOIN kv_store source_kv ON source_kv.entity_key = gt.entity_key
442
471
  AND (source_kv.user_id = effective_user_id OR source_kv.user_id IS NULL)
443
472
  CROSS JOIN LATERAL jsonb_array_elements(COALESCE(source_kv.graph_edges, '[]'::jsonb)) AS edge
444
- JOIN kv_store target_kv ON target_kv.entity_key = (edge->>'dst')::VARCHAR(255)
473
+ JOIN kv_store target_kv ON target_kv.entity_key = normalize_key((edge->>'dst')::VARCHAR(255))
445
474
  AND (target_kv.user_id = effective_user_id OR target_kv.user_id IS NULL)
446
475
  WHERE gt.depth < p_max_depth
447
476
  AND (p_rel_type IS NULL OR (edge->>'rel_type')::VARCHAR(100) = p_rel_type)
@@ -657,7 +686,7 @@ BEGIN
657
686
  MIN(msg_counts.first_msg)::TIMESTAMP AS first_message_at,
658
687
  MAX(msg_counts.last_msg)::TIMESTAMP AS last_message_at
659
688
  FROM shared_sessions ss
660
- LEFT JOIN users u ON u.user_id = ss.owner_user_id AND u.tenant_id = ss.tenant_id
689
+ LEFT JOIN users u ON u.id::text = ss.owner_user_id AND u.tenant_id = ss.tenant_id
661
690
  LEFT JOIN (
662
691
  SELECT
663
692
  m.session_id,