Skip to content

Commit 2640588

Browse files
committed
feat: add @objectstack/service-ai dependency and auto-register AIServicePlugin in Serve command
1 parent d609f4d commit 2640588

3 files changed

Lines changed: 22 additions & 16 deletions

File tree

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@objectstack/plugin-hono-server": "workspace:*",
4646
"@objectstack/rest": "workspace:*",
4747
"@objectstack/runtime": "workspace:^",
48+
"@objectstack/service-ai": "workspace:*",
4849
"@objectstack/spec": "workspace:*",
4950
"@oclif/core": "^4.10.3",
5051
"bundle-require": "^5.1.0",

packages/cli/src/commands/serve.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -243,22 +243,6 @@ export default class Serve extends Command {
243243
// No translations and no explicit i18n plugin — this is fine, kernel fallback works
244244
}
245245

246-
// 3c. Auto-register AIServicePlugin if not already present
247-
const hasAiPlugin = plugins.some(
248-
(p: any) => p.name === 'com.objectstack.service-ai'
249-
|| p.constructor?.name === 'AIServicePlugin'
250-
);
251-
if (!hasAiPlugin) {
252-
try {
253-
const aiPkg = '@objectstack/service-ai';
254-
const { AIServicePlugin } = await import(/* webpackIgnore: true */ aiPkg);
255-
await kernel.use(new AIServicePlugin());
256-
trackPlugin('AIService');
257-
} catch {
258-
// @objectstack/service-ai not installed — skip
259-
}
260-
}
261-
262246
// Add HTTP server plugin BEFORE config plugins so that the
263247
// http-server service is available for any plugin that needs it
264248
// during init/start (e.g. AuthPlugin).
@@ -334,6 +318,24 @@ export default class Serve extends Command {
334318
}
335319
}
336320

321+
// 4. Auto-register AIServicePlugin if not already loaded by config plugins.
322+
// Registered AFTER Dispatcher so that the ai:routes hook listener is
323+
// already in place when AIServicePlugin.start() fires the hook.
324+
const hasAIPlugin = plugins.some(
325+
(p: any) => p.name === 'com.objectstack.service-ai'
326+
|| p.constructor?.name === 'AIServicePlugin'
327+
);
328+
if (!hasAIPlugin) {
329+
try {
330+
const aiPkg = '@objectstack/service-ai';
331+
const { AIServicePlugin } = await import(/* webpackIgnore: true */ aiPkg);
332+
await kernel.use(new AIServicePlugin());
333+
trackPlugin('AIService');
334+
} catch {
335+
// @objectstack/service-ai not installed — AI features unavailable
336+
}
337+
}
338+
337339
// ── Studio UI ─────────────────────────────────────────────────
338340
// In dev mode, Studio UI is enabled by default (use --no-ui to disable).
339341
// Always serves the pre-built dist/ — no Vite dev server, no extra port.

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)