avantgate 1.1.2 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/agent/adapters/custom-adapter.d.ts +50 -0
  2. package/dist/agent/adapters/custom-adapter.d.ts.map +1 -0
  3. package/dist/agent/adapters/index.d.ts +6 -0
  4. package/dist/agent/adapters/index.d.ts.map +1 -0
  5. package/dist/agent/adapters/memory-adapter.d.ts +34 -0
  6. package/dist/agent/adapters/memory-adapter.d.ts.map +1 -0
  7. package/dist/agent/adapters/platform-adapter.d.ts +32 -0
  8. package/dist/agent/adapters/platform-adapter.d.ts.map +1 -0
  9. package/dist/agent/adapters/prisma-adapter.d.ts +55 -0
  10. package/dist/agent/adapters/prisma-adapter.d.ts.map +1 -0
  11. package/dist/agent/adapters/sqlite-adapter.d.ts +31 -0
  12. package/dist/agent/adapters/sqlite-adapter.d.ts.map +1 -0
  13. package/dist/agent/dto.d.ts +58 -0
  14. package/dist/agent/dto.d.ts.map +1 -0
  15. package/dist/agent/errors.d.ts +50 -0
  16. package/dist/agent/errors.d.ts.map +1 -0
  17. package/dist/agent/factory.d.ts +21 -0
  18. package/dist/agent/factory.d.ts.map +1 -0
  19. package/dist/agent/guardrails.d.ts +14 -0
  20. package/dist/agent/guardrails.d.ts.map +1 -0
  21. package/dist/agent/index.d.ts +17 -742
  22. package/dist/agent/index.d.ts.map +1 -0
  23. package/dist/agent/index.js +224 -31
  24. package/dist/agent/index.mjs +223 -31
  25. package/dist/agent/isolated-tool.d.ts +9 -0
  26. package/dist/agent/isolated-tool.d.ts.map +1 -0
  27. package/dist/agent/registry.d.ts +71 -0
  28. package/dist/agent/registry.d.ts.map +1 -0
  29. package/dist/agent/step-runner.d.ts +12 -0
  30. package/dist/agent/step-runner.d.ts.map +1 -0
  31. package/dist/agent/strategy.d.ts +37 -0
  32. package/dist/agent/strategy.d.ts.map +1 -0
  33. package/dist/agent/telemetry/http-exporter.d.ts +24 -0
  34. package/dist/agent/telemetry/http-exporter.d.ts.map +1 -0
  35. package/dist/agent/telemetry/index.d.ts +3 -0
  36. package/dist/agent/telemetry/index.d.ts.map +1 -0
  37. package/dist/agent/telemetry/types.d.ts +92 -0
  38. package/dist/agent/telemetry/types.d.ts.map +1 -0
  39. package/dist/agent/tool-invoker.d.ts +17 -0
  40. package/dist/agent/tool-invoker.d.ts.map +1 -0
  41. package/dist/agent/tool-state.d.ts +7 -0
  42. package/dist/agent/tool-state.d.ts.map +1 -0
  43. package/dist/agent/types.d.ts +243 -0
  44. package/dist/agent/types.d.ts.map +1 -0
  45. package/dist/control-layer.d.ts +49 -0
  46. package/dist/control-layer.d.ts.map +1 -0
  47. package/dist/finance/factory.d.ts +11 -0
  48. package/dist/finance/factory.d.ts.map +1 -0
  49. package/dist/finance/index.d.ts +9 -76
  50. package/dist/finance/index.d.ts.map +1 -0
  51. package/dist/finance/normalizer.d.ts +19 -0
  52. package/dist/finance/normalizer.d.ts.map +1 -0
  53. package/dist/finance/strategies/french-pcg.strategy.d.ts +10 -0
  54. package/dist/finance/strategies/french-pcg.strategy.d.ts.map +1 -0
  55. package/dist/finance/strategies/international.strategy.d.ts +10 -0
  56. package/dist/finance/strategies/international.strategy.d.ts.map +1 -0
  57. package/dist/finance/strategies/swiss-co.strategy.d.ts +10 -0
  58. package/dist/finance/strategies/swiss-co.strategy.d.ts.map +1 -0
  59. package/dist/finance/strategies/uk-ifrs.strategy.d.ts +10 -0
  60. package/dist/finance/strategies/uk-ifrs.strategy.d.ts.map +1 -0
  61. package/dist/finance/strategies/us-gaap.strategy.d.ts +10 -0
  62. package/dist/finance/strategies/us-gaap.strategy.d.ts.map +1 -0
  63. package/dist/{strategy.interface-CB4_ZAuk.d.ts → finance/strategy.interface.d.ts} +5 -6
  64. package/dist/finance/strategy.interface.d.ts.map +1 -0
  65. package/dist/index.d.ts +9 -390
  66. package/dist/index.d.ts.map +1 -0
  67. package/dist/index.mjs +3 -3
  68. package/dist/input-guard.d.ts +13 -0
  69. package/dist/input-guard.d.ts.map +1 -0
  70. package/dist/pricing.d.ts +49 -0
  71. package/dist/pricing.d.ts.map +1 -0
  72. package/dist/prompts/index.d.ts +5 -0
  73. package/dist/prompts/index.d.ts.map +1 -0
  74. package/dist/prompts/prompt-builder.d.ts +31 -0
  75. package/dist/prompts/prompt-builder.d.ts.map +1 -0
  76. package/dist/prompts/prompt-registry.d.ts +13 -0
  77. package/dist/prompts/prompt-registry.d.ts.map +1 -0
  78. package/dist/prompts/prompt-template.d.ts +17 -0
  79. package/dist/prompts/prompt-template.d.ts.map +1 -0
  80. package/dist/prompts/types.d.ts +39 -0
  81. package/dist/prompts/types.d.ts.map +1 -0
  82. package/dist/providers/http-client.d.ts +18 -0
  83. package/dist/providers/http-client.d.ts.map +1 -0
  84. package/dist/response-validator.d.ts +18 -0
  85. package/dist/response-validator.d.ts.map +1 -0
  86. package/dist/sanitizer.d.ts +11 -0
  87. package/dist/sanitizer.d.ts.map +1 -0
  88. package/dist/types.d.ts +146 -0
  89. package/dist/types.d.ts.map +1 -0
  90. package/package.json +3 -3
  91. package/dist/agent/index.d.mts +0 -743
  92. package/dist/finance/index.d.mts +0 -76
  93. package/dist/index.d.mts +0 -390
  94. 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"}
@@ -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
- constructor(toolName, requiredRole) {
93
- const roleMsg = requiredRole ? ` (requires role "${requiredRole}")` : "";
94
- super(`Access denied for tool "${toolName}"${roleMsg}.`);
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
- this.requiredRole = requiredRole;
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
- toolAlias || config.name
374
+ toolIdentifier
326
375
  );
327
376
  tool._lastPiiFilteredCount = protection.count;
328
377
  return protection.sanitized;
@@ -332,6 +381,18 @@ function createIsolatedTool(config) {
332
381
  }
333
382
 
334
383
  // src/agent/dto.ts
384
+ function extractWhitelistedFields(data, keys) {
385
+ const result = {};
386
+ if (!data || typeof data !== "object") {
387
+ return result;
388
+ }
389
+ for (const key of keys) {
390
+ if (key in data) {
391
+ result[key] = data[key];
392
+ }
393
+ }
394
+ return result;
395
+ }
335
396
  var dto = {
336
397
  /**
337
398
  * Generates a boolean acknowledgment for mutations ({ success: true | false }).
@@ -358,20 +419,16 @@ var dto = {
358
419
  };
359
420
  },
360
421
  /**
361
- * Filters raw output by extracting only a strict whitelist of allowed fields.
422
+ * Filters raw output by extracting only a whitelist of allowed fields.
423
+ * Supports optional TSource generic parameter for auto-completion.
362
424
  */
363
- pick: (keys) => (data) => {
364
- const result = {};
365
- if (!data || typeof data !== "object") {
366
- return result;
367
- }
368
- for (const key of keys) {
369
- if (key in data) {
370
- result[key] = data[key];
371
- }
372
- }
373
- return result;
374
- }
425
+ pick: (keys) => (data) => extractWhitelistedFields(data, keys),
426
+ /**
427
+ * Compile-time guarded exhaustive projection.
428
+ * Forces developers to explicitly classify every key of TSource as either 'keep' (sent to LLM)
429
+ * or 'drop' (ignored), preventing silent schema drift when source types evolve.
430
+ */
431
+ exhaustivePick: () => (config) => (data) => extractWhitelistedFields(data, config.keep)
375
432
  };
376
433
 
377
434
  // src/agent/factory.ts
@@ -405,6 +462,65 @@ var AgentToolFactory = class _AgentToolFactory {
405
462
  };
406
463
 
407
464
  // src/agent/registry.ts
465
+ function isCoreTool(item) {
466
+ return typeof item.execute === "function" && "_toolId" in item;
467
+ }
468
+ function normalizeToolDefinition(toolDef) {
469
+ if (isCoreTool(toolDef)) {
470
+ return {
471
+ id: toolDef._toolId || toolDef._toolName,
472
+ name: toolDef._toolName,
473
+ alias: toolDef._toolAlias,
474
+ description: toolDef.description,
475
+ domain: toolDef._domain,
476
+ resource: toolDef._resource,
477
+ roles: toolDef._roles ? Array.from(toolDef._roles) : void 0,
478
+ permissions: toolDef._permissions ? Array.from(toolDef._permissions) : void 0,
479
+ requireApproval: toolDef._requireApproval,
480
+ tool: toolDef
481
+ };
482
+ }
483
+ const id = toolDef.id || toolDef.name || toolDef.tool?._toolId;
484
+ const publicName = toolDef.alias || toolDef.name || toolDef.tool?._toolAlias || toolDef.tool?._toolName;
485
+ const roles = toolDef.roles ?? (toolDef.tool?._roles ? Array.from(toolDef.tool._roles) : toolDef.requiredRoles);
486
+ const permissions = toolDef.permissions ?? (toolDef.tool?._permissions ? Array.from(toolDef.tool._permissions) : void 0);
487
+ return {
488
+ ...toolDef,
489
+ id,
490
+ name: toolDef.name || toolDef.tool?._toolName || id,
491
+ alias: publicName,
492
+ domain: toolDef.domain ?? toolDef.tool?._domain,
493
+ resource: toolDef.resource ?? toolDef.tool?._resource,
494
+ roles,
495
+ permissions,
496
+ requireApproval: toolDef.requireApproval ?? toolDef.tool?._requireApproval
497
+ };
498
+ }
499
+ function matchesRoleFilter(tool, role) {
500
+ if (!role) {
501
+ return true;
502
+ }
503
+ const roles = tool.roles ?? tool.requiredRoles;
504
+ if (!roles || roles.length === 0) {
505
+ return true;
506
+ }
507
+ return roles.includes(role);
508
+ }
509
+ function toDescriptor(tool) {
510
+ return {
511
+ id: tool.id,
512
+ name: tool.name,
513
+ alias: tool.alias,
514
+ description: tool.description,
515
+ domain: tool.domain,
516
+ resource: tool.resource,
517
+ roles: tool.roles ?? tool.requiredRoles,
518
+ permissions: tool.permissions,
519
+ requireApproval: tool.requireApproval,
520
+ cacheTTL: tool.tool._cacheTTL,
521
+ tags: tool.tags
522
+ };
523
+ }
408
524
  var ToolRegistry = class _ToolRegistry {
409
525
  toolsById = /* @__PURE__ */ new Map();
410
526
  toolsByPublicName = /* @__PURE__ */ new Map();
@@ -412,16 +528,21 @@ var ToolRegistry = class _ToolRegistry {
412
528
  * Registers a new tool in the registry.
413
529
  */
414
530
  register(toolDef) {
415
- const id = toolDef.id || toolDef.name;
416
- const publicName = toolDef.alias || toolDef.name;
417
- const normalizedDef = {
418
- ...toolDef,
419
- id
420
- };
421
- this.toolsById.set(id, normalizedDef);
531
+ const normalizedDef = normalizeToolDefinition(toolDef);
532
+ const publicName = normalizedDef.alias || normalizedDef.name;
533
+ this.toolsById.set(normalizedDef.id, normalizedDef);
422
534
  this.toolsByPublicName.set(publicName, normalizedDef);
423
535
  return this;
424
536
  }
537
+ /**
538
+ * Registers multiple tools in batch.
539
+ */
540
+ registerMany(tools) {
541
+ for (const tool of tools) {
542
+ this.register(tool);
543
+ }
544
+ return this;
545
+ }
425
546
  /**
426
547
  * Retrieves a tool by its ID or public name/alias.
427
548
  */
@@ -452,6 +573,12 @@ var ToolRegistry = class _ToolRegistry {
452
573
  getAll() {
453
574
  return Array.from(this.toolsById.values());
454
575
  }
576
+ /**
577
+ * Filters tools belonging to a specific business domain.
578
+ */
579
+ getByDomain(domain) {
580
+ return this.getAll().filter((item) => item.domain === domain);
581
+ }
455
582
  /**
456
583
  * Filters tools matching a specific workflow phase.
457
584
  */
@@ -469,12 +596,26 @@ var ToolRegistry = class _ToolRegistry {
469
596
  filterByRoles(userRoles) {
470
597
  const roleSet = new Set(userRoles);
471
598
  return this.getAll().filter((item) => {
472
- if (!item.requiredRoles || item.requiredRoles.length === 0) {
599
+ const roles = item.roles ?? item.requiredRoles;
600
+ if (!roles || roles.length === 0) {
473
601
  return true;
474
602
  }
475
- return item.requiredRoles.some((role) => roleSet.has(role));
603
+ return roles.some((role) => roleSet.has(role));
476
604
  });
477
605
  }
606
+ /**
607
+ * Exports headless technical descriptors without UI rendering coupling.
608
+ */
609
+ getDescriptors(filter) {
610
+ let list = this.getAll();
611
+ if (filter?.domain) {
612
+ list = list.filter((item) => item.domain === filter.domain);
613
+ }
614
+ if (filter?.role) {
615
+ list = list.filter((item) => matchesRoleFilter(item, filter.role));
616
+ }
617
+ return list.map(toDescriptor);
618
+ }
478
619
  /**
479
620
  * Converts instance registered tools to the record map format required by Vercel AI SDK.
480
621
  */
@@ -486,8 +627,12 @@ var ToolRegistry = class _ToolRegistry {
486
627
  * If anonymize is true, uses alias (if defined) as dictionary key instead of technical name.
487
628
  */
488
629
  static toRecord(tools, options = {}) {
630
+ let filtered = tools;
631
+ if (options.domain) {
632
+ filtered = filtered.filter((item) => item.domain === options.domain);
633
+ }
489
634
  const record = {};
490
- for (const item of tools) {
635
+ for (const item of filtered) {
491
636
  const key = options.anonymize && item.alias ? item.alias : item.name;
492
637
  record[key] = item.tool;
493
638
  }
@@ -513,17 +658,64 @@ var PhaseBasedToolStrategy = class {
513
658
  var RoleBasedToolStrategy = class {
514
659
  selectTools(tools, context) {
515
660
  if (!context.role) {
516
- return tools.filter((t) => !t.requiredRoles || t.requiredRoles.length === 0);
661
+ return tools.filter((toolCandidate) => {
662
+ const roles = toolCandidate.roles ?? toolCandidate.requiredRoles;
663
+ return !roles || roles.length === 0;
664
+ });
517
665
  }
518
666
  const currentRole = context.role;
519
667
  return tools.filter((item) => {
520
- if (!item.requiredRoles || item.requiredRoles.length === 0) {
668
+ const roles = item.roles ?? item.requiredRoles;
669
+ if (!roles || roles.length === 0) {
521
670
  return true;
522
671
  }
523
- return item.requiredRoles.includes(currentRole);
672
+ return roles.includes(currentRole);
524
673
  });
525
674
  }
526
675
  };
676
+ function matchesDomain(tool, allowedDomains) {
677
+ if (!allowedDomains) {
678
+ return true;
679
+ }
680
+ return Boolean(tool.domain && allowedDomains.has(tool.domain));
681
+ }
682
+ function matchesRoles(tool, context) {
683
+ const toolRoles = tool.roles ?? tool.requiredRoles;
684
+ if (!toolRoles || toolRoles.length === 0) {
685
+ return true;
686
+ }
687
+ const userRoles = [];
688
+ if (context.role) {
689
+ userRoles.push(context.role);
690
+ }
691
+ if (context.roles) {
692
+ userRoles.push(...context.roles);
693
+ }
694
+ if (userRoles.length === 0) {
695
+ return false;
696
+ }
697
+ return toolRoles.some((roleName) => userRoles.includes(roleName));
698
+ }
699
+ function matchesPermissions(tool, context) {
700
+ if (!tool.permissions || tool.permissions.length === 0) {
701
+ return true;
702
+ }
703
+ const userPermissions = context.permissions ?? [];
704
+ return tool.permissions.every((permissionName) => userPermissions.includes(permissionName));
705
+ }
706
+ var AccessControlToolStrategy = class {
707
+ allowedDomains;
708
+ constructor(options) {
709
+ if (options?.allowedDomains) {
710
+ this.allowedDomains = new Set(options.allowedDomains);
711
+ }
712
+ }
713
+ selectTools(tools, context) {
714
+ return tools.filter(
715
+ (tool) => matchesDomain(tool, this.allowedDomains) && matchesRoles(tool, context) && matchesPermissions(tool, context)
716
+ );
717
+ }
718
+ };
527
719
  var CompositeToolStrategy = class {
528
720
  strategies;
529
721
  constructor(strategies) {
@@ -1772,6 +1964,7 @@ var HttpTelemetryExporter = class {
1772
1964
  };
1773
1965
  // Annotate the CommonJS export names for ESM import in node:
1774
1966
  0 && (module.exports = {
1967
+ AccessControlToolStrategy,
1775
1968
  AgentToolFactory,
1776
1969
  CircularToolCallError,
1777
1970
  CompositeToolStrategy,