forked from NVIDIA/NemoClaw
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmanaged-tool-gateway.ts
More file actions
55 lines (48 loc) · 1.82 KB
/
Copy pathmanaged-tool-gateway.ts
File metadata and controls
55 lines (48 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
import { existsSync, readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
export type ManagedToolGatewayEntry = {
service: string;
config: Record<string, unknown>;
envKey: string;
envValue: string;
};
export type ManagedToolGatewayMatrix = Record<string, ManagedToolGatewayEntry>;
export function loadManagedToolGatewayMatrix(): ManagedToolGatewayMatrix {
const scriptDir = dirname(fileURLToPath(import.meta.url));
const candidates = [
process.env.NEMOCLAW_HERMES_TOOL_GATEWAY_MATRIX_PATH,
join(scriptDir, "hermes-managed-tool-gateway-matrix.json"),
join(scriptDir, "../hermes-managed-tool-gateway-matrix.json"),
join(scriptDir, "../../../scripts/hermes-managed-tool-gateway-matrix.json"),
].filter((candidate): candidate is string => Boolean(candidate));
for (const candidate of candidates) {
if (!existsSync(candidate)) continue;
return JSON.parse(readFileSync(candidate, "utf8")) as ManagedToolGatewayMatrix;
}
throw new Error("Hermes managed tool gateway matrix not found");
}
export function applyManagedToolConfig(
config: Record<string, unknown>,
entryConfig: Record<string, unknown>,
): void {
for (const [section, sectionValue] of Object.entries(entryConfig)) {
if (
sectionValue &&
typeof sectionValue === "object" &&
!Array.isArray(sectionValue) &&
config[section] &&
typeof config[section] === "object" &&
!Array.isArray(config[section])
) {
config[section] = {
...(config[section] as Record<string, unknown>),
...(sectionValue as Record<string, unknown>),
};
} else {
config[section] = sectionValue;
}
}
}