@adminforth/agent 1.26.12 → 1.26.14
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 +15 -46
- package/build.log +1 -1
- package/dist/apiBasedTools.js +9 -31
- package/package.json +1 -1
package/apiBasedTools.ts
CHANGED
|
@@ -46,9 +46,11 @@ type GetResourceDataToolResponse = {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
type DateTimeColumnType = AdminForthDataTypes.DATETIME | AdminForthDataTypes.TIME;
|
|
49
|
+
type InternalApiOriginProvider = {
|
|
50
|
+
getInternalApiOrigin?: () => string | undefined;
|
|
51
|
+
};
|
|
49
52
|
|
|
50
53
|
const DEFAULT_USER_TIME_ZONE = 'UTC';
|
|
51
|
-
const DEFAULT_REQUEST_PROTOCOL = process.env.NODE_ENV === 'production' ? 'https' : 'http';
|
|
52
54
|
|
|
53
55
|
function getInputString(inputs: Record<string, unknown> | undefined, key: string) {
|
|
54
56
|
const value = inputs?.[key];
|
|
@@ -580,22 +582,6 @@ const HEADERS_NOT_FORWARDED_TO_API_TOOL = new Set([
|
|
|
580
582
|
'upgrade',
|
|
581
583
|
]);
|
|
582
584
|
|
|
583
|
-
function getHeaderValue(
|
|
584
|
-
headers: Partial<HttpExtra>['headers'] | undefined,
|
|
585
|
-
headerName: string,
|
|
586
|
-
) {
|
|
587
|
-
const normalizedHeaderName = headerName.toLowerCase();
|
|
588
|
-
const value = Object.entries(headers ?? {}).find(
|
|
589
|
-
([name]) => name.toLowerCase() === normalizedHeaderName,
|
|
590
|
-
)?.[1];
|
|
591
|
-
|
|
592
|
-
if (typeof value !== 'string') {
|
|
593
|
-
return undefined;
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
return value.split(',')[0].trim();
|
|
597
|
-
}
|
|
598
|
-
|
|
599
585
|
function isAbsoluteHttpUrl(value: string) {
|
|
600
586
|
try {
|
|
601
587
|
const url = new URL(value);
|
|
@@ -605,42 +591,25 @@ function isAbsoluteHttpUrl(value: string) {
|
|
|
605
591
|
}
|
|
606
592
|
}
|
|
607
593
|
|
|
608
|
-
function getRequestOrigin(httpExtra?: Partial<HttpExtra>) {
|
|
609
|
-
const requestUrl = httpExtra?.requestUrl;
|
|
610
|
-
|
|
611
|
-
if (requestUrl && isAbsoluteHttpUrl(requestUrl)) {
|
|
612
|
-
return new URL(requestUrl).origin;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
const host = getHeaderValue(httpExtra?.headers, 'x-forwarded-host')
|
|
616
|
-
?? getHeaderValue(httpExtra?.headers, 'host');
|
|
617
|
-
|
|
618
|
-
if (!host) {
|
|
619
|
-
return undefined;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
const protocol = getHeaderValue(httpExtra?.headers, 'x-forwarded-proto') ?? DEFAULT_REQUEST_PROTOCOL;
|
|
623
|
-
return `${protocol}://${host}`;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
594
|
function resolveOpenApiRequestUrl(params: {
|
|
627
|
-
|
|
595
|
+
adminforth: IAdminForth;
|
|
628
596
|
path: string;
|
|
629
597
|
toolName: string;
|
|
630
598
|
}) {
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
}
|
|
599
|
+
const internalApiOrigin = (params.adminforth.express as InternalApiOriginProvider)
|
|
600
|
+
.getInternalApiOrigin?.();
|
|
634
601
|
|
|
635
|
-
|
|
602
|
+
if (internalApiOrigin) {
|
|
603
|
+
const path = isAbsoluteHttpUrl(params.path)
|
|
604
|
+
? `${new URL(params.path).pathname}${new URL(params.path).search}`
|
|
605
|
+
: params.path;
|
|
636
606
|
|
|
637
|
-
|
|
638
|
-
throw new Error(
|
|
639
|
-
`Tool "${params.toolName}" has relative OpenAPI path "${params.path}" but request host header is unavailable.`,
|
|
640
|
-
);
|
|
607
|
+
return new URL(path, internalApiOrigin).toString();
|
|
641
608
|
}
|
|
642
609
|
|
|
643
|
-
|
|
610
|
+
throw new Error(
|
|
611
|
+
`Tool "${params.toolName}" cannot call OpenAPI path "${params.path}" because internal API origin is unavailable.`,
|
|
612
|
+
);
|
|
644
613
|
}
|
|
645
614
|
|
|
646
615
|
function createToolRequestHeaders(
|
|
@@ -736,7 +705,7 @@ async function callOpenApiSchema(params: {
|
|
|
736
705
|
userTimeZone,
|
|
737
706
|
);
|
|
738
707
|
const requestUrl = resolveOpenApiRequestUrl({
|
|
739
|
-
|
|
708
|
+
adminforth,
|
|
740
709
|
path: schema.path,
|
|
741
710
|
toolName,
|
|
742
711
|
});
|
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 207,
|
|
41
|
+
sent 207,954 bytes received 558 bytes 417,024.00 bytes/sec
|
|
42
42
|
total size is 205,644 speedup is 0.99
|
package/dist/apiBasedTools.js
CHANGED
|
@@ -16,7 +16,6 @@ import YAML from 'yaml';
|
|
|
16
16
|
dayjs.extend(utc);
|
|
17
17
|
dayjs.extend(timezone);
|
|
18
18
|
const DEFAULT_USER_TIME_ZONE = 'UTC';
|
|
19
|
-
const DEFAULT_REQUEST_PROTOCOL = process.env.NODE_ENV === 'production' ? 'https' : 'http';
|
|
20
19
|
function getInputString(inputs, key) {
|
|
21
20
|
const value = inputs === null || inputs === void 0 ? void 0 : inputs[key];
|
|
22
21
|
return typeof value === 'string' && value ? value : undefined;
|
|
@@ -395,15 +394,6 @@ const HEADERS_NOT_FORWARDED_TO_API_TOOL = new Set([
|
|
|
395
394
|
'transfer-encoding',
|
|
396
395
|
'upgrade',
|
|
397
396
|
]);
|
|
398
|
-
function getHeaderValue(headers, headerName) {
|
|
399
|
-
var _a;
|
|
400
|
-
const normalizedHeaderName = headerName.toLowerCase();
|
|
401
|
-
const value = (_a = Object.entries(headers !== null && headers !== void 0 ? headers : {}).find(([name]) => name.toLowerCase() === normalizedHeaderName)) === null || _a === void 0 ? void 0 : _a[1];
|
|
402
|
-
if (typeof value !== 'string') {
|
|
403
|
-
return undefined;
|
|
404
|
-
}
|
|
405
|
-
return value.split(',')[0].trim();
|
|
406
|
-
}
|
|
407
397
|
function isAbsoluteHttpUrl(value) {
|
|
408
398
|
try {
|
|
409
399
|
const url = new URL(value);
|
|
@@ -413,28 +403,16 @@ function isAbsoluteHttpUrl(value) {
|
|
|
413
403
|
return false;
|
|
414
404
|
}
|
|
415
405
|
}
|
|
416
|
-
function getRequestOrigin(httpExtra) {
|
|
417
|
-
var _a, _b;
|
|
418
|
-
const requestUrl = httpExtra === null || httpExtra === void 0 ? void 0 : httpExtra.requestUrl;
|
|
419
|
-
if (requestUrl && isAbsoluteHttpUrl(requestUrl)) {
|
|
420
|
-
return new URL(requestUrl).origin;
|
|
421
|
-
}
|
|
422
|
-
const host = (_a = getHeaderValue(httpExtra === null || httpExtra === void 0 ? void 0 : httpExtra.headers, 'x-forwarded-host')) !== null && _a !== void 0 ? _a : getHeaderValue(httpExtra === null || httpExtra === void 0 ? void 0 : httpExtra.headers, 'host');
|
|
423
|
-
if (!host) {
|
|
424
|
-
return undefined;
|
|
425
|
-
}
|
|
426
|
-
const protocol = (_b = getHeaderValue(httpExtra === null || httpExtra === void 0 ? void 0 : httpExtra.headers, 'x-forwarded-proto')) !== null && _b !== void 0 ? _b : DEFAULT_REQUEST_PROTOCOL;
|
|
427
|
-
return `${protocol}://${host}`;
|
|
428
|
-
}
|
|
429
406
|
function resolveOpenApiRequestUrl(params) {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
407
|
+
var _a, _b;
|
|
408
|
+
const internalApiOrigin = (_b = (_a = params.adminforth.express).getInternalApiOrigin) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
409
|
+
if (internalApiOrigin) {
|
|
410
|
+
const path = isAbsoluteHttpUrl(params.path)
|
|
411
|
+
? `${new URL(params.path).pathname}${new URL(params.path).search}`
|
|
412
|
+
: params.path;
|
|
413
|
+
return new URL(path, internalApiOrigin).toString();
|
|
436
414
|
}
|
|
437
|
-
|
|
415
|
+
throw new Error(`Tool "${params.toolName}" cannot call OpenAPI path "${params.path}" because internal API origin is unavailable.`);
|
|
438
416
|
}
|
|
439
417
|
function createToolRequestHeaders(httpExtra, userTimeZone) {
|
|
440
418
|
var _a;
|
|
@@ -499,7 +477,7 @@ function callOpenApiSchema(params) {
|
|
|
499
477
|
const method = schema.method.toUpperCase();
|
|
500
478
|
const body = normalizeDateTimeInputsToUtc(((_a = inputs !== null && inputs !== void 0 ? inputs : httpExtra === null || httpExtra === void 0 ? void 0 : httpExtra.body) !== null && _a !== void 0 ? _a : {}), adminforth, userTimeZone);
|
|
501
479
|
const requestUrl = resolveOpenApiRequestUrl({
|
|
502
|
-
|
|
480
|
+
adminforth,
|
|
503
481
|
path: schema.path,
|
|
504
482
|
toolName,
|
|
505
483
|
});
|