🎥 Make videos programmatically with React
AI JSDoc
Jonny Burgeraa3baae3b241
diff --git a/packages/ai-improvements/improve-docs.ts b/packages/ai-improvements/improve-docs.tsindex a9fb0a8499..522c2bb811 100644--- a/packages/ai-improvements/improve-docs.ts+++ b/packages/ai-improvements/improve-docs.ts@@ -1,51 +1,53 @@-import path from "path";-import { OpenAI } from "openai";-import { getApis } from "./map-over-api";-import { findMistakes } from "./tasks/find-mistakes";-import { generateJSDocTask } from "./tasks/generate-jsdoc";+import {OpenAI} from 'openai';+import path from 'path';+import {getApis} from './map-over-api';+import {findMistakes} from './tasks/find-mistakes';+import {generateJSDocTask} from './tasks/generate-jsdoc';const openai = new OpenAI({- apiKey: process.env.OPEN_AI_API_KEY,+ apiKey: process.env.OPEN_AI_API_KEY,});const apis = await getApis();-const task = "generate-jsdoc";+const task = 'generate-jsdoc';for (const api of apis) {- const contents = await Bun.file(api.filePath).text();- if (!api.sourceCodePath) {- continue;- }-- const flag = path.join(".done", api.id);-- if (await Bun.file(flag).exists()) {- console.log(`Article ${api.title} already processed`);- continue;- }-- const file = path.join(process.cwd(), "..", "..", api.sourceCodePath);- console.log(file);- const sourceContents = await Bun.file(file).text();- console.log(`Article ${api.title} contains source code`);-- const reply =- task === "generate-jsdoc"- ? await generateJSDocTask({- contents,- link: api.link,- openai,- sourceContents,- })- : await findMistakes({- sourceContents,- openai,- contents,- });-- await Bun.write(flag, "txt");- if (reply !== "OK") {- process.exit(0);- }+ const contents = await Bun.file(api.filePath).text();+ if (!api.sourceCodePath) {+ continue;+ }++ const flag = path.join('.done', api.id);++ if (await Bun.file(flag).exists()) {+ console.log(`Article ${api.title} already processed`);+ continue;+ }++ const file = path.join(process.cwd(), '..', '..', api.sourceCodePath);+ console.log(file);+ const sourceContents = await Bun.file(file).text();+ console.log(`Article ${api.title} contains source code`);++ const reply =+ task === 'generate-jsdoc'+ ? await generateJSDocTask({+ contents,+ link: api.link,+ openai,+ sourceContents,+ filePath: file,+ title: api.title,+ })+ : await findMistakes({+ sourceContents,+ openai,+ contents,+ });++ await Bun.write(flag, 'txt');+ if (reply !== 'OK') {+ process.exit(0);+ }}diff --git a/packages/ai-improvements/package.json b/packages/ai-improvements/package.jsonindex de841a6b8e..9a3ba20db6 100644--- a/packages/ai-improvements/package.json+++ b/packages/ai-improvements/package.json@@ -4,7 +4,9 @@},"name": "ai-improvements","dependencies": {- "openai": "4.67.1"+ "openai": "4.67.1",+ "recast": "0.23.9",+ "@babel/types": "7.24.0"},"private": true,"version": "4.0.244"diff --git a/packages/ai-improvements/tasks/add-jsdoc-comment.ts b/packages/ai-improvements/tasks/add-jsdoc-comment.tsnew file mode 100644index 0000000000..ca26121863--- /dev/null+++ b/packages/ai-improvements/tasks/add-jsdoc-comment.ts@@ -0,0 +1,63 @@+import type {File} from '@babel/types';+import * as recast from 'recast';+import * as tsParser from 'recast/parsers/babel-ts';++export const addJsDocComment = ({+ documentTitle,+ sourceCode,+}: {+ documentTitle: string;+ sourceCode: string;+}) => {+ const ast = recast.parse(sourceCode, {+ parser: tsParser,+ }) as File;++ const withoutParentheses = documentTitle+ .replace(/\(.*\)/, '')+ .replace(/\</, '')+ .replace(/\>/, '')+ .replace(/\\/, '');++ recast.visit(ast, {+ visitExportNamedDeclaration: (p) => {+ const node = p.node;++ if (node.type !== 'ExportNamedDeclaration') {+ return node;+ }++ if (!node.declaration) {+ return node;+ }+ if (node.declaration.type !== 'VariableDeclaration') {+ return node;+ }+ const declaration = node.declaration.declarations[0];+ if (!declaration) {+ return node;+ }+ if (declaration.type !== 'VariableDeclarator') {+ return node;+ }+ if (declaration.id.type !== 'Identifier') {+ return node;+ }+ if (declaration.id.name !== withoutParentheses) {+ return node;+ }++ const newComment = recast.types.builders.commentBlock('hi there');+ return {+ ...node,+ leadingComments: [newComment],+ };+ },+ });++ const output = recast.print(ast, {+ parser: tsParser,+ }).code;++ return output;+};diff --git a/packages/ai-improvements/tasks/generate-jsdoc.ts b/packages/ai-improvements/tasks/generate-jsdoc.tsindex 427d4a21bc..4aa248a646 100644--- a/packages/ai-improvements/tasks/generate-jsdoc.ts+++ b/packages/ai-improvements/tasks/generate-jsdoc.ts@@ -1,59 +1,72 @@-import { OpenAI } from "openai";+import {OpenAI} from 'openai';+import {addJsDocComment} from './add-jsdoc-comment';export const generateJSDocTask = async ({- sourceContents,- openai,- contents,- link,+ sourceContents,+ openai,+ contents,+ link,+ title,+ filePath,}: {- sourceContents: string;- openai: OpenAI;- contents: string;- link: string;+ sourceContents: string;+ openai: OpenAI;+ contents: string;+ link: string;+ title: string;+ filePath: string;}) => {- const stream = await openai.chat.completions.create({- model: "gpt-4-turbo",- messages: [- {- role: "system",- content: [- "You are going to be given an API source code and an API documentation, and a URL to use.",- "Check if the function already has a JSDoc comment.",- "If it does, respond only with 'OK'.",- "If not, write a JSDoc comment for the function. Only write the JSDoc comment, don't reply anything else.",- "Put the URL as the documentation.",- "This is the right format for a JSDoc comment:\n",- `+ const stream = await openai.chat.completions.create({+ model: 'gpt-4-turbo',+ messages: [+ {+ role: 'system',+ content: [+ 'You are going to be given an API source code and an API documentation, and a URL to use.',+ 'Check if the function already has a JSDoc comment.',+ "If it does, respond only with 'OK'.",+ "If not, write a JSDoc comment for the function. Only write the JSDoc comment, don't reply anything else.",+ 'Put the URL as the documentation.',+ 'This is the right format for a JSDoc comment:\n',+ `/*** @description Triggers a render on a lambda given a composition and a lambda function.* @see [Documentation](https://remotion.dev/docs/lambda/rendermediaonlambda)- * @param params.functionName The name of the Lambda function that should be used- * @param params.serveUrl The URL of the deployed project* @returns {Promise<RenderMediaOnLambdaOutput>} See documentation for detailed structure*/`,- ].join("\n"),- },- {- role: "system",- content: "This is the url to use:\n" + link,- },- {- role: "user",- content: "This is the source code for the API:\n" + sourceContents,- },- {- role: "user",- content: "This is the markdown of the documentation:\n" + contents,- },- ],- stream: true,- });- let reply = "";- for await (const chunk of stream) {- reply += chunk.choices[0]?.delta?.content || "";- process.stdout.write(chunk.choices[0]?.delta?.content || "");- }+ ].join('\n'),+ },+ {+ role: 'system',+ content: 'This is the url to use:\n' + link,+ },+ {+ role: 'user',+ content: 'This is the source code for the API:\n' + sourceContents,+ },+ {+ role: 'user',+ content: 'This is the markdown of the documentation:\n' + contents,+ },+ ],+ stream: true,+ });+ let reply = '';+ for await (const chunk of stream) {+ reply += chunk.choices[0]?.delta?.content || '';+ process.stdout.write(chunk.choices[0]?.delta?.content || '');+ }- return reply;+ if (reply === 'OK') {+ return reply;+ }++ const newDocument = addJsDocComment({+ documentTitle: title,+ sourceCode: sourceContents,+ });+ await Bun.write(filePath, newDocument);++ return reply;};diff --git a/packages/core/src/use-current-scale.ts b/packages/core/src/use-current-scale.tsindex ca8401780d..77548fbd6d 100644--- a/packages/core/src/use-current-scale.ts+++ b/packages/core/src/use-current-scale.ts@@ -71,8 +71,12 @@ export const calculateScale = ({};/**- * Gets the current scale of the container in which the component is being rendered.- * Only works in the Remotion Studio and in the Remotion Player.+ * Retrieves the current scale of the canvas within Remotion's Studio or Player context.+ * In the Studio, it corresponds to the zoom level (1 equals no scaling, i.e., 100% zoom).+ * In the Player, it indicates the scaling necessary to fit the video into the player.+ * If called outside of a Remotion context, by default, it throws an error unless configured not to.+ * @see [Documentation](https://remotion.dev/docs/use-current-scale)+ * @returns {number} The current scaling factor.*/export const useCurrentScale = (options?: Options) => {const hasContext = React.useContext(CurrentScaleContext);diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 40da9d192b..69c6a12285 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -39,9 +39,15 @@ importers:packages/ai-improvements:dependencies:+ '@babel/types':+ specifier: 7.24.0+ version: 7.24.0openai:specifier: 4.67.1version: 4.67.1([email protected])+ recast:+ specifier: 0.23.9+ version: 0.23.9packages/animated-emoji:dependencies:@@ -4393,7 +4399,7 @@ packages:resolution: {integrity: sha512-o9HBZL1G2129luEUlG1hB4N/nlYNWHnpwlND9eOMclRqqu1YDy2sSYVCFUZwl8I1Gxh+QSRrP2vD7EpUmFVXxg==}engines: {node: '>=6.9.0'}dependencies:- '@babel/types': 7.25.6+ '@babel/types': 7.26.0'@jridgewell/gen-mapping': 0.3.5'@jridgewell/trace-mapping': 0.3.25jsesc: 2.5.2@@ -4402,7 +4408,7 @@ packages:resolution: {integrity: sha512-VPC82gr1seXOpkjAAKoLhP50vx4vGNlF4msF64dSFq1P8RfB+QAuJWGHPXXPc8QyfVWwwB/TNNU4+ayZmHNbZw==}engines: {node: '>=6.9.0'}dependencies:- '@babel/types': 7.25.6+ '@babel/types': 7.26.0'@jridgewell/gen-mapping': 0.3.5'@jridgewell/trace-mapping': 0.3.25jsesc: 2.5.2@@ -4435,7 +4441,7 @@ packages:resolution: {integrity: sha512-BaDeOonYvhdKw+JoMVkAixAAJzG2jVPIwWoKBPdYuY9b452e2rPuI9QPYh3KpofZ3pW2akOmwZLOiOsHMiqRAg==}engines: {node: '>=6.9.0'}dependencies:- '@babel/types': 7.25.6+ '@babel/types': 7.26.0/@babel/[email protected]:resolution: {integrity: sha512-gv7320KBUFJz1RnylIg5WWYPRXKZ884AGkYpgpWW02TH66Dl+HaC1t1CKd0z3R4b6hdYEcmrNZHUmfCP+1u3/g==}@@ -4449,7 +4455,7 @@ packages:engines: {node: '>=6.9.0'}dependencies:'@babel/traverse': 7.25.6- '@babel/types': 7.25.6+ '@babel/types': 7.26.0transitivePeerDependencies:- supports-colordev: false@@ -4638,7 +4644,7 @@ packages:resolution: {integrity: sha512-DoiN84+4Gnd0ncbBOM9AZENV4a5ZiL39HYMyZJGZ/AZEykHYdJw0wW3kdcsh9/Kn+BRXHLkkklZ51ecPKmI1CQ==}engines: {node: '>=6.9.0'}dependencies:- '@babel/types': 7.25.6+ '@babel/types': 7.26.0/@babel/[email protected]:resolution: {integrity: sha512-Z91cOMM4DseLIGOnog+Z8OI6YseR9bua+HpvLAQ2XayUGU+neTtX+97caALaLdyu53I/fjhbeCnWnRH1O3jFOw==}@@ -4654,7 +4660,7 @@ packages:engines: {node: '>=6.9.0'}dependencies:'@babel/template': 7.25.0- '@babel/types': 7.25.6+ '@babel/types': 7.26.0/@babel/[email protected]:resolution: {integrity: sha512-1/AlxSF92CmGZzHnC515hm4SirTxtpDnLEJ0UyEMgTMZN+6bxXKg04dKhiRx5Enel+SUA1G1t5Ed/yQia0efrA==}@@ -4674,7 +4680,7 @@ packages:resolution: {integrity: sha512-MJJwhkoGy5c4ehfoRyrJ/owKeMl19U54h27YYftT0o2teQ3FJ3nQUf/I3LlJsX4l3qlw7WRXUmiyajvHXoTubQ==}engines: {node: '>=6.9.0'}dependencies:- '@babel/types': 7.25.6+ '@babel/types': 7.26.0/@babel/[email protected]:resolution: {integrity: sha512-cokOMkxC/BTyNP1AlY25HuBWM32iCEsLPI4BHDpJCHHm1FU2E7dKWWIXJgQgSFiu4lp8q3bL1BIKwqkSUviqtA==}@@ -4714,7 +4720,7 @@ packages:engines: {node: '>=6.9.0'}dependencies:'@babel/traverse': 7.25.6- '@babel/types': 7.25.6+ '@babel/types': 7.26.0transitivePeerDependencies:- supports-color@@ -4735,7 +4741,7 @@ packages:'@babel/helper-replace-supers': 7.15.4'@babel/helper-simple-access': 7.15.4'@babel/helper-split-export-declaration': 7.15.4- '@babel/helper-validator-identifier': 7.15.7+ '@babel/helper-validator-identifier': 7.25.9'@babel/template': 7.15.4'@babel/traverse': 7.15.4'@babel/types': 7.24.0@@ -4752,7 +4758,7 @@ packages:'@babel/core': 7.23.2'@babel/helper-module-imports': 7.24.7'@babel/helper-simple-access': 7.24.7- '@babel/helper-validator-identifier': 7.24.7+ '@babel/helper-validator-identifier': 7.25.9'@babel/traverse': 7.25.6transitivePeerDependencies:- supports-color@@ -4887,7 +4893,7 @@ packages:engines: {node: '>=6.9.0'}dependencies:'@babel/traverse': 7.25.6- '@babel/types': 7.25.6+ '@babel/types': 7.26.0transitivePeerDependencies:- supports-color@@ -4906,7 +4912,7 @@ packages:engines: {node: '>=6.9.0'}dependencies:'@babel/traverse': 7.25.6- '@babel/types': 7.25.6+ '@babel/types': 7.26.0transitivePeerDependencies:- supports-color@@ -4931,33 +4937,12 @@ packages:resolution: {integrity: sha512-oy5V7pD+UvfkEATUKvIjvIAH/xCzfsFVw7ygW2SI6NClZzquT+mwdTfgfdbUiceh6iQO0CHtCPsyze/MZ2YbAA==}engines: {node: '>=6.9.0'}dependencies:- '@babel/types': 7.25.6-- /@babel/[email protected]:- resolution: {integrity: sha512-803gmbQdqwdf4olxrX4AJyFBV/RTr3rSmOj0rKwesmzlfhYNDEs+/iOcznzpNWlJlIlTJC2QfPFcHB6DlzdVLQ==}- engines: {node: '>=6.9.0'}-- /@babel/[email protected]:- resolution: {integrity: sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ==}- engines: {node: '>=6.9.0'}+ '@babel/types': 7.26.0/@babel/[email protected]:resolution: {integrity: sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA==}engines: {node: '>=6.9.0'}- /@babel/[email protected]:- resolution: {integrity: sha512-K4JvCtQqad9OY2+yTU8w+E82ywk/fe+ELNlt1G8z3bVGlZfn/hOcQQsUhGhW/N+tb3fxK800wLtKOE/aM0m72w==}- engines: {node: '>=6.9.0'}- dev: false-- /@babel/[email protected]:- resolution: {integrity: sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==}- engines: {node: '>=6.9.0'}-- /@babel/[email protected]:- resolution: {integrity: sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==}- engines: {node: '>=6.9.0'}-/@babel/[email protected]:resolution: {integrity: sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==}engines: {node: '>=6.9.0'}@@ -5003,7 +4988,7 @@ packages:engines: {node: '>=6.9.0'}dependencies:'@babel/template': 7.25.0- '@babel/types': 7.25.6+ '@babel/types': 7.26.0/@babel/[email protected]:resolution: {integrity: sha512-tbhNuIxNcVb21pInl3ZSjksLCvgdZy9KwJ8brv993QtIVKJBBkYXz4q4ZbAv31GdnC+R90np23L5FbEBlthAEw==}@@ -5033,7 +5018,7 @@ packages:engines: {node: '>=6.0.0'}hasBin: truedependencies:- '@babel/types': 7.25.6+ '@babel/types': 7.26.0/@babel/[email protected]:resolution: {integrity: sha512-DWMCZH9WA4Maitz2q21SRKHo9QXZxkDsbNZoVD62gusNtNBBqDg9i7uOhASfTfIGNzW+O+r7+jAlM8dwphcJKQ==}@@ -6014,7 +5999,7 @@ packages:'@babel/helper-hoist-variables': 7.24.7'@babel/helper-module-transforms': 7.25.2(@babel/[email protected])'@babel/helper-plugin-utils': 7.24.8- '@babel/helper-validator-identifier': 7.24.7+ '@babel/helper-validator-identifier': 7.25.9transitivePeerDependencies:- supports-colordev: false@@ -7160,7 +7145,7 @@ packages:dependencies:'@babel/code-frame': 7.24.7'@babel/parser': 7.25.6- '@babel/types': 7.25.6+ '@babel/types': 7.26.0/@babel/[email protected]:resolution: {integrity: sha512-9DGttpmPvIxBb/2uwpVo3dqJ+O6RooAFOS+lB+xDqoE2PVCE8nfoHMdZLpfCQRLwvohzXISPZcgxt80xLfsuwg==}@@ -7198,7 +7183,7 @@ packages:'@babel/helper-hoist-variables': 7.24.7'@babel/helper-split-export-declaration': 7.24.7'@babel/parser': 7.25.6- '@babel/types': 7.25.6+ '@babel/types': 7.26.0debug: 4.3.7globals: 11.12.0transitivePeerDependencies:@@ -7212,7 +7197,7 @@ packages:'@babel/generator': 7.25.6'@babel/parser': 7.25.6'@babel/template': 7.25.0- '@babel/types': 7.25.6+ '@babel/types': 7.26.0debug: 4.3.7globals: 11.12.0transitivePeerDependencies:@@ -7236,15 +7221,7 @@ packages:resolution: {integrity: sha512-+j7a5c253RfKh8iABBhywc8NSfP5LURe7Uh4qpsh6jc+aLJguvmIUBdjSdEMQv2bENrCR5MfRdjGo7vzS/ob7w==}engines: {node: '>=6.9.0'}dependencies:- '@babel/helper-string-parser': 7.23.4- '@babel/helper-validator-identifier': 7.22.20- to-fast-properties: 2.0.0-- /@babel/[email protected]:- resolution: {integrity: sha512-/l42B1qxpG6RdfYf343Uw1vmDjeNhneUXtzhojE7pDgfpEypmRhI6j1kr17XCVv4Cgl9HdAiQY2x0GwKm7rWCw==}- engines: {node: '>=6.9.0'}- dependencies:- '@babel/helper-string-parser': 7.24.8+ '@babel/helper-string-parser': 7.25.9'@babel/helper-validator-identifier': 7.25.9to-fast-properties: 2.0.0