Skip to content

Conversation

@maparent
Copy link
Collaborator

@maparent maparent commented May 23, 2025

Work by Sid: Hyde utility, embedding route, supabase insert routes
Marc-Antoine: introduce generated types, further work on insert routes

Summary by CodeRabbit

  • New Features

    • Introduced multiple new API endpoints for managing accounts, persons, platforms, spaces, documents, content, and content embeddings, including batch operations.
    • Added endpoints for generating text embeddings using OpenAI.
    • Implemented standardized API responses, error handling, and CORS support across endpoints.
  • Enhancements

    • Improved input validation and processing for content and embedding records.
    • Unified batch insertion logic with detailed error reporting and partial error handling.
  • Chores

    • Added new dependencies for Supabase SSR support and OpenAI integration.
    • Updated environment variable handling in build and deployment configuration.
  • Documentation

    • Added comprehensive TypeScript types for the Supabase database schema, supporting type-safe operations.

@linear
Copy link

linear bot commented May 23, 2025

@vercel
Copy link

vercel bot commented May 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
discourse-graph ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2025 2:42pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 23, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This update introduces a comprehensive Supabase-backed API layer for a Next.js application, implementing CRUD and batch operations for entities like Person, Account, Platform, Space, Content, Document, and Content Embeddings. It adds utility modules for Supabase integration, type-safe database access, validation, and batch processing. An OpenAI embedding API route is also included.

Changes

Files/Paths Change Summary
apps/website/app/api/embeddings/openai/small/route.ts Added API route for generating OpenAI text embeddings with POST and OPTIONS handlers, including request validation, timeout, and CORS handling.
apps/website/app/api/supabase/account/[id].ts, .../content/[id].ts, .../document/[id].ts,
.../person/[id].ts, .../platform/[id].ts, .../space/[id].ts,
.../content-embedding/[id].ts
Added standard GET, DELETE, and OPTIONS handlers for entity-specific endpoints using default utility functions.
apps/website/app/api/supabase/account/route.ts, .../content/route.ts,
.../document/route.ts, .../person/route.ts, .../platform/route.ts, .../space/route.ts,
.../content-embedding/route.ts
Implemented POST (create or get) and OPTIONS handlers for each entity, with input validation, upsert logic, and standardized API responses.
apps/website/app/api/supabase/content/batch/route.ts, .../content-embedding/batch/route.ts Added batch POST and OPTIONS routes for inserting multiple content or embedding records with validation, grouping, and partial error reporting.
apps/website/app/utils/supabase/apiUtils.ts Introduced utility functions for standardized API responses, error handling, default CRUD handlers, and CORS-compliant responses.
apps/website/app/utils/supabase/dbUtils.ts Added database utility functions for upsert, batch insert, validation, and error management, including handling of unique and foreign key constraints.
apps/website/app/utils/supabase/server.ts Added function to create a Supabase server client with Next.js cookie integration for SSR.
apps/website/app/utils/supabase/validators.ts Added validators and processors for content and embedding input/output, ensuring type and value correctness for API and database operations.
apps/website/app/utils/supabase/types.gen.ts Added generated TypeScript types for the Supabase public schema, including tables, functions, enums, and utility types.
apps/website/package.json Added dependencies: @supabase/ssr and openai.
packages/database/types.gen.ts Updated database types: changed nullability, removed/added fields, and updated relationships for several tables (Account, AutomatedAgent, Concept, etc).
turbo.json Added NODE_ENV to passThroughEnv for build, dev, deploy, and publish tasks.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Route
    participant Validator
    participant SupabaseClient
    participant DBUtils

    Client->>API_Route: POST /api/supabase/content (JSON body)
    API_Route->>Validator: Validate input
    Validator-->>API_Route: Valid/Invalid
    alt Valid
        API_Route->>SupabaseClient: Create instance
        API_Route->>DBUtils: getOrCreateEntity(input)
        DBUtils-->>SupabaseClient: Upsert/fetch entity
        SupabaseClient-->>DBUtils: Entity or error
        DBUtils-->>API_Route: Result (entity, error, created)
        API_Route-->>Client: JSON response (entity, status, error)
    else Invalid
        API_Route-->>Client: JSON error response (400)
    end
Loading
sequenceDiagram
    participant Client
    participant API_Route
    participant Validator
    participant SupabaseClient
    participant DBUtils

    Client->>API_Route: POST /api/supabase/content-embedding/batch (JSON array)
    API_Route->>Validator: Validate input array
    Validator-->>API_Route: Valid/Invalid
    alt Valid
        API_Route->>DBUtils: Batch insert/process by model
        DBUtils-->>SupabaseClient: Batch upsert per model
        SupabaseClient-->>DBUtils: Results or errors
        DBUtils-->>API_Route: Aggregated results, partial errors
        API_Route-->>Client: JSON response (records, partial errors, status)
    else Invalid
        API_Route-->>Client: JSON error response (400)
    end
Loading

Possibly related PRs

Suggested reviewers

  • mdroidian

Poem

In fields of code where Supabase grows,
The rabbits hop where the API flows.
Embeddings and content, all batch-processed neat,
With validators and types, our backend’s complete!
From OpenAI’s magic to tables so bright,
We nibble on data all day and all night.
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@maparent

This comment was marked as outdated.

@coderabbitai

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as outdated.

@mdroidian

This comment was marked as outdated.

@maparent

This comment was marked as outdated.

Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

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

A quick once over to remove comments, adhere to style guide, etc.
Once these comments are addressed, please re tag me for review.

Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

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

Mostly notes for myself later. I'm approving this now and will review/merge #177 into this. Do not push any more changes.

Comment on lines +11 to +19
/**
* Sends a standardized JSON response.
* @param request The original NextRequest.
* @param data The data payload for successful responses.
* @param error An error message string if the operation failed.
* @param details Optional detailed error information.
* @param status The HTTP status code for the response.
* @param created A boolean indicating if a resource was created (influences status code: 201 vs 200).
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

The problem with JSDoc's is that they need to be kept up to date. If they are created at all, they should be after the review is passed and ready to be merged. As we can see, these are already out of date.

* @param tableName The name of the table.
* @param insertData Data to upsert
* @param uniqueOn The expected uniqueOn key.
* @returns Promise<GetOrCreateEntityResult<T>>
Copy link
Contributor

Choose a reason for hiding this comment

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

.

tableName: keyof Database["public"]["Tables"];
items: TablesInsert<TableName>[];
uniqueOn?: (keyof TablesInsert<TableName>)[]; // Uses pKey otherwise
inputValidator?: ItemValidator<TablesInsert<TableName>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

.

* Default GET handler for retrieving a resource by Id
*/
export const makeDefaultGetHandler =
(tableName: keyof Database["public"]["Tables"], pk: string = "id") =>
Copy link
Contributor

Choose a reason for hiding this comment

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

.

@mdroidian mdroidian merged commit 7c90190 into main May 30, 2025
3 checks passed
@mdroidian mdroidian deleted the eng-294-create-supabase-routes-squashed branch May 30, 2025 02:48
@github-project-automation github-project-automation bot moved this to Done in General May 30, 2025
This was referenced May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants