avantgate 1.6.1 → 1.7.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.
Files changed (37) hide show
  1. package/README.md +15 -1
  2. package/dist/agent/index.js +97 -24
  3. package/dist/agent/index.mjs +5 -2
  4. package/dist/agent/isolated-tool.d.ts +8 -3
  5. package/dist/agent/isolated-tool.d.ts.map +1 -1
  6. package/dist/agent/types.d.ts +16 -0
  7. package/dist/agent/types.d.ts.map +1 -1
  8. package/dist/{chunk-CO26LNFD.mjs → chunk-36ULFTM2.mjs} +8 -8
  9. package/dist/{chunk-4XWO3NZW.mjs → chunk-AH5XXSS4.mjs} +1 -1
  10. package/dist/{chunk-5VA3EKPJ.mjs → chunk-W27A25DK.mjs} +97 -25
  11. package/dist/chunk-Y6FXYEAI.mjs +10 -0
  12. package/dist/client/index.mjs +2 -0
  13. package/dist/control-layer.d.ts +7 -7
  14. package/dist/control-layer.d.ts.map +1 -1
  15. package/dist/finance/index.js +6 -6
  16. package/dist/finance/index.mjs +2 -1
  17. package/dist/finance/normalizer.d.ts +2 -2
  18. package/dist/finance/normalizer.d.ts.map +1 -1
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +421 -130
  22. package/dist/index.mjs +318 -103
  23. package/dist/input-guard.d.ts +2 -2
  24. package/dist/input-guard.d.ts.map +1 -1
  25. package/dist/pricing.d.ts +17 -16
  26. package/dist/pricing.d.ts.map +1 -1
  27. package/dist/providers/http-client.d.ts +2 -2
  28. package/dist/providers/http-client.d.ts.map +1 -1
  29. package/dist/response-validator.d.ts +2 -2
  30. package/dist/response-validator.d.ts.map +1 -1
  31. package/dist/sanitizer.d.ts +1 -1
  32. package/dist/sanitizer.d.ts.map +1 -1
  33. package/dist/sqlite-pricing-adapter.d.ts +87 -0
  34. package/dist/sqlite-pricing-adapter.d.ts.map +1 -0
  35. package/dist/workflow/index.js +92 -24
  36. package/dist/workflow/index.mjs +3 -2
  37. package/package.json +4 -2
@@ -6,8 +6,8 @@ export interface InputGuardResult {
6
6
  valid: boolean;
7
7
  blockedReason?: string;
8
8
  }
9
- export declare function validateUserInput(input: string, options?: {
9
+ export declare const validateUserInput: (input: string, options?: {
10
10
  detectInjection?: boolean;
11
11
  maxLength?: number;
12
- }): InputGuardResult;
12
+ }) => InputGuardResult;
13
13
  //# sourceMappingURL=input-guard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"input-guard.d.ts","sourceRoot":"","sources":["../src/input-guard.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;IAAE,eAAe,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1D,gBAAgB,CAqBlB"}
1
+ {"version":3,"file":"input-guard.d.ts","sourceRoot":"","sources":["../src/input-guard.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,iBAAiB,GAC5B,OAAO,MAAM,EACb,UAAU;IAAE,eAAe,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,KAC1D,gBAqBF,CAAA"}
package/dist/pricing.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ModelPrice, PricingAdapter } from "./types";
2
2
  export type { ModelPrice, PricingAdapter };
3
+ export * from "./sqlite-pricing-adapter";
3
4
  export interface CalculateCostOptions {
4
5
  provider?: string;
5
6
  providerPricing?: ModelPrice;
@@ -17,10 +18,10 @@ export declare class CachedPricingAdapter implements PricingAdapter {
17
18
  private ttlMs;
18
19
  private delegate;
19
20
  constructor(delegate: PricingAdapter, ttlMs?: number);
20
- fetchPrice(model: string, provider?: string): Promise<ModelPrice | undefined>;
21
- peek(model: string, provider?: string): ModelPrice | undefined;
22
- clearCache(): void;
23
- invalidate(model?: string, provider?: string): void;
21
+ fetchPrice: (model: string, provider?: string) => Promise<ModelPrice | undefined>;
22
+ peek: (model: string, provider?: string) => ModelPrice | undefined;
23
+ clearCache: () => void;
24
+ invalidate: (model?: string, provider?: string) => void;
24
25
  }
25
26
  /**
26
27
  * Registre de tarification dynamique.
@@ -29,21 +30,21 @@ export declare class CachedPricingAdapter implements PricingAdapter {
29
30
  export declare class PricingRegistry {
30
31
  private static prices;
31
32
  private static adapter?;
32
- static registerPrice(identifier: string, price: ModelPrice): void;
33
- static registerDistributorPrices(distributor: string, priceMap: Record<string, ModelPrice>): void;
34
- static registerPrices(prices: Record<string, ModelPrice>): void;
35
- static getPrice(model: string, provider?: string): ModelPrice | undefined;
36
- static setAdapter(adapter: PricingAdapter): void;
37
- static getAdapter(): PricingAdapter | undefined;
38
- static clear(): void;
33
+ static registerPrice: (identifier: string, price: ModelPrice) => void;
34
+ static registerDistributorPrices: (distributor: string, priceMap: Record<string, ModelPrice>) => void;
35
+ static registerPrices: (prices: Record<string, ModelPrice>) => void;
36
+ static getPrice: (model: string, provider?: string) => ModelPrice | undefined;
37
+ static setAdapter: (adapter: PricingAdapter) => void;
38
+ static getAdapter: () => PricingAdapter | undefined;
39
+ static clear: () => void;
39
40
  /**
40
41
  * Réinitialise le registre en chargeant le catalogue d'exemple SEED_MODEL_PRICES.
41
42
  */
42
- static loadSeedPrices(): void;
43
- static getAllPrices(): Record<string, ModelPrice>;
43
+ static loadSeedPrices: () => void;
44
+ static getAllPrices: () => Record<string, ModelPrice>;
44
45
  }
45
46
  export declare const DEFAULT_MODEL_PRICES: Record<string, ModelPrice>;
46
- export declare function resolveModelPrice(model: string, options?: CalculateCostOptions | string): ModelPrice | undefined;
47
- export declare function resolveModelPriceAsync(model: string, options?: CalculateCostOptions | string): Promise<ModelPrice | undefined>;
48
- export declare function calculateCostUSD(model: string, promptTokens: number, completionTokens: number, cacheHitTokens?: number, options?: CalculateCostOptions | string): number;
47
+ export declare const resolveModelPrice: (model: string, options?: CalculateCostOptions | string) => ModelPrice | undefined;
48
+ export declare const resolveModelPriceAsync: (model: string, options?: CalculateCostOptions | string) => Promise<ModelPrice | undefined>;
49
+ export declare const calculateCostUSD: (model: string, promptTokens: number, completionTokens: number, cacheHitTokens?: number, options?: CalculateCostOptions | string) => number;
49
50
  //# sourceMappingURL=pricing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../src/pricing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC1D,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC;AAE3C,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,UAAU,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC3C,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CA0BxD,CAAC;AAMF,qBAAa,oBAAqB,YAAW,cAAc;IACzD,OAAO,CAAC,KAAK,CAA+D;IAC5E,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,QAAQ,CAAiB;gBAErB,QAAQ,EAAE,cAAc,EAAE,KAAK,GAAE,MAAsB;IAK7D,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAwBnF,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC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AAG,MAAM,KACtC,MAcF,CAAC"}
@@ -9,10 +9,10 @@ export declare class HttpProviderClient implements LLMProviderPort {
9
9
  private buildHeaders;
10
10
  private buildPayload;
11
11
  private extractUsage;
12
- complete(options: LLMCompletionOptions): Promise<{
12
+ complete: (options: LLMCompletionOptions) => Promise<{
13
13
  text: string;
14
14
  usage?: LLMUsage;
15
15
  }>;
16
16
  }
17
- export declare function createHttpProviderClient(config: ProviderConfig): HttpProviderClient;
17
+ export declare const createHttpProviderClient: (config: ProviderConfig) => HttpProviderClient;
18
18
  //# sourceMappingURL=http-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/providers/http-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,QAAQ,EAER,cAAc,EACf,MAAM,UAAU,CAAC;AA+BlB,qBAAa,kBAAmB,YAAW,eAAe;IACxD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAE1B,MAAM,EAAE,cAAc;IAOlC,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,YAAY;IAiBpB,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,YAAY;IAYd,QAAQ,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,QAAQ,CAAA;KAAE,CAAC;CAyB3F;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,cAAc,GAAG,kBAAkB,CAEnF"}
1
+ {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/providers/http-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,QAAQ,EAER,cAAc,EACf,MAAM,UAAU,CAAC;AA+BlB,qBAAa,kBAAmB,YAAW,eAAe;IACxD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAE1B,MAAM,EAAE,cAAc;IAOlC,OAAO,CAAC,eAAe,CAMrB;IAEF,OAAO,CAAC,YAAY,CAelB;IAEF,OAAO,CAAC,YAAY,CAUlB;IAEF,OAAO,CAAC,YAAY,CAUlB;IAEF,QAAQ,GAAU,SAAS,oBAAoB,KAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,QAAQ,CAAA;KAAE,CAAC,CAwB3F;CACH;AAED,eAAO,MAAM,wBAAwB,GAAI,QAAQ,cAAc,KAAG,kBAEjE,CAAC"}
@@ -9,10 +9,10 @@ export interface ValidateOptions {
9
9
  * Nettoie et extrait un bloc JSON valide depuis une réponse de LLM
10
10
  * (gère les blocs markdown ```json ... ```, les balises de réflexion, etc.)
11
11
  */
12
- export declare function extractAndCleanJSON(rawText: string): string;
12
+ export declare const extractAndCleanJSON: (rawText: string) => string;
13
13
  /**
14
14
  * Valide et auto-répare une sortie JSON contre un schéma Zod.
15
15
  * Supporte l'option de normalisation financière (parenthèses négatives, formats comptables).
16
16
  */
17
- export declare function validateWithZod<T>(rawText: string, schema: z.ZodType<T>, options?: ValidateOptions): T;
17
+ export declare const validateWithZod: <T>(rawText: string, schema: z.ZodType<T>, options?: ValidateOptions) => T;
18
18
  //# sourceMappingURL=response-validator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"response-validator.d.ts","sourceRoot":"","sources":["../src/response-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAE9E,MAAM,WAAW,eAAe;IAC9B,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IACzC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,yBAAyB,CAAC;CAC1C;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAkC3D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,eAAe,GACxB,CAAC,CAsBH"}
1
+ {"version":3,"file":"response-validator.d.ts","sourceRoot":"","sources":["../src/response-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAE9E,MAAM,WAAW,eAAe;IAC9B,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IACzC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,yBAAyB,CAAC;CAC1C;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,KAAG,MAkCrD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAC/B,SAAS,MAAM,EACf,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EACpB,UAAU,eAAe,KACxB,CAsBF,CAAA"}
@@ -7,5 +7,5 @@ export interface SanitizeResult {
7
7
  text: string;
8
8
  maskedCount: number;
9
9
  }
10
- export declare function sanitizePII(input: string): SanitizeResult;
10
+ export declare const sanitizePII: (input: string) => SanitizeResult;
11
11
  //# sourceMappingURL=sanitizer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sanitizer.d.ts","sourceRoot":"","sources":["../src/sanitizer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkBH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CA2DzD"}
1
+ {"version":3,"file":"sanitizer.d.ts","sourceRoot":"","sources":["../src/sanitizer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkBH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,cA2D3C,CAAA"}
@@ -0,0 +1,87 @@
1
+ import type { ModelPrice, PricingAdapter } from "./types";
2
+ export interface SqliteDatabaseLike {
3
+ exec(sql: string): void;
4
+ prepare(sql: string): {
5
+ run(...params: unknown[]): unknown;
6
+ all(...params: unknown[]): unknown[];
7
+ get(...params: unknown[]): unknown;
8
+ };
9
+ close?(): void;
10
+ }
11
+ export interface SqlitePricingAdapterOptions {
12
+ /**
13
+ * Chemin vers le fichier SQLite local (par exemple "./data/gatewall.db" ou "./data/pricing.db").
14
+ * Utilisez ":memory:" pour une base volatile en mémoire.
15
+ */
16
+ dbPath?: string;
17
+ /**
18
+ * Instance personnalisée compatible SQLite (DatabaseSync de node:sqlite ou better-sqlite3).
19
+ */
20
+ db?: SqliteDatabaseLike;
21
+ /**
22
+ * Nom de la table de tarification (défaut : "model_pricing").
23
+ */
24
+ tableName?: string;
25
+ /**
26
+ * Si true, injecte automatiquement SEED_MODEL_PRICES si la table est vide lors de l'initialisation.
27
+ */
28
+ autoSeed?: boolean;
29
+ }
30
+ export interface StoredModelPriceRow {
31
+ provider: string;
32
+ model: string;
33
+ prompt_usd_per_million: number;
34
+ completion_usd_per_million: number;
35
+ cache_hit_usd_per_million: number | null;
36
+ is_active: number;
37
+ updated_at: string;
38
+ }
39
+ export interface ModelPricingRecord {
40
+ provider: string;
41
+ model: string;
42
+ price: ModelPrice;
43
+ isActive: boolean;
44
+ updatedAt: string;
45
+ }
46
+ /**
47
+ * Adaptateur de tarification SQLite Zero-Infrastructure pour avantGate.
48
+ * Implémente le port PricingAdapter avec persistance locale et support hot-reload.
49
+ */
50
+ export declare class SqlitePricingAdapter implements PricingAdapter {
51
+ private db;
52
+ private tableName;
53
+ constructor(options?: SqlitePricingAdapterOptions);
54
+ private initDatabase;
55
+ private initSchema;
56
+ /**
57
+ * Implémentation du port avantGate PricingAdapter.
58
+ * Résolution hiérarchique : (provider, model) -> (provider/model) -> (model).
59
+ */
60
+ fetchPrice: (model: string, provider?: string) => ModelPrice | undefined;
61
+ private queryActiveRow;
62
+ private queryByModelOnly;
63
+ private mapRowToPrice;
64
+ /**
65
+ * Enregistre ou met à jour la tarification d'un modèle.
66
+ */
67
+ upsertPrice: (provider: string, model: string, price: ModelPrice, isActive?: boolean) => void;
68
+ /**
69
+ * Supprime une règle tarifaire de la base de données.
70
+ */
71
+ deletePrice: (provider: string, model: string) => boolean;
72
+ /**
73
+ * Retourne l'ensemble des règles tarifaires enregistrées.
74
+ */
75
+ getAllPrices: () => ModelPricingRecord[];
76
+ /**
77
+ * Remplit la base avec le catalogue de départ SEED_MODEL_PRICES.
78
+ * @param force Si true, écrase les tarifs existants. Si false, insère uniquement les modèles manquants.
79
+ * @returns Le nombre d'enregistrements insérés.
80
+ */
81
+ seedDefaultPrices: (force?: boolean) => number;
82
+ /**
83
+ * Ferme la connexion SQLite sous-jacente si supporté.
84
+ */
85
+ close: () => void;
86
+ }
87
+ //# sourceMappingURL=sqlite-pricing-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-pricing-adapter.d.ts","sourceRoot":"","sources":["../src/sqlite-pricing-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,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UrD,OAAO,CAAC,YAAY,CAmBlB;IAEF,OAAO,CAAC,UAAU,CAehB;IAEF;;;OAGG;IACH,UAAU,GAAI,OAAO,MAAM,EAAE,WAAW,MAAM,KAAG,UAAU,GAAG,SAAS,CAyBrE;IAEF,OAAO,CAAC,cAAc,CAQpB;IAEF,OAAO,CAAC,gBAAgB,CAQtB;IAEF,OAAO,CAAC,aAAa,CAQnB;IAEF;;OAEG;IACH,WAAW,GAAI,UAAU,MAAM,EAAE,OAAO,MAAM,EAAE,OAAO,UAAU,EAAE,WAAU,OAAc,KAAG,IAAI,CAoBhG;IAEF;;OAEG;IACH,WAAW,GAAI,UAAU,MAAM,EAAE,OAAO,MAAM,KAAG,OAAO,CAUtD;IAEF;;OAEG;IACH,YAAY,QAAO,kBAAkB,EAAE,CAerC;IAEF;;;;OAIG;IACH,iBAAiB,GAAI,QAAO,OAAe,KAAG,MAAM,CAgDlD;IAEF;;OAEG;IACH,KAAK,QAAO,IAAI,CAId;CACH"}
@@ -89,7 +89,7 @@ var SPI_LABELLED_REGEX = /(?:(?:num[ée]ro\s+fiscal|spi|n[°o]\s*fiscal|d[ée]cl
89
89
  var SPI_FORMATTED_REGEX = /\b[0-3]\d(?:\s+\d{2}){5}\s+\d\b/g;
90
90
  var IBAN_REGEX = /\b[A-Z]{2}\s*[0-9]{2}(?:[\s\r\n.-]*[A-Z0-9]){11,30}\b/g;
91
91
  var BIC_LABELLED_REGEX = /(?:(?:bic|swift)\s*[:=]?\s*)\b([A-Z]{4}[A-Z]{2}[A-Z0-9]{2}(?:[A-Z0-9]{3})?)\b/gi;
92
- function sanitizePII(input) {
92
+ var sanitizePII = (input) => {
93
93
  let count = 0;
94
94
  let result = input;
95
95
  result = result.replace(EMAIL_REGEX, () => {
@@ -132,7 +132,7 @@ function sanitizePII(input) {
132
132
  return match;
133
133
  });
134
134
  return { text: result, maskedCount: count };
135
- }
135
+ };
136
136
 
137
137
  // src/agent/guardrails.ts
138
138
  function sanitizeString(value) {
@@ -187,7 +187,23 @@ function auditToolResult(data, options) {
187
187
  }
188
188
 
189
189
  // src/agent/isolated-tool.ts
190
- async function verifyDataAccessGuard(guard, args, context, toolIdentifier) {
190
+ var verifyRoles = (configuredRoles, context, toolIdentifier) => {
191
+ if (!configuredRoles || configuredRoles.length === 0) {
192
+ return;
193
+ }
194
+ const userRoles = [
195
+ ...context.roles ?? [],
196
+ ...context.role ? [context.role] : []
197
+ ];
198
+ const hasAllowedRole = configuredRoles.some((role) => userRoles.includes(role));
199
+ if (!hasAllowedRole) {
200
+ throw new ToolAccessDeniedError(
201
+ toolIdentifier,
202
+ "Access denied: insufficient role permissions"
203
+ );
204
+ }
205
+ };
206
+ var verifyDataAccessGuard = async (guard, args, context, toolIdentifier) => {
191
207
  if (!guard) {
192
208
  return;
193
209
  }
@@ -195,8 +211,55 @@ async function verifyDataAccessGuard(guard, args, context, toolIdentifier) {
195
211
  if (!isAllowed) {
196
212
  throw new ToolAccessDeniedError(toolIdentifier, "Access denied by data access guard");
197
213
  }
198
- }
199
- async function resolveInvalidationTags(config, args, rawResult, context) {
214
+ };
215
+ var verifyTenantIsolation = (assertTenant, rawResult, context, toolIdentifier) => {
216
+ if (!assertTenant) {
217
+ return;
218
+ }
219
+ if (!context.tenantId) {
220
+ throw new ToolAccessDeniedError(
221
+ toolIdentifier,
222
+ "Access denied: missing session tenantId in execution context for multi-tenant tool"
223
+ );
224
+ }
225
+ const recordTenantId = assertTenant(rawResult);
226
+ if (recordTenantId && recordTenantId !== context.tenantId) {
227
+ throw new ToolAccessDeniedError(
228
+ toolIdentifier,
229
+ `Cross-tenant IDOR access violation: record tenant '${recordTenantId}' does not match session tenant '${context.tenantId}'`
230
+ );
231
+ }
232
+ };
233
+ var verifyResourceOwnership = async (assertOwnership, rawResult, context, toolIdentifier) => {
234
+ if (!assertOwnership) {
235
+ return;
236
+ }
237
+ const isOwner = await assertOwnership(rawResult, context);
238
+ if (!isOwner) {
239
+ throw new ToolAccessDeniedError(
240
+ toolIdentifier,
241
+ "Ownership IDOR access violation: user does not own or have access to this resource"
242
+ );
243
+ }
244
+ };
245
+ var checkSuspiciousParameters = (parameters, toolName) => {
246
+ if (!parameters || typeof parameters !== "object") {
247
+ return;
248
+ }
249
+ const zodShape = parameters.shape;
250
+ if (!zodShape || typeof zodShape !== "object") {
251
+ return;
252
+ }
253
+ const suspiciousKeys = ["tenantId", "tenant_id", "ownerTenantId"];
254
+ for (const key of suspiciousKeys) {
255
+ if (key in zodShape) {
256
+ console.warn(
257
+ `[avantGate Security Warning] Tool '${toolName}' defines '${key}' as a model parameter. Tenancy should be inferred from the trusted server context (context.tenantId) rather than supplied by the untrusted model to prevent IDOR attacks.`
258
+ );
259
+ }
260
+ }
261
+ };
262
+ var resolveInvalidationTags = async (config, args, rawResult, context) => {
200
263
  if (!config.invalidationTags) {
201
264
  return void 0;
202
265
  }
@@ -205,33 +268,29 @@ async function resolveInvalidationTags(config, args, rawResult, context) {
205
268
  await context.onInvalidationTags(tags);
206
269
  }
207
270
  return tags;
208
- }
209
- async function dispatchClientData(rawResult, callback) {
271
+ };
272
+ var dispatchClientData = async (rawResult, callback) => {
210
273
  if (!callback) {
211
274
  return;
212
275
  }
213
276
  await callback(rawResult);
214
- }
215
- async function produceLlmPayload(rawResult, args, context, transformer) {
277
+ };
278
+ var produceLlmPayload = async (rawResult, args, context, transformer) => {
216
279
  if (transformer) {
217
280
  return await transformer(rawResult, args, context);
218
281
  }
219
282
  return rawResult;
220
- }
221
- function validateLlmDto(payload, schema, toolIdentifier) {
283
+ };
284
+ var validateLlmDto = (payload, schema, toolIdentifier) => {
222
285
  const parseResult = schema.safeParse(payload);
223
286
  if (!parseResult.success) {
224
287
  const issues = parseResult.error.issues ?? [];
225
288
  const errorMessages = issues.map((issue) => `${issue.path.join(".") || "root"}: ${issue.message}`).join(", ");
226
- throw new DtoValidationError(
227
- toolIdentifier,
228
- errorMessages,
229
- issues
230
- );
289
+ throw new DtoValidationError(toolIdentifier, errorMessages, issues);
231
290
  }
232
291
  return parseResult.data;
233
- }
234
- function protectLlmPayload(payload, toolIdentifier, sanitizePii = true, throwOnPii = false) {
292
+ };
293
+ var protectLlmPayload = (payload, toolIdentifier, sanitizePii = true, throwOnPii = false) => {
235
294
  if (!sanitizePii) {
236
295
  return { sanitized: payload, count: 0 };
237
296
  }
@@ -240,8 +299,8 @@ function protectLlmPayload(payload, toolIdentifier, sanitizePii = true, throwOnP
240
299
  throwOnPii
241
300
  });
242
301
  return { sanitized: sanitizedData, count: maskedCount };
243
- }
244
- async function processLlmPayload(rawResult, args, context, config, toolIdentifier) {
302
+ };
303
+ var processLlmPayload = async (rawResult, args, context, config, toolIdentifier) => {
245
304
  let payload = await produceLlmPayload(rawResult, args, context, config.llmDto);
246
305
  if (config.llmDtoSchema) {
247
306
  payload = validateLlmDto(payload, config.llmDtoSchema, toolIdentifier);
@@ -252,14 +311,15 @@ async function processLlmPayload(rawResult, args, context, config, toolIdentifie
252
311
  config.sanitizePii !== false,
253
312
  config.throwOnPii === true
254
313
  );
255
- }
256
- function createIsolatedTool(config) {
314
+ };
315
+ var createIsolatedTool = (config) => {
257
316
  const toolId = config.id || config.name;
258
317
  const toolAlias = config.alias;
259
318
  const clientCallback = config.clientDto;
260
319
  const toolIdentifier = toolAlias || config.name;
261
320
  const toolImpact = config.impact ?? "READ_ONLY";
262
321
  const requireApproval = config.requireApproval ?? toolImpact === "DESTRUCTIVE";
322
+ checkSuspiciousParameters(config.parameters, config.name);
263
323
  const tool = {
264
324
  description: config.description,
265
325
  parameters: config.parameters,
@@ -275,11 +335,12 @@ function createIsolatedTool(config) {
275
335
  _requireApproval: requireApproval,
276
336
  _lastPiiFilteredCount: 0,
277
337
  _lastInvalidationTags: void 0,
278
- async execute(args, context) {
338
+ execute: async (args, context) => {
279
339
  const updatedContext = {
280
340
  ...context,
281
341
  callChain: context?.callChain ?? Object.freeze([toolId])
282
342
  };
343
+ verifyRoles(config.roles, updatedContext, toolIdentifier);
283
344
  await verifyDataAccessGuard(
284
345
  config.dataAccessGuard,
285
346
  args,
@@ -287,6 +348,13 @@ function createIsolatedTool(config) {
287
348
  toolIdentifier
288
349
  );
289
350
  const rawResult = await config.execute(args, updatedContext);
351
+ verifyTenantIsolation(config.assertTenant, rawResult, updatedContext, toolIdentifier);
352
+ await verifyResourceOwnership(
353
+ config.assertOwnership,
354
+ rawResult,
355
+ updatedContext,
356
+ toolIdentifier
357
+ );
290
358
  const tags = await resolveInvalidationTags(
291
359
  config,
292
360
  args,
@@ -309,7 +377,7 @@ function createIsolatedTool(config) {
309
377
  }
310
378
  };
311
379
  return tool;
312
- }
380
+ };
313
381
 
314
382
  // src/workflow/errors.ts
315
383
  var WorkflowSagaRollbackError = class extends Error {
@@ -5,8 +5,9 @@ import {
5
5
  defineWorkflow,
6
6
  executeWorkflow,
7
7
  isWorkflowAbortSignal
8
- } from "../chunk-4XWO3NZW.mjs";
9
- import "../chunk-5VA3EKPJ.mjs";
8
+ } from "../chunk-AH5XXSS4.mjs";
9
+ import "../chunk-W27A25DK.mjs";
10
+ import "../chunk-Y6FXYEAI.mjs";
10
11
  export {
11
12
  WorkflowAbortSignal,
12
13
  WorkflowSagaRollbackError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "avantgate",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "description": "Zero-infrastructure, in-process AI Application Firewall (AI-WAF) & privacy control plane for TypeScript: real-time prompt guardrails, zero-egress PII redaction, agent tool isolation, anti-IDOR defense, pre-flight token budgets, and multi-model failover.",
5
5
  "author": "Gatewall Team",
6
6
  "license": "MIT",
@@ -82,7 +82,8 @@
82
82
  ],
83
83
  "scripts": {
84
84
  "build": "tsup src/index.ts src/finance/index.ts src/agent/index.ts src/workflow/index.ts src/client/index.ts --format cjs --format esm --clean && tsc --emitDeclarationOnly --outDir dist",
85
- "test": "tsx tests/avantgate.test.ts && tsx tests/preflight-budget.test.ts && tsx tests/financial-normalizer.test.ts && tsx tests/prompt-builder.test.ts && tsx tests/pii-extended.test.ts && npm run test:agent && npm run test:workflow && npm run test:client",
85
+ "test": "tsx tests/avantgate.test.ts && tsx tests/preflight-budget.test.ts && tsx tests/sqlite-pricing-adapter.test.ts && tsx tests/financial-normalizer.test.ts && tsx tests/prompt-builder.test.ts && tsx tests/pii-extended.test.ts && npm run test:agent && npm run test:workflow && npm run test:client",
86
+ "test:pricing": "tsx tests/sqlite-pricing-adapter.test.ts",
86
87
  "test:finance": "tsx tests/financial-normalizer.test.ts",
87
88
  "test:prompts": "tsx tests/prompt-builder.test.ts",
88
89
  "test:pii": "tsx tests/pii-extended.test.ts",
@@ -102,6 +103,7 @@
102
103
  "zod": "^3.23.0 || ^4.0.0"
103
104
  },
104
105
  "devDependencies": {
106
+ "@types/node": "^26.6.2",
105
107
  "@types/react": "^18.3.18",
106
108
  "react": "^18.3.1",
107
109
  "tsup": "^8.3.5",