handle powershell prompt objects

This commit is contained in:
2026-05-09 18:31:24 +08:00
parent f6fbd7fd61
commit d5bdeba458

View File

@@ -203,8 +203,24 @@ function uploadedFileToPart(file: Express.Multer.File): GeminiPart {
}; };
} }
function normalizeTextInput(value: unknown) {
if (typeof value === 'string') {
return value;
}
if (Array.isArray(value)) {
return value.map((item) => normalizeTextInput(item)).join('\n');
}
if (value && typeof value === 'object' && 'value' in value) {
return normalizeTextInput((value as { value: unknown }).value);
}
return value == null ? '' : String(value);
}
async function buildParts(body: GenerateRequest, files: Express.Multer.File[] = []) { async function buildParts(body: GenerateRequest, files: Express.Multer.File[] = []) {
const prompt = (body.prompt || body.instruction || '').trim(); const prompt = normalizeTextInput(body.prompt || body.instruction).trim();
if (!prompt) { if (!prompt) {
throw new Error('prompt or instruction is required.'); throw new Error('prompt or instruction is required.');
} }