@adminforth/agent 1.24.10 → 1.24.12
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
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type IAdminForth,
|
|
6
6
|
type IAdminForthHttpResponse,
|
|
7
7
|
type IHttpServer,
|
|
8
|
+
type IRegisteredApiSchema,
|
|
8
9
|
} from 'adminforth';
|
|
9
10
|
import dayjs from 'dayjs';
|
|
10
11
|
import timezone from 'dayjs/plugin/timezone.js';
|
|
@@ -467,6 +468,25 @@ function endpointPathToToolName(path: string) {
|
|
|
467
468
|
.replace(/^_+|_+$/g, '');
|
|
468
469
|
}
|
|
469
470
|
|
|
471
|
+
function stripAdminApiPrefix(path: string, adminforth: IAdminForth) {
|
|
472
|
+
const configuredBaseUrl = adminforth.config.baseUrl || '';
|
|
473
|
+
const normalizedBaseUrl = configuredBaseUrl.endsWith('/')
|
|
474
|
+
? configuredBaseUrl.slice(0, -1)
|
|
475
|
+
: configuredBaseUrl;
|
|
476
|
+
const apiPrefix = `${normalizedBaseUrl}/adminapi/v1`;
|
|
477
|
+
|
|
478
|
+
if (path.startsWith(apiPrefix)) {
|
|
479
|
+
const strippedPath = path.slice(apiPrefix.length);
|
|
480
|
+
return strippedPath.startsWith('/') ? strippedPath : `/${strippedPath}`;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
return path;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function openApiSchemaPathToToolName(path: string, adminforth: IAdminForth) {
|
|
487
|
+
return endpointPathToToolName(stripAdminApiPrefix(path, adminforth));
|
|
488
|
+
}
|
|
489
|
+
|
|
470
490
|
export async function formatApiBasedToolCall(params: {
|
|
471
491
|
adminforth: IAdminForth;
|
|
472
492
|
adminUser?: AdminUser;
|
|
@@ -739,15 +759,10 @@ export function prepareApiBasedTools(adminforth: IAdminForth): Record<string, Ap
|
|
|
739
759
|
const captureServer: IHttpServer = {
|
|
740
760
|
setupSpaServer() {},
|
|
741
761
|
endpoint: ((options: EndpointWithSchemas) => {
|
|
742
|
-
const normalizedResponseSchema = options.response_schema ?? options.responce_schema;
|
|
743
|
-
if (!options.request_schema && !normalizedResponseSchema) {
|
|
744
|
-
return;
|
|
745
|
-
}
|
|
746
|
-
|
|
747
762
|
capturedEndpoints.push({
|
|
748
763
|
...options,
|
|
749
|
-
response_schema:
|
|
750
|
-
normalizedResponseSchema,
|
|
764
|
+
response_schema: options.response_schema ?? options.responce_schema,
|
|
765
|
+
normalizedResponseSchema: options.response_schema ?? options.responce_schema,
|
|
751
766
|
});
|
|
752
767
|
}) as IHttpServer['endpoint'],
|
|
753
768
|
};
|
|
@@ -758,15 +773,30 @@ export function prepareApiBasedTools(adminforth: IAdminForth): Record<string, Ap
|
|
|
758
773
|
const capturedEndpointsByToolName = Object.fromEntries(
|
|
759
774
|
capturedEndpoints.map((endpoint) => [endpointPathToToolName(endpoint.path), endpoint]),
|
|
760
775
|
);
|
|
776
|
+
const openApiSchemas = adminforth.openApi.registeredSchemas.filter(
|
|
777
|
+
(schema) => schema.request_schema || schema.response_schema,
|
|
778
|
+
);
|
|
779
|
+
const openApiSchemasByToolName = new Map<string, IRegisteredApiSchema>();
|
|
761
780
|
|
|
762
|
-
for (const
|
|
763
|
-
const toolName =
|
|
781
|
+
for (const schema of openApiSchemas) {
|
|
782
|
+
const toolName = openApiSchemaPathToToolName(schema.path, adminforth);
|
|
783
|
+
openApiSchemasByToolName.set(toolName, schema);
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
for (const [toolName, schema] of openApiSchemasByToolName.entries()) {
|
|
787
|
+
const endpoint = capturedEndpointsByToolName[toolName];
|
|
764
788
|
apiBasedTools[toolName] = {
|
|
765
|
-
description:
|
|
766
|
-
input_schema:
|
|
767
|
-
input_schma:
|
|
768
|
-
output_schema:
|
|
789
|
+
description: schema.description,
|
|
790
|
+
input_schema: schema.request_schema,
|
|
791
|
+
input_schma: schema.request_schema,
|
|
792
|
+
output_schema: schema.response_schema,
|
|
769
793
|
call: async ({ adminUser, adminuser, inputs, httpExtra, userTimeZone } = {}) => {
|
|
794
|
+
if (!endpoint) {
|
|
795
|
+
throw new Error(
|
|
796
|
+
`Tool "${toolName}" is defined in OpenAPI but has no callable AdminForth endpoint handler.`,
|
|
797
|
+
);
|
|
798
|
+
}
|
|
799
|
+
|
|
770
800
|
const output = await callCapturedEndpoint({
|
|
771
801
|
adminforth,
|
|
772
802
|
endpoint,
|
package/build.log
CHANGED
|
@@ -38,5 +38,5 @@ custom/skills/fetch_data/SKILL.md
|
|
|
38
38
|
custom/skills/mutate_data/
|
|
39
39
|
custom/skills/mutate_data/SKILL.md
|
|
40
40
|
|
|
41
|
-
sent 201,
|
|
41
|
+
sent 201,341 bytes received 562 bytes 403,806.00 bytes/sec
|
|
42
42
|
total size is 199,037 speedup is 0.99
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
<header class="border-b border-black/5 px-3 py-2 text-[0.7rem] font-semibold uppercase tracking-[0.22em] text-gray-500 dark:border-white/10 dark:text-gray-400">
|
|
50
50
|
{{ section.label }}
|
|
51
51
|
</header>
|
|
52
|
-
<div class="grid grid-cols-[auto,1fr] gap-x-3 gap-y-1 px-3 py-3 font-mono text-xs leading-5 text-gray-700 dark:text-gray-200">
|
|
52
|
+
<div class="select-all grid grid-cols-[auto,1fr] gap-x-3 gap-y-1 px-3 py-3 font-mono text-xs leading-5 text-gray-700 dark:text-gray-200">
|
|
53
53
|
<template v-for="line in section.lines" :key="`${section.label}-${line.number}`">
|
|
54
|
-
<span class="
|
|
54
|
+
<span class=" text-[0.7rem] text-gray-400 dark:text-gray-500">{{ line.number }}</span>
|
|
55
55
|
<span class="whitespace-pre-wrap break-words">{{ line.content || ' ' }}</span>
|
|
56
56
|
</template>
|
|
57
57
|
</div>
|
package/dist/apiBasedTools.js
CHANGED
|
@@ -286,6 +286,21 @@ function endpointPathToToolName(path) {
|
|
|
286
286
|
.replace(/[^a-zA-Z0-9_]+/g, '_')
|
|
287
287
|
.replace(/^_+|_+$/g, '');
|
|
288
288
|
}
|
|
289
|
+
function stripAdminApiPrefix(path, adminforth) {
|
|
290
|
+
const configuredBaseUrl = adminforth.config.baseUrl || '';
|
|
291
|
+
const normalizedBaseUrl = configuredBaseUrl.endsWith('/')
|
|
292
|
+
? configuredBaseUrl.slice(0, -1)
|
|
293
|
+
: configuredBaseUrl;
|
|
294
|
+
const apiPrefix = `${normalizedBaseUrl}/adminapi/v1`;
|
|
295
|
+
if (path.startsWith(apiPrefix)) {
|
|
296
|
+
const strippedPath = path.slice(apiPrefix.length);
|
|
297
|
+
return strippedPath.startsWith('/') ? strippedPath : `/${strippedPath}`;
|
|
298
|
+
}
|
|
299
|
+
return path;
|
|
300
|
+
}
|
|
301
|
+
function openApiSchemaPathToToolName(path, adminforth) {
|
|
302
|
+
return endpointPathToToolName(stripAdminApiPrefix(path, adminforth));
|
|
303
|
+
}
|
|
289
304
|
export function formatApiBasedToolCall(params) {
|
|
290
305
|
return __awaiter(this, void 0, void 0, function* () {
|
|
291
306
|
var _a;
|
|
@@ -478,25 +493,30 @@ export function prepareApiBasedTools(adminforth) {
|
|
|
478
493
|
const captureServer = {
|
|
479
494
|
setupSpaServer() { },
|
|
480
495
|
endpoint: ((options) => {
|
|
481
|
-
var _a;
|
|
482
|
-
|
|
483
|
-
if (!options.request_schema && !normalizedResponseSchema) {
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
capturedEndpoints.push(Object.assign(Object.assign({}, options), { response_schema: normalizedResponseSchema, normalizedResponseSchema }));
|
|
496
|
+
var _a, _b;
|
|
497
|
+
capturedEndpoints.push(Object.assign(Object.assign({}, options), { response_schema: (_a = options.response_schema) !== null && _a !== void 0 ? _a : options.responce_schema, normalizedResponseSchema: (_b = options.response_schema) !== null && _b !== void 0 ? _b : options.responce_schema }));
|
|
487
498
|
}),
|
|
488
499
|
};
|
|
489
500
|
adminforth.setupEndpoints(captureServer);
|
|
490
501
|
const apiBasedTools = {};
|
|
491
502
|
const capturedEndpointsByToolName = Object.fromEntries(capturedEndpoints.map((endpoint) => [endpointPathToToolName(endpoint.path), endpoint]));
|
|
492
|
-
|
|
493
|
-
|
|
503
|
+
const openApiSchemas = adminforth.openApi.registeredSchemas.filter((schema) => schema.request_schema || schema.response_schema);
|
|
504
|
+
const openApiSchemasByToolName = new Map();
|
|
505
|
+
for (const schema of openApiSchemas) {
|
|
506
|
+
const toolName = openApiSchemaPathToToolName(schema.path, adminforth);
|
|
507
|
+
openApiSchemasByToolName.set(toolName, schema);
|
|
508
|
+
}
|
|
509
|
+
for (const [toolName, schema] of openApiSchemasByToolName.entries()) {
|
|
510
|
+
const endpoint = capturedEndpointsByToolName[toolName];
|
|
494
511
|
apiBasedTools[toolName] = {
|
|
495
|
-
description:
|
|
496
|
-
input_schema:
|
|
497
|
-
input_schma:
|
|
498
|
-
output_schema:
|
|
512
|
+
description: schema.description,
|
|
513
|
+
input_schema: schema.request_schema,
|
|
514
|
+
input_schma: schema.request_schema,
|
|
515
|
+
output_schema: schema.response_schema,
|
|
499
516
|
call: (...args_1) => __awaiter(this, [...args_1], void 0, function* ({ adminUser, adminuser, inputs, httpExtra, userTimeZone } = {}) {
|
|
517
|
+
if (!endpoint) {
|
|
518
|
+
throw new Error(`Tool "${toolName}" is defined in OpenAPI but has no callable AdminForth endpoint handler.`);
|
|
519
|
+
}
|
|
500
520
|
const output = yield callCapturedEndpoint({
|
|
501
521
|
adminforth,
|
|
502
522
|
endpoint,
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
<header class="border-b border-black/5 px-3 py-2 text-[0.7rem] font-semibold uppercase tracking-[0.22em] text-gray-500 dark:border-white/10 dark:text-gray-400">
|
|
50
50
|
{{ section.label }}
|
|
51
51
|
</header>
|
|
52
|
-
<div class="grid grid-cols-[auto,1fr] gap-x-3 gap-y-1 px-3 py-3 font-mono text-xs leading-5 text-gray-700 dark:text-gray-200">
|
|
52
|
+
<div class="select-all grid grid-cols-[auto,1fr] gap-x-3 gap-y-1 px-3 py-3 font-mono text-xs leading-5 text-gray-700 dark:text-gray-200">
|
|
53
53
|
<template v-for="line in section.lines" :key="`${section.label}-${line.number}`">
|
|
54
|
-
<span class="
|
|
54
|
+
<span class=" text-[0.7rem] text-gray-400 dark:text-gray-500">{{ line.number }}</span>
|
|
55
55
|
<span class="whitespace-pre-wrap break-words">{{ line.content || ' ' }}</span>
|
|
56
56
|
</template>
|
|
57
57
|
</div>
|