(
value: PartListUnion,
options?: { verbose?: boolean },
)
| 12 | * If verbose is true, includes summary representations of non-text parts. |
| 13 | */ |
| 14 | export function partToString( |
| 15 | value: PartListUnion, |
| 16 | options?: { verbose?: boolean }, |
| 17 | ): string { |
| 18 | if (!value) { |
| 19 | return ''; |
| 20 | } |
| 21 | if (typeof value === 'string') { |
| 22 | return value; |
| 23 | } |
| 24 | if (Array.isArray(value)) { |
| 25 | return value.map((part) => partToString(part, options)).join(''); |
| 26 | } |
| 27 | |
| 28 | // Cast to Part, assuming it might contain project-specific fields |
| 29 | const part = value as Part & { |
| 30 | videoMetadata?: unknown; |
| 31 | thought?: string; |
| 32 | codeExecutionResult?: unknown; |
| 33 | executableCode?: unknown; |
| 34 | }; |
| 35 | |
| 36 | if (options?.verbose) { |
| 37 | if (part.videoMetadata !== undefined) { |
| 38 | return `[Video Metadata]`; |
| 39 | } |
| 40 | if (part.thought !== undefined) { |
| 41 | return `[Thought: ${part.thought}]`; |
| 42 | } |
| 43 | if (part.codeExecutionResult !== undefined) { |
| 44 | return `[Code Execution Result]`; |
| 45 | } |
| 46 | if (part.executableCode !== undefined) { |
| 47 | return `[Executable Code]`; |
| 48 | } |
| 49 | |
| 50 | // Standard Part fields |
| 51 | if (part.fileData !== undefined) { |
| 52 | return `[File Data]`; |
| 53 | } |
| 54 | if (part.functionCall !== undefined) { |
| 55 | return `[Function Call: ${part.functionCall.name}]`; |
| 56 | } |
| 57 | if (part.functionResponse !== undefined) { |
| 58 | return `[Function Response: ${part.functionResponse.name}]`; |
| 59 | } |
| 60 | if (part.inlineData !== undefined) { |
| 61 | return `<${part.inlineData.mimeType}>`; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return part.text ?? ''; |
| 66 | } |
| 67 | |
| 68 | export function getResponseText( |
| 69 | response: GenerateContentResponse, |
no outgoing calls
no test coverage detected