Skip to content

Commit bacb33a

Browse files
fix: keep Bedrock live smoke on Bedrock runtime (#99607)
* fix: preserve Bedrock live API providers * fix: derive Bedrock smoke region from AWS config * fix: honor Bedrock discovery region in smoke * fix: keep Bedrock live smoke on Bedrock runtime --------- Co-authored-by: openclaw-clownfish[bot] <280122609+openclaw-clownfish[bot]@users.noreply.github.com>
1 parent c0a0c22 commit bacb33a

3 files changed

Lines changed: 616 additions & 17 deletions

File tree

packages/ai/src/api-registry.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
// LLM Runtime tests cover api registry behavior.
2-
import { describe, expect, it, vi } from "vitest";
2+
import { afterEach, describe, expect, it, vi } from "vitest";
33
import {
44
createApiRegistry,
55
createAssistantMessageEventStream,
66
createLlmRuntime,
77
type Model,
88
} from "./index.js";
9+
import {
10+
getApiProvider,
11+
streamSimple as streamSimpleDefault,
12+
unregisterApiProviders,
13+
} from "./internal/default-runtime.js";
914

1015
const TEST_SOURCE_ID = "test:llm-runtime-api-registry";
1116
const emptyStream = () => createAssistantMessageEventStream();
@@ -24,6 +29,10 @@ const model = {
2429
} satisfies Model;
2530

2631
describe("LLM API registry", () => {
32+
afterEach(() => {
33+
unregisterApiProviders(TEST_SOURCE_ID);
34+
});
35+
2736
it("rejects mismatched model API calls", () => {
2837
const registry = createApiRegistry();
2938
registry.registerApiProvider(
@@ -56,6 +65,27 @@ describe("LLM API registry", () => {
5665
);
5766
});
5867

68+
it("shares default runtime registrations across duplicated module instances", async () => {
69+
const duplicateRuntime = (await import(
70+
["./internal/default-runtime.js", "duplicate-runtime"].join("?")
71+
)) as typeof import("./internal/default-runtime.js");
72+
const streamSimple = vi.fn(emptyStream);
73+
duplicateRuntime.registerApiProvider(
74+
{
75+
api: "test-api",
76+
stream: emptyStream,
77+
streamSimple,
78+
},
79+
TEST_SOURCE_ID,
80+
);
81+
82+
expect(getApiProvider("test-api")).toBeDefined();
83+
84+
streamSimpleDefault(model, { messages: [] });
85+
86+
expect(streamSimple).toHaveBeenCalledOnce();
87+
});
88+
5989
it("unregisters every provider owned by one source", () => {
6090
const registry = createApiRegistry();
6191
for (const api of ["test-api", "test-api-2"] as const) {

packages/ai/src/internal/default-runtime.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,32 @@
22
// facade (src/llm). Deliberately not part of the public package API: external
33
// consumers create isolated runtimes via createLlmRuntime(); exporting these
44
// from the root barrel would reintroduce the mutable process-global registry.
5-
import { createApiRegistry } from "../api-registry.js";
6-
import { createLlmRuntime } from "../stream.js";
5+
import { createApiRegistry, type ApiRegistry } from "../api-registry.js";
6+
import { createLlmRuntime, type LlmRuntime } from "../stream.js";
77

8-
export const defaultApiRegistry = createApiRegistry();
9-
export const defaultLlmRuntime = createLlmRuntime(defaultApiRegistry);
8+
type DefaultRuntimeState = {
9+
registry: ApiRegistry;
10+
runtime: LlmRuntime;
11+
};
12+
13+
const DEFAULT_RUNTIME_KEY = Symbol.for("openclaw.ai.defaultRuntime");
14+
15+
function resolveDefaultRuntime(): DefaultRuntimeState {
16+
const globalStore = globalThis as Record<PropertyKey, unknown>;
17+
if (Object.hasOwn(globalStore, DEFAULT_RUNTIME_KEY)) {
18+
return globalStore[DEFAULT_RUNTIME_KEY] as DefaultRuntimeState;
19+
}
20+
const registry = createApiRegistry();
21+
const runtime = createLlmRuntime(registry);
22+
const state = { registry, runtime };
23+
globalStore[DEFAULT_RUNTIME_KEY] = state;
24+
return state;
25+
}
26+
27+
const defaultRuntime = resolveDefaultRuntime();
28+
29+
export const defaultApiRegistry = defaultRuntime.registry;
30+
export const defaultLlmRuntime = defaultRuntime.runtime;
1031

1132
export const {
1233
registerApiProvider,

0 commit comments

Comments
 (0)