- fusion du bandeau et de l'ancienne ligne d'état en une seule ligne d'état - refus de la lecture des longs fichiers et enregistrement des longues sorties shell - ajout du réglage « imposer », actif par défaut, sans blocage si MIAM ne répond pas - suppression du fichier types/index.d.ts
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
// Seuils et bornes pour la détection des sorties trop volumineuses.
|
|
|
|
export const SEUIL = 20000
|
|
export const PLAGE_MAX = 400
|
|
|
|
// Extensions considérées comme binaires (images et PDF), insensibles à la casse.
|
|
const EXTENSIONS_BINAIRES = new Set(['png', 'jpg', 'jpeg', 'gif', 'webp', 'pdf'])
|
|
|
|
// Vérifie si le chemin pointe vers un fichier binaire (image ou PDF).
|
|
function estBinaire(chemin: string): boolean {
|
|
// Isoler le nom de fichier (après le dernier séparateur de dossier).
|
|
const nom = chemin.split(/[/\\]/).pop() ?? ''
|
|
// Extraire l'extension (après le dernier point du nom de fichier).
|
|
const point = nom.lastIndexOf('.')
|
|
if (point === -1 || point === nom.length - 1) {
|
|
return false
|
|
}
|
|
return EXTENSIONS_BINAIRES.has(nom.slice(point + 1).toLowerCase())
|
|
}
|
|
|
|
// Vérifie si la lecture est bornée (limit est un nombre strictement positif et ≤ PLAGE_MAX).
|
|
function estBornee(limit: unknown): boolean {
|
|
return typeof limit === 'number' && limit > 0 && limit <= PLAGE_MAX
|
|
}
|
|
|
|
export function lectureTropLongue(args: { file_path?: unknown; limit?: unknown }, taille: number): boolean {
|
|
// Condition 1 : taille au-delà du seuil.
|
|
if (taille < SEUIL) {
|
|
return false
|
|
}
|
|
|
|
// Condition 2 : chemin de fichier texte (pas une image ni un PDF).
|
|
const chemin = args.file_path
|
|
if (typeof chemin !== 'string' || estBinaire(chemin)) {
|
|
return false
|
|
}
|
|
|
|
// Condition 3 : lecture non bornée.
|
|
return !estBornee(args.limit)
|
|
}
|
|
|
|
export function sortieTropLongue(texte: string | undefined): boolean {
|
|
return texte !== undefined && texte.length >= SEUIL
|
|
}
|
|
|
|
export function nomSortie(toolUseId: string): string {
|
|
// Remplacer chaque caractère non alphanumérique (sauf _ et -) par un underscore.
|
|
const idNettoye = toolUseId.replace(/[^A-Za-z0-9_-]/g, '_')
|
|
return `sortie-${idNettoye}.txt`
|
|
}
|