@adminforth/agent 2.0.9 → 2.0.10
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/apiBasedTools.ts +13 -3
- package/dist/apiBasedTools.js +10 -3
- package/package.json +1 -1
package/apiBasedTools.ts
CHANGED
|
@@ -635,6 +635,14 @@ function stringifyToolOutput(output: unknown): string {
|
|
|
635
635
|
return YAML.stringify(output === undefined ? EMPTY_HANDLER_RESPONSE_ERROR : output);
|
|
636
636
|
}
|
|
637
637
|
|
|
638
|
+
function attachDurationMs(output: unknown, durationMs: number): unknown {
|
|
639
|
+
if (output !== null && typeof output === 'object' && !Array.isArray(output)) {
|
|
640
|
+
return { ...output, durationMs };
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
return { result: output, durationMs };
|
|
644
|
+
}
|
|
645
|
+
|
|
638
646
|
export function prepareApiBasedTools(
|
|
639
647
|
adminforth: IAdminForth,
|
|
640
648
|
hiddenResourceIds: Iterable<string> = [],
|
|
@@ -666,11 +674,13 @@ export function prepareApiBasedTools(
|
|
|
666
674
|
input_schema: schema.request_schema,
|
|
667
675
|
agent: schema.agent,
|
|
668
676
|
call: async ({ adminUser, adminuser, abortSignal, inputs, userTimeZone, acceptLanguage } = {}) => {
|
|
677
|
+
const startedAt = Date.now();
|
|
678
|
+
|
|
669
679
|
if (isHiddenResourceCall(hiddenResourceIdSet, inputs)) {
|
|
670
|
-
return stringifyToolOutput({
|
|
680
|
+
return stringifyToolOutput(attachDurationMs({
|
|
671
681
|
error: 'RESOURCE_NOT_AVAILABLE',
|
|
672
682
|
message: 'This resource is not available to the agent.',
|
|
673
|
-
});
|
|
683
|
+
}, Date.now() - startedAt));
|
|
674
684
|
}
|
|
675
685
|
|
|
676
686
|
const output = await callOpenApiSchema({
|
|
@@ -693,7 +703,7 @@ export function prepareApiBasedTools(
|
|
|
693
703
|
userTimeZone,
|
|
694
704
|
});
|
|
695
705
|
|
|
696
|
-
return stringifyToolOutput(processedOutput);
|
|
706
|
+
return stringifyToolOutput(attachDurationMs(processedOutput, Date.now() - startedAt));
|
|
697
707
|
},
|
|
698
708
|
};
|
|
699
709
|
}
|
package/dist/apiBasedTools.js
CHANGED
|
@@ -432,6 +432,12 @@ function callOpenApiSchema(params) {
|
|
|
432
432
|
function stringifyToolOutput(output) {
|
|
433
433
|
return YAML.stringify(output === undefined ? EMPTY_HANDLER_RESPONSE_ERROR : output);
|
|
434
434
|
}
|
|
435
|
+
function attachDurationMs(output, durationMs) {
|
|
436
|
+
if (output !== null && typeof output === 'object' && !Array.isArray(output)) {
|
|
437
|
+
return Object.assign(Object.assign({}, output), { durationMs });
|
|
438
|
+
}
|
|
439
|
+
return { result: output, durationMs };
|
|
440
|
+
}
|
|
435
441
|
export function prepareApiBasedTools(adminforth, hiddenResourceIds = []) {
|
|
436
442
|
const apiBasedTools = {};
|
|
437
443
|
const openApiSchemas = adminforth.openApi.registeredSchemas;
|
|
@@ -451,11 +457,12 @@ export function prepareApiBasedTools(adminforth, hiddenResourceIds = []) {
|
|
|
451
457
|
input_schema: schema.request_schema,
|
|
452
458
|
agent: schema.agent,
|
|
453
459
|
call: (...args_1) => __awaiter(this, [...args_1], void 0, function* ({ adminUser, adminuser, abortSignal, inputs, userTimeZone, acceptLanguage } = {}) {
|
|
460
|
+
const startedAt = Date.now();
|
|
454
461
|
if (isHiddenResourceCall(hiddenResourceIdSet, inputs)) {
|
|
455
|
-
return stringifyToolOutput({
|
|
462
|
+
return stringifyToolOutput(attachDurationMs({
|
|
456
463
|
error: 'RESOURCE_NOT_AVAILABLE',
|
|
457
464
|
message: 'This resource is not available to the agent.',
|
|
458
|
-
});
|
|
465
|
+
}, Date.now() - startedAt));
|
|
459
466
|
}
|
|
460
467
|
const output = yield callOpenApiSchema({
|
|
461
468
|
adminforth,
|
|
@@ -475,7 +482,7 @@ export function prepareApiBasedTools(adminforth, hiddenResourceIds = []) {
|
|
|
475
482
|
toolName,
|
|
476
483
|
userTimeZone,
|
|
477
484
|
});
|
|
478
|
-
return stringifyToolOutput(processedOutput);
|
|
485
|
+
return stringifyToolOutput(attachDurationMs(processedOutput, Date.now() - startedAt));
|
|
479
486
|
}),
|
|
480
487
|
};
|
|
481
488
|
}
|