Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix: preserve nested router runtime id (#14474)

YuTengjingead5631babc6
diff --git a/packages/model-runtime/src/core/RouterRuntime/createRuntime.test.ts b/packages/model-runtime/src/core/RouterRuntime/createRuntime.test.ts
index 533ba25a342..eb0b4234ff9 100644
--- a/packages/model-runtime/src/core/RouterRuntime/createRuntime.test.ts
+++ b/packages/model-runtime/src/core/RouterRuntime/createRuntime.test.ts
@@ -1159,5 +1159,45 @@ describe('createRouterRuntime', () => {
expect(constructorOptions[0].apiKey).toBe('default-api-key');
});
+
+ it('should preserve inherited runtime id across nested router runtimes', async () => {
+ const constructorOptions: any[] = [];
+
+ class LeafRuntime implements LobeRuntimeAI {
+ constructor(options: any) {
+ constructorOptions.push(options);
+ }
+ chat = vi.fn().mockResolvedValue('response');
+ }
+
+ const InnerRuntime = createRouterRuntime({
+ id: 'deepseek',
+ routers: [
+ {
+ apiType: 'deepseek',
+ models: ['deepseek-v4-pro'],
+ options: {},
+ runtime: LeafRuntime as any,
+ },
+ ],
+ });
+
+ const OuterRuntime = createRouterRuntime({
+ id: 'lobehub',
+ routers: [
+ {
+ apiType: 'deepseek',
+ models: ['deepseek-v4-pro'],
+ options: {},
+ runtime: InnerRuntime as any,
+ },
+ ],
+ });
+
+ const runtime = new OuterRuntime();
+ await runtime.chat({ messages: [], model: 'deepseek-v4-pro', temperature: 0.7 });
+
+ expect(constructorOptions[0]).toEqual(expect.objectContaining({ id: 'lobehub' }));
+ });
});
});
diff --git a/packages/model-runtime/src/core/RouterRuntime/createRuntime.ts b/packages/model-runtime/src/core/RouterRuntime/createRuntime.ts
index 6c7ed23d0c7..83137ff2ed7 100644
--- a/packages/model-runtime/src/core/RouterRuntime/createRuntime.ts
+++ b/packages/model-runtime/src/core/RouterRuntime/createRuntime.ts
@@ -196,7 +196,7 @@ export const createRouterRuntime = ({
// Save configuration without creating runtimes
this._routers = routers;
this._params = params;
- this._id = id;
+ this._id = options.id ?? id;
}
/**