Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

const {
startBedrockRuntimeAdapterFromEnv,
} = require("../dist/lib/inference/bedrock-runtime-adapter");
import { startBedrockRuntimeAdapterFromEnv } from "../dist/lib/inference/bedrock-runtime-adapter.js";

try {
startBedrockRuntimeAdapterFromEnv();
Expand Down
18 changes: 18 additions & 0 deletions src/lib/inference/bedrock-runtime-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
createOpenAiChatCompletion,
streamOpenAiChatCompletion,
} from "./bedrock-runtime-adapter";
import { isLocalAdapterProcess } from "./local-adapter-lifecycle";

const servers: http.Server[] = [];

Expand Down Expand Up @@ -382,6 +383,23 @@ describe("Bedrock Runtime OpenAI adapter", () => {
expect(body.error.message).toContain("Could not load credentials");
});

it("spawns the typed .mts launcher entrypoint", () => {
expect(__test.getAdapterScriptPath().endsWith("bedrock-runtime-adapter.mts")).toBe(true);
});

it("recognizes adapter processes launched from the old and new launcher filenames", () => {
const needle = __test.adapterProcessNeedle;
expect(
isLocalAdapterProcess(4321, needle, () => "node /opt/nemoclaw/scripts/bedrock-runtime-adapter.mts"),
).toBe(true);
expect(
isLocalAdapterProcess(4321, needle, () => "node /opt/nemoclaw/scripts/bedrock-runtime-adapter.js"),
).toBe(true);
expect(
isLocalAdapterProcess(4321, needle, () => "node /opt/nemoclaw/scripts/openrouter-runtime-adapter-entry.js"),
).toBe(false);
});

it("includes forwarded AWS environment in the adapter reuse hash", () => {
const savedContainerCredentials = process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI;
const savedSharedCredentials = process.env.AWS_SHARED_CREDENTIALS_FILE;
Expand Down
10 changes: 7 additions & 3 deletions src/lib/inference/bedrock-runtime-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,22 +316,24 @@ function loadPersistedPid(): number | null {
return loadLocalAdapterPid(PID_PATH);
}

const ADAPTER_PROCESS_NEEDLE = "bedrock-runtime-adapter";

function isAdapterProcess(pid: number | null | undefined): boolean {
return isLocalAdapterProcess(pid, "bedrock-runtime-adapter.js", runCapture);
return isLocalAdapterProcess(pid, ADAPTER_PROCESS_NEEDLE, runCapture);
}

function killStaleAdapter(): void {
killLocalAdapterPid({
pidPath: PID_PATH,
processNeedle: "bedrock-runtime-adapter.js",
processNeedle: ADAPTER_PROCESS_NEEDLE,
run,
runCapture,
});
}

function getAdapterScriptPath(): string {
const scriptsDir = typeof SCRIPTS === "string" ? SCRIPTS : path.join(process.cwd(), "scripts");
return path.join(scriptsDir, "bedrock-runtime-adapter.js");
return path.join(scriptsDir, "bedrock-runtime-adapter.mts");
Comment thread
laitingsheng marked this conversation as resolved.
Outdated
}

function copyAwsEnv(extra: Record<string, string>): void {
Expand Down Expand Up @@ -478,4 +480,6 @@ export function getCompatibleAnthropicCredentialForBedrock(): string | null {

export const __test = {
adapterCredentialHash,
adapterProcessNeedle: ADAPTER_PROCESS_NEEDLE,
getAdapterScriptPath,
};
2 changes: 1 addition & 1 deletion test/e2e/live/bedrock-runtime-compatible-anthropic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ function stopBedrockAdapter(home: string): void {
}

function isBedrockAdapterProcess(pid: number): boolean {
const expectedScript = "bedrock-runtime-adapter.js";
const expectedScript = "bedrock-runtime-adapter";
try {
const cmdline = fs.readFileSync(`/proc/${pid}/cmdline`, "utf8").replaceAll("\0", " ");
if (cmdline.includes(expectedScript)) return true;
Expand Down
Loading