avantgate 2.3.0 → 2.4.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.
@@ -8,8 +8,8 @@ export interface AfterExecutionState {
8
8
  responseText: string;
9
9
  metadata?: Record<string, unknown>;
10
10
  }
11
- export declare const applySingleBeforeMiddleware: (middleware: AvantGateMiddleware, current: BeforeExecutionState, model: string, temperature?: number) => Promise<BeforeExecutionState>;
12
- export declare const executeBeforeRequestHooks: (middlewares: AvantGateMiddleware[] | undefined, context: BeforeRequestContext) => Promise<BeforeExecutionState>;
13
- export declare const applySingleAfterMiddleware: (middleware: AvantGateMiddleware, current: AfterExecutionState, baseContext: Omit<AfterResponseContext, "responseText" | "metadata">) => Promise<AfterExecutionState>;
14
- export declare const executeAfterResponseHooks: (middlewares: AvantGateMiddleware[] | undefined, context: AfterResponseContext) => Promise<AfterExecutionState>;
11
+ export declare const applySingleBeforeMiddleware: (middleware: AvantGateMiddleware, current: BeforeExecutionState, model: string, temperature?: number, timeoutMs?: number) => Promise<BeforeExecutionState>;
12
+ export declare const executeBeforeRequestHooks: (middlewares: AvantGateMiddleware[] | undefined, context: BeforeRequestContext, timeoutMs?: number) => Promise<BeforeExecutionState>;
13
+ export declare const applySingleAfterMiddleware: (middleware: AvantGateMiddleware, current: AfterExecutionState, baseContext: Omit<AfterResponseContext, "responseText" | "metadata">, timeoutMs?: number) => Promise<AfterExecutionState>;
14
+ export declare const executeAfterResponseHooks: (middlewares: AvantGateMiddleware[] | undefined, context: AfterResponseContext, timeoutMs?: number) => Promise<AfterExecutionState>;
15
15
  //# sourceMappingURL=middleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB,MAAM,WA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CAAC;AAEF,eAAO,MAAM,OAAO;2BA3D4B,iBAAiB,KAAG,kBAAkB;iCAkBhC,iBAAiB,KAAG,kBAAkB;8BAsBzC,iBAAiB,KAAG,kBAAkB;CAuBxF,CAAC"}
1
+ {"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAA+B,MAAM,SAAS,CAAC;AAE/F,MAAM,WAAW,iBAAkB,SAAQ,OAAO,CAAC,kBAAkB,CAAC;IACpE,OAAO,EAAE,cAAc,CAAC;CACzB;AAED,eAAO,MAAM,sBAAsB,GAAI,SAAS,iBAAiB,KAAG,kBAkBnE,CAAC;AAEF,eAAO,MAAM,4BAA4B,GAAI,SAAS,iBAAiB,KAAG,kBAsBzE,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,SAAS,iBAAiB,KAAG,kBAiBtE,CAAC;AAEF,eAAO,MAAM,OAAO;2BA/D4B,iBAAiB,KAAG,kBAAkB;iCAoBhC,iBAAiB,KAAG,kBAAkB;8BAwBzC,iBAAiB,KAAG,kBAAkB;CAuBxF,CAAC"}
@@ -4,11 +4,14 @@ export declare class HttpProviderClient implements LLMProviderPort {
4
4
  private readonly baseUrl;
5
5
  private readonly apiKey?;
6
6
  private readonly providerType;
7
+ private readonly ttftTimeoutMs;
8
+ private readonly idleTimeoutMs;
7
9
  constructor(config: ProviderConfig);
8
10
  private resolveEndpoint;
9
11
  private buildHeaders;
10
12
  private buildPayload;
11
13
  private extractUsage;
14
+ private readStreamWithHeartbeat;
12
15
  complete: (options: LLMCompletionOptions) => Promise<{
13
16
  text: string;
14
17
  usage?: LLMUsage;
@@ -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;A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,QAAQ,GAAU,SAAS,oBAAoB,KAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,QAAQ,CAAA;KAAE,CAAC,CA2D3F;CACH;AAED,eAAO,MAAM,wBAAwB,GAAI,QAAQ,cAAc,KAAG,kBAEjE,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,8 +1,30 @@
1
1
  import { z } from "zod";
2
- export interface ChatMessage {
3
- role: "system" | "user" | "assistant" | "tool";
4
- content: string;
5
- }
2
+ export declare const ChatRoleSchema: z.ZodEnum<{
3
+ system: "system";
4
+ user: "user";
5
+ assistant: "assistant";
6
+ tool: "tool";
7
+ }>;
8
+ export type ChatRole = z.infer<typeof ChatRoleSchema>;
9
+ export declare const ChatMessageSchema: z.ZodObject<{
10
+ role: z.ZodEnum<{
11
+ system: "system";
12
+ user: "user";
13
+ assistant: "assistant";
14
+ tool: "tool";
15
+ }>;
16
+ content: z.ZodString;
17
+ }, z.core.$strict>;
18
+ export declare const ChatMessagesArraySchema: z.ZodArray<z.ZodObject<{
19
+ role: z.ZodEnum<{
20
+ system: "system";
21
+ user: "user";
22
+ assistant: "assistant";
23
+ tool: "tool";
24
+ }>;
25
+ content: z.ZodString;
26
+ }, z.core.$strict>>;
27
+ export type ChatMessage = z.infer<typeof ChatMessageSchema>;
6
28
  export interface LLMUsage {
7
29
  promptTokens?: number;
8
30
  completionTokens?: number;
@@ -46,6 +68,25 @@ export declare class ConfigurationError extends Error {
46
68
  export declare class BudgetExceededError extends Error {
47
69
  constructor(message: string);
48
70
  }
71
+ export declare class ProviderTTFTTimeoutError extends Error {
72
+ readonly ttftTimeoutMs: number;
73
+ constructor(message: string, ttftTimeoutMs: number);
74
+ }
75
+ export declare class ProviderIdleTimeoutError extends Error {
76
+ readonly idleTimeoutMs: number;
77
+ constructor(message: string, idleTimeoutMs: number);
78
+ }
79
+ export type BudgetReservationStatus = "RESERVED" | "SETTLED" | "RELEASED" | "UNCONFIRMED_TIMEOUT";
80
+ export interface BudgetReservation {
81
+ id: string;
82
+ tenantId?: string;
83
+ parentRunId?: string;
84
+ estimatedCostUsd: number;
85
+ settledCostUsd?: number;
86
+ status: BudgetReservationStatus;
87
+ createdAt: number;
88
+ updatedAt: number;
89
+ }
49
90
  export declare class SecretLeakBlockedError extends Error {
50
91
  readonly detections?: Array<{
51
92
  type: string;
@@ -66,6 +107,8 @@ export interface ProviderConfig {
66
107
  baseUrl?: string;
67
108
  client?: LLMProviderPort;
68
109
  pricing?: ModelPrice;
110
+ ttftTimeoutMs?: number;
111
+ idleTimeoutMs?: number;
69
112
  }
70
113
  export type TermCategory = "PROJECT" | "COMPANY" | "INFRA" | "CUSTOM";
71
114
  export interface CustomRedactionTermDef {
@@ -116,10 +159,10 @@ export interface FeaturesConfig {
116
159
  finance?: FinanceFeaturesConfig;
117
160
  }
118
161
  export interface BeforeRequestContext {
119
- messages: ChatMessage[];
162
+ messages: readonly ChatMessage[];
120
163
  model: string;
121
164
  temperature?: number;
122
- metadata?: Record<string, unknown>;
165
+ metadata?: Readonly<Record<string, unknown>>;
123
166
  }
124
167
  export interface BeforeRequestResult {
125
168
  messages?: ChatMessage[];
@@ -130,7 +173,7 @@ export interface BeforeRequestResult {
130
173
  };
131
174
  }
132
175
  export interface AfterResponseContext {
133
- messages: ChatMessage[];
176
+ messages: readonly ChatMessage[];
134
177
  responseText: string;
135
178
  modelUsed: string;
136
179
  tokens: {
@@ -141,7 +184,7 @@ export interface AfterResponseContext {
141
184
  costUSD: number;
142
185
  attempts: number;
143
186
  failoverOccurred: boolean;
144
- metadata?: Record<string, unknown>;
187
+ metadata?: Readonly<Record<string, unknown>>;
145
188
  }
146
189
  export interface AfterResponseResult {
147
190
  responseText?: string;
@@ -169,6 +212,8 @@ export interface ControlLayerConfig {
169
212
  customPricing?: Record<string, ModelPrice>;
170
213
  mockSimulation?: boolean;
171
214
  middlewares?: AvantGateMiddleware[];
215
+ middlewareTimeoutMs?: number;
216
+ reScanIngressAfterHooks?: boolean;
172
217
  }
173
218
  export interface ExecutionResult {
174
219
  text: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,0BAA0B,CAAC,CAAC;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC;IACrF,MAAM,CAAC,CAAC,OAAO,EAAE,oBA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BAA+B,CAAC,CAAC;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,eAAe,CAAC;IACnC,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B"}
@@ -0,0 +1,5 @@
1
+ export interface DeepFreezeOptions {
2
+ maxDepth?: number;
3
+ }
4
+ export declare const deepFreeze: <T>(target: T, options?: DeepFreezeOptions, currentDepth?: number, visited?: WeakSet<object>) => Readonly<T>;
5
+ //# sourceMappingURL=immutability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"immutability.d.ts","sourceRoot":"","sources":["../../src/utils/immutability.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,UAAU,GAAI,CAAC,EAC1B,QAAQ,CAAC,EACT,UAAU,iBAAiB,EAC3B,qBAAgB,EAChB,yBAA+B,KAC9B,QAAQ,CAAC,CAAC,CA4BZ,CAAC"}
@@ -80,6 +80,25 @@ var DtoValidationError = class extends Error {
80
80
  this.issues = issues;
81
81
  }
82
82
  };
83
+ var AmbiguousToolExecutionError = class extends Error {
84
+ toolCallId;
85
+ toolName;
86
+ impact;
87
+ originalError;
88
+ constructor(details, toolName, impact) {
89
+ const isStr = typeof details === "string";
90
+ const callId = isStr ? details : details.toolCallId;
91
+ const name = isStr ? toolName : details.toolName;
92
+ const imp = isStr ? impact ?? "MUTATIVE" : details.impact ?? "MUTATIVE";
93
+ const msg = isStr ? "" : details.message ? `: ${details.message}` : "";
94
+ super(`Ambiguous tool execution detected for [${name || "tool"}::${callId}] (${imp})${msg}. Re-execution blocked without reconciliation.`);
95
+ this.name = "AmbiguousToolExecutionError";
96
+ this.toolCallId = callId;
97
+ this.toolName = name;
98
+ this.impact = imp;
99
+ this.originalError = isStr ? void 0 : details.originalError;
100
+ }
101
+ };
83
102
 
84
103
  // src/sanitizer.ts
85
104
  var EMAIL_REGEX = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b/g;
@@ -186,16 +205,220 @@ function auditToolResult(data, options) {
186
205
  };
187
206
  }
188
207
 
208
+ // src/agent/tool-resilience.ts
209
+ var MAX_FALLBACK_CAP = 1e3;
210
+ var inMemoryFallbackStore = /* @__PURE__ */ new Map();
211
+ var setFallbackRecord = (toolCallId, record) => {
212
+ if (inMemoryFallbackStore.size >= MAX_FALLBACK_CAP) {
213
+ const firstKey = inMemoryFallbackStore.keys().next().value;
214
+ if (firstKey) inMemoryFallbackStore.delete(firstKey);
215
+ }
216
+ inMemoryFallbackStore.set(toolCallId, record);
217
+ };
218
+ var isDeterministicClientError = (error) => {
219
+ if (!error || typeof error !== "object") {
220
+ return false;
221
+ }
222
+ const err = error;
223
+ const status = Number(err.status ?? err.statusCode);
224
+ if (status >= 400 && status < 500 && status !== 408 && status !== 429) {
225
+ return true;
226
+ }
227
+ return err.name === "DtoValidationError" || err.name === "ToolAccessDeniedError";
228
+ };
229
+ var isAmbiguousTimeoutError = (error, isTimedOut) => {
230
+ if (isTimedOut) return true;
231
+ if (!error || typeof error !== "object") return false;
232
+ const err = error;
233
+ const name = String(err.name ?? "");
234
+ const status = Number(err.status ?? err.statusCode);
235
+ if (name === "AbortError" || name === "TimeoutError") return true;
236
+ if (status === 408 || status === 502 || status === 503 || status === 504) return true;
237
+ const msg = String(err.message ?? "").toLowerCase();
238
+ const code = String(err.code ?? "").toLowerCase();
239
+ return ["timeout", "etimedout", "econnreset", "socket hang up", "network error", "fetch failed"].some((key) => msg.includes(key) || code.includes(key));
240
+ };
241
+ var classifyErrorStatus = (error, isTimedOut) => {
242
+ if (isDeterministicClientError(error)) {
243
+ return "FAILED";
244
+ }
245
+ if (isAmbiguousTimeoutError(error, isTimedOut)) {
246
+ return "UNCONFIRMED_TIMEOUT";
247
+ }
248
+ return "FAILED";
249
+ };
250
+ var getToolExecutionRecord = async (storage, toolCallId) => {
251
+ if (!storage) {
252
+ return inMemoryFallbackStore.get(toolCallId) ?? null;
253
+ }
254
+ if (storage.getStateValue) {
255
+ const val = await storage.getStateValue(`tool_resilience:${toolCallId}`);
256
+ if (val) return val;
257
+ const directVal = await storage.getStateValue(toolCallId);
258
+ if (directVal) return directVal;
259
+ }
260
+ const step = await storage.getStep("_tool_resilience", toolCallId);
261
+ return step?.metadata?.resilienceRecord ?? null;
262
+ };
263
+ var saveToStateStorage = async (storage, toolCallId, record) => {
264
+ if (!storage.setStateValue) return;
265
+ await storage.setStateValue(`tool_resilience:${toolCallId}`, record);
266
+ await storage.setStateValue(toolCallId, record);
267
+ };
268
+ var saveResilienceRecord = async (storage, record) => {
269
+ if (!storage) {
270
+ setFallbackRecord(record.toolCallId, record);
271
+ return;
272
+ }
273
+ await saveToStateStorage(storage, record.toolCallId, record);
274
+ const status = record.status === "COMPLETED" ? "COMPLETED" : record.status === "FAILED" ? "FAILED" : "RUNNING";
275
+ await storage.saveStep({
276
+ workflowId: "_tool_resilience",
277
+ stepId: record.toolCallId,
278
+ status,
279
+ result: record.result,
280
+ error: record.error,
281
+ metadata: { resilienceRecord: record },
282
+ createdAt: new Date(record.startedAt).toISOString(),
283
+ updatedAt: new Date(record.updatedAt).toISOString()
284
+ });
285
+ };
286
+ var handleAmbiguousFailure = (options, originalError) => {
287
+ const workflowId = options.workflowId ?? "_tool_resilience";
288
+ if (options.suspendOnAmbiguous) {
289
+ throw new StepSuspendedError(options.toolCallId, workflowId, {
290
+ toolCallId: options.toolCallId,
291
+ impact: options.impact,
292
+ reason: "Ambiguous mutation requires human intervention",
293
+ originalError
294
+ });
295
+ }
296
+ throw new AmbiguousToolExecutionError({
297
+ toolCallId: options.toolCallId,
298
+ toolName: options.toolName,
299
+ impact: options.impact,
300
+ message: "Ambiguous execution state (UNCONFIRMED_TIMEOUT). Re-execution blocked without reconciliation.",
301
+ originalError
302
+ });
303
+ };
304
+ var saveReconciledRecord = async (options, result) => {
305
+ await saveResilienceRecord(options.storage, {
306
+ toolCallId: options.toolCallId,
307
+ status: "COMPLETED",
308
+ result,
309
+ impact: options.impact,
310
+ startedAt: Date.now(),
311
+ updatedAt: Date.now()
312
+ });
313
+ return { result, isCached: true, status: "COMPLETED" };
314
+ };
315
+ var tryReconciliation = async (options) => {
316
+ if (!options.onAmbiguousRetry) {
317
+ return handleAmbiguousFailure(options);
318
+ }
319
+ try {
320
+ const outcome = await options.onAmbiguousRetry({ toolCallId: options.toolCallId, args: options.args });
321
+ if (!outcome.reconciled) {
322
+ return handleAmbiguousFailure(options);
323
+ }
324
+ return await saveReconciledRecord(options, outcome.result);
325
+ } catch (err) {
326
+ if (err instanceof StepSuspendedError || err instanceof AmbiguousToolExecutionError) throw err;
327
+ return handleAmbiguousFailure(options, err);
328
+ }
329
+ };
330
+ var checkExistingState = async (options) => {
331
+ const existing = await getToolExecutionRecord(options.storage, options.toolCallId);
332
+ if (!existing) {
333
+ return null;
334
+ }
335
+ if (existing.status === "COMPLETED") {
336
+ return { result: existing.result, isCached: true, status: "COMPLETED" };
337
+ }
338
+ if (existing.status === "UNCONFIRMED_TIMEOUT") {
339
+ if (options.impact === "READ_ONLY") {
340
+ return null;
341
+ }
342
+ return await tryReconciliation(options);
343
+ }
344
+ return null;
345
+ };
346
+ var executeActionWithTimeout = async (action, timeoutMs, idempotencyKey) => {
347
+ const controller = new AbortController();
348
+ let isTimedOut = false;
349
+ const timer = setTimeout(() => {
350
+ isTimedOut = true;
351
+ controller.abort(new Error(`Tool execution timed out after ${timeoutMs}ms`));
352
+ }, timeoutMs);
353
+ try {
354
+ const result = await action(controller.signal, idempotencyKey);
355
+ return { result, isTimedOut: false };
356
+ } catch (error) {
357
+ return { error, isTimedOut };
358
+ } finally {
359
+ clearTimeout(timer);
360
+ }
361
+ };
362
+ var saveFailureRecord = async (options, startedAt, error, isTimedOut) => {
363
+ const status = classifyErrorStatus(error, isTimedOut);
364
+ const errorMsg = error instanceof Error ? error.message : String(error);
365
+ await saveResilienceRecord(options.storage, {
366
+ toolCallId: options.toolCallId,
367
+ status,
368
+ error: errorMsg,
369
+ impact: options.impact,
370
+ startedAt,
371
+ updatedAt: Date.now()
372
+ });
373
+ throw error;
374
+ };
375
+ var saveSuccessRecord = async (options, startedAt, result) => {
376
+ await saveResilienceRecord(options.storage, {
377
+ toolCallId: options.toolCallId,
378
+ status: "COMPLETED",
379
+ result,
380
+ impact: options.impact,
381
+ startedAt,
382
+ updatedAt: Date.now()
383
+ });
384
+ return { result, isCached: false, status: "COMPLETED" };
385
+ };
386
+ var claimExecutionIntent = async (options, startedAt) => {
387
+ await saveResilienceRecord(options.storage, {
388
+ toolCallId: options.toolCallId,
389
+ status: "CLAIMED",
390
+ impact: options.impact,
391
+ startedAt,
392
+ updatedAt: startedAt
393
+ });
394
+ };
395
+ var withToolResilience = async (options) => {
396
+ const existingResult = await checkExistingState(options);
397
+ if (existingResult) {
398
+ return existingResult;
399
+ }
400
+ const startedAt = Date.now();
401
+ const idempotencyKey = options.idempotencyKey || options.toolCallId;
402
+ await claimExecutionIntent(options, startedAt);
403
+ const timeoutMs = options.timeoutMs ?? 3e4;
404
+ const outcome = await executeActionWithTimeout(options.action, timeoutMs, idempotencyKey);
405
+ if (outcome.error) {
406
+ return await saveFailureRecord(options, startedAt, outcome.error, outcome.isTimedOut);
407
+ }
408
+ return await saveSuccessRecord(options, startedAt, outcome.result);
409
+ };
410
+
189
411
  // src/agent/isolated-tool.ts
190
412
  var verifyRoles = (configuredRoles, context, toolIdentifier) => {
191
413
  if (!configuredRoles || configuredRoles.length === 0) {
192
414
  return;
193
415
  }
194
- const userRoles = [
195
- ...context.roles ?? [],
196
- ...context.role ? [context.role] : []
197
- ];
198
- const hasAllowedRole = configuredRoles.some((role) => userRoles.includes(role));
416
+ if (!context.role && (!context.roles || context.roles.length === 0)) {
417
+ throw new ToolAccessDeniedError(toolIdentifier, "Access denied: insufficient role permissions");
418
+ }
419
+ const roleSet = new Set(context.roles ?? []);
420
+ if (context.role) roleSet.add(context.role);
421
+ const hasAllowedRole = configuredRoles.some((role) => roleSet.has(role));
199
422
  if (!hasAllowedRole) {
200
423
  throw new ToolAccessDeniedError(
201
424
  toolIdentifier,
@@ -312,6 +535,35 @@ var processLlmPayload = async (rawResult, args, context, config, toolIdentifier)
312
535
  config.throwOnPii === true
313
536
  );
314
537
  };
538
+ var buildResilientContext = (config, args, context) => {
539
+ const toolCallId = context.toolCallId || `call_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`;
540
+ const genKey = config.resilience?.idempotencyKeyGenerator?.(args, context);
541
+ const idempotencyKey = context.idempotencyKey || genKey || toolCallId;
542
+ const resilientContext = { ...context, toolCallId, idempotencyKey };
543
+ return { toolCallId, idempotencyKey, resilientContext };
544
+ };
545
+ var executeWithResilienceGuard = async (config, args, context, toolIdentifier) => {
546
+ if (!config.resilience) {
547
+ return await config.execute(args, context);
548
+ }
549
+ const { toolCallId, idempotencyKey, resilientContext } = buildResilientContext(config, args, context);
550
+ const outcome = await withToolResilience({
551
+ toolCallId,
552
+ toolName: toolIdentifier,
553
+ storage: context.storage,
554
+ impact: config.impact ?? "READ_ONLY",
555
+ idempotencyKey,
556
+ timeoutMs: config.resilience.timeoutMs,
557
+ suspendOnAmbiguous: config.resilience.suspendOnAmbiguous,
558
+ workflowId: context.workflowId,
559
+ args,
560
+ action: async (signal, idKey) => {
561
+ return await config.execute(args, { ...resilientContext, abortSignal: signal, idempotencyKey: idKey });
562
+ },
563
+ onAmbiguousRetry: config.resilience.onAmbiguousRetry
564
+ });
565
+ return outcome.result;
566
+ };
315
567
  var createIsolatedTool = (config) => {
316
568
  const toolId = config.id || config.name;
317
569
  const toolAlias = config.alias;
@@ -333,6 +585,7 @@ var createIsolatedTool = (config) => {
333
585
  _roles: config.roles ? Object.freeze([...config.roles]) : void 0,
334
586
  _impact: toolImpact,
335
587
  _requireApproval: requireApproval,
588
+ _resilience: config.resilience,
336
589
  _lastPiiFilteredCount: 0,
337
590
  _lastInvalidationTags: void 0,
338
591
  execute: async (args, context) => {
@@ -347,7 +600,12 @@ var createIsolatedTool = (config) => {
347
600
  updatedContext,
348
601
  toolIdentifier
349
602
  );
350
- const rawResult = await config.execute(args, updatedContext);
603
+ const rawResult = await executeWithResilienceGuard(
604
+ config,
605
+ args,
606
+ updatedContext,
607
+ toolIdentifier
608
+ );
351
609
  verifyTenantIsolation(config.assertTenant, rawResult, updatedContext, toolIdentifier);
352
610
  await verifyResourceOwnership(
353
611
  config.assertOwnership,
@@ -5,8 +5,8 @@ import {
5
5
  defineWorkflow,
6
6
  executeWorkflow,
7
7
  isWorkflowAbortSignal
8
- } from "../chunk-AH5XXSS4.mjs";
9
- import "../chunk-W27A25DK.mjs";
8
+ } from "../chunk-KEJ4VNSN.mjs";
9
+ import "../chunk-B22KKIQQ.mjs";
10
10
  import "../chunk-Y6FXYEAI.mjs";
11
11
  export {
12
12
  WorkflowAbortSignal,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "avantgate",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "Zero-infrastructure, in-process AI Application Firewall (AI-WAF), privacy control plane & headless UI canvas for TypeScript: real-time prompt guardrails, zero-egress PII redaction, deterministic tool envelopes, anti-IDOR defense, pre-flight token budgets, and multi-model failover.",
5
5
  "author": "Gatewall Team",
6
6
  "license": "MIT",
@@ -96,16 +96,17 @@
96
96
  ],
97
97
  "scripts": {
98
98
  "build": "tsup src/index.ts src/finance/index.ts src/agent/index.ts src/workflow/index.ts src/client/index.ts src/ui/index.ts src/ui/react/index.ts --format cjs --format esm --clean && tsc --emitDeclarationOnly --outDir dist",
99
- "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 && tsx tests/output-dlp-secret-guard.test.ts && tsx tests/middleware-lifecycle.test.ts && tsx tests/presets.test.ts && npm run test:agent && npm run test:workflow && npm run test:client && npm run test:ui",
99
+ "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 && tsx tests/output-dlp-secret-guard.test.ts && tsx tests/utils/immutability.test.ts && tsx tests/middleware-lifecycle.test.ts && tsx tests/presets.test.ts && tsx tests/finops/pessimistic-budget.test.ts && tsx tests/providers/stream-timeout.test.ts && npm run test:agent && npm run test:workflow && npm run test:client && npm run test:ui",
100
+ "test:finops": "tsx tests/finops/pessimistic-budget.test.ts && tsx tests/providers/stream-timeout.test.ts",
100
101
  "test:presets": "tsx tests/presets.test.ts",
101
- "test:middleware": "tsx tests/middleware-lifecycle.test.ts",
102
+ "test:middleware": "tsx tests/utils/immutability.test.ts && tsx tests/middleware-lifecycle.test.ts",
102
103
  "test:ui": "tsx tests/ui/envelope.test.ts && tsx tests/ui/reducer.test.ts && tsx tests/ui/sanitize.test.ts && tsx tests/ui/react-registry.test.tsx",
103
104
  "test:secrets": "tsx tests/output-dlp-secret-guard.test.ts",
104
105
  "test:pricing": "tsx tests/sqlite-pricing-adapter.test.ts",
105
106
  "test:finance": "tsx tests/financial-normalizer.test.ts",
106
107
  "test:prompts": "tsx tests/prompt-builder.test.ts",
107
108
  "test:pii": "tsx tests/pii-extended.test.ts",
108
- "test:agent": "tsx tests/agent/step-runner.test.ts && tsx tests/agent/isolated-tool.test.ts && tsx tests/agent/dto-pattern.test.ts && tsx tests/agent/tool-patterns.test.ts && tsx tests/agent/storage-adapters.test.ts && tsx tests/agent/tool-aliasing.test.ts && tsx tests/agent/tool-chaining.test.ts && tsx tests/agent/tool-storage.test.ts && tsx tests/agent/telemetry-exporter.test.ts && tsx tests/agent/platform-adapter.test.ts && tsx tests/agent/tool-governance.test.ts && tsx tests/agent/tool-impact.test.ts && tsx tests/agent/idempotency-guard.test.ts",
109
+ "test:agent": "tsx tests/agent/step-runner.test.ts && tsx tests/agent/isolated-tool.test.ts && tsx tests/agent/dto-pattern.test.ts && tsx tests/agent/tool-patterns.test.ts && tsx tests/agent/storage-adapters.test.ts && tsx tests/agent/tool-aliasing.test.ts && tsx tests/agent/tool-chaining.test.ts && tsx tests/agent/tool-storage.test.ts && tsx tests/agent/telemetry-exporter.test.ts && tsx tests/agent/platform-adapter.test.ts && tsx tests/agent/tool-governance.test.ts && tsx tests/agent/tool-impact.test.ts && tsx tests/agent/idempotency-guard.test.ts && tsx tests/agent/tool-resilience.test.ts",
109
110
  "test:workflow": "tsx tests/workflow/workflow-saga.test.ts && tsx tests/workflow/workflow-abort.test.ts",
110
111
  "test:client": "tsx tests/client/browser-exporter.test.ts && tsx tests/client/use-avantgate-task.test.ts && tsx tests/client/task-runner.test.ts",
111
112
  "test:demo": "tsx tests/agent/prospect-ai-demo-scenario.test.ts",