basant307/AI_Governance_Project
048
1/**2 * @license3 * Copyright 2026 Qwen4 * SPDX-License-Identifier: Apache-2.05 */6 7import type { Part, PartListUnion } from '@google/genai';8import { normalizePartList } from './nonInteractiveHelpers.js';9 10export const MID_TURN_USER_MESSAGE_PREFIX =11 '\n[User message received during tool execution]: ';12 13export function prefixMidTurnUserMessageParts(14 parts: PartListUnion,15 displayText: string,16): Part[] {17 const partArray = normalizePartList(parts);18 if (partArray.length === 0) {19 return [{ text: `${MID_TURN_USER_MESSAGE_PREFIX}${displayText}` }];20 }21 22 const [firstPart, ...rest] = partArray;23 if ('text' in firstPart && typeof firstPart.text === 'string') {24 return [25 {26 ...firstPart,27 text: `${MID_TURN_USER_MESSAGE_PREFIX}${firstPart.text}`,28 },29 ...rest,30 ];31 }32 33 return [34 { text: `${MID_TURN_USER_MESSAGE_PREFIX}${displayText}` },35 ...partArray,36 ];37}38 