mirror of
https://github.com/codeflash-ai/codeflash-internal.git
synced 2026-05-04 18:25:18 +00:00
dedup the prisma.schema file and minor fixes & upgrade on version (#1417)
### **User description** Closes https://linear.app/codeflash-ai/issue/CF-511/dedupe-the-js-directory-in-code <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Dependency Updates** - Updated `@codeflash-ai/common` package version to 1.0.9 - Updated `@prisma/client` and `prisma` dependencies to version 6.2.1 - Added TypeScript dev dependency - **Package Configuration** - Updated import paths for common modules - Added build and clean scripts - Modified package entry points - Added transpilation configuration for Next.js - **Prisma Schema Changes** - Removed database models for API keys, users, and optimization features - **Code Refactoring** - Improved type safety in function signatures - Updated import statements - Standardized code formatting - Enhanced error handling with optional chaining - **Infrastructure** - Updated GitHub npm registry authentication token - Added TypeScript configuration file - Introduced new README documentation for project setup and usage <!-- end of auto-generated comment: release notes by coderabbit.ai --> ___ ### **PR Type** Enhancement, Bug fix, Dependencies ___ ### **Description** - Updated Prisma dependencies to version 6.2.1 across multiple packages. - Added new npm scripts for Prisma migrations and generation. - Refactored and improved code formatting in `pr-changes-utils.ts`. - Fixed issues with file path handling in `pr-changes-utils.ts`. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><details><summary>1 files</summary><table> <tr> <td><strong>pr-changes-utils.ts</strong><dd><code>Refactored utility functions and improved code formatting</code></dd></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-ac6988771dc3fdb0666757d9bace579f70856f1f383ddd5db264484f1b6016e4">+54/-48</a> </td> </tr> </table></details></td></tr><tr><td><strong>Dependencies</strong></td><td><details><summary>3 files</summary><table> <tr> <td><strong>package.json</strong><dd><code>Updated Prisma dependencies and added migration scripts</code> </dd></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-53ddfb1f8a02f1231d3d15a2e694ffe1407d2cc01d3e685de5653b67fec571c7">+5/-3</a> </td> </tr> <tr> <td><strong>package.json</strong><dd><code>Updated Prisma dependencies and added migration scripts</code> </dd></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-4edec169b0f8d3312edaf35b5cc8521fe1edfa163ce174f60eff51906896601f">+5/-3</a> </td> </tr> <tr> <td><strong>package.json</strong><dd><code>Updated Prisma dependencies</code> </dd></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-b0d32af9c2caaba1377ec3e924eb553105cdc86e244018ffc6a866c530523599">+2/-2</a> </td> </tr> </table></details></td></tr><tr><td><strong>Additional files</strong></td><td><details><summary>25 files</summary><table> <tr> <td><strong>package-lock.json</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-75446c74353509ca0232d6a1350aef075ced8f72bd568e9bafa09cf255683142">+11667/-0</a></td> </tr> <tr> <td><strong>package-lock.json</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-0214c85d1717ad8b736e0296bb8cbf50db2aed068f31316d3c39904824a14f8e">+15284/-0</a></td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-249a9ce984a8d28465df7c46d14176335a3e3072a09295a2fc6c2a089706ac87">+0/-52</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-b65a93e0149b8757f9758bf4447b09c391e6d7f6753e3b8119aeb634bfa1e58a">+0/-35</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-0e2d258b7bc4efa2728784ff4979d1db99b19ce569add87f907dc0058e1cdf92">+0/-14</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-0297920ff8b9ca5872f0c23b91af90bb3b1f698c4ce1a6e979bcc57253d1fc14">+0/-19</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-10092bc1fc1cb33292d2de51fa103ead3329f89da4e5263ce7156f9fe058a8ac">+0/-13</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-6a150698bbc2c55fffa7c8203a6baa4ae76800a92dab2af3db4455a979e1efc8">+0/-12</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-b861d3b13254809a5d4c2ac173650d832bd5a531070275ed47b0364e7d708002">+0/-3</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-3d975c9205361ffb41d75cbea296f1d5d3c995d7028cb723b84cdbdbaa14d6b6">+0/-10</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-c5e086fcd9e4cb5a31cccf9e021d33a8e5a823b5e9d5cd1f411e69cc954bcf3e">+0/-12</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-29d527d29b192dd7e335033c92797341179428888b151e07fb2a0a25904f900c">+0/-2</a> </td> </tr> <tr> <td><strong>migration_lock.toml</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-b12ade4703dcaa9647c60141524ec9178f0a8623c93a6792294289720e4f2618">+0/-3</a> </td> </tr> <tr> <td><strong>package-lock.json</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-54c17cef859f033fc84a59da2e977235ebc494943710c25d132e310ec500c5ef">+1926/-0</a></td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-3ac66eaa7bef6c5be52f465f23c01223d3092570e152a43260261eca73e2cd67">+0/-52</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-13fe21e5b5c119eb53d56a89833335001674d050d1c625ca91261e2aac5ff626">+0/-35</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-8e28adcb61d403ff9e17d0c0fd9189121f3778aea9c8afd0cd33113cbd976aca">+0/-14</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-13b918ec21eabf2dc38d6850ba3ef8fdaf7fc3d76c5a5d62e5131ef5431e6bd2">+0/-19</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-65b00a3a9add469eaeca6a86a4b9b23b4ad1f5bd533c7e4bd65827d6d1e5653a">+0/-13</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-61253604e58cb25b1e7436ccc7a935a58dc91c709e7ca23f7d4ab9001394b49c">+0/-12</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-08f6c4ab5dc1aba11a55931bf07ff68e645185a1c0dce1f71e68704bd823032c">+0/-3</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-40674ec008e93d4ea34a92f20e426bcd958c5b868ccaa4d8ade800ef397fafcc">+0/-10</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-56208f997a8e939f82fad576f18c055589a33811dd7b537632aa0b97935bd3e6">+0/-12</a> </td> </tr> <tr> <td><strong>migration.sql</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-58ddb0f84b902f4106e1f6921b6538cea46be9ded33b9766d8cb658b7d76331b">+0/-2</a> </td> </tr> <tr> <td><strong>migration_lock.toml</strong></td> <td><a href="https://github.com/codeflash-ai/codeflash/pull/1417/files#diff-44423d32fecc24a69cc5d2d075987e28b6ab13da9730940621da28c0786b37e0">+0/-3</a> </td> </tr> </table></details></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull request to receive relevant information --------- Co-authored-by: Kevin Turcios <turcioskevinr@gmail.com>
This commit is contained in:
parent
9c83dee4a6
commit
bcf6644656
52 changed files with 29141 additions and 575 deletions
106
js/README.md
Normal file
106
js/README.md
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
# CodeFlash AI
|
||||
|
||||
## Overview
|
||||
|
||||
CodeFlash AI is a JavaScript/TypeScript monorepo that provides a scalable and modular architecture for web applications, focusing on efficient code sharing and robust development practices.
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
js/
|
||||
├── common/ # Shared code and database schema
|
||||
├── cf-api/ # Backend API service
|
||||
└── cf-webapp/ # Next.js web application
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Node.js (v18+ recommended)
|
||||
- npm (v9+)
|
||||
- Prisma CLI
|
||||
|
||||
## Setup
|
||||
|
||||
### 1. Clone the Repository
|
||||
|
||||
```bash
|
||||
git clone https://github.com/your-org/codeflash-ai.git
|
||||
cd codeflash-ai/js
|
||||
```
|
||||
|
||||
### 2. Install Dependencies
|
||||
|
||||
```bash
|
||||
# Install root and project dependencies
|
||||
npm install
|
||||
cd common && npm install
|
||||
cd ../cf-api && npm install
|
||||
cd ../cf-webapp && npm install
|
||||
```
|
||||
|
||||
### 3. Database Configuration
|
||||
|
||||
```bash
|
||||
# Generate Prisma client and run migrations
|
||||
cd common
|
||||
npx prisma generate
|
||||
npx prisma migrate dev
|
||||
```
|
||||
|
||||
## Development Workflow
|
||||
|
||||
### Start Development Servers
|
||||
|
||||
```bash
|
||||
# Start API server
|
||||
cd cf-api
|
||||
npm run start
|
||||
|
||||
# Start web application
|
||||
cd cf-webapp
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### Build Common Package
|
||||
|
||||
```bash
|
||||
cd common
|
||||
npm run build
|
||||
```
|
||||
|
||||
## Key Components
|
||||
|
||||
### Common Package (`@codeflash-ai/common`)
|
||||
|
||||
- Shared TypeScript utilities
|
||||
- Prisma database schema
|
||||
- Reusable functions across projects
|
||||
|
||||
#### Installation in Other Projects
|
||||
|
||||
```bash
|
||||
npm install @codeflash-ai/common
|
||||
```
|
||||
|
||||
#### Usage Example
|
||||
|
||||
```typescript
|
||||
import { createOrUpdateUser } from "@codeflash-ai/common";
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. Always build the common package after making changes
|
||||
2. Keep shared logic in the `common` package
|
||||
3. Use TypeScript for type safety
|
||||
4. Follow existing code structure
|
||||
5. Never commit sensitive data or build artifacts
|
||||
|
||||
## Publishing common Package
|
||||
|
||||
```bash
|
||||
# Publish common package to npm
|
||||
cd common
|
||||
npm run build
|
||||
npm publish
|
||||
```
|
||||
|
|
@ -3,7 +3,7 @@ import fs from "fs"
|
|||
import {
|
||||
getGithubAppPrivateKey,
|
||||
getGithubAppWebhookSecret,
|
||||
} from "@codeflash-ai/common/azure-keyvault"
|
||||
} from "@codeflash-ai/common/dist/src/azure-keyvault"
|
||||
|
||||
import { posthog } from "../analytics"
|
||||
import * as Sentry from "@sentry/node"
|
||||
|
|
@ -18,7 +18,7 @@ const PRIVATE_KEY: string =
|
|||
const WEBHOOK_SECRET: string =
|
||||
process.env.NODE_ENV === "production"
|
||||
? await getGithubAppWebhookSecret()
|
||||
: process.env.GH_APP_WEBHOOK_SECRET
|
||||
: (process.env.GH_APP_WEBHOOK_SECRET ?? "default-secret")
|
||||
|
||||
export const githubApp = new App({
|
||||
appId: APP_ID,
|
||||
|
|
@ -42,7 +42,7 @@ githubApp.webhooks.onAny(async ({ id, name, payload }) => {
|
|||
console.log(`Github App: Received webhook event ${name} (${id})`)
|
||||
console.log(`Payload: ${JSON.stringify(payload)}`)
|
||||
posthog.capture({
|
||||
distinctId: `github|${payload.sender.id}`,
|
||||
distinctId: `github|${payload.sender?.id}`,
|
||||
event: `cfapi-github-webhook-received`,
|
||||
properties: {
|
||||
event: name,
|
||||
|
|
@ -218,7 +218,7 @@ githubApp.webhooks.on("pull_request.synchronize", async ({ octokit, payload }) =
|
|||
if (payload.pull_request) {
|
||||
console.log(
|
||||
`Received a pull request synchronize event. PR #${payload.pull_request.number} ` +
|
||||
`by ${payload.pull_request.user.login} was updated with new commits.`,
|
||||
`by ${payload.pull_request?.user?.login} was updated with new commits.`,
|
||||
)
|
||||
// Retrieve the list of commits for the pull request
|
||||
const commits = await octokit.rest.pulls.listCommits({
|
||||
|
|
@ -266,7 +266,7 @@ githubApp.webhooks.on("pull_request.synchronize", async ({ octokit, payload }) =
|
|||
// Optional: Handle errors
|
||||
githubApp.webhooks.onError((error) => {
|
||||
console.log(`Error occurred in Github App: ${error}`)
|
||||
if (error.name === "AggregateError") {
|
||||
if (error instanceof Error && error.name === "AggregateError") {
|
||||
// Log Secret verification errors
|
||||
console.log(`Possible webhook secret verification error: ${JSON.stringify(error.event)}`)
|
||||
} else {
|
||||
|
|
@ -279,4 +279,4 @@ export const ghAppPathPrefix: string = "/cfapi/github"
|
|||
|
||||
export const ghAppMiddleware = createNodeMiddleware(githubApp, {
|
||||
pathPrefix: ghAppPathPrefix,
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,13 +1,24 @@
|
|||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import fs from "fs"
|
||||
import path from "path"
|
||||
|
||||
const PR_HEADER_TEMPLATE = fs.readFileSync(path.join(__dirname, "optimization_results_header.md"), "utf8")
|
||||
const PR_DETAILS_TEMPLATE = fs.readFileSync(path.join(__dirname, "optimization_results_details.md"), "utf8")
|
||||
const PR_TEST_REPORT_TEMPLATE = fs.readFileSync(path.join(__dirname, "optimization_results_test_report.md"), "utf8")
|
||||
|
||||
|
||||
const PR_HEADER_TEMPLATE = fs.readFileSync(
|
||||
path.join(__dirname, "optimization_results_header.md"),
|
||||
"utf8",
|
||||
)
|
||||
const PR_DETAILS_TEMPLATE = fs.readFileSync(
|
||||
path.join(__dirname, "optimization_results_details.md"),
|
||||
"utf8",
|
||||
)
|
||||
const PR_TEST_REPORT_TEMPLATE = fs.readFileSync(
|
||||
path.join(__dirname, "optimization_results_test_report.md"),
|
||||
"utf8",
|
||||
)
|
||||
|
||||
const summaryLinesRegex = new RegExp(
|
||||
/### 📄 ([\d,]+(\.\d+)?)% \(([\d,]+(\.\d+)?)x\) speedup for \*\*\*`(.+?)` in `(.+?)`\*\*\*/g
|
||||
);
|
||||
/### 📄 ([\d,]+(\.\d+)?)% \(([\d,]+(\.\d+)?)x\) speedup for \*\*\*`(.+?)` in `(.+?)`\*\*\*/g,
|
||||
)
|
||||
type ReportTable = Record<
|
||||
string,
|
||||
{
|
||||
|
|
@ -18,7 +29,6 @@ type ReportTable = Record<
|
|||
|
||||
type PrCommentFields = Record<string, any>
|
||||
|
||||
|
||||
export function buildPrCommentBody(
|
||||
prCommentFields: PrCommentFields,
|
||||
existingTests: any,
|
||||
|
|
@ -60,60 +70,59 @@ export function buildResultTestReport(
|
|||
|
||||
let reportTableMd: string = ""
|
||||
// Initialize the markdown table
|
||||
reportTableMd += '| Test | Status |\n';
|
||||
reportTableMd += '| --------------------------- | ----------------- |\n';
|
||||
reportTableMd += "| Test | Status |\n"
|
||||
reportTableMd += "| --------------------------- | ----------------- |\n"
|
||||
|
||||
// Loop through each test type and construct the table rows
|
||||
for (const [testType, { passed = 0, failed = 0 }] of Object.entries(reportTableDict)) {
|
||||
if (testType.includes('🎨')) {
|
||||
continue;
|
||||
if (testType.includes("🎨")) {
|
||||
continue
|
||||
}
|
||||
let status = '';
|
||||
let detailsNote = '';
|
||||
let status = ""
|
||||
let detailsNote = ""
|
||||
|
||||
// Determine the status based on passed counts
|
||||
if (passed > 0) {
|
||||
status = `✅ **${passed} Passed**`;
|
||||
status = `✅ **${passed} Passed**`
|
||||
} else {
|
||||
status = '🔘 **None Found**';
|
||||
status = "🔘 **None Found**"
|
||||
}
|
||||
|
||||
// If there are details, note that they are available below
|
||||
if ((passed > 0) && (testType.includes('Existing') || testType.includes('Generated'))) {
|
||||
detailsNote = 'See below';
|
||||
if (passed > 0 && (testType.includes("Existing") || testType.includes("Generated"))) {
|
||||
detailsNote = "See below"
|
||||
} else {
|
||||
detailsNote = '';
|
||||
detailsNote = ""
|
||||
}
|
||||
|
||||
// Add the row to the markdown table
|
||||
reportTableMd += `| ${testType} | ${status} |\n`;
|
||||
reportTableMd += `| ${testType} | ${status} |\n`
|
||||
}
|
||||
reportTableMd += `|📊 Tests Coverage | ${coverage_message} |\n`;
|
||||
|
||||
reportTableMd += `|📊 Tests Coverage | ${coverage_message} |\n`
|
||||
|
||||
// Add detailed test outputs below the table
|
||||
for (const [testType, { passed = 0, failed = 0 }] of Object.entries(reportTableDict)) {
|
||||
// Only include details for Existing and Generated tests with results
|
||||
if ((passed > 0) && (testType.includes('Existing') || testType.includes('Generated'))) {
|
||||
if (passed > 0 && (testType.includes("Existing") || testType.includes("Generated"))) {
|
||||
// Add a heading for the test type details
|
||||
|
||||
reportTableMd += `<details>\n`;
|
||||
reportTableMd += `<summary>${testType} Details</summary>\n\n`;
|
||||
reportTableMd += `<details>\n`
|
||||
reportTableMd += `<summary>${testType} Details</summary>\n\n`
|
||||
|
||||
// Include the relevant test code
|
||||
if (testType.includes('Existing')) {
|
||||
reportTableMd += '```python\n';
|
||||
reportTableMd += existingTests.trim();
|
||||
reportTableMd += '\n```\n';
|
||||
} else if (testType.includes('Generated')) {
|
||||
reportTableMd += '```python\n';
|
||||
reportTableMd += generatedTests.trim();
|
||||
reportTableMd += '\n```\n';
|
||||
if (testType.includes("Existing")) {
|
||||
reportTableMd += "```python\n"
|
||||
reportTableMd += existingTests.trim()
|
||||
reportTableMd += "\n```\n"
|
||||
} else if (testType.includes("Generated")) {
|
||||
reportTableMd += "```python\n"
|
||||
reportTableMd += generatedTests.trim()
|
||||
reportTableMd += "\n```\n"
|
||||
} else {
|
||||
reportTableMd += '_No additional details available._\n';
|
||||
reportTableMd += "_No additional details available._\n"
|
||||
}
|
||||
|
||||
reportTableMd += `\n</details>\n\n`;
|
||||
reportTableMd += `\n</details>\n\n`
|
||||
}
|
||||
}
|
||||
// Add the final markdown content (e.g., the feedback section)
|
||||
|
|
@ -121,33 +130,33 @@ export function buildResultTestReport(
|
|||
${reportTableMd}
|
||||
|
||||
:loudspeaker: Feedback on this optimization? [](https://codeflash.ai/discord)
|
||||
`;
|
||||
`
|
||||
|
||||
return PR_TEST_REPORT_TEMPLATE.replace(/\{report_table}/g, finalMarkdown)
|
||||
}
|
||||
|
||||
export function parseAndCreateOptimizationsDict(
|
||||
prBody: string,
|
||||
prComments: { body: string }[]
|
||||
prComments: { body: string }[],
|
||||
): Record<string, Set<string>> {
|
||||
const optimizations: Record<string, Set<string>> = {};
|
||||
const optimizations: Record<string, Set<string>> = {}
|
||||
|
||||
const textsToParse = [prBody, ...prComments.map((comment) => comment.body)];
|
||||
const textsToParse = [prBody, ...prComments.map((comment) => comment.body)]
|
||||
for (const text of textsToParse) {
|
||||
let match;
|
||||
let match
|
||||
|
||||
while ((match = summaryLinesRegex.exec(text)) !== null) {
|
||||
const functionName = match[5];
|
||||
const filePath = match[6];
|
||||
const functionName = match[5]
|
||||
const filePath = match[6]
|
||||
|
||||
if (!optimizations[filePath]) {
|
||||
optimizations[filePath] = new Set();
|
||||
optimizations[filePath] = new Set()
|
||||
}
|
||||
optimizations[filePath].add(functionName);
|
||||
optimizations[filePath].add(functionName)
|
||||
}
|
||||
}
|
||||
|
||||
return optimizations;
|
||||
return optimizations
|
||||
}
|
||||
|
||||
export function buildDependentPrTitle(
|
||||
|
|
@ -159,9 +168,7 @@ export function buildDependentPrTitle(
|
|||
return buildPrTitle(functionName, speedupPct) + ` in PR #${pullNumber} (\`${baseBranch}\`)`
|
||||
}
|
||||
|
||||
|
||||
export function buildPrTitle(functionName: string, speedupPct: string): string {
|
||||
const type = functionName.includes(".") ? "method" : "function"
|
||||
return `⚡️ Speed up ${type} \`${functionName}\` by ${speedupPct}`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { posthog } from "../analytics"
|
||||
import { userForAPIKey } from "@codeflash-ai/common/token-functions"
|
||||
import { userForAPIKey } from "@codeflash-ai/common"
|
||||
|
||||
// Middleware to check for valid API key
|
||||
export async function checkForValidAPIKey(req: AuthorizedUserReq, res, next: () => void) {
|
||||
export async function checkForValidAPIKey(req: AuthorizedUserReq, res: Response, next: () => void) {
|
||||
const authHeader = req.headers.authorization
|
||||
if (authHeader == null) {
|
||||
posthog.capture({
|
||||
|
|
|
|||
11660
js/cf-api/package-lock.json
generated
Normal file
11660
js/cf-api/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -7,16 +7,18 @@
|
|||
"npx": "npx",
|
||||
"build": "npm install --loglevel verbose && npx prisma generate",
|
||||
"deploy": "az webapp up -n codeflash-api --sku P1V2 --runtime NODE:20-lts",
|
||||
"start": "npx tsx index.ts"
|
||||
"start": "npx prisma generate && npx tsx index.ts",
|
||||
"prisma:generate": "cd ../common && npx prisma generate",
|
||||
"prisma:migrate": "cd ../common && npx prisma migrate dev"
|
||||
},
|
||||
"dependencies": {
|
||||
"@awaitjs/express": "^0.9.0",
|
||||
"@azure/identity": "^4.0.0",
|
||||
"@azure/keyvault-keys": "^4.7.2",
|
||||
"@azure/keyvault-secrets": "^4.7.0",
|
||||
"@codeflash-ai/common": "1.0.8",
|
||||
"@codeflash-ai/common": "1.0.9",
|
||||
"@notionhq/client": "^2.2.14",
|
||||
"@prisma/client": "^6.1.0",
|
||||
"@prisma/client": "^6.2.1",
|
||||
"@sentry/node": "^8.7.0",
|
||||
"@sentry/profiling-node": "^8.7.0",
|
||||
"@slack/web-api": "^7.4.0",
|
||||
|
|
@ -46,7 +48,10 @@
|
|||
"eslint-plugin-promise": "^6.1.1",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "^3.4.2",
|
||||
"prisma": "^6.1.0",
|
||||
"prisma": "^6.2.1",
|
||||
"ts-jest": "^29.1.1"
|
||||
},
|
||||
"prisma": {
|
||||
"schema": "./node_modules/@codeflash-ai/common/prisma/schema.prisma"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
-- CreateTable
|
||||
CREATE TABLE "accounts"
|
||||
(
|
||||
"id" SERIAL NOT NULL,
|
||||
"userId" INTEGER NOT NULL,
|
||||
"type" VARCHAR(255) NOT NULL,
|
||||
"provider" VARCHAR(255) NOT NULL,
|
||||
"providerAccountId" VARCHAR(255) NOT NULL,
|
||||
"refresh_token" TEXT,
|
||||
"access_token" TEXT,
|
||||
"expires_at" BIGINT,
|
||||
"id_token" TEXT,
|
||||
"scope" TEXT,
|
||||
"session_state" TEXT,
|
||||
"token_type" TEXT,
|
||||
|
||||
CONSTRAINT "accounts_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "sessions"
|
||||
(
|
||||
"id" SERIAL NOT NULL,
|
||||
"userId" INTEGER NOT NULL,
|
||||
"expires" TIMESTAMPTZ(6) NOT NULL,
|
||||
"sessionToken" VARCHAR(255) NOT NULL,
|
||||
|
||||
CONSTRAINT "sessions_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "users"
|
||||
(
|
||||
"id" SERIAL NOT NULL,
|
||||
"name" VARCHAR(255),
|
||||
"email" VARCHAR(255),
|
||||
"emailVerified" TIMESTAMPTZ(6),
|
||||
"image" TEXT,
|
||||
|
||||
CONSTRAINT "users_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "verification_token"
|
||||
(
|
||||
"identifier" TEXT NOT NULL,
|
||||
"expires" TIMESTAMPTZ(6) NOT NULL,
|
||||
"token" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "verification_token_pk" PRIMARY KEY ("identifier", "token")
|
||||
);
|
||||
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `accounts` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `sessions` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `users` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `verification_token` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropTable
|
||||
DROP TABLE "accounts";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "sessions";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "users";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "verification_token";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "cf_api_keys"
|
||||
(
|
||||
"id" SERIAL NOT NULL,
|
||||
"key" VARCHAR(255) NOT NULL,
|
||||
"suffix" VARCHAR(4) NOT NULL,
|
||||
"name" VARCHAR(255) NOT NULL,
|
||||
"created_at" TIMESTAMPTZ(6) NOT NULL,
|
||||
"last_used" TIMESTAMPTZ(6) NOT NULL,
|
||||
"user_id" TEXT,
|
||||
"org_id" TEXT,
|
||||
|
||||
CONSTRAINT "cf_api_keys_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[key]` on the table `cf_api_keys` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "cf_api_keys" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP,
|
||||
ALTER
|
||||
COLUMN "last_used" DROP
|
||||
NOT NULL;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "cf_api_keys_key_key" ON "cf_api_keys" ("key");
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
-- CreateTable
|
||||
CREATE TABLE "optimization_features" (
|
||||
"trace_id" CHAR(36) NOT NULL,
|
||||
"original_code" TEXT NOT NULL,
|
||||
"optimizations_raw" JSONB,
|
||||
"optimizations_post" JSONB,
|
||||
"explanations" JSONB,
|
||||
"speedup_ratio" JSONB,
|
||||
"original_runtime" DOUBLE PRECISION,
|
||||
"optimized_runtime" JSONB,
|
||||
"is_correct" JSONB,
|
||||
"generated_test" TEXT[],
|
||||
"test_framework" TEXT,
|
||||
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"aiservice_commit_id" TEXT NOT NULL,
|
||||
"metadata" JSONB,
|
||||
|
||||
CONSTRAINT "optimization_features_pkey" PRIMARY KEY ("trace_id")
|
||||
);
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `explanations` on the `optimization_features` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "optimization_features" DROP COLUMN "explanations",
|
||||
ADD COLUMN "explanations_post" JSONB,
|
||||
ADD COLUMN "explanations_raw" JSONB,
|
||||
ALTER COLUMN "original_code" DROP NOT NULL,
|
||||
ALTER COLUMN "created_at" DROP NOT NULL,
|
||||
ALTER COLUMN "aiservice_commit_id" DROP NOT NULL;
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `org_id` on the `cf_api_keys` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "cf_api_keys" DROP COLUMN "org_id",
|
||||
ADD COLUMN "tier" TEXT;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "optimization_features" ADD COLUMN "user_id" TEXT;
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "optimization_features"
|
||||
ADD COLUMN "experiment_id" TEXT;
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `experiment_id` on the `optimization_features` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "optimization_features"
|
||||
DROP COLUMN "experiment_id",
|
||||
ADD COLUMN "experiment_metadata" JSONB;
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
-- CreateTable
|
||||
CREATE TABLE "users" (
|
||||
"user_id" TEXT NOT NULL,
|
||||
"github_username" TEXT NOT NULL,
|
||||
"email" TEXT,
|
||||
"name" TEXT,
|
||||
|
||||
CONSTRAINT "users_pkey" PRIMARY KEY ("user_id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "users_github_username_key" ON "users"("github_username");
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "onboarding_completed" BOOLEAN NOT NULL DEFAULT false;
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (i.e. Git)
|
||||
provider = "postgresql"
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model cf_api_keys {
|
||||
id Int @id @default(autoincrement())
|
||||
key String @unique @db.VarChar(255)
|
||||
suffix String @db.VarChar(4)
|
||||
name String @db.VarChar(255)
|
||||
created_at DateTime @default(now()) @db.Timestamptz(6)
|
||||
last_used DateTime? @db.Timestamptz(6)
|
||||
user_id String?
|
||||
tier String?
|
||||
}
|
||||
|
||||
model users {
|
||||
user_id String @id
|
||||
github_username String @unique
|
||||
email String?
|
||||
name String?
|
||||
onboarding_completed Boolean @default(false)
|
||||
created_at DateTime @default(now()) @db.Timestamptz(6)
|
||||
}
|
||||
|
||||
model optimization_features {
|
||||
trace_id String @id @db.Char(36)
|
||||
original_code String?
|
||||
optimizations_raw Json?
|
||||
optimizations_post Json?
|
||||
speedup_ratio Json?
|
||||
original_runtime Float?
|
||||
optimized_runtime Json?
|
||||
is_correct Json?
|
||||
generated_test String[]
|
||||
instrumented_generated_test String[]
|
||||
test_framework String?
|
||||
created_at DateTime? @default(now()) @db.Timestamptz(6)
|
||||
aiservice_commit_id String?
|
||||
metadata Json?
|
||||
explanations_post Json?
|
||||
explanations_raw Json?
|
||||
user_id String?
|
||||
experiment_metadata Json?
|
||||
pull_request Json?
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
/** @type {import("next").NextConfig} */
|
||||
let nextConfig
|
||||
nextConfig = {
|
||||
transpilePackages: ["@codeflash-ai/common"],
|
||||
experimental: { serverActions: { allowedOrigins: ["app.codeflash.ai", "localhost:3000"] } },
|
||||
typescript: {
|
||||
ignoreBuildErrors: false,
|
||||
|
|
@ -11,22 +12,6 @@ nextConfig = {
|
|||
|
||||
import { withSentryConfig } from "@sentry/nextjs"
|
||||
|
||||
// nextConfig.webpack = (config) => {
|
||||
// config.module.rules.push({
|
||||
// test: /\.tsx?$/,
|
||||
// use: [
|
||||
// {
|
||||
// loader: 'ts-loader',
|
||||
// options: {
|
||||
// transpileOnly: true,
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// exclude: /node_modules/,
|
||||
// });
|
||||
// return config;
|
||||
// };
|
||||
|
||||
export default withSentryConfig(
|
||||
nextConfig,
|
||||
{
|
||||
|
|
|
|||
15276
js/cf-webapp/package-lock.json
generated
Normal file
15276
js/cf-webapp/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -8,14 +8,16 @@
|
|||
"deploy": "az webapp up -n codeflash-webapp-2 --sku P1V2 --runtime NODE:20-lts",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"test": "vitest"
|
||||
"test": "vitest",
|
||||
"prisma:generate": "npx prisma generate",
|
||||
"prisma:migrate": "npx prisma migrate dev"
|
||||
},
|
||||
"dependencies": {
|
||||
"@auth0/nextjs-auth0": "^3.3.0",
|
||||
"@azure/msal-node": "^2.6.6",
|
||||
"@codeflash-ai/common": "1.0.8",
|
||||
"@codeflash-ai/common": "1.0.9",
|
||||
"@hookform/resolvers": "^3.3.2",
|
||||
"@prisma/client": "^5.15.0",
|
||||
"@prisma/client": "^6.2.1",
|
||||
"@radix-ui/react-dialog": "^1.0.5",
|
||||
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
||||
"@radix-ui/react-label": "^2.0.2",
|
||||
|
|
@ -69,10 +71,13 @@
|
|||
"@testing-library/react": "^16.0.0",
|
||||
"jsdom": "^24.1.0",
|
||||
"prettier": "3.2.5",
|
||||
"prisma": "^5.15.0",
|
||||
"prisma": "^6.2.1",
|
||||
"typescript": "^5.4.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0 < 21.0.0"
|
||||
},
|
||||
"prisma": {
|
||||
"schema": "./node_modules/@codeflash-ai/common/prisma/schema.prisma"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
-- CreateTable
|
||||
CREATE TABLE "accounts"
|
||||
(
|
||||
"id" SERIAL NOT NULL,
|
||||
"userId" INTEGER NOT NULL,
|
||||
"type" VARCHAR(255) NOT NULL,
|
||||
"provider" VARCHAR(255) NOT NULL,
|
||||
"providerAccountId" VARCHAR(255) NOT NULL,
|
||||
"refresh_token" TEXT,
|
||||
"access_token" TEXT,
|
||||
"expires_at" BIGINT,
|
||||
"id_token" TEXT,
|
||||
"scope" TEXT,
|
||||
"session_state" TEXT,
|
||||
"token_type" TEXT,
|
||||
|
||||
CONSTRAINT "accounts_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "sessions"
|
||||
(
|
||||
"id" SERIAL NOT NULL,
|
||||
"userId" INTEGER NOT NULL,
|
||||
"expires" TIMESTAMPTZ(6) NOT NULL,
|
||||
"sessionToken" VARCHAR(255) NOT NULL,
|
||||
|
||||
CONSTRAINT "sessions_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "users"
|
||||
(
|
||||
"id" SERIAL NOT NULL,
|
||||
"name" VARCHAR(255),
|
||||
"email" VARCHAR(255),
|
||||
"emailVerified" TIMESTAMPTZ(6),
|
||||
"image" TEXT,
|
||||
|
||||
CONSTRAINT "users_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "verification_token"
|
||||
(
|
||||
"identifier" TEXT NOT NULL,
|
||||
"expires" TIMESTAMPTZ(6) NOT NULL,
|
||||
"token" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "verification_token_pk" PRIMARY KEY ("identifier", "token")
|
||||
);
|
||||
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `accounts` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `sessions` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `users` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `verification_token` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropTable
|
||||
DROP TABLE "accounts";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "sessions";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "users";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "verification_token";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "cf_api_keys"
|
||||
(
|
||||
"id" SERIAL NOT NULL,
|
||||
"key" VARCHAR(255) NOT NULL,
|
||||
"suffix" VARCHAR(4) NOT NULL,
|
||||
"name" VARCHAR(255) NOT NULL,
|
||||
"created_at" TIMESTAMPTZ(6) NOT NULL,
|
||||
"last_used" TIMESTAMPTZ(6) NOT NULL,
|
||||
"user_id" TEXT,
|
||||
"org_id" TEXT,
|
||||
|
||||
CONSTRAINT "cf_api_keys_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[key]` on the table `cf_api_keys` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "cf_api_keys" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP,
|
||||
ALTER
|
||||
COLUMN "last_used" DROP
|
||||
NOT NULL;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "cf_api_keys_key_key" ON "cf_api_keys" ("key");
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
-- CreateTable
|
||||
CREATE TABLE "optimization_features" (
|
||||
"trace_id" CHAR(36) NOT NULL,
|
||||
"original_code" TEXT NOT NULL,
|
||||
"optimizations_raw" JSONB,
|
||||
"optimizations_post" JSONB,
|
||||
"explanations" JSONB,
|
||||
"speedup_ratio" JSONB,
|
||||
"original_runtime" DOUBLE PRECISION,
|
||||
"optimized_runtime" JSONB,
|
||||
"is_correct" JSONB,
|
||||
"generated_test" TEXT[],
|
||||
"test_framework" TEXT,
|
||||
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"aiservice_commit_id" TEXT NOT NULL,
|
||||
"metadata" JSONB,
|
||||
|
||||
CONSTRAINT "optimization_features_pkey" PRIMARY KEY ("trace_id")
|
||||
);
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `explanations` on the `optimization_features` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "optimization_features" DROP COLUMN "explanations",
|
||||
ADD COLUMN "explanations_post" JSONB,
|
||||
ADD COLUMN "explanations_raw" JSONB,
|
||||
ALTER COLUMN "original_code" DROP NOT NULL,
|
||||
ALTER COLUMN "created_at" DROP NOT NULL,
|
||||
ALTER COLUMN "aiservice_commit_id" DROP NOT NULL;
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `org_id` on the `cf_api_keys` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "cf_api_keys" DROP COLUMN "org_id",
|
||||
ADD COLUMN "tier" TEXT;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "optimization_features" ADD COLUMN "user_id" TEXT;
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "optimization_features"
|
||||
ADD COLUMN "experiment_id" TEXT;
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `experiment_id` on the `optimization_features` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "optimization_features"
|
||||
DROP COLUMN "experiment_id",
|
||||
ADD COLUMN "experiment_metadata" JSONB;
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
-- CreateTable
|
||||
CREATE TABLE "users" (
|
||||
"user_id" TEXT NOT NULL,
|
||||
"github_username" TEXT NOT NULL,
|
||||
"email" TEXT,
|
||||
"name" TEXT,
|
||||
|
||||
CONSTRAINT "users_pkey" PRIMARY KEY ("user_id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "users_github_username_key" ON "users"("github_username");
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "onboarding_completed" BOOLEAN NOT NULL DEFAULT false;
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (i.e. Git)
|
||||
provider = "postgresql"
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model cf_api_keys {
|
||||
id Int @id @default(autoincrement())
|
||||
key String @unique @db.VarChar(255)
|
||||
suffix String @db.VarChar(4)
|
||||
name String @db.VarChar(255)
|
||||
created_at DateTime @default(now()) @db.Timestamptz(6)
|
||||
last_used DateTime? @db.Timestamptz(6)
|
||||
user_id String?
|
||||
tier String?
|
||||
}
|
||||
|
||||
model users {
|
||||
user_id String @id
|
||||
github_username String @unique
|
||||
email String?
|
||||
name String?
|
||||
onboarding_completed Boolean @default(false)
|
||||
}
|
||||
|
||||
model optimization_features {
|
||||
trace_id String @id @db.Char(36)
|
||||
original_code String?
|
||||
optimizations_raw Json?
|
||||
optimizations_post Json?
|
||||
speedup_ratio Json?
|
||||
original_runtime Float?
|
||||
optimized_runtime Json?
|
||||
is_correct Json?
|
||||
generated_test String[]
|
||||
instrumented_generated_test String[]
|
||||
test_framework String?
|
||||
created_at DateTime? @default(now()) @db.Timestamptz(6)
|
||||
aiservice_commit_id String?
|
||||
metadata Json?
|
||||
explanations_post Json?
|
||||
explanations_raw Json?
|
||||
user_id String?
|
||||
experiment_metadata Json?
|
||||
pull_request Json?
|
||||
}
|
||||
|
|
@ -1,5 +1,12 @@
|
|||
"use client"
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table"
|
||||
import ReactMarkdown from "react-markdown"
|
||||
import { DeleteApiKeyButton } from "@/app/app/apikeys/delete-api-key-button"
|
||||
import React, { type JSX } from "react"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"use server"
|
||||
import { getSession } from "@auth0/nextjs-auth0"
|
||||
import { redirect } from "next/navigation"
|
||||
import { deleteAPIKeyById, genAndStoreAPITokenHash } from "@codeflash-ai/common/token-functions"
|
||||
import { deleteAPIKeyById, genAndStoreAPITokenHash } from "@codeflash-ai/common"
|
||||
|
||||
export async function generateToken(keyName: string): Promise<string> {
|
||||
const user = await getSession()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
import { redirect } from "next/navigation"
|
||||
import { getSession } from "@auth0/nextjs-auth0"
|
||||
import { type JSX } from "react"
|
||||
import { createOrUpdateUser, hasCompletedOnboarding } from "@codeflash-ai/common/user-functions"
|
||||
import { createOrUpdateUser, hasCompletedOnboarding } from "@codeflash-ai/common"
|
||||
import PostHogClient from "@/app/app/posthog"
|
||||
|
||||
// export const metadata: Metadata = {
|
||||
|
|
@ -33,8 +33,7 @@ export default async function AuthenticationPage(): Promise<JSX.Element> {
|
|||
})
|
||||
posthog.capture({
|
||||
distinctId: user.sub,
|
||||
properties: { username: user.nickname,
|
||||
email: user.email },
|
||||
properties: { username: user.nickname, email: user.email },
|
||||
event: "webapp-user-logged-in",
|
||||
})
|
||||
await posthog.shutdown()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"use server"
|
||||
|
||||
import { getSession } from "@auth0/nextjs-auth0"
|
||||
import { markUserCompletedOnboarding, submitOnboardingQuestions } from "@codeflash-ai/common/user-functions"
|
||||
import { markUserCompletedOnboarding, submitOnboardingQuestions } from "@codeflash-ai/common"
|
||||
import PostHogClient from "@/app/app/posthog"
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
|
|
@ -41,8 +41,7 @@ export async function SubmitFirstOnboardingPage(
|
|||
await submitOnboardingQuestions(user_id, email)
|
||||
}
|
||||
|
||||
export async function SubmitSkipOnboardingPage(
|
||||
): Promise<void> {
|
||||
export async function SubmitSkipOnboardingPage(): Promise<void> {
|
||||
const session = await getSession()
|
||||
if (session == null) {
|
||||
console.log("No session, redirecting to login")
|
||||
|
|
@ -68,4 +67,4 @@ export async function SubmitSkipOnboardingPage(
|
|||
await posthog.shutdown()
|
||||
|
||||
await markUserCompletedOnboarding(user_id)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
3
js/common/.gitignore
vendored
Normal file
3
js/common/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
node_modules
|
||||
dist
|
||||
*.tgz
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
//npm.pkg.github.com/:_authToken=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
|
||||
//npm.pkg.github.com/:_authToken=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
|
||||
@codeflash-ai:registry=https://npm.pkg.github.com
|
||||
1941
js/common/package-lock.json
generated
Normal file
1941
js/common/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,27 +1,35 @@
|
|||
{
|
||||
"name": "@codeflash-ai/common",
|
||||
"version": "1.0.8",
|
||||
"main": "index.ts",
|
||||
"type": "module",
|
||||
"types": "index.d.ts",
|
||||
"version": "1.0.9",
|
||||
"main": "dist/src/index.js",
|
||||
"types": "dist/src/index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/codeflash-ai/codeflash.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npx prisma generate && tsc",
|
||||
"clean": "rm -rf dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"@azure/identity": "^4.2.0",
|
||||
"@azure/keyvault-secrets": "^4.8.0",
|
||||
"@azure/msal-node": "^2.9.0",
|
||||
"@prisma/client": "^5.15.0"
|
||||
"@prisma/client": "^6.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.10.1",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"prettier": "^3.3.0",
|
||||
"prisma": "^5.15.0"
|
||||
"prisma": "^6.2.1",
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://npm.pkg.github.com"
|
||||
}
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"prisma"
|
||||
]
|
||||
}
|
||||
|
|
@ -27,23 +27,23 @@ model users {
|
|||
}
|
||||
|
||||
model optimization_features {
|
||||
trace_id String @id @db.Char(36)
|
||||
original_code String?
|
||||
optimizations_raw Json?
|
||||
optimizations_post Json?
|
||||
speedup_ratio Json?
|
||||
original_runtime Float?
|
||||
optimized_runtime Json?
|
||||
is_correct Json?
|
||||
generated_test String[]
|
||||
trace_id String @id @db.Char(36)
|
||||
original_code String?
|
||||
optimizations_raw Json?
|
||||
optimizations_post Json?
|
||||
speedup_ratio Json?
|
||||
original_runtime Float?
|
||||
optimized_runtime Json?
|
||||
is_correct Json?
|
||||
generated_test String[]
|
||||
instrumented_generated_test String[]
|
||||
test_framework String?
|
||||
created_at DateTime? @default(now()) @db.Timestamptz(6)
|
||||
aiservice_commit_id String?
|
||||
metadata Json?
|
||||
explanations_post Json?
|
||||
explanations_raw Json?
|
||||
user_id String?
|
||||
experiment_metadata Json?
|
||||
pull_request Json?
|
||||
test_framework String?
|
||||
created_at DateTime? @default(now()) @db.Timestamptz(6)
|
||||
aiservice_commit_id String?
|
||||
metadata Json?
|
||||
explanations_post Json?
|
||||
explanations_raw Json?
|
||||
user_id String?
|
||||
experiment_metadata Json?
|
||||
pull_request Json?
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
// https://github.com/vercel/next.js/issues/46070
|
||||
// is resolved.
|
||||
// export * from '@prisma/client';
|
||||
export * from "./token-functions"
|
||||
export * from "./user-functions"
|
||||
|
||||
import { PrismaClient } from "@prisma/client"
|
||||
|
||||
export const prisma = new PrismaClient()
|
||||
prisma.cf_api_keys
|
||||
export { prisma } from "./prisma-client"
|
||||
// Use prismaClient instead of new PrismaClient()
|
||||
4
js/common/src/prisma-client.ts
Normal file
4
js/common/src/prisma-client.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// common/src/lib/prisma-client.ts
|
||||
import { PrismaClient } from "@prisma/client"
|
||||
|
||||
export const prisma = new PrismaClient()
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
"use server"
|
||||
import util from "util"
|
||||
import { createHash, type Hash, randomBytes } from "crypto"
|
||||
import { prisma } from "./index"
|
||||
import { cf_api_keys } from "@prisma/client"
|
||||
import { prisma } from "./prisma-client"
|
||||
|
||||
// const prisma = new PrismaClient()
|
||||
async function generateRandomAPIKey(): Promise<string> {
|
||||
const randomBytesAsync = util.promisify(randomBytes)
|
||||
const token = (await randomBytesAsync(48)).toString("base64url")
|
||||
|
|
@ -68,7 +66,7 @@ export async function userForAPIKey(key: string): Promise<null | string> {
|
|||
}
|
||||
}
|
||||
|
||||
export async function deleteAPIKeyById(id: number, userId: string): Promise<cf_api_keys> {
|
||||
export async function deleteAPIKeyById(id: number, userId: string) {
|
||||
return prisma.cf_api_keys.delete({
|
||||
where: {
|
||||
id,
|
||||
|
|
@ -1,13 +1,12 @@
|
|||
"use server"
|
||||
import { prisma } from "./index"
|
||||
import { users } from "@prisma/client"
|
||||
import { prisma } from "./prisma-client"
|
||||
|
||||
export async function createOrUpdateUser(
|
||||
user_id: string,
|
||||
github_username: string,
|
||||
email: string | null,
|
||||
name: string | null,
|
||||
): Promise<users> {
|
||||
) {
|
||||
return prisma.users.upsert({
|
||||
where: { user_id },
|
||||
update: { email, github_username, name },
|
||||
13
js/common/tsconfig.json
Normal file
13
js/common/tsconfig.json
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2020",
|
||||
"module": "commonjs",
|
||||
"outDir": "./dist",
|
||||
"rootDir": ".",
|
||||
"declaration": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
Loading…
Reference in a new issue