avantgate 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { F as FinancialJurisdictionCode } from './strategy.interface-CB4_ZAuk.mjs';
2
3
 
3
4
  interface ChatMessage {
4
5
  role: "system" | "user" | "assistant" | "tool";
@@ -33,12 +34,28 @@ interface LLMProviderPort {
33
34
  stream?(options: LLMCompletionOptions): AsyncGenerator<string, LLMUsage | undefined>;
34
35
  generateStructuredOutput?<T>(options: LLMStructuredOutputOptions<T>): Promise<T>;
35
36
  }
37
+ interface ModelPrice {
38
+ promptUSDPerMillion: number;
39
+ completionUSDPerMillion: number;
40
+ cacheHitUSDPerMillion?: number;
41
+ }
42
+ interface PricingAdapter {
43
+ fetchPrice(model: string, provider?: string): Promise<ModelPrice | undefined> | ModelPrice | undefined;
44
+ }
45
+ declare class ConfigurationError extends Error {
46
+ constructor(message: string);
47
+ }
48
+ declare class BudgetExceededError extends Error {
49
+ constructor(message: string);
50
+ }
51
+
36
52
  interface ProviderConfig {
37
53
  provider: "deepseek" | "mistral" | "openai" | "ollama" | "openrouter" | "custom";
38
54
  model: string;
39
55
  apiKey?: string;
40
56
  baseUrl?: string;
41
57
  client?: LLMProviderPort;
58
+ pricing?: ModelPrice;
42
59
  }
43
60
  interface SecurityConfig {
44
61
  detectPromptInjection?: boolean;
@@ -67,6 +84,15 @@ interface AuditSinkPort {
67
84
  readonly name: string;
68
85
  log(record: AuditRecord): Promise<void> | void;
69
86
  }
87
+ interface FinanceFeaturesConfig {
88
+ enableFrenchAccounting?: boolean;
89
+ stripCurrencySymbols?: boolean;
90
+ jurisdiction?: "FR" | "US" | "UK" | "CH" | "INTERNATIONAL";
91
+ autoDetect?: boolean;
92
+ }
93
+ interface FeaturesConfig {
94
+ finance?: FinanceFeaturesConfig;
95
+ }
70
96
  interface ControlLayerConfig {
71
97
  primary: ProviderConfig;
72
98
  fallback?: ProviderConfig;
@@ -78,6 +104,11 @@ interface ControlLayerConfig {
78
104
  security?: SecurityConfig;
79
105
  hourlyTokenLimit?: number;
80
106
  dailyTokenLimit?: number;
107
+ features?: FeaturesConfig;
108
+ pricingAdapter?: PricingAdapter;
109
+ pricingCacheTtlMs?: number;
110
+ customPricing?: Record<string, ModelPrice>;
111
+ mockSimulation?: boolean;
81
112
  }
82
113
  interface ExecutionResult {
83
114
  text: string;
@@ -103,18 +134,67 @@ interface StructuredExecutionResult<T> {
103
134
  modelUsed: string;
104
135
  failoverOccurred: boolean;
105
136
  }
137
+ interface GenerateStructuredOutputOptions<T> {
138
+ model?: string;
139
+ messages: ChatMessage[];
140
+ schema: z.ZodType<T>;
141
+ schemaName?: string;
142
+ maxRetries?: number;
143
+ temperature?: number;
144
+ providerOverride?: LLMProviderPort;
145
+ financialNormalizer?: boolean;
146
+ }
106
147
 
107
- interface ModelPrice {
108
- promptUSDPerMillion: number;
109
- completionUSDPerMillion: number;
110
- cacheHitUSDPerMillion?: number;
148
+ interface CalculateCostOptions {
149
+ provider?: string;
150
+ providerPricing?: ModelPrice;
151
+ customPricing?: Record<string, ModelPrice>;
152
+ adapter?: PricingAdapter;
153
+ }
154
+ /**
155
+ * Catalogue indicatif non injecté par défaut dans le moteur.
156
+ * Les utilisateurs peuvent s'en servir comme jeu de données initial (ex: seed Prisma)
157
+ * ou pour peupler le PricingRegistry s'ils souhaitent des valeurs de départ.
158
+ */
159
+ declare const SEED_MODEL_PRICES: Record<string, ModelPrice>;
160
+ declare class CachedPricingAdapter implements PricingAdapter {
161
+ private cache;
162
+ private ttlMs;
163
+ private delegate;
164
+ constructor(delegate: PricingAdapter, ttlMs?: number);
165
+ fetchPrice(model: string, provider?: string): Promise<ModelPrice | undefined>;
166
+ peek(model: string, provider?: string): ModelPrice | undefined;
167
+ clearCache(): void;
168
+ invalidate(model?: string, provider?: string): void;
169
+ }
170
+ /**
171
+ * Registre de tarification dynamique.
172
+ * Démarre 100% vide : aucune valeur codée en dur n'est imposée par défaut (Option A : Strict & Truthful).
173
+ */
174
+ declare class PricingRegistry {
175
+ private static prices;
176
+ private static adapter?;
177
+ static registerPrice(identifier: string, price: ModelPrice): void;
178
+ static registerDistributorPrices(distributor: string, priceMap: Record<string, ModelPrice>): void;
179
+ static registerPrices(prices: Record<string, ModelPrice>): void;
180
+ static getPrice(model: string, provider?: string): ModelPrice | undefined;
181
+ static setAdapter(adapter: PricingAdapter): void;
182
+ static getAdapter(): PricingAdapter | undefined;
183
+ static clear(): void;
184
+ /**
185
+ * Réinitialise le registre en chargeant le catalogue d'exemple SEED_MODEL_PRICES.
186
+ */
187
+ static loadSeedPrices(): void;
188
+ static getAllPrices(): Record<string, ModelPrice>;
111
189
  }
112
190
  declare const DEFAULT_MODEL_PRICES: Record<string, ModelPrice>;
113
- declare function calculateCostUSD(model: string, promptTokens: number, completionTokens: number, cacheHitTokens?: number): number;
191
+ declare function resolveModelPrice(model: string, options?: CalculateCostOptions | string): ModelPrice | undefined;
192
+ declare function resolveModelPriceAsync(model: string, options?: CalculateCostOptions | string): Promise<ModelPrice | undefined>;
193
+ declare function calculateCostUSD(model: string, promptTokens: number, completionTokens: number, cacheHitTokens?: number, options?: CalculateCostOptions | string): number;
114
194
 
115
195
  /**
116
196
  * In-Flight PII Sanitizer for AvantGate.
117
- * Masque les données sensibles (email, numéros de téléphone, NIR/sécurité sociale, IBAN)
197
+ * Masque les données sensibles (email, téléphone, NIR/sécurité sociale, IBAN/BIC, numéro fiscal SPI)
118
198
  * avant l'envoi vers des API cloud.
119
199
  */
120
200
  interface SanitizeResult {
@@ -136,6 +216,11 @@ declare function validateUserInput(input: string, options?: {
136
216
  maxLength?: number;
137
217
  }): InputGuardResult;
138
218
 
219
+ interface ValidateOptions {
220
+ normalizer?: (rawText: string) => string;
221
+ financialNormalizer?: boolean;
222
+ jurisdiction?: FinancialJurisdictionCode;
223
+ }
139
224
  /**
140
225
  * Nettoie et extrait un bloc JSON valide depuis une réponse de LLM
141
226
  * (gère les blocs markdown ```json ... ```, les balises de réflexion, etc.)
@@ -143,13 +228,20 @@ declare function validateUserInput(input: string, options?: {
143
228
  declare function extractAndCleanJSON(rawText: string): string;
144
229
  /**
145
230
  * Valide et auto-répare une sortie JSON contre un schéma Zod.
231
+ * Supporte l'option de normalisation financière (parenthèses négatives, formats comptables).
146
232
  */
147
- declare function validateWithZod<T>(rawText: string, schema: z.ZodType<T>): T;
233
+ declare function validateWithZod<T>(rawText: string, schema: z.ZodType<T>, options?: ValidateOptions): T;
148
234
 
149
235
  declare class AvantGateControlLayer {
150
236
  private config;
237
+ private cachedPricingAdapter?;
151
238
  constructor(config: ControlLayerConfig);
239
+ private resolveProviderConfig;
240
+ private findProviderConfig;
241
+ private calculateCost;
152
242
  private applySecurityGuards;
243
+ private checkPreflightBudget;
244
+ private checkPostExecutionBudget;
153
245
  private buildMessages;
154
246
  private resolveTokens;
155
247
  private getProviderChain;
@@ -159,7 +251,7 @@ declare class AvantGateControlLayer {
159
251
  private assembleResult;
160
252
  private notifyAuditSink;
161
253
  /**
162
- * Exécute une requête avec garde d'entrée, masquage PII, et calcul des coûts.
254
+ * Exécute une requête avec garde d'entrée, masquage PII, garde pré-vol et calcul des coûts.
163
255
  */
164
256
  execute(options: {
165
257
  userQuery: string;
@@ -177,8 +269,122 @@ declare class AvantGateControlLayer {
177
269
  temperature?: number;
178
270
  providerOverride?: LLMProviderPort;
179
271
  }): Promise<StructuredExecutionResult<T>>;
272
+ /**
273
+ * Méthode unifiée de premier niveau pour l'extraction structurée sans code boilerplate.
274
+ * Gère le failover multi-fournisseurs, les retries, la validation Zod et la normalisation financière.
275
+ */
276
+ generateStructuredOutput<T>(options: GenerateStructuredOutputOptions<T>): Promise<StructuredExecutionResult<T>>;
180
277
  }
181
278
  declare function createLLMControlLayer(config: ControlLayerConfig): AvantGateControlLayer;
182
279
  declare const createAvantGate: typeof createLLMControlLayer;
183
280
 
184
- export { type AuditRecord, type AuditSinkPort, AvantGateControlLayer, type ChatMessage, type ControlLayerConfig, DEFAULT_MODEL_PRICES, type ExecutionResult, type InputGuardResult, type LLMCompletionOptions, type LLMProviderPort, type LLMStructuredOutputOptions, type LLMUsage, type ModelPrice, type ProviderConfig, type RetryConfig, type SanitizeResult, type SecurityConfig, type StructuredExecutionResult, AvantGateControlLayer as ZenLLMControlLayer, calculateCostUSD, createAvantGate, createLLMControlLayer, extractAndCleanJSON, sanitizePII, validateUserInput, validateWithZod };
281
+ interface PromptMessage {
282
+ role: "system" | "user" | "assistant";
283
+ content: string;
284
+ }
285
+ type PromptLabel = "production" | "staging" | "experimental";
286
+ interface PromptTemplateOptions<TVariables extends Record<string, unknown> = Record<string, unknown>> {
287
+ id: string;
288
+ version: number;
289
+ label?: PromptLabel;
290
+ description?: string;
291
+ template: string;
292
+ inputSchema?: z.ZodType<TVariables>;
293
+ antiInjection?: {
294
+ enabled?: boolean;
295
+ blockPatterns?: RegExp[];
296
+ sanitizer?: (value: string) => string;
297
+ };
298
+ }
299
+ interface PromptValidationResult {
300
+ isValid: boolean;
301
+ threats: string[];
302
+ }
303
+ interface ITokenBudget {
304
+ count(text: string): number;
305
+ remaining(): number;
306
+ reserve(slot: string, text: string): void;
307
+ forceReserve(slot: string, text: string): void;
308
+ getAllocated(): number;
309
+ reset(): void;
310
+ }
311
+ interface BuildResult {
312
+ messages: PromptMessage[];
313
+ promptText: string;
314
+ allocatedTokens?: number;
315
+ isTruncated: boolean;
316
+ truncatedSlot?: "context" | "pinnedFacts" | "user";
317
+ }
318
+
319
+ declare class PromptTemplate<TVariables extends Record<string, unknown> = Record<string, unknown>> {
320
+ readonly id: string;
321
+ readonly version: number;
322
+ readonly label: PromptLabel;
323
+ readonly description?: string;
324
+ readonly template: string;
325
+ readonly inputSchema?: z.ZodType<TVariables>;
326
+ private blockPatterns;
327
+ private antiInjectionEnabled;
328
+ private customSanitizer?;
329
+ constructor(options: PromptTemplateOptions<TVariables>);
330
+ validateUserInput(variables: TVariables): PromptValidationResult;
331
+ format(variables: TVariables): string;
332
+ }
333
+
334
+ declare class PromptBuilder {
335
+ private personaSlot;
336
+ private rulesSlot;
337
+ private retryHintSlot;
338
+ private fewShotSlot;
339
+ private pinnedFactsSlot;
340
+ private contextSlot;
341
+ private userPayloadSlot;
342
+ private schemaContractText;
343
+ constructor(templateOrId?: string | PromptTemplate);
344
+ withPersona(persona: string): this;
345
+ withRules(rules: string | string[]): this;
346
+ withRetryHint(hint: string): this;
347
+ withFewShot(examples: Array<{
348
+ question: string;
349
+ answer: string;
350
+ }>): this;
351
+ withPinnedFacts(facts: string | Record<string, unknown>): this;
352
+ withContext(context: string): this;
353
+ withUserPayload(payload: string): this;
354
+ schemaContract<T>(schema: z.ZodType<T>, options?: {
355
+ schemaName?: string;
356
+ }): this;
357
+ private assembleMessages;
358
+ toMessages(): PromptMessage[];
359
+ build(budget?: ITokenBudget): BuildResult;
360
+ }
361
+
362
+ declare class PromptRegistry {
363
+ private static registry;
364
+ static register<T extends Record<string, unknown>>(templateOrOptions: PromptTemplate<T> | PromptTemplateOptions<T>): void;
365
+ static get<T extends Record<string, unknown> = Record<string, unknown>>(id: string, options?: {
366
+ version?: number;
367
+ label?: PromptLabel;
368
+ }): PromptTemplate<T>;
369
+ static has(id: string): boolean;
370
+ static clear(): void;
371
+ }
372
+
373
+ declare class HttpProviderClient implements LLMProviderPort {
374
+ readonly name: string;
375
+ private readonly baseUrl;
376
+ private readonly apiKey?;
377
+ private readonly providerType;
378
+ constructor(config: ProviderConfig);
379
+ private resolveEndpoint;
380
+ private buildHeaders;
381
+ private buildPayload;
382
+ private extractUsage;
383
+ complete(options: LLMCompletionOptions): Promise<{
384
+ text: string;
385
+ usage?: LLMUsage;
386
+ }>;
387
+ }
388
+ declare function createHttpProviderClient(config: ProviderConfig): HttpProviderClient;
389
+
390
+ export { type AuditRecord, type AuditSinkPort, BudgetExceededError as AvantGateBudgetExceededError, ConfigurationError as AvantGateConfigurationError, AvantGateControlLayer, BudgetExceededError, type BuildResult, CachedPricingAdapter, type CalculateCostOptions, type ChatMessage, ConfigurationError, type ControlLayerConfig, DEFAULT_MODEL_PRICES, type ExecutionResult, type FeaturesConfig, type FinanceFeaturesConfig, type GenerateStructuredOutputOptions, HttpProviderClient, type ITokenBudget, type InputGuardResult, type LLMCompletionOptions, type LLMProviderPort, type LLMStructuredOutputOptions, type LLMUsage, type ModelPrice, type PricingAdapter, PricingRegistry, PromptBuilder, type PromptLabel, type PromptMessage, PromptRegistry, PromptTemplate, type PromptTemplateOptions, type PromptValidationResult, type ProviderConfig, type RetryConfig, SEED_MODEL_PRICES, type SanitizeResult, type SecurityConfig, type StructuredExecutionResult, type ValidateOptions, AvantGateControlLayer as ZenLLMControlLayer, calculateCostUSD, createAvantGate, createHttpProviderClient, createLLMControlLayer, extractAndCleanJSON, resolveModelPrice, resolveModelPriceAsync, sanitizePII, validateUserInput, validateWithZod };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { F as FinancialJurisdictionCode } from './strategy.interface-CB4_ZAuk.js';
2
3
 
3
4
  interface ChatMessage {
4
5
  role: "system" | "user" | "assistant" | "tool";
@@ -33,12 +34,28 @@ interface LLMProviderPort {
33
34
  stream?(options: LLMCompletionOptions): AsyncGenerator<string, LLMUsage | undefined>;
34
35
  generateStructuredOutput?<T>(options: LLMStructuredOutputOptions<T>): Promise<T>;
35
36
  }
37
+ interface ModelPrice {
38
+ promptUSDPerMillion: number;
39
+ completionUSDPerMillion: number;
40
+ cacheHitUSDPerMillion?: number;
41
+ }
42
+ interface PricingAdapter {
43
+ fetchPrice(model: string, provider?: string): Promise<ModelPrice | undefined> | ModelPrice | undefined;
44
+ }
45
+ declare class ConfigurationError extends Error {
46
+ constructor(message: string);
47
+ }
48
+ declare class BudgetExceededError extends Error {
49
+ constructor(message: string);
50
+ }
51
+
36
52
  interface ProviderConfig {
37
53
  provider: "deepseek" | "mistral" | "openai" | "ollama" | "openrouter" | "custom";
38
54
  model: string;
39
55
  apiKey?: string;
40
56
  baseUrl?: string;
41
57
  client?: LLMProviderPort;
58
+ pricing?: ModelPrice;
42
59
  }
43
60
  interface SecurityConfig {
44
61
  detectPromptInjection?: boolean;
@@ -67,6 +84,15 @@ interface AuditSinkPort {
67
84
  readonly name: string;
68
85
  log(record: AuditRecord): Promise<void> | void;
69
86
  }
87
+ interface FinanceFeaturesConfig {
88
+ enableFrenchAccounting?: boolean;
89
+ stripCurrencySymbols?: boolean;
90
+ jurisdiction?: "FR" | "US" | "UK" | "CH" | "INTERNATIONAL";
91
+ autoDetect?: boolean;
92
+ }
93
+ interface FeaturesConfig {
94
+ finance?: FinanceFeaturesConfig;
95
+ }
70
96
  interface ControlLayerConfig {
71
97
  primary: ProviderConfig;
72
98
  fallback?: ProviderConfig;
@@ -78,6 +104,11 @@ interface ControlLayerConfig {
78
104
  security?: SecurityConfig;
79
105
  hourlyTokenLimit?: number;
80
106
  dailyTokenLimit?: number;
107
+ features?: FeaturesConfig;
108
+ pricingAdapter?: PricingAdapter;
109
+ pricingCacheTtlMs?: number;
110
+ customPricing?: Record<string, ModelPrice>;
111
+ mockSimulation?: boolean;
81
112
  }
82
113
  interface ExecutionResult {
83
114
  text: string;
@@ -103,18 +134,67 @@ interface StructuredExecutionResult<T> {
103
134
  modelUsed: string;
104
135
  failoverOccurred: boolean;
105
136
  }
137
+ interface GenerateStructuredOutputOptions<T> {
138
+ model?: string;
139
+ messages: ChatMessage[];
140
+ schema: z.ZodType<T>;
141
+ schemaName?: string;
142
+ maxRetries?: number;
143
+ temperature?: number;
144
+ providerOverride?: LLMProviderPort;
145
+ financialNormalizer?: boolean;
146
+ }
106
147
 
107
- interface ModelPrice {
108
- promptUSDPerMillion: number;
109
- completionUSDPerMillion: number;
110
- cacheHitUSDPerMillion?: number;
148
+ interface CalculateCostOptions {
149
+ provider?: string;
150
+ providerPricing?: ModelPrice;
151
+ customPricing?: Record<string, ModelPrice>;
152
+ adapter?: PricingAdapter;
153
+ }
154
+ /**
155
+ * Catalogue indicatif non injecté par défaut dans le moteur.
156
+ * Les utilisateurs peuvent s'en servir comme jeu de données initial (ex: seed Prisma)
157
+ * ou pour peupler le PricingRegistry s'ils souhaitent des valeurs de départ.
158
+ */
159
+ declare const SEED_MODEL_PRICES: Record<string, ModelPrice>;
160
+ declare class CachedPricingAdapter implements PricingAdapter {
161
+ private cache;
162
+ private ttlMs;
163
+ private delegate;
164
+ constructor(delegate: PricingAdapter, ttlMs?: number);
165
+ fetchPrice(model: string, provider?: string): Promise<ModelPrice | undefined>;
166
+ peek(model: string, provider?: string): ModelPrice | undefined;
167
+ clearCache(): void;
168
+ invalidate(model?: string, provider?: string): void;
169
+ }
170
+ /**
171
+ * Registre de tarification dynamique.
172
+ * Démarre 100% vide : aucune valeur codée en dur n'est imposée par défaut (Option A : Strict & Truthful).
173
+ */
174
+ declare class PricingRegistry {
175
+ private static prices;
176
+ private static adapter?;
177
+ static registerPrice(identifier: string, price: ModelPrice): void;
178
+ static registerDistributorPrices(distributor: string, priceMap: Record<string, ModelPrice>): void;
179
+ static registerPrices(prices: Record<string, ModelPrice>): void;
180
+ static getPrice(model: string, provider?: string): ModelPrice | undefined;
181
+ static setAdapter(adapter: PricingAdapter): void;
182
+ static getAdapter(): PricingAdapter | undefined;
183
+ static clear(): void;
184
+ /**
185
+ * Réinitialise le registre en chargeant le catalogue d'exemple SEED_MODEL_PRICES.
186
+ */
187
+ static loadSeedPrices(): void;
188
+ static getAllPrices(): Record<string, ModelPrice>;
111
189
  }
112
190
  declare const DEFAULT_MODEL_PRICES: Record<string, ModelPrice>;
113
- declare function calculateCostUSD(model: string, promptTokens: number, completionTokens: number, cacheHitTokens?: number): number;
191
+ declare function resolveModelPrice(model: string, options?: CalculateCostOptions | string): ModelPrice | undefined;
192
+ declare function resolveModelPriceAsync(model: string, options?: CalculateCostOptions | string): Promise<ModelPrice | undefined>;
193
+ declare function calculateCostUSD(model: string, promptTokens: number, completionTokens: number, cacheHitTokens?: number, options?: CalculateCostOptions | string): number;
114
194
 
115
195
  /**
116
196
  * In-Flight PII Sanitizer for AvantGate.
117
- * Masque les données sensibles (email, numéros de téléphone, NIR/sécurité sociale, IBAN)
197
+ * Masque les données sensibles (email, téléphone, NIR/sécurité sociale, IBAN/BIC, numéro fiscal SPI)
118
198
  * avant l'envoi vers des API cloud.
119
199
  */
120
200
  interface SanitizeResult {
@@ -136,6 +216,11 @@ declare function validateUserInput(input: string, options?: {
136
216
  maxLength?: number;
137
217
  }): InputGuardResult;
138
218
 
219
+ interface ValidateOptions {
220
+ normalizer?: (rawText: string) => string;
221
+ financialNormalizer?: boolean;
222
+ jurisdiction?: FinancialJurisdictionCode;
223
+ }
139
224
  /**
140
225
  * Nettoie et extrait un bloc JSON valide depuis une réponse de LLM
141
226
  * (gère les blocs markdown ```json ... ```, les balises de réflexion, etc.)
@@ -143,13 +228,20 @@ declare function validateUserInput(input: string, options?: {
143
228
  declare function extractAndCleanJSON(rawText: string): string;
144
229
  /**
145
230
  * Valide et auto-répare une sortie JSON contre un schéma Zod.
231
+ * Supporte l'option de normalisation financière (parenthèses négatives, formats comptables).
146
232
  */
147
- declare function validateWithZod<T>(rawText: string, schema: z.ZodType<T>): T;
233
+ declare function validateWithZod<T>(rawText: string, schema: z.ZodType<T>, options?: ValidateOptions): T;
148
234
 
149
235
  declare class AvantGateControlLayer {
150
236
  private config;
237
+ private cachedPricingAdapter?;
151
238
  constructor(config: ControlLayerConfig);
239
+ private resolveProviderConfig;
240
+ private findProviderConfig;
241
+ private calculateCost;
152
242
  private applySecurityGuards;
243
+ private checkPreflightBudget;
244
+ private checkPostExecutionBudget;
153
245
  private buildMessages;
154
246
  private resolveTokens;
155
247
  private getProviderChain;
@@ -159,7 +251,7 @@ declare class AvantGateControlLayer {
159
251
  private assembleResult;
160
252
  private notifyAuditSink;
161
253
  /**
162
- * Exécute une requête avec garde d'entrée, masquage PII, et calcul des coûts.
254
+ * Exécute une requête avec garde d'entrée, masquage PII, garde pré-vol et calcul des coûts.
163
255
  */
164
256
  execute(options: {
165
257
  userQuery: string;
@@ -177,8 +269,122 @@ declare class AvantGateControlLayer {
177
269
  temperature?: number;
178
270
  providerOverride?: LLMProviderPort;
179
271
  }): Promise<StructuredExecutionResult<T>>;
272
+ /**
273
+ * Méthode unifiée de premier niveau pour l'extraction structurée sans code boilerplate.
274
+ * Gère le failover multi-fournisseurs, les retries, la validation Zod et la normalisation financière.
275
+ */
276
+ generateStructuredOutput<T>(options: GenerateStructuredOutputOptions<T>): Promise<StructuredExecutionResult<T>>;
180
277
  }
181
278
  declare function createLLMControlLayer(config: ControlLayerConfig): AvantGateControlLayer;
182
279
  declare const createAvantGate: typeof createLLMControlLayer;
183
280
 
184
- export { type AuditRecord, type AuditSinkPort, AvantGateControlLayer, type ChatMessage, type ControlLayerConfig, DEFAULT_MODEL_PRICES, type ExecutionResult, type InputGuardResult, type LLMCompletionOptions, type LLMProviderPort, type LLMStructuredOutputOptions, type LLMUsage, type ModelPrice, type ProviderConfig, type RetryConfig, type SanitizeResult, type SecurityConfig, type StructuredExecutionResult, AvantGateControlLayer as ZenLLMControlLayer, calculateCostUSD, createAvantGate, createLLMControlLayer, extractAndCleanJSON, sanitizePII, validateUserInput, validateWithZod };
281
+ interface PromptMessage {
282
+ role: "system" | "user" | "assistant";
283
+ content: string;
284
+ }
285
+ type PromptLabel = "production" | "staging" | "experimental";
286
+ interface PromptTemplateOptions<TVariables extends Record<string, unknown> = Record<string, unknown>> {
287
+ id: string;
288
+ version: number;
289
+ label?: PromptLabel;
290
+ description?: string;
291
+ template: string;
292
+ inputSchema?: z.ZodType<TVariables>;
293
+ antiInjection?: {
294
+ enabled?: boolean;
295
+ blockPatterns?: RegExp[];
296
+ sanitizer?: (value: string) => string;
297
+ };
298
+ }
299
+ interface PromptValidationResult {
300
+ isValid: boolean;
301
+ threats: string[];
302
+ }
303
+ interface ITokenBudget {
304
+ count(text: string): number;
305
+ remaining(): number;
306
+ reserve(slot: string, text: string): void;
307
+ forceReserve(slot: string, text: string): void;
308
+ getAllocated(): number;
309
+ reset(): void;
310
+ }
311
+ interface BuildResult {
312
+ messages: PromptMessage[];
313
+ promptText: string;
314
+ allocatedTokens?: number;
315
+ isTruncated: boolean;
316
+ truncatedSlot?: "context" | "pinnedFacts" | "user";
317
+ }
318
+
319
+ declare class PromptTemplate<TVariables extends Record<string, unknown> = Record<string, unknown>> {
320
+ readonly id: string;
321
+ readonly version: number;
322
+ readonly label: PromptLabel;
323
+ readonly description?: string;
324
+ readonly template: string;
325
+ readonly inputSchema?: z.ZodType<TVariables>;
326
+ private blockPatterns;
327
+ private antiInjectionEnabled;
328
+ private customSanitizer?;
329
+ constructor(options: PromptTemplateOptions<TVariables>);
330
+ validateUserInput(variables: TVariables): PromptValidationResult;
331
+ format(variables: TVariables): string;
332
+ }
333
+
334
+ declare class PromptBuilder {
335
+ private personaSlot;
336
+ private rulesSlot;
337
+ private retryHintSlot;
338
+ private fewShotSlot;
339
+ private pinnedFactsSlot;
340
+ private contextSlot;
341
+ private userPayloadSlot;
342
+ private schemaContractText;
343
+ constructor(templateOrId?: string | PromptTemplate);
344
+ withPersona(persona: string): this;
345
+ withRules(rules: string | string[]): this;
346
+ withRetryHint(hint: string): this;
347
+ withFewShot(examples: Array<{
348
+ question: string;
349
+ answer: string;
350
+ }>): this;
351
+ withPinnedFacts(facts: string | Record<string, unknown>): this;
352
+ withContext(context: string): this;
353
+ withUserPayload(payload: string): this;
354
+ schemaContract<T>(schema: z.ZodType<T>, options?: {
355
+ schemaName?: string;
356
+ }): this;
357
+ private assembleMessages;
358
+ toMessages(): PromptMessage[];
359
+ build(budget?: ITokenBudget): BuildResult;
360
+ }
361
+
362
+ declare class PromptRegistry {
363
+ private static registry;
364
+ static register<T extends Record<string, unknown>>(templateOrOptions: PromptTemplate<T> | PromptTemplateOptions<T>): void;
365
+ static get<T extends Record<string, unknown> = Record<string, unknown>>(id: string, options?: {
366
+ version?: number;
367
+ label?: PromptLabel;
368
+ }): PromptTemplate<T>;
369
+ static has(id: string): boolean;
370
+ static clear(): void;
371
+ }
372
+
373
+ declare class HttpProviderClient implements LLMProviderPort {
374
+ readonly name: string;
375
+ private readonly baseUrl;
376
+ private readonly apiKey?;
377
+ private readonly providerType;
378
+ constructor(config: ProviderConfig);
379
+ private resolveEndpoint;
380
+ private buildHeaders;
381
+ private buildPayload;
382
+ private extractUsage;
383
+ complete(options: LLMCompletionOptions): Promise<{
384
+ text: string;
385
+ usage?: LLMUsage;
386
+ }>;
387
+ }
388
+ declare function createHttpProviderClient(config: ProviderConfig): HttpProviderClient;
389
+
390
+ export { type AuditRecord, type AuditSinkPort, BudgetExceededError as AvantGateBudgetExceededError, ConfigurationError as AvantGateConfigurationError, AvantGateControlLayer, BudgetExceededError, type BuildResult, CachedPricingAdapter, type CalculateCostOptions, type ChatMessage, ConfigurationError, type ControlLayerConfig, DEFAULT_MODEL_PRICES, type ExecutionResult, type FeaturesConfig, type FinanceFeaturesConfig, type GenerateStructuredOutputOptions, HttpProviderClient, type ITokenBudget, type InputGuardResult, type LLMCompletionOptions, type LLMProviderPort, type LLMStructuredOutputOptions, type LLMUsage, type ModelPrice, type PricingAdapter, PricingRegistry, PromptBuilder, type PromptLabel, type PromptMessage, PromptRegistry, PromptTemplate, type PromptTemplateOptions, type PromptValidationResult, type ProviderConfig, type RetryConfig, SEED_MODEL_PRICES, type SanitizeResult, type SecurityConfig, type StructuredExecutionResult, type ValidateOptions, AvantGateControlLayer as ZenLLMControlLayer, calculateCostUSD, createAvantGate, createHttpProviderClient, createLLMControlLayer, extractAndCleanJSON, resolveModelPrice, resolveModelPriceAsync, sanitizePII, validateUserInput, validateWithZod };