Skip to content

[integrations] REST API gateway - #12

Merged
alanshurafa merged 313 commits into
mainfrom
contrib/alanshurafa/rest-api-gateway
Jul 6, 2026
Merged

[integrations] REST API gateway#12
alanshurafa merged 313 commits into
mainfrom
contrib/alanshurafa/rest-api-gateway

Conversation

@alanshurafa

Copy link
Copy Markdown
Owner

Summary

  • REST API gateway with 20 endpoints for non-MCP clients (dashboards, webhooks, ChatGPT Actions, Gemini)
  • Ported from ExoCortex open-brain-rest with OB1 adaptations
  • Full CRUD, semantic + text search, capture with enrichment, stats, ingest proxy, duplicate resolution, knowledge graph entity browsing

Key Features

  • CORS support — wildcard * for browser and Electron clients
  • Three auth methods — query param, header, or Bearer token
  • Sensitivity filtering — restricted content blocked at capture and hidden from queries
  • Smart ingest proxy/ingest and /ingestion-jobs endpoints proxy to the smart-ingest function
  • Knowledge graph/entities endpoints query the graph (optional, requires schema)
  • Duplicate management — find and resolve near-duplicate thought pairs with metadata merging

Files

File Lines Purpose
index.ts 933 REST server with 20 route handlers
_shared/helpers.ts 770 Shared utilities (from enhanced-mcp)
_shared/config.ts 204 Constants and types
README.md 155 Setup guide with endpoint table, auth docs, troubleshooting
metadata.json 18 OB1 contribution metadata
deno.json 5 Deno import map

Test plan

  • Verify gate checks pass
  • Deploy and test /health endpoint
  • Test /search (semantic + text modes)
  • Test /capture with and without skip_classification
  • Test CRUD operations on /thought/:id
  • Test /stats endpoint

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread integrations/rest-api/index.ts Outdated
Comment on lines +146 to +148
const thoughtMatch = path.match(/^\/thought\/(\d+)$/);
if (thoughtMatch) {
const id = Number(thoughtMatch[1]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread integrations/rest-api/index.ts Outdated
Comment on lines +295 to +296
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");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +214 to +217
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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@github-actions github-actions Bot added documentation Improvements or additions to documentation recipe labels Apr 6, 2026
@alanshurafa
alanshurafa force-pushed the contrib/alanshurafa/rest-api-gateway branch from 36d0c7b to a9ff574 Compare April 18, 2026 02:42
alanshurafa and others added 22 commits April 18, 2026 14:14
…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>
…gth === 2 to protect bidirectional shortest-path
justfinethanku and others added 29 commits June 7, 2026 20:47
…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
…lanshurafa/brain-backup

[recipes] Brain backup and export
…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
…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>
@alanshurafa
alanshurafa merged commit b530543 into main Jul 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.