Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

defer the service-definitions route's imports to the call site (#7567)

[._.]/ Adam Eivy659126317c24
diff --git a/server/routes/providers.js b/server/routes/providers.js
index d708d08407..a51f089a7a 100644
--- a/server/routes/providers.js
+++ b/server/routes/providers.js
@@ -22,8 +22,6 @@ import {
refreshServiceCatalog,
updateService,
} from '../services/providerServices.js';
-import { presentServiceDefinition } from '../lib/providerServiceInstances.js';
-import { SERVICE_DEFINITIONS } from '../lib/serviceDefinitions.js';
import { Router } from 'express';
import { asyncHandler, ServerError } from '../lib/errorHandler.js';
import { testVision, runVisionTestSuite, checkVisionHealth } from '../services/visionTest.js';
@@ -519,10 +517,17 @@ export function createPortOSProviderRoutes(aiToolkit) {
* is obtained. Code-only data — no instance, no credential — so it is
* cacheable for the process lifetime. Declared above `/services/:slug` by
* name rather than position: its own segment can never be read as a slug.
+ * Deferred imports like the catalog handler below: a suite that mocks
+ * `providerServices.js` would otherwise instantiate the instance/definition
+ * subtree through this route file alone (server/AGENTS.md "Import scoping").
*/
- router.get('/service-definitions', (_req, res) => {
+ router.get('/service-definitions', asyncHandler(async (_req, res) => {
+ const [{ SERVICE_DEFINITIONS }, { presentServiceDefinition }] = await Promise.all([
+ import('../lib/serviceDefinitions.js'),
+ import('../lib/providerServiceInstances.js'),
+ ]);
res.json({ definitions: SERVICE_DEFINITIONS.map(presentServiceDefinition) });
- });
+ }));
// Create an instance from a definition. Nothing is probed and no route is
// minted; the catalog starts `unknown` until the explicit refresh below.