Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial scaffolding for using LLMs to generate JS in Budibase. #15711

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

samwho
Copy link
Collaborator

@samwho samwho commented Mar 11, 2025

Description

This feature is behind a feature flag while in development, so this PR won't be releasing anything to users.

What's in here:

  • A new endpoint, POST /api/ai/js that the frontend talks to as a proxy to whatever LLM we use.
  • Some new UI elements for showing a "generate with AI" button on JS codeblocks.
  • A little bit of TypeScript conversion in bbui for good measure.

Copy link

qa-wolf bot commented Mar 11, 2025

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

@samwho samwho marked this pull request as ready for review March 11, 2025 09:42
@samwho samwho requested a review from a team as a code owner March 11, 2025 09:42
@samwho samwho requested review from adrinr, Copilot and PClmnt and removed request for a team March 11, 2025 09:42
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR introduces scaffolding to enable AI-generated JavaScript within Budibase behind a feature flag.

  • Adds a new API endpoint (/api/ai/js) to proxy requests to an LLM service.
  • Implements a controller to interface with OpenAI for generating JavaScript code.
  • Extends type definitions and integrates the new endpoint into the frontend API.

Reviewed Changes

File Description
packages/server/src/api/routes/ai.ts Defines the new API route for AI JS generation
packages/server/src/api/controllers/ai.ts Implements the controller logic that invokes OpenAI for code generation
packages/types/src/api/web/ai.ts Adds request/response interfaces for the new endpoint
packages/frontend-core/src/api/ai.ts Integrates the new endpoint into the frontend API client
packages/types/src/api/web/index.ts Re-exports new type definitions
packages/types/src/sdk/featureFlag.ts Adds the new feature flag for AI JS generation
packages/server/src/api/routes/index.ts Updates route imports to include the new/renamed AI routes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

@samwho samwho requested a review from Copilot March 11, 2025 09:52
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR introduces the initial scaffolding for AI-generated JavaScript in Budibase, enabling backend processing via an endpoint and updating frontend API interfaces.

  • Added a new endpoint (POST /api/ai/js) in the server controller to handle AI JS generation.
  • Updated routing and types across server and frontend to support the AI functionality.
  • Extended feature flags to include an "AI_JS_GENERATION" flag to toggle the feature.

Reviewed Changes

File Description
packages/server/src/api/controllers/ai.ts Introduces the endpoint logic, including API key and prompt handling.
packages/server/src/api/routes/ai.ts Adds a new route for the AI JS generation endpoint.
packages/types/src/api/web/ai.ts Defines request and response types for the AI endpoint.
packages/frontend-core/src/api/ai.ts Adds the client function to call the new AI JS generation endpoint.
packages/types/src/api/web/index.ts Updates exports to include the new AI API types.
packages/types/src/sdk/featureFlag.ts Incorporates the new AI_JS_GENERATION feature flag.
packages/server/src/api/routes/index.ts Updates main routes to include the new AI route under the pro namespace.

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Copy link
Collaborator

@PClmnt PClmnt left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -5,30 +5,39 @@

export let value: string | undefined = undefined
export let label: string | undefined = undefined
export let labelPosition: string = "above"
export let labelPosition = "above"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be using the position enum, instead?

})
suggestedCode = code
popoverWidth = 100
promptLoading = false
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be wrapped in a try/finally? Otherwise it will be stuck to loading forever

@@ -428,6 +477,50 @@
<div tabindex="-1" bind:this={textarea} />
</div>

{#if aiGenEnabled}
<button
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason on why not using bbui buttons? Are the designs not matching?

}

if (!env.OPENAI_API_KEY) {
ctx.throw(400, "OpenAI API key is not set")
Copy link
Collaborator

Choose a reason for hiding this comment

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

These 400 look strange to me. None of them is "bad request", both of them are due server conditions, no because of the request


const router: Router = new Router()

router.post("/api/ai/js", auth.builderOrAdmin, controller.generateJs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this not be builder only?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants