CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
userPromptExpansionHook.ts46 linesDownload Raw Back to utils
1/**2 * @license3 * Copyright 2026 Qwen Team4 * SPDX-License-Identifier: Apache-2.05 */6 7import type { PartListUnion } from '@google/genai';8import {9  partToString,10  sanitizeUserPromptExpansionAdditionalContext,11} from '@qwen-code/qwen-code-core';12 13export function appendUserPromptExpansionAdditionalContext(14  content: PartListUnion,15  additionalContext: string | undefined,16): PartListUnion {17  if (!additionalContext) {18    return content;19  }20 21  const suffix = `\n\n${additionalContext}`;22  if (typeof content === 'string') {23    return `${content}${suffix}`;24  }25  if (Array.isArray(content)) {26    return [...content, { text: suffix }];27  }28  return [content, { text: suffix }];29}30 31export function serializeUserPromptExpansionPrompt(32  content: PartListUnion,33): string {34  // Hook inputs should see the same verbose text form the model receives after35  // slash-command expansion, including non-text parts that would otherwise be36  // hidden by the compact serializer.37  return partToString(content, { verbose: true });38}39 40export function formatUserPromptExpansionBlockedMessage(41  reason: string,42): string {43  const sanitizedReason = sanitizeUserPromptExpansionAdditionalContext(reason);44  return `UserPromptExpansion blocked: ${sanitizedReason}`;45}46 
basant307/AI_Governance_Project · CoolFace