[integrations] REST API gateway - #12
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4046b5fce3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const thoughtMatch = path.match(/^\/thought\/(\d+)$/); | ||
| if (thoughtMatch) { | ||
| const id = Number(thoughtMatch[1]); |
There was a problem hiding this comment.
Accept UUID thought IDs in route matching
The thought routes currently only match numeric IDs (/^(\\d+)$/), but this repository’s default schema uses UUID thought IDs (docs/01-getting-started.md shows thoughts.id uuid, and schemas/enhanced-thoughts/schema.sql defines get_thought_connections(p_thought_id UUID)). With the current regex and Number(...) coercion, valid UUID URLs like /thought/<uuid> never match and these endpoints return 404 instead of operating on existing thoughts.
Useful? React with 👍 / 👎.
| const result = data as { thought_id: number; action: string; content_fingerprint: string } | null; | ||
| if (!result?.thought_id) throw new Error("upsert_thought returned no result"); |
There was a problem hiding this comment.
Parse upsert_thought response using returned id field
The capture handler assumes upsert_thought returns { thought_id, action, content_fingerprint }, then throws when thought_id is missing. In this repo’s documented setup, upsert_thought returns JSON with id (see docs/01-getting-started.md), and existing server code reads upsertResult?.id; with that standard function, /capture will fail with upsert_thought returned no result even when insert/update succeeded.
Useful? React with 👍 / 👎.
| const filter: Record<string, unknown> = {}; | ||
| if (excludeRestricted) filter.exclude_restricted = true; | ||
| const { data, error } = await supabase.rpc("search_thoughts_text", { | ||
| p_query: query, p_limit: limit, p_filter: filter, p_offset: offset, |
There was a problem hiding this comment.
Remove exclude flag from metadata filter in text search
In text mode, exclude_restricted is encoded as p_filter.exclude_restricted, but search_thoughts_text applies p_filter as t.metadata @> p_filter (see schemas/enhanced-thoughts/schema.sql) and does not interpret that key as a sensitivity predicate. This means default requests (exclude_restricted true) effectively require each thought’s metadata to contain { "exclude_restricted": true }, causing most text searches to return empty results rather than excluding restricted rows.
Useful? React with 👍 / 👎.
36d0c7b to
a9ff574
Compare
…h current generator
…ch provenance-chains contract
…test_path + traverse_graph) The previous recursive-CTE implementations enumerated every path to every reachable node, which exploded on densely connected graphs (a hub with 1k+ neighbours at depth 2 produced tens of thousands of rows) and depended on the per-path ANY(path) check to break cycles. On a cyclic graph that exceeded the statement_timeout the planner never actually pruned the walk. Replace both functions with iterative plpgsql BFS: - Global seen-set (UUID[]) so each node is visited at most once - JSONB parent-pointer map records the first (parent, relation) that reached each node; BFS's "first discovery wins" invariant is enforced with DISTINCT ON (next_id) - Shared reconstruct_bfs_path() helper walks the parent map end -> start with a safety guard against malformed maps - find_shortest_path keeps bidirectional edge traversal; traverse_graph keeps outgoing-only with optional relationship_type filter - Signatures, argument order, RETURNS shape, and language (plpgsql, no SECURITY DEFINER) match the original so this is a body-only rewrite - All queries scope by p_user_id to preserve the multi-tenant isolation the edge function relies on (service_role bypasses RLS) Update the README's "How It Works" section and function table to describe the new implementation so the docs don't contradict the SQL. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Standalone Node script that exercises traverse_graph and find_shortest_path against a live Supabase project with ob-graph installed. Picks an arbitrary edge, calls both RPCs at depth 1/2/6, and prints row counts + timings so maintainers can confirm the iterative-BFS rewrite stays inside the statement_timeout and returns sensible shapes before shipping. Reads SUPABASE_PROJECT_REF, SUPABASE_SERVICE_ROLE_KEY, and OB_GRAPH_USER_ID from recipes/ob-graph/.env.local so the service-role key never lands in repo history. Sets process.exitCode=1 on any RPC failure so CI or shell chaining picks up a non-zero exit. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…rsive CTE (preserve contract)
…directional shortest-path
…gth === 2 to protect bidirectional shortest-path
…allel edges produce 3 D-rows
…shortest_path + traverse_graph
…lanshurafa/smart-ingest [integrations] Smart ingest Edge Function
…wicegood/dashboard-open-next-cloudflare [dashboards] open-brain-dashboard-next: add Cloudflare Workers deploy support
…lanshurafa/enhanced-thoughts [schemas] Enhanced thoughts columns and utility RPCs
…rain-health-monitoring
…rain-health-monitoring
…lanshurafa/brain-backup [recipes] Brain backup and export
…rain-health-monitoring
…lanshurafa/brain-health-monitoring [recipes] Brain health monitoring views
…ns1002/per-request-mcp [integrations] Fix per-request McpServer instantiation for stable MCP connections
…xcfi-scott/delete-thought-mcp [integrations] delete_thought MCP
…er/typed-reasoning-edges-comment-syntax-fix [schemas] Fix typed-reasoning-edges COMMENT ON syntax error
…uto-capture-claude-code
…lanshurafa/auto-capture-claude-code [skills] Auto-capture Claude Code adapter
Accepting the access key via ?key= leaks it into CDN/proxy/Supabase access logs. Accept it only via the x-brain-key or Authorization: Bearer headers, matching enhanced-mcp. Updates README examples + auth docs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
State that the service-role backend bypasses RLS (key = full-brain access, single-tenant by design) and that the key must be high-entropy since rate limiting is best-effort. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Key Features
*for browser and Electron clients/ingestand/ingestion-jobsendpoints proxy to the smart-ingest function/entitiesendpoints query the graph (optional, requires schema)Files
index.ts_shared/helpers.ts_shared/config.tsREADME.mdmetadata.jsondeno.jsonTest plan
/healthendpoint/search(semantic + text modes)/capturewith and withoutskip_classification/thought/:id/statsendpoint🤖 Generated with Claude Code