avantgate 1.0.0 → 1.1.0

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";
@@ -67,6 +68,15 @@ interface AuditSinkPort {
67
68
  readonly name: string;
68
69
  log(record: AuditRecord): Promise<void> | void;
69
70
  }
71
+ interface FinanceFeaturesConfig {
72
+ enableFrenchAccounting?: boolean;
73
+ stripCurrencySymbols?: boolean;
74
+ jurisdiction?: "FR" | "US" | "UK" | "CH" | "INTERNATIONAL";
75
+ autoDetect?: boolean;
76
+ }
77
+ interface FeaturesConfig {
78
+ finance?: FinanceFeaturesConfig;
79
+ }
70
80
  interface ControlLayerConfig {
71
81
  primary: ProviderConfig;
72
82
  fallback?: ProviderConfig;
@@ -78,6 +88,7 @@ interface ControlLayerConfig {
78
88
  security?: SecurityConfig;
79
89
  hourlyTokenLimit?: number;
80
90
  dailyTokenLimit?: number;
91
+ features?: FeaturesConfig;
81
92
  }
82
93
  interface ExecutionResult {
83
94
  text: string;
@@ -103,6 +114,16 @@ interface StructuredExecutionResult<T> {
103
114
  modelUsed: string;
104
115
  failoverOccurred: boolean;
105
116
  }
117
+ interface GenerateStructuredOutputOptions<T> {
118
+ model?: string;
119
+ messages: ChatMessage[];
120
+ schema: z.ZodType<T>;
121
+ schemaName?: string;
122
+ maxRetries?: number;
123
+ temperature?: number;
124
+ providerOverride?: LLMProviderPort;
125
+ financialNormalizer?: boolean;
126
+ }
106
127
 
107
128
  interface ModelPrice {
108
129
  promptUSDPerMillion: number;
@@ -114,7 +135,7 @@ declare function calculateCostUSD(model: string, promptTokens: number, completio
114
135
 
115
136
  /**
116
137
  * In-Flight PII Sanitizer for AvantGate.
117
- * Masque les données sensibles (email, numéros de téléphone, NIR/sécurité sociale, IBAN)
138
+ * Masque les données sensibles (email, téléphone, NIR/sécurité sociale, IBAN/BIC, numéro fiscal SPI)
118
139
  * avant l'envoi vers des API cloud.
119
140
  */
120
141
  interface SanitizeResult {
@@ -136,6 +157,11 @@ declare function validateUserInput(input: string, options?: {
136
157
  maxLength?: number;
137
158
  }): InputGuardResult;
138
159
 
160
+ interface ValidateOptions {
161
+ normalizer?: (rawText: string) => string;
162
+ financialNormalizer?: boolean;
163
+ jurisdiction?: FinancialJurisdictionCode;
164
+ }
139
165
  /**
140
166
  * Nettoie et extrait un bloc JSON valide depuis une réponse de LLM
141
167
  * (gère les blocs markdown ```json ... ```, les balises de réflexion, etc.)
@@ -143,8 +169,9 @@ declare function validateUserInput(input: string, options?: {
143
169
  declare function extractAndCleanJSON(rawText: string): string;
144
170
  /**
145
171
  * Valide et auto-répare une sortie JSON contre un schéma Zod.
172
+ * Supporte l'option de normalisation financière (parenthèses négatives, formats comptables).
146
173
  */
147
- declare function validateWithZod<T>(rawText: string, schema: z.ZodType<T>): T;
174
+ declare function validateWithZod<T>(rawText: string, schema: z.ZodType<T>, options?: ValidateOptions): T;
148
175
 
149
176
  declare class AvantGateControlLayer {
150
177
  private config;
@@ -177,8 +204,105 @@ declare class AvantGateControlLayer {
177
204
  temperature?: number;
178
205
  providerOverride?: LLMProviderPort;
179
206
  }): Promise<StructuredExecutionResult<T>>;
207
+ /**
208
+ * Méthode unifiée de premier niveau pour l'extraction structurée sans code boilerplate.
209
+ * Gère le failover multi-fournisseurs, les retries, la validation Zod et la normalisation financière.
210
+ */
211
+ generateStructuredOutput<T>(options: GenerateStructuredOutputOptions<T>): Promise<StructuredExecutionResult<T>>;
180
212
  }
181
213
  declare function createLLMControlLayer(config: ControlLayerConfig): AvantGateControlLayer;
182
214
  declare const createAvantGate: typeof createLLMControlLayer;
183
215
 
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 };
216
+ interface PromptMessage {
217
+ role: "system" | "user" | "assistant";
218
+ content: string;
219
+ }
220
+ type PromptLabel = "production" | "staging" | "experimental";
221
+ interface PromptTemplateOptions<TVariables extends Record<string, unknown> = Record<string, unknown>> {
222
+ id: string;
223
+ version: number;
224
+ label?: PromptLabel;
225
+ description?: string;
226
+ template: string;
227
+ inputSchema?: z.ZodType<TVariables>;
228
+ antiInjection?: {
229
+ enabled?: boolean;
230
+ blockPatterns?: RegExp[];
231
+ sanitizer?: (value: string) => string;
232
+ };
233
+ }
234
+ interface PromptValidationResult {
235
+ isValid: boolean;
236
+ threats: string[];
237
+ }
238
+ interface ITokenBudget {
239
+ count(text: string): number;
240
+ remaining(): number;
241
+ reserve(slot: string, text: string): void;
242
+ forceReserve(slot: string, text: string): void;
243
+ getAllocated(): number;
244
+ reset(): void;
245
+ }
246
+ interface BuildResult {
247
+ messages: PromptMessage[];
248
+ promptText: string;
249
+ allocatedTokens?: number;
250
+ isTruncated: boolean;
251
+ truncatedSlot?: "context" | "pinnedFacts" | "user";
252
+ }
253
+
254
+ declare class PromptTemplate<TVariables extends Record<string, unknown> = Record<string, unknown>> {
255
+ readonly id: string;
256
+ readonly version: number;
257
+ readonly label: PromptLabel;
258
+ readonly description?: string;
259
+ readonly template: string;
260
+ readonly inputSchema?: z.ZodType<TVariables>;
261
+ private blockPatterns;
262
+ private antiInjectionEnabled;
263
+ private customSanitizer?;
264
+ constructor(options: PromptTemplateOptions<TVariables>);
265
+ validateUserInput(variables: TVariables): PromptValidationResult;
266
+ format(variables: TVariables): string;
267
+ }
268
+
269
+ declare class PromptBuilder {
270
+ private personaSlot;
271
+ private rulesSlot;
272
+ private retryHintSlot;
273
+ private fewShotSlot;
274
+ private pinnedFactsSlot;
275
+ private contextSlot;
276
+ private userPayloadSlot;
277
+ private schemaContractText;
278
+ constructor(templateOrId?: string | PromptTemplate);
279
+ withPersona(persona: string): this;
280
+ withRules(rules: string | string[]): this;
281
+ withRetryHint(hint: string): this;
282
+ withFewShot(examples: Array<{
283
+ question: string;
284
+ answer: string;
285
+ }>): this;
286
+ withPinnedFacts(facts: string | Record<string, unknown>): this;
287
+ withContext(context: string): this;
288
+ withUserPayload(payload: string): this;
289
+ schemaContract<T>(schema: z.ZodType<T>, options?: {
290
+ schemaName?: string;
291
+ }): this;
292
+ private assembleMessages;
293
+ toMessages(): PromptMessage[];
294
+ build(budget?: ITokenBudget): BuildResult;
295
+ }
296
+
297
+ declare class PromptRegistry {
298
+ private static registry;
299
+ static register<T extends Record<string, unknown>>(templateOrOptions: PromptTemplate<T> | PromptTemplateOptions<T>): void;
300
+ static get<T extends Record<string, unknown> = Record<string, unknown>>(id: string, options?: {
301
+ version?: number;
302
+ label?: PromptLabel;
303
+ }): PromptTemplate<T>;
304
+ static has(id: string): boolean;
305
+ static clear(): void;
306
+ }
307
+
308
+ export { type AuditRecord, type AuditSinkPort, AvantGateControlLayer, type BuildResult, type ChatMessage, type ControlLayerConfig, DEFAULT_MODEL_PRICES, type ExecutionResult, type FeaturesConfig, type FinanceFeaturesConfig, type GenerateStructuredOutputOptions, type ITokenBudget, type InputGuardResult, type LLMCompletionOptions, type LLMProviderPort, type LLMStructuredOutputOptions, type LLMUsage, type ModelPrice, PromptBuilder, type PromptLabel, type PromptMessage, PromptRegistry, PromptTemplate, type PromptTemplateOptions, type PromptValidationResult, type ProviderConfig, type RetryConfig, type SanitizeResult, type SecurityConfig, type StructuredExecutionResult, type ValidateOptions, AvantGateControlLayer as ZenLLMControlLayer, calculateCostUSD, createAvantGate, createLLMControlLayer, extractAndCleanJSON, 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";
@@ -67,6 +68,15 @@ interface AuditSinkPort {
67
68
  readonly name: string;
68
69
  log(record: AuditRecord): Promise<void> | void;
69
70
  }
71
+ interface FinanceFeaturesConfig {
72
+ enableFrenchAccounting?: boolean;
73
+ stripCurrencySymbols?: boolean;
74
+ jurisdiction?: "FR" | "US" | "UK" | "CH" | "INTERNATIONAL";
75
+ autoDetect?: boolean;
76
+ }
77
+ interface FeaturesConfig {
78
+ finance?: FinanceFeaturesConfig;
79
+ }
70
80
  interface ControlLayerConfig {
71
81
  primary: ProviderConfig;
72
82
  fallback?: ProviderConfig;
@@ -78,6 +88,7 @@ interface ControlLayerConfig {
78
88
  security?: SecurityConfig;
79
89
  hourlyTokenLimit?: number;
80
90
  dailyTokenLimit?: number;
91
+ features?: FeaturesConfig;
81
92
  }
82
93
  interface ExecutionResult {
83
94
  text: string;
@@ -103,6 +114,16 @@ interface StructuredExecutionResult<T> {
103
114
  modelUsed: string;
104
115
  failoverOccurred: boolean;
105
116
  }
117
+ interface GenerateStructuredOutputOptions<T> {
118
+ model?: string;
119
+ messages: ChatMessage[];
120
+ schema: z.ZodType<T>;
121
+ schemaName?: string;
122
+ maxRetries?: number;
123
+ temperature?: number;
124
+ providerOverride?: LLMProviderPort;
125
+ financialNormalizer?: boolean;
126
+ }
106
127
 
107
128
  interface ModelPrice {
108
129
  promptUSDPerMillion: number;
@@ -114,7 +135,7 @@ declare function calculateCostUSD(model: string, promptTokens: number, completio
114
135
 
115
136
  /**
116
137
  * In-Flight PII Sanitizer for AvantGate.
117
- * Masque les données sensibles (email, numéros de téléphone, NIR/sécurité sociale, IBAN)
138
+ * Masque les données sensibles (email, téléphone, NIR/sécurité sociale, IBAN/BIC, numéro fiscal SPI)
118
139
  * avant l'envoi vers des API cloud.
119
140
  */
120
141
  interface SanitizeResult {
@@ -136,6 +157,11 @@ declare function validateUserInput(input: string, options?: {
136
157
  maxLength?: number;
137
158
  }): InputGuardResult;
138
159
 
160
+ interface ValidateOptions {
161
+ normalizer?: (rawText: string) => string;
162
+ financialNormalizer?: boolean;
163
+ jurisdiction?: FinancialJurisdictionCode;
164
+ }
139
165
  /**
140
166
  * Nettoie et extrait un bloc JSON valide depuis une réponse de LLM
141
167
  * (gère les blocs markdown ```json ... ```, les balises de réflexion, etc.)
@@ -143,8 +169,9 @@ declare function validateUserInput(input: string, options?: {
143
169
  declare function extractAndCleanJSON(rawText: string): string;
144
170
  /**
145
171
  * Valide et auto-répare une sortie JSON contre un schéma Zod.
172
+ * Supporte l'option de normalisation financière (parenthèses négatives, formats comptables).
146
173
  */
147
- declare function validateWithZod<T>(rawText: string, schema: z.ZodType<T>): T;
174
+ declare function validateWithZod<T>(rawText: string, schema: z.ZodType<T>, options?: ValidateOptions): T;
148
175
 
149
176
  declare class AvantGateControlLayer {
150
177
  private config;
@@ -177,8 +204,105 @@ declare class AvantGateControlLayer {
177
204
  temperature?: number;
178
205
  providerOverride?: LLMProviderPort;
179
206
  }): Promise<StructuredExecutionResult<T>>;
207
+ /**
208
+ * Méthode unifiée de premier niveau pour l'extraction structurée sans code boilerplate.
209
+ * Gère le failover multi-fournisseurs, les retries, la validation Zod et la normalisation financière.
210
+ */
211
+ generateStructuredOutput<T>(options: GenerateStructuredOutputOptions<T>): Promise<StructuredExecutionResult<T>>;
180
212
  }
181
213
  declare function createLLMControlLayer(config: ControlLayerConfig): AvantGateControlLayer;
182
214
  declare const createAvantGate: typeof createLLMControlLayer;
183
215
 
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 };
216
+ interface PromptMessage {
217
+ role: "system" | "user" | "assistant";
218
+ content: string;
219
+ }
220
+ type PromptLabel = "production" | "staging" | "experimental";
221
+ interface PromptTemplateOptions<TVariables extends Record<string, unknown> = Record<string, unknown>> {
222
+ id: string;
223
+ version: number;
224
+ label?: PromptLabel;
225
+ description?: string;
226
+ template: string;
227
+ inputSchema?: z.ZodType<TVariables>;
228
+ antiInjection?: {
229
+ enabled?: boolean;
230
+ blockPatterns?: RegExp[];
231
+ sanitizer?: (value: string) => string;
232
+ };
233
+ }
234
+ interface PromptValidationResult {
235
+ isValid: boolean;
236
+ threats: string[];
237
+ }
238
+ interface ITokenBudget {
239
+ count(text: string): number;
240
+ remaining(): number;
241
+ reserve(slot: string, text: string): void;
242
+ forceReserve(slot: string, text: string): void;
243
+ getAllocated(): number;
244
+ reset(): void;
245
+ }
246
+ interface BuildResult {
247
+ messages: PromptMessage[];
248
+ promptText: string;
249
+ allocatedTokens?: number;
250
+ isTruncated: boolean;
251
+ truncatedSlot?: "context" | "pinnedFacts" | "user";
252
+ }
253
+
254
+ declare class PromptTemplate<TVariables extends Record<string, unknown> = Record<string, unknown>> {
255
+ readonly id: string;
256
+ readonly version: number;
257
+ readonly label: PromptLabel;
258
+ readonly description?: string;
259
+ readonly template: string;
260
+ readonly inputSchema?: z.ZodType<TVariables>;
261
+ private blockPatterns;
262
+ private antiInjectionEnabled;
263
+ private customSanitizer?;
264
+ constructor(options: PromptTemplateOptions<TVariables>);
265
+ validateUserInput(variables: TVariables): PromptValidationResult;
266
+ format(variables: TVariables): string;
267
+ }
268
+
269
+ declare class PromptBuilder {
270
+ private personaSlot;
271
+ private rulesSlot;
272
+ private retryHintSlot;
273
+ private fewShotSlot;
274
+ private pinnedFactsSlot;
275
+ private contextSlot;
276
+ private userPayloadSlot;
277
+ private schemaContractText;
278
+ constructor(templateOrId?: string | PromptTemplate);
279
+ withPersona(persona: string): this;
280
+ withRules(rules: string | string[]): this;
281
+ withRetryHint(hint: string): this;
282
+ withFewShot(examples: Array<{
283
+ question: string;
284
+ answer: string;
285
+ }>): this;
286
+ withPinnedFacts(facts: string | Record<string, unknown>): this;
287
+ withContext(context: string): this;
288
+ withUserPayload(payload: string): this;
289
+ schemaContract<T>(schema: z.ZodType<T>, options?: {
290
+ schemaName?: string;
291
+ }): this;
292
+ private assembleMessages;
293
+ toMessages(): PromptMessage[];
294
+ build(budget?: ITokenBudget): BuildResult;
295
+ }
296
+
297
+ declare class PromptRegistry {
298
+ private static registry;
299
+ static register<T extends Record<string, unknown>>(templateOrOptions: PromptTemplate<T> | PromptTemplateOptions<T>): void;
300
+ static get<T extends Record<string, unknown> = Record<string, unknown>>(id: string, options?: {
301
+ version?: number;
302
+ label?: PromptLabel;
303
+ }): PromptTemplate<T>;
304
+ static has(id: string): boolean;
305
+ static clear(): void;
306
+ }
307
+
308
+ export { type AuditRecord, type AuditSinkPort, AvantGateControlLayer, type BuildResult, type ChatMessage, type ControlLayerConfig, DEFAULT_MODEL_PRICES, type ExecutionResult, type FeaturesConfig, type FinanceFeaturesConfig, type GenerateStructuredOutputOptions, type ITokenBudget, type InputGuardResult, type LLMCompletionOptions, type LLMProviderPort, type LLMStructuredOutputOptions, type LLMUsage, type ModelPrice, PromptBuilder, type PromptLabel, type PromptMessage, PromptRegistry, PromptTemplate, type PromptTemplateOptions, type PromptValidationResult, type ProviderConfig, type RetryConfig, type SanitizeResult, type SecurityConfig, type StructuredExecutionResult, type ValidateOptions, AvantGateControlLayer as ZenLLMControlLayer, calculateCostUSD, createAvantGate, createLLMControlLayer, extractAndCleanJSON, sanitizePII, validateUserInput, validateWithZod };