avantgate 1.1.1 → 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/README.md +15 -398
- 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 -703
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +294 -30
- package/dist/agent/index.mjs +290 -29
- 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 -704
- 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,9 +20,11 @@ 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,
|
|
27
|
+
DtoValidationError: () => DtoValidationError,
|
|
26
28
|
HttpTelemetryExporter: () => HttpTelemetryExporter,
|
|
27
29
|
KeyValueStorageAdapter: () => KeyValueStorageAdapter,
|
|
28
30
|
MemoryStorageAdapter: () => MemoryStorageAdapter,
|
|
@@ -45,7 +47,8 @@ __export(agent_exports, {
|
|
|
45
47
|
createIsolatedTool: () => createIsolatedTool,
|
|
46
48
|
createStepRunner: () => createStepRunner,
|
|
47
49
|
createToolInvoker: () => createToolInvoker,
|
|
48
|
-
createToolSharedState: () => createToolSharedState
|
|
50
|
+
createToolSharedState: () => createToolSharedState,
|
|
51
|
+
dto: () => dto
|
|
49
52
|
});
|
|
50
53
|
module.exports = __toCommonJS(agent_exports);
|
|
51
54
|
|
|
@@ -87,12 +90,19 @@ var StepExecutionError = class extends Error {
|
|
|
87
90
|
var ToolAccessDeniedError = class extends Error {
|
|
88
91
|
toolName;
|
|
89
92
|
requiredRole;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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}.`);
|
|
93
99
|
this.name = "ToolAccessDeniedError";
|
|
94
100
|
this.toolName = toolName;
|
|
95
|
-
|
|
101
|
+
if (isRole) {
|
|
102
|
+
this.requiredRole = reasonOrRole;
|
|
103
|
+
} else {
|
|
104
|
+
this.reason = reasonOrRole;
|
|
105
|
+
}
|
|
96
106
|
}
|
|
97
107
|
};
|
|
98
108
|
var CircularToolCallError = class extends Error {
|
|
@@ -131,6 +141,16 @@ var ToolNotFoundError = class extends Error {
|
|
|
131
141
|
this.toolId = toolId;
|
|
132
142
|
}
|
|
133
143
|
};
|
|
144
|
+
var DtoValidationError = class extends Error {
|
|
145
|
+
toolName;
|
|
146
|
+
issues;
|
|
147
|
+
constructor(toolName, message, issues = []) {
|
|
148
|
+
super(`LLM DTO validation failed for tool "${toolName}": ${message}`);
|
|
149
|
+
this.name = "DtoValidationError";
|
|
150
|
+
this.toolName = toolName;
|
|
151
|
+
this.issues = issues;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
134
154
|
|
|
135
155
|
// src/sanitizer.ts
|
|
136
156
|
var EMAIL_REGEX = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b/g;
|
|
@@ -238,18 +258,50 @@ function auditToolResult(data, options) {
|
|
|
238
258
|
}
|
|
239
259
|
|
|
240
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
|
+
}
|
|
241
280
|
async function dispatchClientData(rawResult, callback) {
|
|
242
281
|
if (!callback) {
|
|
243
282
|
return;
|
|
244
283
|
}
|
|
245
284
|
await callback(rawResult);
|
|
246
285
|
}
|
|
247
|
-
function produceLlmPayload(rawResult, args, transformer) {
|
|
286
|
+
async function produceLlmPayload(rawResult, args, context, transformer) {
|
|
248
287
|
if (transformer) {
|
|
249
|
-
return transformer(rawResult, args);
|
|
288
|
+
return await transformer(rawResult, args, context);
|
|
250
289
|
}
|
|
251
290
|
return rawResult;
|
|
252
291
|
}
|
|
292
|
+
function validateLlmDto(payload, schema, toolIdentifier) {
|
|
293
|
+
const parseResult = schema.safeParse(payload);
|
|
294
|
+
if (!parseResult.success) {
|
|
295
|
+
const issues = parseResult.error.issues ?? [];
|
|
296
|
+
const errorMessages = issues.map((issue) => `${issue.path.join(".") || "root"}: ${issue.message}`).join(", ");
|
|
297
|
+
throw new DtoValidationError(
|
|
298
|
+
toolIdentifier,
|
|
299
|
+
errorMessages,
|
|
300
|
+
issues
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
return parseResult.data;
|
|
304
|
+
}
|
|
253
305
|
function protectLlmPayload(payload, toolIdentifier, sanitizePii = true, throwOnPii = false) {
|
|
254
306
|
if (!sanitizePii) {
|
|
255
307
|
return { sanitized: payload, count: 0 };
|
|
@@ -260,9 +312,23 @@ function protectLlmPayload(payload, toolIdentifier, sanitizePii = true, throwOnP
|
|
|
260
312
|
});
|
|
261
313
|
return { sanitized: sanitizedData, count: maskedCount };
|
|
262
314
|
}
|
|
315
|
+
async function processLlmPayload(rawResult, args, context, config, toolIdentifier) {
|
|
316
|
+
let payload = await produceLlmPayload(rawResult, args, context, config.llmDto);
|
|
317
|
+
if (config.llmDtoSchema) {
|
|
318
|
+
payload = validateLlmDto(payload, config.llmDtoSchema, toolIdentifier);
|
|
319
|
+
}
|
|
320
|
+
return protectLlmPayload(
|
|
321
|
+
payload,
|
|
322
|
+
toolIdentifier,
|
|
323
|
+
config.sanitizePii !== false,
|
|
324
|
+
config.throwOnPii === true
|
|
325
|
+
);
|
|
326
|
+
}
|
|
263
327
|
function createIsolatedTool(config) {
|
|
264
328
|
const toolId = config.id || config.name;
|
|
265
329
|
const toolAlias = config.alias;
|
|
330
|
+
const clientCallback = config.clientDto;
|
|
331
|
+
const toolIdentifier = toolAlias || config.name;
|
|
266
332
|
const tool = {
|
|
267
333
|
description: config.description,
|
|
268
334
|
parameters: config.parameters,
|
|
@@ -271,24 +337,41 @@ function createIsolatedTool(config) {
|
|
|
271
337
|
_toolAlias: toolAlias,
|
|
272
338
|
_isIsolated: true,
|
|
273
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,
|
|
274
345
|
_lastPiiFilteredCount: 0,
|
|
346
|
+
_lastInvalidationTags: void 0,
|
|
275
347
|
async execute(args, context) {
|
|
276
348
|
const updatedContext = {
|
|
277
349
|
...context,
|
|
278
350
|
callChain: context?.callChain ?? Object.freeze([toolId])
|
|
279
351
|
};
|
|
352
|
+
await verifyDataAccessGuard(
|
|
353
|
+
config.dataAccessGuard,
|
|
354
|
+
args,
|
|
355
|
+
updatedContext,
|
|
356
|
+
toolIdentifier
|
|
357
|
+
);
|
|
280
358
|
const rawResult = await config.execute(args, updatedContext);
|
|
281
|
-
await
|
|
282
|
-
|
|
283
|
-
rawResult,
|
|
359
|
+
const tags = await resolveInvalidationTags(
|
|
360
|
+
config,
|
|
284
361
|
args,
|
|
285
|
-
|
|
362
|
+
rawResult,
|
|
363
|
+
updatedContext
|
|
286
364
|
);
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
365
|
+
if (tags) {
|
|
366
|
+
tool._lastInvalidationTags = tags;
|
|
367
|
+
}
|
|
368
|
+
await dispatchClientData(rawResult, clientCallback);
|
|
369
|
+
const protection = await processLlmPayload(
|
|
370
|
+
rawResult,
|
|
371
|
+
args,
|
|
372
|
+
updatedContext,
|
|
373
|
+
config,
|
|
374
|
+
toolIdentifier
|
|
292
375
|
);
|
|
293
376
|
tool._lastPiiFilteredCount = protection.count;
|
|
294
377
|
return protection.sanitized;
|
|
@@ -297,6 +380,49 @@ function createIsolatedTool(config) {
|
|
|
297
380
|
return tool;
|
|
298
381
|
}
|
|
299
382
|
|
|
383
|
+
// src/agent/dto.ts
|
|
384
|
+
var dto = {
|
|
385
|
+
/**
|
|
386
|
+
* Generates a boolean acknowledgment for mutations ({ success: true | false }).
|
|
387
|
+
* If rawResult contains a boolean `success` property, it is preserved; otherwise defaults to true.
|
|
388
|
+
*/
|
|
389
|
+
boolean: () => (data) => ({
|
|
390
|
+
success: typeof data?.success === "boolean" ? data.success : true
|
|
391
|
+
}),
|
|
392
|
+
/**
|
|
393
|
+
* Generates a boolean acknowledgment preserving an opaque technical identifier for tool chaining.
|
|
394
|
+
*/
|
|
395
|
+
booleanWithId: (idKey = "id") => (data) => ({
|
|
396
|
+
success: typeof data?.success === "boolean" ? data.success : true,
|
|
397
|
+
[idKey]: data?.[idKey]
|
|
398
|
+
}),
|
|
399
|
+
/**
|
|
400
|
+
* Extracts a numeric count from a list or nested array property without exposing items to the LLM.
|
|
401
|
+
*/
|
|
402
|
+
count: (arrayKey) => (data) => {
|
|
403
|
+
const list = arrayKey ? data?.[arrayKey] : data;
|
|
404
|
+
return {
|
|
405
|
+
success: true,
|
|
406
|
+
count: Array.isArray(list) ? list.length : 0
|
|
407
|
+
};
|
|
408
|
+
},
|
|
409
|
+
/**
|
|
410
|
+
* Filters raw output by extracting only a strict whitelist of allowed fields.
|
|
411
|
+
*/
|
|
412
|
+
pick: (keys) => (data) => {
|
|
413
|
+
const result = {};
|
|
414
|
+
if (!data || typeof data !== "object") {
|
|
415
|
+
return result;
|
|
416
|
+
}
|
|
417
|
+
for (const key of keys) {
|
|
418
|
+
if (key in data) {
|
|
419
|
+
result[key] = data[key];
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return result;
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
|
|
300
426
|
// src/agent/factory.ts
|
|
301
427
|
var AgentToolFactory = class _AgentToolFactory {
|
|
302
428
|
context;
|
|
@@ -328,6 +454,65 @@ var AgentToolFactory = class _AgentToolFactory {
|
|
|
328
454
|
};
|
|
329
455
|
|
|
330
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
|
+
}
|
|
331
516
|
var ToolRegistry = class _ToolRegistry {
|
|
332
517
|
toolsById = /* @__PURE__ */ new Map();
|
|
333
518
|
toolsByPublicName = /* @__PURE__ */ new Map();
|
|
@@ -335,16 +520,21 @@ var ToolRegistry = class _ToolRegistry {
|
|
|
335
520
|
* Registers a new tool in the registry.
|
|
336
521
|
*/
|
|
337
522
|
register(toolDef) {
|
|
338
|
-
const
|
|
339
|
-
const publicName =
|
|
340
|
-
|
|
341
|
-
...toolDef,
|
|
342
|
-
id
|
|
343
|
-
};
|
|
344
|
-
this.toolsById.set(id, normalizedDef);
|
|
523
|
+
const normalizedDef = normalizeToolDefinition(toolDef);
|
|
524
|
+
const publicName = normalizedDef.alias || normalizedDef.name;
|
|
525
|
+
this.toolsById.set(normalizedDef.id, normalizedDef);
|
|
345
526
|
this.toolsByPublicName.set(publicName, normalizedDef);
|
|
346
527
|
return this;
|
|
347
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
|
+
}
|
|
348
538
|
/**
|
|
349
539
|
* Retrieves a tool by its ID or public name/alias.
|
|
350
540
|
*/
|
|
@@ -375,6 +565,12 @@ var ToolRegistry = class _ToolRegistry {
|
|
|
375
565
|
getAll() {
|
|
376
566
|
return Array.from(this.toolsById.values());
|
|
377
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
|
+
}
|
|
378
574
|
/**
|
|
379
575
|
* Filters tools matching a specific workflow phase.
|
|
380
576
|
*/
|
|
@@ -392,12 +588,26 @@ var ToolRegistry = class _ToolRegistry {
|
|
|
392
588
|
filterByRoles(userRoles) {
|
|
393
589
|
const roleSet = new Set(userRoles);
|
|
394
590
|
return this.getAll().filter((item) => {
|
|
395
|
-
|
|
591
|
+
const roles = item.roles ?? item.requiredRoles;
|
|
592
|
+
if (!roles || roles.length === 0) {
|
|
396
593
|
return true;
|
|
397
594
|
}
|
|
398
|
-
return
|
|
595
|
+
return roles.some((role) => roleSet.has(role));
|
|
399
596
|
});
|
|
400
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
|
+
}
|
|
401
611
|
/**
|
|
402
612
|
* Converts instance registered tools to the record map format required by Vercel AI SDK.
|
|
403
613
|
*/
|
|
@@ -409,8 +619,12 @@ var ToolRegistry = class _ToolRegistry {
|
|
|
409
619
|
* If anonymize is true, uses alias (if defined) as dictionary key instead of technical name.
|
|
410
620
|
*/
|
|
411
621
|
static toRecord(tools, options = {}) {
|
|
622
|
+
let filtered = tools;
|
|
623
|
+
if (options.domain) {
|
|
624
|
+
filtered = filtered.filter((item) => item.domain === options.domain);
|
|
625
|
+
}
|
|
412
626
|
const record = {};
|
|
413
|
-
for (const item of
|
|
627
|
+
for (const item of filtered) {
|
|
414
628
|
const key = options.anonymize && item.alias ? item.alias : item.name;
|
|
415
629
|
record[key] = item.tool;
|
|
416
630
|
}
|
|
@@ -436,17 +650,64 @@ var PhaseBasedToolStrategy = class {
|
|
|
436
650
|
var RoleBasedToolStrategy = class {
|
|
437
651
|
selectTools(tools, context) {
|
|
438
652
|
if (!context.role) {
|
|
439
|
-
return tools.filter((
|
|
653
|
+
return tools.filter((toolCandidate) => {
|
|
654
|
+
const roles = toolCandidate.roles ?? toolCandidate.requiredRoles;
|
|
655
|
+
return !roles || roles.length === 0;
|
|
656
|
+
});
|
|
440
657
|
}
|
|
441
658
|
const currentRole = context.role;
|
|
442
659
|
return tools.filter((item) => {
|
|
443
|
-
|
|
660
|
+
const roles = item.roles ?? item.requiredRoles;
|
|
661
|
+
if (!roles || roles.length === 0) {
|
|
444
662
|
return true;
|
|
445
663
|
}
|
|
446
|
-
return
|
|
664
|
+
return roles.includes(currentRole);
|
|
447
665
|
});
|
|
448
666
|
}
|
|
449
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
|
+
};
|
|
450
711
|
var CompositeToolStrategy = class {
|
|
451
712
|
strategies;
|
|
452
713
|
constructor(strategies) {
|
|
@@ -1695,9 +1956,11 @@ var HttpTelemetryExporter = class {
|
|
|
1695
1956
|
};
|
|
1696
1957
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1697
1958
|
0 && (module.exports = {
|
|
1959
|
+
AccessControlToolStrategy,
|
|
1698
1960
|
AgentToolFactory,
|
|
1699
1961
|
CircularToolCallError,
|
|
1700
1962
|
CompositeToolStrategy,
|
|
1963
|
+
DtoValidationError,
|
|
1701
1964
|
HttpTelemetryExporter,
|
|
1702
1965
|
KeyValueStorageAdapter,
|
|
1703
1966
|
MemoryStorageAdapter,
|
|
@@ -1720,5 +1983,6 @@ var HttpTelemetryExporter = class {
|
|
|
1720
1983
|
createIsolatedTool,
|
|
1721
1984
|
createStepRunner,
|
|
1722
1985
|
createToolInvoker,
|
|
1723
|
-
createToolSharedState
|
|
1986
|
+
createToolSharedState,
|
|
1987
|
+
dto
|
|
1724
1988
|
});
|