avantgate 1.1.2 → 1.2.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/agent/adapters/custom-adapter.d.ts +50 -0
- package/dist/agent/adapters/custom-adapter.d.ts.map +1 -0
- package/dist/agent/adapters/index.d.ts +6 -0
- package/dist/agent/adapters/index.d.ts.map +1 -0
- package/dist/agent/adapters/memory-adapter.d.ts +34 -0
- package/dist/agent/adapters/memory-adapter.d.ts.map +1 -0
- package/dist/agent/adapters/platform-adapter.d.ts +32 -0
- package/dist/agent/adapters/platform-adapter.d.ts.map +1 -0
- package/dist/agent/adapters/prisma-adapter.d.ts +55 -0
- package/dist/agent/adapters/prisma-adapter.d.ts.map +1 -0
- package/dist/agent/adapters/sqlite-adapter.d.ts +31 -0
- package/dist/agent/adapters/sqlite-adapter.d.ts.map +1 -0
- package/dist/agent/dto.d.ts +32 -0
- package/dist/agent/dto.d.ts.map +1 -0
- package/dist/agent/errors.d.ts +50 -0
- package/dist/agent/errors.d.ts.map +1 -0
- package/dist/agent/factory.d.ts +21 -0
- package/dist/agent/factory.d.ts.map +1 -0
- package/dist/agent/guardrails.d.ts +14 -0
- package/dist/agent/guardrails.d.ts.map +1 -0
- package/dist/agent/index.d.ts +17 -742
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +203 -18
- package/dist/agent/index.mjs +202 -18
- package/dist/agent/isolated-tool.d.ts +9 -0
- package/dist/agent/isolated-tool.d.ts.map +1 -0
- package/dist/agent/registry.d.ts +71 -0
- package/dist/agent/registry.d.ts.map +1 -0
- package/dist/agent/step-runner.d.ts +12 -0
- package/dist/agent/step-runner.d.ts.map +1 -0
- package/dist/agent/strategy.d.ts +37 -0
- package/dist/agent/strategy.d.ts.map +1 -0
- package/dist/agent/telemetry/http-exporter.d.ts +24 -0
- package/dist/agent/telemetry/http-exporter.d.ts.map +1 -0
- package/dist/agent/telemetry/index.d.ts +3 -0
- package/dist/agent/telemetry/index.d.ts.map +1 -0
- package/dist/agent/telemetry/types.d.ts +92 -0
- package/dist/agent/telemetry/types.d.ts.map +1 -0
- package/dist/agent/tool-invoker.d.ts +17 -0
- package/dist/agent/tool-invoker.d.ts.map +1 -0
- package/dist/agent/tool-state.d.ts +7 -0
- package/dist/agent/tool-state.d.ts.map +1 -0
- package/dist/agent/types.d.ts +243 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/control-layer.d.ts +49 -0
- package/dist/control-layer.d.ts.map +1 -0
- package/dist/finance/factory.d.ts +11 -0
- package/dist/finance/factory.d.ts.map +1 -0
- package/dist/finance/index.d.ts +9 -76
- package/dist/finance/index.d.ts.map +1 -0
- package/dist/finance/normalizer.d.ts +19 -0
- package/dist/finance/normalizer.d.ts.map +1 -0
- package/dist/finance/strategies/french-pcg.strategy.d.ts +10 -0
- package/dist/finance/strategies/french-pcg.strategy.d.ts.map +1 -0
- package/dist/finance/strategies/international.strategy.d.ts +10 -0
- package/dist/finance/strategies/international.strategy.d.ts.map +1 -0
- package/dist/finance/strategies/swiss-co.strategy.d.ts +10 -0
- package/dist/finance/strategies/swiss-co.strategy.d.ts.map +1 -0
- package/dist/finance/strategies/uk-ifrs.strategy.d.ts +10 -0
- package/dist/finance/strategies/uk-ifrs.strategy.d.ts.map +1 -0
- package/dist/finance/strategies/us-gaap.strategy.d.ts +10 -0
- package/dist/finance/strategies/us-gaap.strategy.d.ts.map +1 -0
- package/dist/{strategy.interface-CB4_ZAuk.d.ts → finance/strategy.interface.d.ts} +5 -6
- package/dist/finance/strategy.interface.d.ts.map +1 -0
- package/dist/index.d.ts +9 -390
- package/dist/index.d.ts.map +1 -0
- package/dist/input-guard.d.ts +13 -0
- package/dist/input-guard.d.ts.map +1 -0
- package/dist/pricing.d.ts +49 -0
- package/dist/pricing.d.ts.map +1 -0
- package/dist/prompts/index.d.ts +5 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/prompt-builder.d.ts +31 -0
- package/dist/prompts/prompt-builder.d.ts.map +1 -0
- package/dist/prompts/prompt-registry.d.ts +13 -0
- package/dist/prompts/prompt-registry.d.ts.map +1 -0
- package/dist/prompts/prompt-template.d.ts +17 -0
- package/dist/prompts/prompt-template.d.ts.map +1 -0
- package/dist/prompts/types.d.ts +39 -0
- package/dist/prompts/types.d.ts.map +1 -0
- package/dist/providers/http-client.d.ts +18 -0
- package/dist/providers/http-client.d.ts.map +1 -0
- package/dist/response-validator.d.ts +18 -0
- package/dist/response-validator.d.ts.map +1 -0
- package/dist/sanitizer.d.ts +11 -0
- package/dist/sanitizer.d.ts.map +1 -0
- package/dist/types.d.ts +146 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +3 -3
- package/dist/agent/index.d.mts +0 -743
- package/dist/finance/index.d.mts +0 -76
- package/dist/index.d.mts +0 -390
- package/dist/strategy.interface-CB4_ZAuk.d.mts +0 -16
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
|
package/dist/agent/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/agent/index.ts
|
|
21
21
|
var agent_exports = {};
|
|
22
22
|
__export(agent_exports, {
|
|
23
|
+
AccessControlToolStrategy: () => AccessControlToolStrategy,
|
|
23
24
|
AgentToolFactory: () => AgentToolFactory,
|
|
24
25
|
CircularToolCallError: () => CircularToolCallError,
|
|
25
26
|
CompositeToolStrategy: () => CompositeToolStrategy,
|
|
@@ -89,12 +90,19 @@ var StepExecutionError = class extends Error {
|
|
|
89
90
|
var ToolAccessDeniedError = class extends Error {
|
|
90
91
|
toolName;
|
|
91
92
|
requiredRole;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
reason;
|
|
94
|
+
constructor(toolName, reasonOrRole) {
|
|
95
|
+
const isRole = Boolean(reasonOrRole && !reasonOrRole.includes(" "));
|
|
96
|
+
const roleMsg = isRole ? ` (requires role "${reasonOrRole}")` : "";
|
|
97
|
+
const reasonMsg = reasonOrRole && !isRole ? `: ${reasonOrRole}` : "";
|
|
98
|
+
super(`Access denied for tool "${toolName}"${roleMsg}${reasonMsg}.`);
|
|
95
99
|
this.name = "ToolAccessDeniedError";
|
|
96
100
|
this.toolName = toolName;
|
|
97
|
-
|
|
101
|
+
if (isRole) {
|
|
102
|
+
this.requiredRole = reasonOrRole;
|
|
103
|
+
} else {
|
|
104
|
+
this.reason = reasonOrRole;
|
|
105
|
+
}
|
|
98
106
|
}
|
|
99
107
|
};
|
|
100
108
|
var CircularToolCallError = class extends Error {
|
|
@@ -250,6 +258,25 @@ function auditToolResult(data, options) {
|
|
|
250
258
|
}
|
|
251
259
|
|
|
252
260
|
// src/agent/isolated-tool.ts
|
|
261
|
+
async function verifyDataAccessGuard(guard, args, context, toolIdentifier) {
|
|
262
|
+
if (!guard) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const isAllowed = await guard(args, context);
|
|
266
|
+
if (!isAllowed) {
|
|
267
|
+
throw new ToolAccessDeniedError(toolIdentifier, "Access denied by data access guard");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async function resolveInvalidationTags(config, args, rawResult, context) {
|
|
271
|
+
if (!config.invalidationTags) {
|
|
272
|
+
return void 0;
|
|
273
|
+
}
|
|
274
|
+
const tags = typeof config.invalidationTags === "function" ? await config.invalidationTags(args, rawResult) : config.invalidationTags;
|
|
275
|
+
if (tags && tags.length > 0 && context?.onInvalidationTags) {
|
|
276
|
+
await context.onInvalidationTags(tags);
|
|
277
|
+
}
|
|
278
|
+
return tags;
|
|
279
|
+
}
|
|
253
280
|
async function dispatchClientData(rawResult, callback) {
|
|
254
281
|
if (!callback) {
|
|
255
282
|
return;
|
|
@@ -301,6 +328,7 @@ function createIsolatedTool(config) {
|
|
|
301
328
|
const toolId = config.id || config.name;
|
|
302
329
|
const toolAlias = config.alias;
|
|
303
330
|
const clientCallback = config.clientDto;
|
|
331
|
+
const toolIdentifier = toolAlias || config.name;
|
|
304
332
|
const tool = {
|
|
305
333
|
description: config.description,
|
|
306
334
|
parameters: config.parameters,
|
|
@@ -309,20 +337,41 @@ function createIsolatedTool(config) {
|
|
|
309
337
|
_toolAlias: toolAlias,
|
|
310
338
|
_isIsolated: true,
|
|
311
339
|
_cacheTTL: config.cacheTTL,
|
|
340
|
+
_domain: config.domain,
|
|
341
|
+
_resource: config.resource,
|
|
342
|
+
_roles: config.roles ? Object.freeze([...config.roles]) : void 0,
|
|
343
|
+
_permissions: config.permissions ? Object.freeze([...config.permissions]) : void 0,
|
|
344
|
+
_requireApproval: config.requireApproval ?? false,
|
|
312
345
|
_lastPiiFilteredCount: 0,
|
|
346
|
+
_lastInvalidationTags: void 0,
|
|
313
347
|
async execute(args, context) {
|
|
314
348
|
const updatedContext = {
|
|
315
349
|
...context,
|
|
316
350
|
callChain: context?.callChain ?? Object.freeze([toolId])
|
|
317
351
|
};
|
|
352
|
+
await verifyDataAccessGuard(
|
|
353
|
+
config.dataAccessGuard,
|
|
354
|
+
args,
|
|
355
|
+
updatedContext,
|
|
356
|
+
toolIdentifier
|
|
357
|
+
);
|
|
318
358
|
const rawResult = await config.execute(args, updatedContext);
|
|
359
|
+
const tags = await resolveInvalidationTags(
|
|
360
|
+
config,
|
|
361
|
+
args,
|
|
362
|
+
rawResult,
|
|
363
|
+
updatedContext
|
|
364
|
+
);
|
|
365
|
+
if (tags) {
|
|
366
|
+
tool._lastInvalidationTags = tags;
|
|
367
|
+
}
|
|
319
368
|
await dispatchClientData(rawResult, clientCallback);
|
|
320
369
|
const protection = await processLlmPayload(
|
|
321
370
|
rawResult,
|
|
322
371
|
args,
|
|
323
372
|
updatedContext,
|
|
324
373
|
config,
|
|
325
|
-
|
|
374
|
+
toolIdentifier
|
|
326
375
|
);
|
|
327
376
|
tool._lastPiiFilteredCount = protection.count;
|
|
328
377
|
return protection.sanitized;
|
|
@@ -405,6 +454,65 @@ var AgentToolFactory = class _AgentToolFactory {
|
|
|
405
454
|
};
|
|
406
455
|
|
|
407
456
|
// src/agent/registry.ts
|
|
457
|
+
function isCoreTool(item) {
|
|
458
|
+
return typeof item.execute === "function" && "_toolId" in item;
|
|
459
|
+
}
|
|
460
|
+
function normalizeToolDefinition(toolDef) {
|
|
461
|
+
if (isCoreTool(toolDef)) {
|
|
462
|
+
return {
|
|
463
|
+
id: toolDef._toolId || toolDef._toolName,
|
|
464
|
+
name: toolDef._toolName,
|
|
465
|
+
alias: toolDef._toolAlias,
|
|
466
|
+
description: toolDef.description,
|
|
467
|
+
domain: toolDef._domain,
|
|
468
|
+
resource: toolDef._resource,
|
|
469
|
+
roles: toolDef._roles ? Array.from(toolDef._roles) : void 0,
|
|
470
|
+
permissions: toolDef._permissions ? Array.from(toolDef._permissions) : void 0,
|
|
471
|
+
requireApproval: toolDef._requireApproval,
|
|
472
|
+
tool: toolDef
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
const id = toolDef.id || toolDef.name || toolDef.tool?._toolId;
|
|
476
|
+
const publicName = toolDef.alias || toolDef.name || toolDef.tool?._toolAlias || toolDef.tool?._toolName;
|
|
477
|
+
const roles = toolDef.roles ?? (toolDef.tool?._roles ? Array.from(toolDef.tool._roles) : toolDef.requiredRoles);
|
|
478
|
+
const permissions = toolDef.permissions ?? (toolDef.tool?._permissions ? Array.from(toolDef.tool._permissions) : void 0);
|
|
479
|
+
return {
|
|
480
|
+
...toolDef,
|
|
481
|
+
id,
|
|
482
|
+
name: toolDef.name || toolDef.tool?._toolName || id,
|
|
483
|
+
alias: publicName,
|
|
484
|
+
domain: toolDef.domain ?? toolDef.tool?._domain,
|
|
485
|
+
resource: toolDef.resource ?? toolDef.tool?._resource,
|
|
486
|
+
roles,
|
|
487
|
+
permissions,
|
|
488
|
+
requireApproval: toolDef.requireApproval ?? toolDef.tool?._requireApproval
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
function matchesRoleFilter(tool, role) {
|
|
492
|
+
if (!role) {
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
495
|
+
const roles = tool.roles ?? tool.requiredRoles;
|
|
496
|
+
if (!roles || roles.length === 0) {
|
|
497
|
+
return true;
|
|
498
|
+
}
|
|
499
|
+
return roles.includes(role);
|
|
500
|
+
}
|
|
501
|
+
function toDescriptor(tool) {
|
|
502
|
+
return {
|
|
503
|
+
id: tool.id,
|
|
504
|
+
name: tool.name,
|
|
505
|
+
alias: tool.alias,
|
|
506
|
+
description: tool.description,
|
|
507
|
+
domain: tool.domain,
|
|
508
|
+
resource: tool.resource,
|
|
509
|
+
roles: tool.roles ?? tool.requiredRoles,
|
|
510
|
+
permissions: tool.permissions,
|
|
511
|
+
requireApproval: tool.requireApproval,
|
|
512
|
+
cacheTTL: tool.tool._cacheTTL,
|
|
513
|
+
tags: tool.tags
|
|
514
|
+
};
|
|
515
|
+
}
|
|
408
516
|
var ToolRegistry = class _ToolRegistry {
|
|
409
517
|
toolsById = /* @__PURE__ */ new Map();
|
|
410
518
|
toolsByPublicName = /* @__PURE__ */ new Map();
|
|
@@ -412,16 +520,21 @@ var ToolRegistry = class _ToolRegistry {
|
|
|
412
520
|
* Registers a new tool in the registry.
|
|
413
521
|
*/
|
|
414
522
|
register(toolDef) {
|
|
415
|
-
const
|
|
416
|
-
const publicName =
|
|
417
|
-
|
|
418
|
-
...toolDef,
|
|
419
|
-
id
|
|
420
|
-
};
|
|
421
|
-
this.toolsById.set(id, normalizedDef);
|
|
523
|
+
const normalizedDef = normalizeToolDefinition(toolDef);
|
|
524
|
+
const publicName = normalizedDef.alias || normalizedDef.name;
|
|
525
|
+
this.toolsById.set(normalizedDef.id, normalizedDef);
|
|
422
526
|
this.toolsByPublicName.set(publicName, normalizedDef);
|
|
423
527
|
return this;
|
|
424
528
|
}
|
|
529
|
+
/**
|
|
530
|
+
* Registers multiple tools in batch.
|
|
531
|
+
*/
|
|
532
|
+
registerMany(tools) {
|
|
533
|
+
for (const tool of tools) {
|
|
534
|
+
this.register(tool);
|
|
535
|
+
}
|
|
536
|
+
return this;
|
|
537
|
+
}
|
|
425
538
|
/**
|
|
426
539
|
* Retrieves a tool by its ID or public name/alias.
|
|
427
540
|
*/
|
|
@@ -452,6 +565,12 @@ var ToolRegistry = class _ToolRegistry {
|
|
|
452
565
|
getAll() {
|
|
453
566
|
return Array.from(this.toolsById.values());
|
|
454
567
|
}
|
|
568
|
+
/**
|
|
569
|
+
* Filters tools belonging to a specific business domain.
|
|
570
|
+
*/
|
|
571
|
+
getByDomain(domain) {
|
|
572
|
+
return this.getAll().filter((item) => item.domain === domain);
|
|
573
|
+
}
|
|
455
574
|
/**
|
|
456
575
|
* Filters tools matching a specific workflow phase.
|
|
457
576
|
*/
|
|
@@ -469,12 +588,26 @@ var ToolRegistry = class _ToolRegistry {
|
|
|
469
588
|
filterByRoles(userRoles) {
|
|
470
589
|
const roleSet = new Set(userRoles);
|
|
471
590
|
return this.getAll().filter((item) => {
|
|
472
|
-
|
|
591
|
+
const roles = item.roles ?? item.requiredRoles;
|
|
592
|
+
if (!roles || roles.length === 0) {
|
|
473
593
|
return true;
|
|
474
594
|
}
|
|
475
|
-
return
|
|
595
|
+
return roles.some((role) => roleSet.has(role));
|
|
476
596
|
});
|
|
477
597
|
}
|
|
598
|
+
/**
|
|
599
|
+
* Exports headless technical descriptors without UI rendering coupling.
|
|
600
|
+
*/
|
|
601
|
+
getDescriptors(filter) {
|
|
602
|
+
let list = this.getAll();
|
|
603
|
+
if (filter?.domain) {
|
|
604
|
+
list = list.filter((item) => item.domain === filter.domain);
|
|
605
|
+
}
|
|
606
|
+
if (filter?.role) {
|
|
607
|
+
list = list.filter((item) => matchesRoleFilter(item, filter.role));
|
|
608
|
+
}
|
|
609
|
+
return list.map(toDescriptor);
|
|
610
|
+
}
|
|
478
611
|
/**
|
|
479
612
|
* Converts instance registered tools to the record map format required by Vercel AI SDK.
|
|
480
613
|
*/
|
|
@@ -486,8 +619,12 @@ var ToolRegistry = class _ToolRegistry {
|
|
|
486
619
|
* If anonymize is true, uses alias (if defined) as dictionary key instead of technical name.
|
|
487
620
|
*/
|
|
488
621
|
static toRecord(tools, options = {}) {
|
|
622
|
+
let filtered = tools;
|
|
623
|
+
if (options.domain) {
|
|
624
|
+
filtered = filtered.filter((item) => item.domain === options.domain);
|
|
625
|
+
}
|
|
489
626
|
const record = {};
|
|
490
|
-
for (const item of
|
|
627
|
+
for (const item of filtered) {
|
|
491
628
|
const key = options.anonymize && item.alias ? item.alias : item.name;
|
|
492
629
|
record[key] = item.tool;
|
|
493
630
|
}
|
|
@@ -513,17 +650,64 @@ var PhaseBasedToolStrategy = class {
|
|
|
513
650
|
var RoleBasedToolStrategy = class {
|
|
514
651
|
selectTools(tools, context) {
|
|
515
652
|
if (!context.role) {
|
|
516
|
-
return tools.filter((
|
|
653
|
+
return tools.filter((toolCandidate) => {
|
|
654
|
+
const roles = toolCandidate.roles ?? toolCandidate.requiredRoles;
|
|
655
|
+
return !roles || roles.length === 0;
|
|
656
|
+
});
|
|
517
657
|
}
|
|
518
658
|
const currentRole = context.role;
|
|
519
659
|
return tools.filter((item) => {
|
|
520
|
-
|
|
660
|
+
const roles = item.roles ?? item.requiredRoles;
|
|
661
|
+
if (!roles || roles.length === 0) {
|
|
521
662
|
return true;
|
|
522
663
|
}
|
|
523
|
-
return
|
|
664
|
+
return roles.includes(currentRole);
|
|
524
665
|
});
|
|
525
666
|
}
|
|
526
667
|
};
|
|
668
|
+
function matchesDomain(tool, allowedDomains) {
|
|
669
|
+
if (!allowedDomains) {
|
|
670
|
+
return true;
|
|
671
|
+
}
|
|
672
|
+
return Boolean(tool.domain && allowedDomains.has(tool.domain));
|
|
673
|
+
}
|
|
674
|
+
function matchesRoles(tool, context) {
|
|
675
|
+
const toolRoles = tool.roles ?? tool.requiredRoles;
|
|
676
|
+
if (!toolRoles || toolRoles.length === 0) {
|
|
677
|
+
return true;
|
|
678
|
+
}
|
|
679
|
+
const userRoles = [];
|
|
680
|
+
if (context.role) {
|
|
681
|
+
userRoles.push(context.role);
|
|
682
|
+
}
|
|
683
|
+
if (context.roles) {
|
|
684
|
+
userRoles.push(...context.roles);
|
|
685
|
+
}
|
|
686
|
+
if (userRoles.length === 0) {
|
|
687
|
+
return false;
|
|
688
|
+
}
|
|
689
|
+
return toolRoles.some((roleName) => userRoles.includes(roleName));
|
|
690
|
+
}
|
|
691
|
+
function matchesPermissions(tool, context) {
|
|
692
|
+
if (!tool.permissions || tool.permissions.length === 0) {
|
|
693
|
+
return true;
|
|
694
|
+
}
|
|
695
|
+
const userPermissions = context.permissions ?? [];
|
|
696
|
+
return tool.permissions.every((permissionName) => userPermissions.includes(permissionName));
|
|
697
|
+
}
|
|
698
|
+
var AccessControlToolStrategy = class {
|
|
699
|
+
allowedDomains;
|
|
700
|
+
constructor(options) {
|
|
701
|
+
if (options?.allowedDomains) {
|
|
702
|
+
this.allowedDomains = new Set(options.allowedDomains);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
selectTools(tools, context) {
|
|
706
|
+
return tools.filter(
|
|
707
|
+
(tool) => matchesDomain(tool, this.allowedDomains) && matchesRoles(tool, context) && matchesPermissions(tool, context)
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
};
|
|
527
711
|
var CompositeToolStrategy = class {
|
|
528
712
|
strategies;
|
|
529
713
|
constructor(strategies) {
|
|
@@ -1772,6 +1956,7 @@ var HttpTelemetryExporter = class {
|
|
|
1772
1956
|
};
|
|
1773
1957
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1774
1958
|
0 && (module.exports = {
|
|
1959
|
+
AccessControlToolStrategy,
|
|
1775
1960
|
AgentToolFactory,
|
|
1776
1961
|
CircularToolCallError,
|
|
1777
1962
|
CompositeToolStrategy,
|
package/dist/agent/index.mjs
CHANGED
|
@@ -40,12 +40,19 @@ var StepExecutionError = class extends Error {
|
|
|
40
40
|
var ToolAccessDeniedError = class extends Error {
|
|
41
41
|
toolName;
|
|
42
42
|
requiredRole;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
reason;
|
|
44
|
+
constructor(toolName, reasonOrRole) {
|
|
45
|
+
const isRole = Boolean(reasonOrRole && !reasonOrRole.includes(" "));
|
|
46
|
+
const roleMsg = isRole ? ` (requires role "${reasonOrRole}")` : "";
|
|
47
|
+
const reasonMsg = reasonOrRole && !isRole ? `: ${reasonOrRole}` : "";
|
|
48
|
+
super(`Access denied for tool "${toolName}"${roleMsg}${reasonMsg}.`);
|
|
46
49
|
this.name = "ToolAccessDeniedError";
|
|
47
50
|
this.toolName = toolName;
|
|
48
|
-
|
|
51
|
+
if (isRole) {
|
|
52
|
+
this.requiredRole = reasonOrRole;
|
|
53
|
+
} else {
|
|
54
|
+
this.reason = reasonOrRole;
|
|
55
|
+
}
|
|
49
56
|
}
|
|
50
57
|
};
|
|
51
58
|
var CircularToolCallError = class extends Error {
|
|
@@ -148,6 +155,25 @@ function auditToolResult(data, options) {
|
|
|
148
155
|
}
|
|
149
156
|
|
|
150
157
|
// src/agent/isolated-tool.ts
|
|
158
|
+
async function verifyDataAccessGuard(guard, args, context, toolIdentifier) {
|
|
159
|
+
if (!guard) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const isAllowed = await guard(args, context);
|
|
163
|
+
if (!isAllowed) {
|
|
164
|
+
throw new ToolAccessDeniedError(toolIdentifier, "Access denied by data access guard");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async function resolveInvalidationTags(config, args, rawResult, context) {
|
|
168
|
+
if (!config.invalidationTags) {
|
|
169
|
+
return void 0;
|
|
170
|
+
}
|
|
171
|
+
const tags = typeof config.invalidationTags === "function" ? await config.invalidationTags(args, rawResult) : config.invalidationTags;
|
|
172
|
+
if (tags && tags.length > 0 && context?.onInvalidationTags) {
|
|
173
|
+
await context.onInvalidationTags(tags);
|
|
174
|
+
}
|
|
175
|
+
return tags;
|
|
176
|
+
}
|
|
151
177
|
async function dispatchClientData(rawResult, callback) {
|
|
152
178
|
if (!callback) {
|
|
153
179
|
return;
|
|
@@ -199,6 +225,7 @@ function createIsolatedTool(config) {
|
|
|
199
225
|
const toolId = config.id || config.name;
|
|
200
226
|
const toolAlias = config.alias;
|
|
201
227
|
const clientCallback = config.clientDto;
|
|
228
|
+
const toolIdentifier = toolAlias || config.name;
|
|
202
229
|
const tool = {
|
|
203
230
|
description: config.description,
|
|
204
231
|
parameters: config.parameters,
|
|
@@ -207,20 +234,41 @@ function createIsolatedTool(config) {
|
|
|
207
234
|
_toolAlias: toolAlias,
|
|
208
235
|
_isIsolated: true,
|
|
209
236
|
_cacheTTL: config.cacheTTL,
|
|
237
|
+
_domain: config.domain,
|
|
238
|
+
_resource: config.resource,
|
|
239
|
+
_roles: config.roles ? Object.freeze([...config.roles]) : void 0,
|
|
240
|
+
_permissions: config.permissions ? Object.freeze([...config.permissions]) : void 0,
|
|
241
|
+
_requireApproval: config.requireApproval ?? false,
|
|
210
242
|
_lastPiiFilteredCount: 0,
|
|
243
|
+
_lastInvalidationTags: void 0,
|
|
211
244
|
async execute(args, context) {
|
|
212
245
|
const updatedContext = {
|
|
213
246
|
...context,
|
|
214
247
|
callChain: context?.callChain ?? Object.freeze([toolId])
|
|
215
248
|
};
|
|
249
|
+
await verifyDataAccessGuard(
|
|
250
|
+
config.dataAccessGuard,
|
|
251
|
+
args,
|
|
252
|
+
updatedContext,
|
|
253
|
+
toolIdentifier
|
|
254
|
+
);
|
|
216
255
|
const rawResult = await config.execute(args, updatedContext);
|
|
256
|
+
const tags = await resolveInvalidationTags(
|
|
257
|
+
config,
|
|
258
|
+
args,
|
|
259
|
+
rawResult,
|
|
260
|
+
updatedContext
|
|
261
|
+
);
|
|
262
|
+
if (tags) {
|
|
263
|
+
tool._lastInvalidationTags = tags;
|
|
264
|
+
}
|
|
217
265
|
await dispatchClientData(rawResult, clientCallback);
|
|
218
266
|
const protection = await processLlmPayload(
|
|
219
267
|
rawResult,
|
|
220
268
|
args,
|
|
221
269
|
updatedContext,
|
|
222
270
|
config,
|
|
223
|
-
|
|
271
|
+
toolIdentifier
|
|
224
272
|
);
|
|
225
273
|
tool._lastPiiFilteredCount = protection.count;
|
|
226
274
|
return protection.sanitized;
|
|
@@ -303,6 +351,65 @@ var AgentToolFactory = class _AgentToolFactory {
|
|
|
303
351
|
};
|
|
304
352
|
|
|
305
353
|
// src/agent/registry.ts
|
|
354
|
+
function isCoreTool(item) {
|
|
355
|
+
return typeof item.execute === "function" && "_toolId" in item;
|
|
356
|
+
}
|
|
357
|
+
function normalizeToolDefinition(toolDef) {
|
|
358
|
+
if (isCoreTool(toolDef)) {
|
|
359
|
+
return {
|
|
360
|
+
id: toolDef._toolId || toolDef._toolName,
|
|
361
|
+
name: toolDef._toolName,
|
|
362
|
+
alias: toolDef._toolAlias,
|
|
363
|
+
description: toolDef.description,
|
|
364
|
+
domain: toolDef._domain,
|
|
365
|
+
resource: toolDef._resource,
|
|
366
|
+
roles: toolDef._roles ? Array.from(toolDef._roles) : void 0,
|
|
367
|
+
permissions: toolDef._permissions ? Array.from(toolDef._permissions) : void 0,
|
|
368
|
+
requireApproval: toolDef._requireApproval,
|
|
369
|
+
tool: toolDef
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
const id = toolDef.id || toolDef.name || toolDef.tool?._toolId;
|
|
373
|
+
const publicName = toolDef.alias || toolDef.name || toolDef.tool?._toolAlias || toolDef.tool?._toolName;
|
|
374
|
+
const roles = toolDef.roles ?? (toolDef.tool?._roles ? Array.from(toolDef.tool._roles) : toolDef.requiredRoles);
|
|
375
|
+
const permissions = toolDef.permissions ?? (toolDef.tool?._permissions ? Array.from(toolDef.tool._permissions) : void 0);
|
|
376
|
+
return {
|
|
377
|
+
...toolDef,
|
|
378
|
+
id,
|
|
379
|
+
name: toolDef.name || toolDef.tool?._toolName || id,
|
|
380
|
+
alias: publicName,
|
|
381
|
+
domain: toolDef.domain ?? toolDef.tool?._domain,
|
|
382
|
+
resource: toolDef.resource ?? toolDef.tool?._resource,
|
|
383
|
+
roles,
|
|
384
|
+
permissions,
|
|
385
|
+
requireApproval: toolDef.requireApproval ?? toolDef.tool?._requireApproval
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function matchesRoleFilter(tool, role) {
|
|
389
|
+
if (!role) {
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
const roles = tool.roles ?? tool.requiredRoles;
|
|
393
|
+
if (!roles || roles.length === 0) {
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
return roles.includes(role);
|
|
397
|
+
}
|
|
398
|
+
function toDescriptor(tool) {
|
|
399
|
+
return {
|
|
400
|
+
id: tool.id,
|
|
401
|
+
name: tool.name,
|
|
402
|
+
alias: tool.alias,
|
|
403
|
+
description: tool.description,
|
|
404
|
+
domain: tool.domain,
|
|
405
|
+
resource: tool.resource,
|
|
406
|
+
roles: tool.roles ?? tool.requiredRoles,
|
|
407
|
+
permissions: tool.permissions,
|
|
408
|
+
requireApproval: tool.requireApproval,
|
|
409
|
+
cacheTTL: tool.tool._cacheTTL,
|
|
410
|
+
tags: tool.tags
|
|
411
|
+
};
|
|
412
|
+
}
|
|
306
413
|
var ToolRegistry = class _ToolRegistry {
|
|
307
414
|
toolsById = /* @__PURE__ */ new Map();
|
|
308
415
|
toolsByPublicName = /* @__PURE__ */ new Map();
|
|
@@ -310,16 +417,21 @@ var ToolRegistry = class _ToolRegistry {
|
|
|
310
417
|
* Registers a new tool in the registry.
|
|
311
418
|
*/
|
|
312
419
|
register(toolDef) {
|
|
313
|
-
const
|
|
314
|
-
const publicName =
|
|
315
|
-
|
|
316
|
-
...toolDef,
|
|
317
|
-
id
|
|
318
|
-
};
|
|
319
|
-
this.toolsById.set(id, normalizedDef);
|
|
420
|
+
const normalizedDef = normalizeToolDefinition(toolDef);
|
|
421
|
+
const publicName = normalizedDef.alias || normalizedDef.name;
|
|
422
|
+
this.toolsById.set(normalizedDef.id, normalizedDef);
|
|
320
423
|
this.toolsByPublicName.set(publicName, normalizedDef);
|
|
321
424
|
return this;
|
|
322
425
|
}
|
|
426
|
+
/**
|
|
427
|
+
* Registers multiple tools in batch.
|
|
428
|
+
*/
|
|
429
|
+
registerMany(tools) {
|
|
430
|
+
for (const tool of tools) {
|
|
431
|
+
this.register(tool);
|
|
432
|
+
}
|
|
433
|
+
return this;
|
|
434
|
+
}
|
|
323
435
|
/**
|
|
324
436
|
* Retrieves a tool by its ID or public name/alias.
|
|
325
437
|
*/
|
|
@@ -350,6 +462,12 @@ var ToolRegistry = class _ToolRegistry {
|
|
|
350
462
|
getAll() {
|
|
351
463
|
return Array.from(this.toolsById.values());
|
|
352
464
|
}
|
|
465
|
+
/**
|
|
466
|
+
* Filters tools belonging to a specific business domain.
|
|
467
|
+
*/
|
|
468
|
+
getByDomain(domain) {
|
|
469
|
+
return this.getAll().filter((item) => item.domain === domain);
|
|
470
|
+
}
|
|
353
471
|
/**
|
|
354
472
|
* Filters tools matching a specific workflow phase.
|
|
355
473
|
*/
|
|
@@ -367,12 +485,26 @@ var ToolRegistry = class _ToolRegistry {
|
|
|
367
485
|
filterByRoles(userRoles) {
|
|
368
486
|
const roleSet = new Set(userRoles);
|
|
369
487
|
return this.getAll().filter((item) => {
|
|
370
|
-
|
|
488
|
+
const roles = item.roles ?? item.requiredRoles;
|
|
489
|
+
if (!roles || roles.length === 0) {
|
|
371
490
|
return true;
|
|
372
491
|
}
|
|
373
|
-
return
|
|
492
|
+
return roles.some((role) => roleSet.has(role));
|
|
374
493
|
});
|
|
375
494
|
}
|
|
495
|
+
/**
|
|
496
|
+
* Exports headless technical descriptors without UI rendering coupling.
|
|
497
|
+
*/
|
|
498
|
+
getDescriptors(filter) {
|
|
499
|
+
let list = this.getAll();
|
|
500
|
+
if (filter?.domain) {
|
|
501
|
+
list = list.filter((item) => item.domain === filter.domain);
|
|
502
|
+
}
|
|
503
|
+
if (filter?.role) {
|
|
504
|
+
list = list.filter((item) => matchesRoleFilter(item, filter.role));
|
|
505
|
+
}
|
|
506
|
+
return list.map(toDescriptor);
|
|
507
|
+
}
|
|
376
508
|
/**
|
|
377
509
|
* Converts instance registered tools to the record map format required by Vercel AI SDK.
|
|
378
510
|
*/
|
|
@@ -384,8 +516,12 @@ var ToolRegistry = class _ToolRegistry {
|
|
|
384
516
|
* If anonymize is true, uses alias (if defined) as dictionary key instead of technical name.
|
|
385
517
|
*/
|
|
386
518
|
static toRecord(tools, options = {}) {
|
|
519
|
+
let filtered = tools;
|
|
520
|
+
if (options.domain) {
|
|
521
|
+
filtered = filtered.filter((item) => item.domain === options.domain);
|
|
522
|
+
}
|
|
387
523
|
const record = {};
|
|
388
|
-
for (const item of
|
|
524
|
+
for (const item of filtered) {
|
|
389
525
|
const key = options.anonymize && item.alias ? item.alias : item.name;
|
|
390
526
|
record[key] = item.tool;
|
|
391
527
|
}
|
|
@@ -411,17 +547,64 @@ var PhaseBasedToolStrategy = class {
|
|
|
411
547
|
var RoleBasedToolStrategy = class {
|
|
412
548
|
selectTools(tools, context) {
|
|
413
549
|
if (!context.role) {
|
|
414
|
-
return tools.filter((
|
|
550
|
+
return tools.filter((toolCandidate) => {
|
|
551
|
+
const roles = toolCandidate.roles ?? toolCandidate.requiredRoles;
|
|
552
|
+
return !roles || roles.length === 0;
|
|
553
|
+
});
|
|
415
554
|
}
|
|
416
555
|
const currentRole = context.role;
|
|
417
556
|
return tools.filter((item) => {
|
|
418
|
-
|
|
557
|
+
const roles = item.roles ?? item.requiredRoles;
|
|
558
|
+
if (!roles || roles.length === 0) {
|
|
419
559
|
return true;
|
|
420
560
|
}
|
|
421
|
-
return
|
|
561
|
+
return roles.includes(currentRole);
|
|
422
562
|
});
|
|
423
563
|
}
|
|
424
564
|
};
|
|
565
|
+
function matchesDomain(tool, allowedDomains) {
|
|
566
|
+
if (!allowedDomains) {
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
return Boolean(tool.domain && allowedDomains.has(tool.domain));
|
|
570
|
+
}
|
|
571
|
+
function matchesRoles(tool, context) {
|
|
572
|
+
const toolRoles = tool.roles ?? tool.requiredRoles;
|
|
573
|
+
if (!toolRoles || toolRoles.length === 0) {
|
|
574
|
+
return true;
|
|
575
|
+
}
|
|
576
|
+
const userRoles = [];
|
|
577
|
+
if (context.role) {
|
|
578
|
+
userRoles.push(context.role);
|
|
579
|
+
}
|
|
580
|
+
if (context.roles) {
|
|
581
|
+
userRoles.push(...context.roles);
|
|
582
|
+
}
|
|
583
|
+
if (userRoles.length === 0) {
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
return toolRoles.some((roleName) => userRoles.includes(roleName));
|
|
587
|
+
}
|
|
588
|
+
function matchesPermissions(tool, context) {
|
|
589
|
+
if (!tool.permissions || tool.permissions.length === 0) {
|
|
590
|
+
return true;
|
|
591
|
+
}
|
|
592
|
+
const userPermissions = context.permissions ?? [];
|
|
593
|
+
return tool.permissions.every((permissionName) => userPermissions.includes(permissionName));
|
|
594
|
+
}
|
|
595
|
+
var AccessControlToolStrategy = class {
|
|
596
|
+
allowedDomains;
|
|
597
|
+
constructor(options) {
|
|
598
|
+
if (options?.allowedDomains) {
|
|
599
|
+
this.allowedDomains = new Set(options.allowedDomains);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
selectTools(tools, context) {
|
|
603
|
+
return tools.filter(
|
|
604
|
+
(tool) => matchesDomain(tool, this.allowedDomains) && matchesRoles(tool, context) && matchesPermissions(tool, context)
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
};
|
|
425
608
|
var CompositeToolStrategy = class {
|
|
426
609
|
strategies;
|
|
427
610
|
constructor(strategies) {
|
|
@@ -1669,6 +1852,7 @@ var HttpTelemetryExporter = class {
|
|
|
1669
1852
|
}
|
|
1670
1853
|
};
|
|
1671
1854
|
export {
|
|
1855
|
+
AccessControlToolStrategy,
|
|
1672
1856
|
AgentToolFactory,
|
|
1673
1857
|
CircularToolCallError,
|
|
1674
1858
|
CompositeToolStrategy,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IsolatedToolConfig, VercelAiCoreTool } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Creates an isolated tool compatible with Vercel AI SDK (ai) tool contract.
|
|
4
|
+
* Features dual-channel separation (client data vs minimal LLM DTO),
|
|
5
|
+
* access governance (domain, resource, roles, dataAccessGuard, invalidationTags),
|
|
6
|
+
* stable ID, aliasing, caching, Zod DTO contract validation, and automatic in-flight PII redaction.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createIsolatedTool<TArgs = any, TResult = any, TLLMDto = unknown, TClientDto = TResult>(config: IsolatedToolConfig<TArgs, TResult, TLLMDto, TClientDto>): VercelAiCoreTool<TArgs, TResult>;
|
|
9
|
+
//# sourceMappingURL=isolated-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isolated-tool.d.ts","sourceRoot":"","sources":["../../src/agent/isolated-tool.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAElB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAoHjB;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,GAAG,GAAG,EACX,OAAO,GAAG,GAAG,EACb,OAAO,GAAG,OAAO,EACjB,UAAU,GAAG,OAAO,EAEpB,MAAM,EAAE,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,GAC9D,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CA8DlC"}
|