fix(puter-js): require prompt in ai.txt2img (#3804)

txt2vid rejects missing prompts client-side with prompt_required, but txt2img sent the request to the backend. Add the same guard before the driver call.
This commit is contained in:
Felix-Ayush
2026-09-06 16:39:35 -07:00
committed by GitHub
parent 092a9245ff
commit b1d3a7c191
2 changed files with 9 additions and 0 deletions
+5
View File
@@ -607,6 +607,11 @@ describe('ai.txt2img driver payloads', () => {
expect(img.src).toBe('data:image/png;base64,QUJD');
expect(img.toString()).toBe('data:image/png;base64,QUJD');
});
it('txt2img rejects without a prompt', async () => {
await expect(ai.txt2img({})).rejects.toMatchObject({ code: 'prompt_required' });
expect(FakeXHR.requests).toHaveLength(0);
});
});
describe('ai.txt2vid driver payloads', () => {
+4
View File
@@ -58,6 +58,10 @@ export async function txt2img (promptOrOptions, optionsOrTestMode) {
options = promptOrOptions;
}
if ( ! options.prompt ) {
throw ({ message: 'Prompt parameter is required', code: 'prompt_required' });
}
const driverHint = typeof options.driver === 'string' ? options.driver : undefined;
const imageService = driverHint || 'ai-image';