-
Notifications
You must be signed in to change notification settings - Fork 20
fix: coerce duration props to Number() in renderers #183
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -150,7 +150,7 @@ export async function renderVideo( | |||||
| const { video } = await ctx.generateVideo({ | ||||||
| model, | ||||||
| prompt: resolvedPrompt, | ||||||
| duration: props.duration ?? 5, | ||||||
| duration: Number(props.duration) || 5, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n src/react/renderers/video.ts | sed -n '145,165p'Repository: vargHQ/sdk Length of output: 909 🏁 Script executed: rg -n "duration.*\|\|" src/react/renderers/ -A 2 -B 2Repository: vargHQ/sdk Length of output: 390 🏁 Script executed: rg -n "Number.*\|\|" src/ --type ts --type tsx | head -20Repository: vargHQ/sdk Length of output: 81 🏁 Script executed: rg "Number.*\|\|" src/ -A 2 -B 2Repository: vargHQ/sdk Length of output: 2699 fix zero duration fallback bug line 153 has the same suggested patch- duration: Number(props.duration) || 5,
+ duration: Number.isFinite(Number(props.duration)) ? Number(props.duration) : 5,📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| aspectRatio: props.aspectRatio, | ||||||
| providerOptions: props.providerOptions, | ||||||
| cacheKey, | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -647,7 +647,7 @@ export async function resolveVideoElement( | |
| const { video } = await generateVideo({ | ||
| model: model as Parameters<typeof generateVideoRaw>[0]["model"], | ||
| prompt: resolvedPrompt, | ||
| duration: (props.duration as number) ?? 5, | ||
| duration: Number(props.duration) || 5, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "resolve.ts" -path "*/react/*" -type fRepository: vargHQ/sdk Length of output: 76 🏁 Script executed: cat -n ./src/react/resolve.ts | sed -n '640,660p'Repository: vargHQ/sdk Length of output: 910 🏁 Script executed: # find the type definition for props in this function
rg -B 20 "duration: Number\(props\.duration\)" ./src/react/resolve.ts | head -50Repository: vargHQ/sdk Length of output: 622 🏁 Script executed: # find the function signature that contains line 650
rg -B 100 "duration: Number\(props\.duration\)" ./src/react/resolve.ts | grep -E "^export |^async |function |props:" | head -20Repository: vargHQ/sdk Length of output: 36 🏁 Script executed: # get the full function signature starting from the beginning
head -n 650 ./src/react/resolve.ts | tail -n 100 | grep -E "async|function|props|duration" | head -30Repository: vargHQ/sdk Length of output: 258 🏁 Script executed: # find function definition that contains line 650
ast-grep --pattern 'export function $_(props: $_) {
$$$
duration: Number(props.duration) || 5,
$$$
}'Repository: vargHQ/sdk Length of output: 36 🏁 Script executed: # get broader context to find the function signature
sed -n '500,650p' ./src/react/resolve.ts | grep -E "^export|^async|^function|^\s*\(props" | tail -5Repository: vargHQ/sdk Length of output: 96 🏁 Script executed: # get the function signature
sed -n '500,650p' ./src/react/resolve.ts | head -n 150Repository: vargHQ/sdk Length of output: 4827 🏁 Script executed: # check the generateVideoRaw function to understand duration expectations
rg "function generateVideoRaw|export.*generateVideoRaw" -A 10 ./src/react/resolve.tsRepository: vargHQ/sdk Length of output: 36 🏁 Script executed: # find generateVideoRaw definition
rg "generateVideoRaw" . --type ts --type tsx | head -20Repository: vargHQ/sdk Length of output: 81 🏁 Script executed: # find generateVideoRaw definition
rg "generateVideoRaw" . -g "*.ts" | head -20Repository: vargHQ/sdk Length of output: 468 🏁 Script executed: # find and examine the generate-video file
find . -name "generate-video.ts" -path "*/ai-sdk/*" | head -5Repository: vargHQ/sdk Length of output: 84 🏁 Script executed: # get the function signature and docs for generateVideo
head -n 150 ./src/ai-sdk/generate-video.tsRepository: vargHQ/sdk Length of output: 3198 🏁 Script executed: # check if there are tests for duration handling
rg "duration" ./src/react/resolve.ts -B 2 -A 2 | grep -E "duration|test|describe" | head -20Repository: vargHQ/sdk Length of output: 1270 🏁 Script executed: # look at tests to see if duration: 0 is used anywhere
rg "duration.*0" . -g "*.ts" | grep -E "test|duration.*:.*0" | head -15Repository: vargHQ/sdk Length of output: 1338 fix duration coercion that overwrites explicit line 650 uses suggested patch+ const parsedDuration =
+ props.duration === null || props.duration === undefined
+ ? undefined
+ : Number(props.duration);
+
const { video } = await generateVideo({
@@
- duration: Number(props.duration) || 5,
+ duration: Number.isFinite(parsedDuration) ? parsedDuration : 5,🤖 Prompt for AI Agents |
||
| aspectRatio: props.aspectRatio as `${number}:${number}` | undefined, | ||
| providerOptions: props.providerOptions as Parameters< | ||
| typeof generateVideoRaw | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
cat -n src/react/renderers/music.ts | head -50Repository: vargHQ/sdk
Length of output: 2005
switch to strict equality and extract the duration once
lines 30 and 40 both use
!= nulland duplicate the same coercion. violates the "always use strict equality (===)" guideline, and the duplication risks cache key + request misalignment if the logic changes later. extractconst durationonce and reuse it instead. meow 🐱🤖 Prompt for AI Agents