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.
- package/README.md +15 -1
- package/dist/agent/index.js +97 -24
- package/dist/agent/index.mjs +5 -2
- package/dist/agent/isolated-tool.d.ts +8 -3
- package/dist/agent/isolated-tool.d.ts.map +1 -1
- package/dist/agent/types.d.ts +16 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/{chunk-CO26LNFD.mjs → chunk-36ULFTM2.mjs} +8 -8
- package/dist/{chunk-4XWO3NZW.mjs → chunk-AH5XXSS4.mjs} +1 -1
- package/dist/{chunk-5VA3EKPJ.mjs → chunk-W27A25DK.mjs} +97 -25
- package/dist/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/client/index.mjs +2 -0
- package/dist/control-layer.d.ts +7 -7
- package/dist/control-layer.d.ts.map +1 -1
- package/dist/finance/index.js +6 -6
- package/dist/finance/index.mjs +2 -1
- package/dist/finance/normalizer.d.ts +2 -2
- package/dist/finance/normalizer.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +421 -130
- package/dist/index.mjs +318 -103
- package/dist/input-guard.d.ts +2 -2
- package/dist/input-guard.d.ts.map +1 -1
- package/dist/pricing.d.ts +17 -16
- package/dist/pricing.d.ts.map +1 -1
- package/dist/providers/http-client.d.ts +2 -2
- package/dist/providers/http-client.d.ts.map +1 -1
- package/dist/response-validator.d.ts +2 -2
- package/dist/response-validator.d.ts.map +1 -1
- package/dist/sanitizer.d.ts +1 -1
- package/dist/sanitizer.d.ts.map +1 -1
- package/dist/sqlite-pricing-adapter.d.ts +87 -0
- package/dist/sqlite-pricing-adapter.d.ts.map +1 -0
- package/dist/workflow/index.js +92 -24
- package/dist/workflow/index.mjs +3 -2
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ Contact our team at [contact@gatewall.fr](mailto:contact@gatewall.fr) for privat
|
|
|
90
90
|
- 🔒 **Zero-Egress Data Loss Prevention (DLP)**: Automated local redaction of emails, phone numbers, IBAN/BIC, and French/EU identifiers (NIR SSN, SPI tax ID) before network egress.
|
|
91
91
|
- ⚡ **Deterministic Workflow Engine (`avantgate/workflow`)**: In-process sequential state machine for multi-step agent orchestrations. Features automatic reverse compensation (Saga Pattern), non-blocking Human-in-the-Loop checkpoints, and safe-by-default AI tool conversion (`asTool()`).
|
|
92
92
|
- 🎭 **Dual-Channel Tool Isolation (`avantgate/agent`)**: Decouples sensitive database records (streamed out-of-band directly to client UIs) from minimal cognitive LLM context (`llmDto`), keeping confidential fields out of context windows.
|
|
93
|
-
- 🛑 **Anti-IDOR &
|
|
93
|
+
- 🛑 **Anti-IDOR & Multi-Tenant Defense**: Strict Row-Level Security, compile-time tenant tool enforcement (`createTenantTool`), post-fetch runtime assertions (`assertTenant`, `assertOwnership`), and native RBAC authorization at the agent tool boundary. See the [Anti-IDOR Architecture Guide](docs/anti-idor.md).
|
|
94
94
|
- 💰 **Denial-of-Wallet & Pre-Flight Budgeting**: Enforces strict token and cent-level USD budget limits, rejecting abusive requests before paying for upstream inference.
|
|
95
95
|
- 🔀 **Zero-Downtime Multi-Model Failover**: Seamless client-side failover to fallback providers (or local zero-cost Ollama) when upstream APIs return HTTP 429/500 errors.
|
|
96
96
|
- 🔧 **Self-Repairing Structured Outputs**: Strict Zod schema compliance with automated heuristic markdown/JSON repair if the model hallucinates formatting.
|
|
@@ -100,6 +100,20 @@ Contact our team at [contact@gatewall.fr](mailto:contact@gatewall.fr) for privat
|
|
|
100
100
|
|
|
101
101
|
---
|
|
102
102
|
|
|
103
|
+
## 📚 Documentation & Guides
|
|
104
|
+
|
|
105
|
+
| Category | In-Depth Guides |
|
|
106
|
+
|---|---|
|
|
107
|
+
| 🚀 **Quickstart** | [Getting Started](docs/getting-started.md) • [Integration Cookbook](docs/examples.md) |
|
|
108
|
+
| 🛡️ **Security & AI-WAF** | [Prompt Guardrails](docs/security/prompt-guardrails.md) • [PII Redaction](docs/security/pii-redaction.md) • [Anti-IDOR Defense](docs/security/anti-idor.md) • [End-to-End Security](docs/security/end-to-end-security.md) |
|
|
109
|
+
| 💰 **FinOps & Cost** | [Pre-Flight Budget Guards](docs/finops/budget-guards.md) • [Pricing Adapters & SQLite](docs/finops/pricing-adapters.md) |
|
|
110
|
+
| 🤖 **Agents & Tools** | [Isolated Tools & DTOs](docs/agents/isolated-tools.md) • [Agent Runtime Manual](docs/agents/agent-runtime.md) • [Inter-Tool Chaining](docs/agents/inter-tool-chaining.md) |
|
|
111
|
+
| 🔄 **Deterministic Sagas** | [Durable Workflows Engine](docs/workflows/durable-workflows.md) |
|
|
112
|
+
| 📊 **Observability** | [GateWall Cockpit Console](docs/observability/gatewall-cockpit.md) • [Telemetry & Browser SDK](docs/observability/telemetry-and-browser-sdk.md) |
|
|
113
|
+
| 💶 **Accounting** | [Financial Normalizer](docs/finance/normalizer.md) |
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
103
117
|
## 📊 Comparison: Direct LLM vs. Cloud AI Proxy vs. AvantGate
|
|
104
118
|
|
|
105
119
|
| Capability & Security Boundary | Direct LLM Calls | Cloud AI Proxy (Helicone / Portkey) | 🛡️ **AvantGate (`avantgate`)** |
|
package/dist/agent/index.js
CHANGED
|
@@ -48,6 +48,7 @@ __export(agent_exports, {
|
|
|
48
48
|
createCustomStorageAdapter: () => createCustomStorageAdapter,
|
|
49
49
|
createIsolatedTool: () => createIsolatedTool,
|
|
50
50
|
createStepRunner: () => createStepRunner,
|
|
51
|
+
createTenantTool: () => createTenantTool,
|
|
51
52
|
createToolInvoker: () => createToolInvoker,
|
|
52
53
|
createToolSharedState: () => createToolSharedState,
|
|
53
54
|
dto: () => dto
|
|
@@ -162,7 +163,7 @@ var SPI_LABELLED_REGEX = /(?:(?:num[ée]ro\s+fiscal|spi|n[°o]\s*fiscal|d[ée]cl
|
|
|
162
163
|
var SPI_FORMATTED_REGEX = /\b[0-3]\d(?:\s+\d{2}){5}\s+\d\b/g;
|
|
163
164
|
var IBAN_REGEX = /\b[A-Z]{2}\s*[0-9]{2}(?:[\s\r\n.-]*[A-Z0-9]){11,30}\b/g;
|
|
164
165
|
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;
|
|
165
|
-
|
|
166
|
+
var sanitizePII = (input) => {
|
|
166
167
|
let count = 0;
|
|
167
168
|
let result = input;
|
|
168
169
|
result = result.replace(EMAIL_REGEX, () => {
|
|
@@ -205,7 +206,7 @@ function sanitizePII(input) {
|
|
|
205
206
|
return match;
|
|
206
207
|
});
|
|
207
208
|
return { text: result, maskedCount: count };
|
|
208
|
-
}
|
|
209
|
+
};
|
|
209
210
|
|
|
210
211
|
// src/agent/guardrails.ts
|
|
211
212
|
function sanitizeString(value) {
|
|
@@ -260,7 +261,23 @@ function auditToolResult(data, options) {
|
|
|
260
261
|
}
|
|
261
262
|
|
|
262
263
|
// src/agent/isolated-tool.ts
|
|
263
|
-
|
|
264
|
+
var verifyRoles = (configuredRoles, context, toolIdentifier) => {
|
|
265
|
+
if (!configuredRoles || configuredRoles.length === 0) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const userRoles = [
|
|
269
|
+
...context.roles ?? [],
|
|
270
|
+
...context.role ? [context.role] : []
|
|
271
|
+
];
|
|
272
|
+
const hasAllowedRole = configuredRoles.some((role) => userRoles.includes(role));
|
|
273
|
+
if (!hasAllowedRole) {
|
|
274
|
+
throw new ToolAccessDeniedError(
|
|
275
|
+
toolIdentifier,
|
|
276
|
+
"Access denied: insufficient role permissions"
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
var verifyDataAccessGuard = async (guard, args, context, toolIdentifier) => {
|
|
264
281
|
if (!guard) {
|
|
265
282
|
return;
|
|
266
283
|
}
|
|
@@ -268,8 +285,55 @@ async function verifyDataAccessGuard(guard, args, context, toolIdentifier) {
|
|
|
268
285
|
if (!isAllowed) {
|
|
269
286
|
throw new ToolAccessDeniedError(toolIdentifier, "Access denied by data access guard");
|
|
270
287
|
}
|
|
271
|
-
}
|
|
272
|
-
|
|
288
|
+
};
|
|
289
|
+
var verifyTenantIsolation = (assertTenant, rawResult, context, toolIdentifier) => {
|
|
290
|
+
if (!assertTenant) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (!context.tenantId) {
|
|
294
|
+
throw new ToolAccessDeniedError(
|
|
295
|
+
toolIdentifier,
|
|
296
|
+
"Access denied: missing session tenantId in execution context for multi-tenant tool"
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
const recordTenantId = assertTenant(rawResult);
|
|
300
|
+
if (recordTenantId && recordTenantId !== context.tenantId) {
|
|
301
|
+
throw new ToolAccessDeniedError(
|
|
302
|
+
toolIdentifier,
|
|
303
|
+
`Cross-tenant IDOR access violation: record tenant '${recordTenantId}' does not match session tenant '${context.tenantId}'`
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
var verifyResourceOwnership = async (assertOwnership, rawResult, context, toolIdentifier) => {
|
|
308
|
+
if (!assertOwnership) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const isOwner = await assertOwnership(rawResult, context);
|
|
312
|
+
if (!isOwner) {
|
|
313
|
+
throw new ToolAccessDeniedError(
|
|
314
|
+
toolIdentifier,
|
|
315
|
+
"Ownership IDOR access violation: user does not own or have access to this resource"
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
var checkSuspiciousParameters = (parameters, toolName) => {
|
|
320
|
+
if (!parameters || typeof parameters !== "object") {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const zodShape = parameters.shape;
|
|
324
|
+
if (!zodShape || typeof zodShape !== "object") {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const suspiciousKeys = ["tenantId", "tenant_id", "ownerTenantId"];
|
|
328
|
+
for (const key of suspiciousKeys) {
|
|
329
|
+
if (key in zodShape) {
|
|
330
|
+
console.warn(
|
|
331
|
+
`[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.`
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
var resolveInvalidationTags = async (config, args, rawResult, context) => {
|
|
273
337
|
if (!config.invalidationTags) {
|
|
274
338
|
return void 0;
|
|
275
339
|
}
|
|
@@ -278,33 +342,29 @@ async function resolveInvalidationTags(config, args, rawResult, context) {
|
|
|
278
342
|
await context.onInvalidationTags(tags);
|
|
279
343
|
}
|
|
280
344
|
return tags;
|
|
281
|
-
}
|
|
282
|
-
async
|
|
345
|
+
};
|
|
346
|
+
var dispatchClientData = async (rawResult, callback) => {
|
|
283
347
|
if (!callback) {
|
|
284
348
|
return;
|
|
285
349
|
}
|
|
286
350
|
await callback(rawResult);
|
|
287
|
-
}
|
|
288
|
-
async
|
|
351
|
+
};
|
|
352
|
+
var produceLlmPayload = async (rawResult, args, context, transformer) => {
|
|
289
353
|
if (transformer) {
|
|
290
354
|
return await transformer(rawResult, args, context);
|
|
291
355
|
}
|
|
292
356
|
return rawResult;
|
|
293
|
-
}
|
|
294
|
-
|
|
357
|
+
};
|
|
358
|
+
var validateLlmDto = (payload, schema, toolIdentifier) => {
|
|
295
359
|
const parseResult = schema.safeParse(payload);
|
|
296
360
|
if (!parseResult.success) {
|
|
297
361
|
const issues = parseResult.error.issues ?? [];
|
|
298
362
|
const errorMessages = issues.map((issue) => `${issue.path.join(".") || "root"}: ${issue.message}`).join(", ");
|
|
299
|
-
throw new DtoValidationError(
|
|
300
|
-
toolIdentifier,
|
|
301
|
-
errorMessages,
|
|
302
|
-
issues
|
|
303
|
-
);
|
|
363
|
+
throw new DtoValidationError(toolIdentifier, errorMessages, issues);
|
|
304
364
|
}
|
|
305
365
|
return parseResult.data;
|
|
306
|
-
}
|
|
307
|
-
|
|
366
|
+
};
|
|
367
|
+
var protectLlmPayload = (payload, toolIdentifier, sanitizePii = true, throwOnPii = false) => {
|
|
308
368
|
if (!sanitizePii) {
|
|
309
369
|
return { sanitized: payload, count: 0 };
|
|
310
370
|
}
|
|
@@ -313,8 +373,8 @@ function protectLlmPayload(payload, toolIdentifier, sanitizePii = true, throwOnP
|
|
|
313
373
|
throwOnPii
|
|
314
374
|
});
|
|
315
375
|
return { sanitized: sanitizedData, count: maskedCount };
|
|
316
|
-
}
|
|
317
|
-
async
|
|
376
|
+
};
|
|
377
|
+
var processLlmPayload = async (rawResult, args, context, config, toolIdentifier) => {
|
|
318
378
|
let payload = await produceLlmPayload(rawResult, args, context, config.llmDto);
|
|
319
379
|
if (config.llmDtoSchema) {
|
|
320
380
|
payload = validateLlmDto(payload, config.llmDtoSchema, toolIdentifier);
|
|
@@ -325,14 +385,15 @@ async function processLlmPayload(rawResult, args, context, config, toolIdentifie
|
|
|
325
385
|
config.sanitizePii !== false,
|
|
326
386
|
config.throwOnPii === true
|
|
327
387
|
);
|
|
328
|
-
}
|
|
329
|
-
|
|
388
|
+
};
|
|
389
|
+
var createIsolatedTool = (config) => {
|
|
330
390
|
const toolId = config.id || config.name;
|
|
331
391
|
const toolAlias = config.alias;
|
|
332
392
|
const clientCallback = config.clientDto;
|
|
333
393
|
const toolIdentifier = toolAlias || config.name;
|
|
334
394
|
const toolImpact = config.impact ?? "READ_ONLY";
|
|
335
395
|
const requireApproval = config.requireApproval ?? toolImpact === "DESTRUCTIVE";
|
|
396
|
+
checkSuspiciousParameters(config.parameters, config.name);
|
|
336
397
|
const tool = {
|
|
337
398
|
description: config.description,
|
|
338
399
|
parameters: config.parameters,
|
|
@@ -348,11 +409,12 @@ function createIsolatedTool(config) {
|
|
|
348
409
|
_requireApproval: requireApproval,
|
|
349
410
|
_lastPiiFilteredCount: 0,
|
|
350
411
|
_lastInvalidationTags: void 0,
|
|
351
|
-
async
|
|
412
|
+
execute: async (args, context) => {
|
|
352
413
|
const updatedContext = {
|
|
353
414
|
...context,
|
|
354
415
|
callChain: context?.callChain ?? Object.freeze([toolId])
|
|
355
416
|
};
|
|
417
|
+
verifyRoles(config.roles, updatedContext, toolIdentifier);
|
|
356
418
|
await verifyDataAccessGuard(
|
|
357
419
|
config.dataAccessGuard,
|
|
358
420
|
args,
|
|
@@ -360,6 +422,13 @@ function createIsolatedTool(config) {
|
|
|
360
422
|
toolIdentifier
|
|
361
423
|
);
|
|
362
424
|
const rawResult = await config.execute(args, updatedContext);
|
|
425
|
+
verifyTenantIsolation(config.assertTenant, rawResult, updatedContext, toolIdentifier);
|
|
426
|
+
await verifyResourceOwnership(
|
|
427
|
+
config.assertOwnership,
|
|
428
|
+
rawResult,
|
|
429
|
+
updatedContext,
|
|
430
|
+
toolIdentifier
|
|
431
|
+
);
|
|
363
432
|
const tags = await resolveInvalidationTags(
|
|
364
433
|
config,
|
|
365
434
|
args,
|
|
@@ -382,7 +451,10 @@ function createIsolatedTool(config) {
|
|
|
382
451
|
}
|
|
383
452
|
};
|
|
384
453
|
return tool;
|
|
385
|
-
}
|
|
454
|
+
};
|
|
455
|
+
var createTenantTool = (config) => {
|
|
456
|
+
return createIsolatedTool(config);
|
|
457
|
+
};
|
|
386
458
|
|
|
387
459
|
// src/agent/dto.ts
|
|
388
460
|
function extractWhitelistedFields(data, keys) {
|
|
@@ -2030,6 +2102,7 @@ var HttpTelemetryExporter = class {
|
|
|
2030
2102
|
createCustomStorageAdapter,
|
|
2031
2103
|
createIsolatedTool,
|
|
2032
2104
|
createStepRunner,
|
|
2105
|
+
createTenantTool,
|
|
2033
2106
|
createToolInvoker,
|
|
2034
2107
|
createToolSharedState,
|
|
2035
2108
|
dto
|
package/dist/agent/index.mjs
CHANGED
|
@@ -9,8 +9,10 @@ import {
|
|
|
9
9
|
ToolNotFoundError,
|
|
10
10
|
ToolSubCallQuotaError,
|
|
11
11
|
auditToolResult,
|
|
12
|
-
createIsolatedTool
|
|
13
|
-
|
|
12
|
+
createIsolatedTool,
|
|
13
|
+
createTenantTool
|
|
14
|
+
} from "../chunk-W27A25DK.mjs";
|
|
15
|
+
import "../chunk-Y6FXYEAI.mjs";
|
|
14
16
|
|
|
15
17
|
// src/agent/dto.ts
|
|
16
18
|
function extractWhitelistedFields(data, keys) {
|
|
@@ -1657,6 +1659,7 @@ export {
|
|
|
1657
1659
|
createCustomStorageAdapter,
|
|
1658
1660
|
createIsolatedTool,
|
|
1659
1661
|
createStepRunner,
|
|
1662
|
+
createTenantTool,
|
|
1660
1663
|
createToolInvoker,
|
|
1661
1664
|
createToolSharedState,
|
|
1662
1665
|
dto
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import type { IsolatedToolConfig, VercelAiCoreTool } from "./types";
|
|
1
|
+
import type { IsolatedToolConfig, TenantToolConfig, VercelAiCoreTool } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Creates an isolated tool compatible with Vercel AI SDK (ai) tool contract.
|
|
4
4
|
* Features dual-channel separation (client data vs minimal LLM DTO),
|
|
5
|
-
* access governance (domain, resource, roles, dataAccessGuard, invalidationTags),
|
|
5
|
+
* access governance (domain, resource, roles, dataAccessGuard, assertTenant, assertOwnership, invalidationTags),
|
|
6
6
|
* stable ID, aliasing, caching, Zod DTO contract validation, and automatic in-flight PII redaction.
|
|
7
7
|
*/
|
|
8
|
-
export declare
|
|
8
|
+
export declare const createIsolatedTool: <TArgs = any, TResult = any, TLLMDto = unknown, TClientDto = TResult>(config: IsolatedToolConfig<TArgs, TResult, TLLMDto, TClientDto>) => VercelAiCoreTool<TArgs, TResult>;
|
|
9
|
+
/**
|
|
10
|
+
* High-assurance factory for multi-tenant and user-owned tools.
|
|
11
|
+
* Compile-time enforcement: strictly requires either assertTenant or assertOwnership.
|
|
12
|
+
*/
|
|
13
|
+
export declare const createTenantTool: <TArgs = any, TResult = any, TLLMDto = unknown, TClientDto = TResult>(config: TenantToolConfig<TArgs, TResult, TLLMDto, TClientDto>) => VercelAiCoreTool<TArgs, TResult>;
|
|
9
14
|
//# sourceMappingURL=isolated-tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isolated-tool.d.ts","sourceRoot":"","sources":["../../src/agent/isolated-tool.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,
|
|
1
|
+
{"version":3,"file":"isolated-tool.d.ts","sourceRoot":"","sources":["../../src/agent/isolated-tool.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EAEhB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAqMjB;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAC7B,KAAK,GAAG,GAAG,EACX,OAAO,GAAG,GAAG,EACb,OAAO,GAAG,OAAO,EACjB,UAAU,GAAG,OAAO,EAEpB,QAAQ,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,KAC9D,gBAAgB,CAAC,KAAK,EAAE,OAAO,CA6EjC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAC3B,KAAK,GAAG,GAAG,EACX,OAAO,GAAG,GAAG,EACb,OAAO,GAAG,OAAO,EACjB,UAAU,GAAG,OAAO,EAEpB,QAAQ,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,KAC5D,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAEjC,CAAC"}
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -107,6 +107,10 @@ export interface StepRunnerConfig {
|
|
|
107
107
|
* Context received by tool execution, supporting inter-tool chaining and shared state.
|
|
108
108
|
*/
|
|
109
109
|
export interface ToolExecutionContext {
|
|
110
|
+
tenantId?: string;
|
|
111
|
+
userId?: string;
|
|
112
|
+
role?: string;
|
|
113
|
+
roles?: string[];
|
|
110
114
|
toolCallId?: string;
|
|
111
115
|
messages?: unknown[];
|
|
112
116
|
abortSignal?: AbortSignal;
|
|
@@ -170,6 +174,8 @@ export interface IsolatedToolConfig<TArgs = any, TResult = any, TLLMDto = unknow
|
|
|
170
174
|
impact?: ToolImpact;
|
|
171
175
|
requireApproval?: boolean;
|
|
172
176
|
dataAccessGuard?: DataAccessGuard<TArgs>;
|
|
177
|
+
assertTenant?: (result: TResult) => string | undefined | null;
|
|
178
|
+
assertOwnership?: (result: TResult, context: ToolExecutionContext) => boolean | Promise<boolean>;
|
|
173
179
|
invalidationTags?: InvalidationTagsResolver<TArgs, TResult>;
|
|
174
180
|
parameters: z.ZodType<TArgs> | unknown;
|
|
175
181
|
cacheTTL?: number;
|
|
@@ -180,6 +186,16 @@ export interface IsolatedToolConfig<TArgs = any, TResult = any, TLLMDto = unknow
|
|
|
180
186
|
sanitizePii?: boolean;
|
|
181
187
|
throwOnPii?: boolean;
|
|
182
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Configuration for createTenantTool requiring either assertTenant or assertOwnership at compile-time.
|
|
191
|
+
*/
|
|
192
|
+
export type TenantToolConfig<TArgs = any, TResult = any, TLLMDto = unknown, TClientDto = TResult> = IsolatedToolConfig<TArgs, TResult, TLLMDto, TClientDto> & ({
|
|
193
|
+
assertTenant: (result: TResult) => string | undefined | null;
|
|
194
|
+
assertOwnership?: (result: TResult, context: ToolExecutionContext) => boolean | Promise<boolean>;
|
|
195
|
+
} | {
|
|
196
|
+
assertTenant?: (result: TResult) => string | undefined | null;
|
|
197
|
+
assertOwnership: (result: TResult, context: ToolExecutionContext) => boolean | Promise<boolean>;
|
|
198
|
+
});
|
|
183
199
|
/**
|
|
184
200
|
* Standard tool contract compatible with Vercel AI SDK (ai) tool definition.
|
|
185
201
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK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Ac,EAAE,EACvB,OAAO,EAAE,WAAW,GACnB,cAAc,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;CACjD"}
|
|
@@ -452,7 +452,7 @@ var AccountingFactory = class {
|
|
|
452
452
|
};
|
|
453
453
|
|
|
454
454
|
// src/response-validator.ts
|
|
455
|
-
|
|
455
|
+
var extractAndCleanJSON = (rawText) => {
|
|
456
456
|
let cleaned = rawText.trim();
|
|
457
457
|
cleaned = cleaned.replace(/<think>[\s\S]*?<\/think>/gi, "").trim();
|
|
458
458
|
const codeBlockMatch = cleaned.match(/```(?:json)?\s*([\s\S]*?)\s*```/i);
|
|
@@ -476,8 +476,8 @@ function extractAndCleanJSON(rawText) {
|
|
|
476
476
|
cleaned = cleaned.slice(startIndex, endIndex + 1);
|
|
477
477
|
}
|
|
478
478
|
return cleaned;
|
|
479
|
-
}
|
|
480
|
-
|
|
479
|
+
};
|
|
480
|
+
var validateWithZod = (rawText, schema, options) => {
|
|
481
481
|
let jsonString = extractAndCleanJSON(rawText);
|
|
482
482
|
if (options?.normalizer) {
|
|
483
483
|
jsonString = options.normalizer(jsonString);
|
|
@@ -492,20 +492,20 @@ function validateWithZod(rawText, schema, options) {
|
|
|
492
492
|
parsed = JSON.parse(sanitized);
|
|
493
493
|
}
|
|
494
494
|
return schema.parse(parsed);
|
|
495
|
-
}
|
|
495
|
+
};
|
|
496
496
|
|
|
497
497
|
// src/finance/normalizer.ts
|
|
498
|
-
|
|
498
|
+
var cleanFinancialJSON = (rawText, options) => {
|
|
499
499
|
if (!rawText) {
|
|
500
500
|
return "";
|
|
501
501
|
}
|
|
502
502
|
const jsonBlock = extractAndCleanJSON(rawText);
|
|
503
503
|
const strategy = options?.jurisdiction ? AccountingFactory.getStrategy(options.jurisdiction) : options?.autoDetect !== false ? AccountingFactory.detectStrategy(rawText) : AccountingFactory.getStrategy("FR");
|
|
504
504
|
return strategy.cleanJSON(jsonBlock);
|
|
505
|
-
}
|
|
506
|
-
|
|
505
|
+
};
|
|
506
|
+
var withFinancialNormalizer = (options) => {
|
|
507
507
|
return (rawText) => cleanFinancialJSON(rawText, options);
|
|
508
|
-
}
|
|
508
|
+
};
|
|
509
509
|
|
|
510
510
|
export {
|
|
511
511
|
FrenchPCGStrategy,
|
|
@@ -6,7 +6,7 @@ var SPI_LABELLED_REGEX = /(?:(?:num[ée]ro\s+fiscal|spi|n[°o]\s*fiscal|d[ée]cl
|
|
|
6
6
|
var SPI_FORMATTED_REGEX = /\b[0-3]\d(?:\s+\d{2}){5}\s+\d\b/g;
|
|
7
7
|
var IBAN_REGEX = /\b[A-Z]{2}\s*[0-9]{2}(?:[\s\r\n.-]*[A-Z0-9]){11,30}\b/g;
|
|
8
8
|
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;
|
|
9
|
-
|
|
9
|
+
var sanitizePII = (input) => {
|
|
10
10
|
let count = 0;
|
|
11
11
|
let result = input;
|
|
12
12
|
result = result.replace(EMAIL_REGEX, () => {
|
|
@@ -49,7 +49,7 @@ function sanitizePII(input) {
|
|
|
49
49
|
return match;
|
|
50
50
|
});
|
|
51
51
|
return { text: result, maskedCount: count };
|
|
52
|
-
}
|
|
52
|
+
};
|
|
53
53
|
|
|
54
54
|
// src/agent/errors.ts
|
|
55
55
|
var StepSuspendedError = class extends Error {
|
|
@@ -204,7 +204,23 @@ function auditToolResult(data, options) {
|
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
// src/agent/isolated-tool.ts
|
|
207
|
-
|
|
207
|
+
var verifyRoles = (configuredRoles, context, toolIdentifier) => {
|
|
208
|
+
if (!configuredRoles || configuredRoles.length === 0) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const userRoles = [
|
|
212
|
+
...context.roles ?? [],
|
|
213
|
+
...context.role ? [context.role] : []
|
|
214
|
+
];
|
|
215
|
+
const hasAllowedRole = configuredRoles.some((role) => userRoles.includes(role));
|
|
216
|
+
if (!hasAllowedRole) {
|
|
217
|
+
throw new ToolAccessDeniedError(
|
|
218
|
+
toolIdentifier,
|
|
219
|
+
"Access denied: insufficient role permissions"
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
var verifyDataAccessGuard = async (guard, args, context, toolIdentifier) => {
|
|
208
224
|
if (!guard) {
|
|
209
225
|
return;
|
|
210
226
|
}
|
|
@@ -212,8 +228,55 @@ async function verifyDataAccessGuard(guard, args, context, toolIdentifier) {
|
|
|
212
228
|
if (!isAllowed) {
|
|
213
229
|
throw new ToolAccessDeniedError(toolIdentifier, "Access denied by data access guard");
|
|
214
230
|
}
|
|
215
|
-
}
|
|
216
|
-
|
|
231
|
+
};
|
|
232
|
+
var verifyTenantIsolation = (assertTenant, rawResult, context, toolIdentifier) => {
|
|
233
|
+
if (!assertTenant) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (!context.tenantId) {
|
|
237
|
+
throw new ToolAccessDeniedError(
|
|
238
|
+
toolIdentifier,
|
|
239
|
+
"Access denied: missing session tenantId in execution context for multi-tenant tool"
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
const recordTenantId = assertTenant(rawResult);
|
|
243
|
+
if (recordTenantId && recordTenantId !== context.tenantId) {
|
|
244
|
+
throw new ToolAccessDeniedError(
|
|
245
|
+
toolIdentifier,
|
|
246
|
+
`Cross-tenant IDOR access violation: record tenant '${recordTenantId}' does not match session tenant '${context.tenantId}'`
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
var verifyResourceOwnership = async (assertOwnership, rawResult, context, toolIdentifier) => {
|
|
251
|
+
if (!assertOwnership) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const isOwner = await assertOwnership(rawResult, context);
|
|
255
|
+
if (!isOwner) {
|
|
256
|
+
throw new ToolAccessDeniedError(
|
|
257
|
+
toolIdentifier,
|
|
258
|
+
"Ownership IDOR access violation: user does not own or have access to this resource"
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
var checkSuspiciousParameters = (parameters, toolName) => {
|
|
263
|
+
if (!parameters || typeof parameters !== "object") {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const zodShape = parameters.shape;
|
|
267
|
+
if (!zodShape || typeof zodShape !== "object") {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const suspiciousKeys = ["tenantId", "tenant_id", "ownerTenantId"];
|
|
271
|
+
for (const key of suspiciousKeys) {
|
|
272
|
+
if (key in zodShape) {
|
|
273
|
+
console.warn(
|
|
274
|
+
`[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.`
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
var resolveInvalidationTags = async (config, args, rawResult, context) => {
|
|
217
280
|
if (!config.invalidationTags) {
|
|
218
281
|
return void 0;
|
|
219
282
|
}
|
|
@@ -222,33 +285,29 @@ async function resolveInvalidationTags(config, args, rawResult, context) {
|
|
|
222
285
|
await context.onInvalidationTags(tags);
|
|
223
286
|
}
|
|
224
287
|
return tags;
|
|
225
|
-
}
|
|
226
|
-
async
|
|
288
|
+
};
|
|
289
|
+
var dispatchClientData = async (rawResult, callback) => {
|
|
227
290
|
if (!callback) {
|
|
228
291
|
return;
|
|
229
292
|
}
|
|
230
293
|
await callback(rawResult);
|
|
231
|
-
}
|
|
232
|
-
async
|
|
294
|
+
};
|
|
295
|
+
var produceLlmPayload = async (rawResult, args, context, transformer) => {
|
|
233
296
|
if (transformer) {
|
|
234
297
|
return await transformer(rawResult, args, context);
|
|
235
298
|
}
|
|
236
299
|
return rawResult;
|
|
237
|
-
}
|
|
238
|
-
|
|
300
|
+
};
|
|
301
|
+
var validateLlmDto = (payload, schema, toolIdentifier) => {
|
|
239
302
|
const parseResult = schema.safeParse(payload);
|
|
240
303
|
if (!parseResult.success) {
|
|
241
304
|
const issues = parseResult.error.issues ?? [];
|
|
242
305
|
const errorMessages = issues.map((issue) => `${issue.path.join(".") || "root"}: ${issue.message}`).join(", ");
|
|
243
|
-
throw new DtoValidationError(
|
|
244
|
-
toolIdentifier,
|
|
245
|
-
errorMessages,
|
|
246
|
-
issues
|
|
247
|
-
);
|
|
306
|
+
throw new DtoValidationError(toolIdentifier, errorMessages, issues);
|
|
248
307
|
}
|
|
249
308
|
return parseResult.data;
|
|
250
|
-
}
|
|
251
|
-
|
|
309
|
+
};
|
|
310
|
+
var protectLlmPayload = (payload, toolIdentifier, sanitizePii = true, throwOnPii = false) => {
|
|
252
311
|
if (!sanitizePii) {
|
|
253
312
|
return { sanitized: payload, count: 0 };
|
|
254
313
|
}
|
|
@@ -257,8 +316,8 @@ function protectLlmPayload(payload, toolIdentifier, sanitizePii = true, throwOnP
|
|
|
257
316
|
throwOnPii
|
|
258
317
|
});
|
|
259
318
|
return { sanitized: sanitizedData, count: maskedCount };
|
|
260
|
-
}
|
|
261
|
-
async
|
|
319
|
+
};
|
|
320
|
+
var processLlmPayload = async (rawResult, args, context, config, toolIdentifier) => {
|
|
262
321
|
let payload = await produceLlmPayload(rawResult, args, context, config.llmDto);
|
|
263
322
|
if (config.llmDtoSchema) {
|
|
264
323
|
payload = validateLlmDto(payload, config.llmDtoSchema, toolIdentifier);
|
|
@@ -269,14 +328,15 @@ async function processLlmPayload(rawResult, args, context, config, toolIdentifie
|
|
|
269
328
|
config.sanitizePii !== false,
|
|
270
329
|
config.throwOnPii === true
|
|
271
330
|
);
|
|
272
|
-
}
|
|
273
|
-
|
|
331
|
+
};
|
|
332
|
+
var createIsolatedTool = (config) => {
|
|
274
333
|
const toolId = config.id || config.name;
|
|
275
334
|
const toolAlias = config.alias;
|
|
276
335
|
const clientCallback = config.clientDto;
|
|
277
336
|
const toolIdentifier = toolAlias || config.name;
|
|
278
337
|
const toolImpact = config.impact ?? "READ_ONLY";
|
|
279
338
|
const requireApproval = config.requireApproval ?? toolImpact === "DESTRUCTIVE";
|
|
339
|
+
checkSuspiciousParameters(config.parameters, config.name);
|
|
280
340
|
const tool = {
|
|
281
341
|
description: config.description,
|
|
282
342
|
parameters: config.parameters,
|
|
@@ -292,11 +352,12 @@ function createIsolatedTool(config) {
|
|
|
292
352
|
_requireApproval: requireApproval,
|
|
293
353
|
_lastPiiFilteredCount: 0,
|
|
294
354
|
_lastInvalidationTags: void 0,
|
|
295
|
-
async
|
|
355
|
+
execute: async (args, context) => {
|
|
296
356
|
const updatedContext = {
|
|
297
357
|
...context,
|
|
298
358
|
callChain: context?.callChain ?? Object.freeze([toolId])
|
|
299
359
|
};
|
|
360
|
+
verifyRoles(config.roles, updatedContext, toolIdentifier);
|
|
300
361
|
await verifyDataAccessGuard(
|
|
301
362
|
config.dataAccessGuard,
|
|
302
363
|
args,
|
|
@@ -304,6 +365,13 @@ function createIsolatedTool(config) {
|
|
|
304
365
|
toolIdentifier
|
|
305
366
|
);
|
|
306
367
|
const rawResult = await config.execute(args, updatedContext);
|
|
368
|
+
verifyTenantIsolation(config.assertTenant, rawResult, updatedContext, toolIdentifier);
|
|
369
|
+
await verifyResourceOwnership(
|
|
370
|
+
config.assertOwnership,
|
|
371
|
+
rawResult,
|
|
372
|
+
updatedContext,
|
|
373
|
+
toolIdentifier
|
|
374
|
+
);
|
|
307
375
|
const tags = await resolveInvalidationTags(
|
|
308
376
|
config,
|
|
309
377
|
args,
|
|
@@ -326,7 +394,10 @@ function createIsolatedTool(config) {
|
|
|
326
394
|
}
|
|
327
395
|
};
|
|
328
396
|
return tool;
|
|
329
|
-
}
|
|
397
|
+
};
|
|
398
|
+
var createTenantTool = (config) => {
|
|
399
|
+
return createIsolatedTool(config);
|
|
400
|
+
};
|
|
330
401
|
|
|
331
402
|
export {
|
|
332
403
|
sanitizePII,
|
|
@@ -340,5 +411,6 @@ export {
|
|
|
340
411
|
ToolNotFoundError,
|
|
341
412
|
DtoValidationError,
|
|
342
413
|
auditToolResult,
|
|
343
|
-
createIsolatedTool
|
|
414
|
+
createIsolatedTool,
|
|
415
|
+
createTenantTool
|
|
344
416
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
__require
|
|
10
|
+
};
|