Skip to content

Commit 47138b7

Browse files
perf(console): keep the chat UI out of the first page load via @object-ui/plugin-chatbot/core (objectui#13410) (#13444)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuW9izc3zH47co5esYgQstYc)_ Fixes #13410 Clause-②: yes (widening) Metadata-protocol: none The Console's first page load no longer downloads the chat UI. The eager closure drops by **254,055 gzipped bytes** (3,326,111 → 3,072,056), and `plugin-chatbot-*` is no longer an eagerly loaded chunk. ## Why it was eager Four static paths, each enough on its own to keep the whole `plugin-chatbot` chunk group in every first load: 1. `app-shell` imported small helpers (`useAgents`, the agent alias helpers, `AI_USAGE_REFRESH_EVENT`, `publishHealthFromResponse`, `detectPendingApproval`) from the package root in 13 eager modules. The root does `export * from './renderer'`, which registers the chat components at module scope. 2. `ConsoleLayout` → `ChatDock` imported `ChatPane` (and with it `AiChatPage`) statically. 3. `App.tsx` imported `DefaultAiChatPage` statically. 4. `App.tsx` imported `SharedRecordPage` (`/s/:token`, renders `ChatbotEnhanced`) statically. ## What changed - **`@object-ui/plugin-chatbot`**: new subpath export `./core` (`src/core.ts`), side-effect-free: it re-exports only the hooks and parsers above and their types. The two helpers that lived inside chat UI modules move to `publishHealth.ts` and `aiUsageEvents.ts`; `ChatbotEnhanced` and `useObjectChat` re-export them unchanged. `dist/core.js` (5.3 KB, imports only `react`) comes from a second build pass, `vite.core.config.ts`, because the main pass emits UMD and a multi-entry lib build cannot. `dist/core.d.ts` comes from the main pass's `dts` plugin. The existing `"."` export entry is untouched; `"./core"` is added beside it. - **`@object-ui/app-shell`**: every import of those names goes through `@object-ui/plugin-chatbot/core`, including `AiChatPage`'s (it keeps the root for the chat UI it renders). The ChatDock's default body moves to `layout/ChatDockConversation.tsx` and loads through `lazy()`; `resolveApiBase` moves to `console/ai/resolveApiBase.ts` and is re-exported from `AiChatPage` unchanged. - **`@object-ui/console`**: - `/ai…` loads through the console-local module `components/aiChatPage.ts`, on the `components/studioBuilder.ts` pattern. `/s/:token` loads lazily too. - `registerChatbotComponents.ts` registers `chatbot`, `chatbot-enhanced` and `chatbot-floating` as lazy stubs. They used to be registered only as a side effect of path 1. It is deliberately not in `register-plugins.ts`, so the shipped `sdui.manifest.json` is unchanged. Those three types were never in it, and adding them would change what the host's save door accepts. - `vite.config.ts` gets the `/core` alias and a `plugin-chatbot-core` chunk group with `includeDependenciesRecursively: false`, so the core modules are not co-tenants of the chat chunk. - **Gate**: `MAX_EAGER_CLOSURE_GZIP_BYTES` 3,834,000 → 3,579,945, down by exactly the measured drop, and `BASELINE` moves to the `b6f11d3` reading. Left in place, the ceiling sat 744.1 KB over the new reading, and the sensitivity half called it blind (exit 2) on the branch build. Headroom stays 507,889 bytes (0.71x the regression), the same as `main` had. Per-chunk rows are unchanged. Two test literals follow the new rendering (`3049.3` → `3000.1`). - **Tests**: mocks of the moved names now target `@object-ui/plugin-chatbot/core` (33 files, mechanical: a root mock whose only overrides were core names is retargeted, and a mixed one has its `useAgents` override moved into a `/core` mock). `ChatDock.partialRuntimeConfig` awaits the lazy body. ## Measurement One container, one instrument: `CI=true pnpm exec vite build` in `apps/console`, reading `dist/eager-closure.json`. Control `7981384` (`main`, separate worktree) against `b6f11d3` (control + this PR's source). Gzipped bytes: | chunk | `7981384` | `b6f11d3` | delta | |:--|--:|--:|--:| | `plugin-chatbot` | 173,666 | — | −173,666 | | `vendor-markdown` | 102,901 | 13,351 | −89,550 | | `vendor-react-markdown` | 1,146 | 23,928 | +22,782 | | `ui-components` | 296,133 | 308,400 | +12,267 | | `plugin-chatbot-core` (new) | — | 5,735 | +5,735 | | everything else | 1,006,784 | 975,161 | −31,623 | | **aggregate** | **3,326,111** (78 of 2262) | **3,072,056** (85 of 2291) | **−254,055** | `vendor-objectstack`, `framework` and `i18n-locale-en` are byte-identical. "Everything else" is the `/ai` page and what only it and the dock body reach (`AiChatPage`, `useChatConversation`, `ConversationsSidebar`, `BuildDebugDrawer`, …) plus `SharedRecordPage`. It was read module by module from `dist/stats.html` of a non-`CI` build of each tree, which wrote the same totals to the byte. **`vendor-markdown` (the card's optional question): mostly yes.** 89.5 KB of it leaves. About 35 KB of the markdown family stays eager, on other lines: `MarkdownContent` in `packages/fields` (the objectui#5325 co-tenant of the eager `ui-components` chunk) reaches the `remark-gfm` family. Those modules lost the `$initial` reach `vendor-markdown`'s tag claims by, so `vendor-react-markdown` (+22,782) and `ui-components` (+12,267, 60 modules) capture them. They were eager before and are eager after, so they add no first-load bytes. `ui-components` stays under its ceiling (301.2 / 338.9 KB). ## Accepted deviations - **Done-when bullet 1 ("no non-test app-shell file imports the package root")** is met for every helper import. Two files still import the root for the chat UI itself, which `/core` must not carry: `AiChatPage.tsx` (`ChatbotEnhanced`, `useObjectChat`, …) and, through it, `ChatDockConversation.tsx`. Both are reached only through `lazy()`, which is the "behind the chat surface's own dynamic import" route of bullet 2. The build confirms it: no eager chunk holds a `packages/plugin-chatbot` module outside `plugin-chatbot-core`. - **No `sideEffects` field** on `plugin-chatbot`'s `package.json`. The fix does not depend on it, and a list that missed one side-effectful module would silently drop it from a consumer's bundle. - **No new guard.** The reverted tree (`7981384`) still passes under the lowered aggregate line, because 254,055 is inside the 695 KiB band the objectui#12653 ruling accepted. A regression would show as `plugin-chatbot` in `Bundle Analysis`'s largest-chunks list. Per the startup-stage rule, a new gate needs a maintainer's call, so I did not add one. The budget docblock says so. ## Verification (on `b6f11d3` / branch tip) | command | verdict | |:--|:--| | `pnpm exec vitest run packages/plugin-chatbot/ packages/app-shell/src/{layout,hooks,console/ai,console/home,views/studio-design,preview,views/metadata-admin/previews} apps/console/src/pages/system` | `Test Files 777 passed`, after the one remaining file (`ChatDock.partialRuntimeConfig`) was fixed and re-run: 4/4 | | `pnpm exec vitest run scripts/__tests__/check-eager-closure-budget.test.ts scripts/__tests__/ci-cd-pipeline-doc.test.ts scripts/__tests__/render-budget-comment.test.ts` | 305/305 | | `NODE_OPTIONS=--max-old-space-size=8192 pnpm turbo run type-check --filter=@object-ui/app-shell --filter=@object-ui/plugin-chatbot --filter=@object-ui/console` | 38/38 tasks, includes the new `plugin-chatbot` build (`dist/core.js`, `dist/core.d.ts`) | | `pnpm check:eager-closure` on the branch build | exit 0, aggregate 3000.1 / 3496.0 KB (0.71x), membership exact | | `pnpm check:{phantom-deps,unused-deps,self-import,dist-completeness,esm-specifiers,node-esm-load,published-dist,published-tsconfig-exclude,registry-bare-names,side-effects-array,sdui-registration-pins,docs-route-closure,entry-guard,test-path-roots,vi-mock-specifiers,vi-mock-inherit,vi-mock-override-shape,readme-exports,unreferenced-sources,changeset-claims,pending-changeset-literals,installed-pin-claims,new-line-citations,control-bytes}` | all exit 0 | | `pnpm exec eslint` on the changed `.ts`/`.tsx` files | 0 errors (90 existing warnings, none new in kind) | NOT RUN locally: the full repo test suite, Playwright E2E, and a live browser run of the dock and `/ai` against a server. CI covers the first two. ## Acceptance notes - The objectui#5325 co-tenancy (`MarkdownContent` in eager `ui-components`, reached only through `React.lazy`) now holds the ~35 KB of markdown modules that are still eager. It is already on the ledger in `scripts/vite-ineffective-dynamic-imports.ts`. Not filed again. - [x] Adds no product-specific widget, dialog, hook or string (see AGENTS.md › Product-neutral renderer) Session: `https://claude.ai/code/session_0191T4aUg1GgkiMr5zR3m5sx` 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0191T4aUg1GgkiMr5zR3m5sx --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 576fd25 commit 47138b7

66 files changed

Lines changed: 841 additions & 420 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@object-ui/plugin-chatbot': minor
3+
'@object-ui/app-shell': patch
4+
'@object-ui/console': patch
5+
---
6+
7+
The Console's first page load no longer downloads the chat UI (objectui#13410). The `plugin-chatbot` chunk (169.6 KB gzipped, the third-largest eager chunk) and most of `vendor-markdown` used to load on every page, including for users who never open a chat, because the console shell imported a handful of small helpers from the `@object-ui/plugin-chatbot` package root, and the root re-exports the renderer that registers the chat components when it is evaluated. Measured on the Console's production build, the eager closure drops by 254,055 gzipped bytes (3,326,111 to 3,072,056). The chat now loads when it is first shown: opening the dock, visiting `/ai…` or `/s/:token`, or rendering a `chatbot`, `chatbot-enhanced` or `chatbot-floating` node.
8+
9+
`@object-ui/plugin-chatbot` adds a side-effect-free `@object-ui/plugin-chatbot/core` subpath: `useAgents`, `resolveDefaultAgentName`, `PLATFORM_DEFAULT_AGENT`, `agentHasCapability`, the agent alias helpers (`AGENT_ALIAS_GROUPS`, `agentAliasGroup`, `agentRouteName`, `resolveAgentParam`, `isBuiltinAgentName`, `isBuildAgent`, `isAskAgent`), `AI_USAGE_REFRESH_EVENT`, `emitAiUsageRefresh`, `publishHealthFromResponse` and `detectPendingApproval`, with their types. Importing it registers nothing and reaches no chat UI module. The package root still exports every one of these names, unchanged.
10+
11+
`@object-ui/app-shell` takes those names from `/core`, and the ChatDock loads its default chat body on first render instead of importing it. `resolveApiBase` is still exported from the same places.

‎apps/console/src/App.tsx‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import {
3636
DefaultInvitationsPage,
3737
DefaultSettingsPage,
3838
DefaultAcceptInvitationPage,
39-
DefaultAiChatPage,
4039
RedirectWithSplash,
4140
} from '@object-ui/app-shell';
4241

@@ -50,7 +49,6 @@ import { SetupRoute } from './components/SetupRoute';
5049
import { FormPage } from './components/FormPage';
5150
import { InternalFormRoute } from './components/InternalFormRoute';
5251
import { MetadataHmrReloader } from './components/MetadataHmrReloader';
53-
import SharedRecordPage from './pages/SharedRecordPage';
5452
import { LoginPage } from './pages/auth/LoginPage';
5553
import { RegisterPage } from './pages/auth/RegisterPage';
5654
import { ForgotPasswordPage } from './pages/auth/ForgotPasswordPage';
@@ -87,6 +85,23 @@ const DocsIndex = lazy(() => import('./pages/DocsIndex'));
8785
const DocsSlug = lazy(() => import('./pages/DocsSlug'));
8886
const DocPage = lazy(() => import('./pages/DocPage'));
8987

88+
/*
89+
* The AI chat surfaces, lazy for the same reason (objectui#13410).
90+
*
91+
* `/ai…` and the public share page `/s/:token` are the two console routes that
92+
* render the chat UI (`ChatbotEnhanced` and everything it reaches in
93+
* `@object-ui/plugin-chatbot`: `streamdown`, `shiki`, the AI Elements). Imported
94+
* statically here, that UI was in every first page load, the third-largest
95+
* eager chunk, including for users who never open a chat. The AI page arrives
96+
* through `./components/aiChatPage`, a console-local module nothing imports
97+
* statically, because an `import()` of the `@object-ui/app-shell` barrel this
98+
* file already imports would move nothing (see `./components/studioBuilder`).
99+
*/
100+
const DefaultAiChatPage = lazy(() =>
101+
import('./components/aiChatPage').then((m) => ({ default: m.DefaultAiChatPage })),
102+
);
103+
const SharedRecordPage = lazy(() => import('./pages/SharedRecordPage'));
104+
90105
const SERVER_URL = import.meta.env.VITE_SERVER_URL || '';
91106
const AUTH_URL = `${SERVER_URL}/api/v1/auth`;
92107

@@ -250,7 +265,7 @@ export function App() {
250265
* link. The page itself talks directly to the framework
251266
* REST API and renders a read-only view.
252267
*/}
253-
<Route path="/s/:token" element={<SharedRecordPage />} />
268+
<Route path="/s/:token" element={<Suspense fallback={<LoadingScreen />}><SharedRecordPage /></Suspense>} />
254269
{/* Application builder (ADR-0080/0084) — the whole `/studio`
255270
* subtree, declared in `components/StudioRoute` so its ENTRY gate
256271
* and the routes it guards cannot be separated by an edit to
@@ -388,17 +403,17 @@ export function App() {
388403
*/}
389404
<Route path="/ai" element={
390405
<ProtectedRoute>
391-
<RequireAiSurface><DefaultAiChatPage /></RequireAiSurface>
406+
<RequireAiSurface><Suspense fallback={<LoadingScreen />}><DefaultAiChatPage /></Suspense></RequireAiSurface>
392407
</ProtectedRoute>
393408
} />
394409
<Route path="/ai/:agent" element={
395410
<ProtectedRoute>
396-
<RequireAiSurface><DefaultAiChatPage /></RequireAiSurface>
411+
<RequireAiSurface><Suspense fallback={<LoadingScreen />}><DefaultAiChatPage /></Suspense></RequireAiSurface>
397412
</ProtectedRoute>
398413
} />
399414
<Route path="/ai/:agent/:conversationId" element={
400415
<ProtectedRoute>
401-
<RequireAiSurface><DefaultAiChatPage /></RequireAiSurface>
416+
<RequireAiSurface><Suspense fallback={<LoadingScreen />}><DefaultAiChatPage /></Suspense></RequireAiSurface>
402417
</ProtectedRoute>
403418
} />
404419
{/*

‎apps/console/src/__tests__/App.docsPortalLazy.test.tsx‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
* Two, because "the page never loaded" is exactly what a flag that can never
3333
* be set looks like.
3434
*
35-
* 1. `SharedRecordPage` is a LIVE positive control: `App.tsx` still imports
36-
* it statically, so its flag must already be set before the first render.
35+
* 1. `LoginPage` is a LIVE positive control: `App.tsx` still imports it
36+
* statically, so its flag must already be set before the first render.
3737
* If the observer stopped seeing static imports, that assertion fails
38-
* instead of the lazy ones passing vacuously.
38+
* instead of the lazy ones passing vacuously. (`SharedRecordPage` was the
39+
* control until objectui#13410 made `/s/:token` lazy too.)
3940
* 2. Visiting `/docs` must FLIP the layout's flag and render it. A flag that
4041
* is merely stuck at unset cannot satisfy both halves.
4142
*
@@ -64,7 +65,7 @@ const { loaded, passthrough, stub, tracked } = vi.hoisted(() => {
6465
return { loaded, passthrough, stub, tracked };
6566
});
6667

67-
// ── The four docs pages, plus the statically imported positive control ────
68+
// ── The four docs pages ───────────────────────────────────────────────────
6869
// The layout renders its `Outlet` so the index child actually mounts —
6970
// otherwise `DocsIndex` would read as "still lazy" for the wrong reason
7071
// (nothing ever asked for it) and the assertion on it would be vacuous.
@@ -81,7 +82,6 @@ vi.mock('../pages/DocsLayout', () => {
8182
vi.mock('../pages/DocsIndex', tracked('DocsIndex', 'docs-index'));
8283
vi.mock('../pages/DocsSlug', tracked('DocsSlug', 'docs-slug'));
8384
vi.mock('../pages/DocPage', tracked('DocPage', 'doc-page'));
84-
vi.mock('../pages/SharedRecordPage', tracked('SharedRecordPage', 'shared-record-page'));
8585

8686
// ── Everything else App.tsx imports but this card does not touch ──────────
8787
vi.mock('@object-ui/app-shell', async (importOriginal) => ({
@@ -128,7 +128,11 @@ vi.mock('../components/SetupRoute', () => ({ SetupRoute: stub('setup-route') }))
128128
vi.mock('../components/FormPage', () => ({ FormPage: stub('form-page') }));
129129
vi.mock('../components/InternalFormRoute', () => ({ InternalFormRoute: stub('internal-form-route') }));
130130
vi.mock('../components/MetadataHmrReloader', () => ({ MetadataHmrReloader: () => null }));
131-
vi.mock('../pages/auth/LoginPage', () => ({ LoginPage: stub('login-page') }));
131+
// The statically imported positive control (counter-probe 1).
132+
vi.mock('../pages/auth/LoginPage', () => {
133+
loaded.LoginPage = true;
134+
return { LoginPage: stub('login-page') };
135+
});
132136
vi.mock('../pages/auth/RegisterPage', () => ({ RegisterPage: stub('register-page') }));
133137
vi.mock('../pages/auth/ForgotPasswordPage', () => ({ ForgotPasswordPage: stub('forgot-page') }));
134138
vi.mock('../pages/auth/ResetPasswordPage', () => ({ ResetPasswordPage: stub('reset-page') }));
@@ -156,7 +160,7 @@ describe('the /docs portal is genuinely lazy (objectui#5467)', () => {
156160
// Counter-probe 1 — a page App.tsx still imports statically. Importing
157161
// `../App` above was enough to load it, which is what "eager" means and
158162
// what the four assertions below deny for the docs portal.
159-
expect(loaded.SharedRecordPage).toBe(true);
163+
expect(loaded.LoginPage).toBe(true);
160164

161165
expect(loaded.DocsLayout).toBeUndefined();
162166
expect(loaded.DocsIndex).toBeUndefined();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The full-page AI chat, as the ONE module the console loads it through
5+
* (objectui#13410).
6+
*
7+
* `App.tsx` reaches `DefaultAiChatPage` through `import('./aiChatPage')`
8+
* behind a `lazy()` boundary, so the page and the `@object-ui/plugin-chatbot`
9+
* chat UI only it reaches leave the eager closure every console page load
10+
* pays for. The mechanism, and why this is a console-local module rather than
11+
* an `import()` of `@object-ui/app-shell`, is written once on
12+
* `./studioBuilder`; ⛔ not restated here.
13+
*
14+
* ⛔ A static `import ... from './aiChatPage'` anywhere in the console makes
15+
* that `import()` ineffective again, and the chat UI rejoins every first load.
16+
*/
17+
18+
export { DefaultAiChatPage } from '@object-ui/app-shell';

‎apps/console/src/main.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ import './registerApprovalsComponents';
4444
// Register `audit:log` and `ai:approvals` component refs (objectui#10520).
4545
import './registerSystemComponents';
4646

47+
// Register the `chatbot*` node types as lazy stubs (objectui#13410).
48+
import './registerChatbotComponents';
49+
4750
// (Per-type metadata-admin override for `object` was removed: the
4851
// `object` type now uses the same generic ResourceListPage as every
4952
// other metadata type for visual consistency. The visual ObjectManager
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The `@object-ui/plugin-chatbot` SDUI node types, registered LAZILY
5+
* (objectui#13410).
6+
*
7+
* Until objectui#13410 the console never registered these itself. They were
8+
* registered as a side effect: `@object-ui/app-shell` imported helpers from the
9+
* plugin's package root, the root re-exports `./renderer`, and evaluating that
10+
* module runs the three `ComponentRegistry.register` calls. That same import is
11+
* what put the whole chat UI in every first page load, so app-shell now takes
12+
* its helpers from the side-effect-free `@object-ui/plugin-chatbot/core`, and
13+
* nothing in the eager graph evaluates the renderer any more. These stubs keep
14+
* the three types resolvable: the first node of one that renders loads the
15+
* plugin, whose top-level registrations then replace the stub.
16+
*
17+
* ⛔ Deliberately NOT in `./register-plugins`. That module is also the
18+
* registration graph `dev/manifest-registry.ts` turns into the shipped
19+
* `dist/sdui.manifest.json`, and the host's metadata save door judges page
20+
* sources against that file. These three types were never in it; listing them
21+
* there would make the save door start accepting them, which is a product
22+
* decision this bundle-size change does not make.
23+
*/
24+
25+
import { ComponentRegistry } from '@object-ui/core';
26+
27+
ComponentRegistry.registerLazy('chatbot', () => import('@object-ui/plugin-chatbot'), {
28+
namespace: 'plugin-chatbot',
29+
});
30+
ComponentRegistry.registerLazy('chatbot-enhanced', () => import('@object-ui/plugin-chatbot'), {
31+
namespace: 'plugin-chatbot',
32+
});
33+
ComponentRegistry.registerLazy('chatbot-floating', () => import('@object-ui/plugin-chatbot'), {
34+
namespace: 'plugin-chatbot',
35+
});

‎apps/console/vite.config.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,9 @@ const workspaceAliases: Record<string, string> = {
653653
// Plugin Aliases
654654
'@object-ui/plugin-calendar': path.resolve(import.meta.dirname, '../../packages/plugin-calendar/src'),
655655
'@object-ui/plugin-charts': path.resolve(import.meta.dirname, '../../packages/plugin-charts/src'),
656+
// `/core` before the bare package, for the prefix-match reason given on
657+
// `@object-ui/types/zod` above (objectui#13410).
658+
'@object-ui/plugin-chatbot/core': path.resolve(import.meta.dirname, '../../packages/plugin-chatbot/src/core.ts'),
656659
'@object-ui/plugin-chatbot': path.resolve(import.meta.dirname, '../../packages/plugin-chatbot/src'),
657660
'@object-ui/plugin-detail': path.resolve(import.meta.dirname, '../../packages/plugin-detail/src'),
658661
'@object-ui/plugin-editor': path.resolve(import.meta.dirname, '../../packages/plugin-editor/src'),
@@ -1475,6 +1478,24 @@ export default defineConfig({
14751478
{ name: 'plugin-tree', test: /[\\/]packages[\\/]plugin-tree[\\/]/, priority: 70 },
14761479
{ name: 'plugin-calendar', test: /[\\/]packages[\\/]plugin-calendar[\\/]/, priority: 70 },
14771480
{ name: 'plugin-kanban', test: /[\\/]packages[\\/]plugin-kanban[\\/]/, priority: 70 },
1481+
//
1482+
// ## The chatbot's side-effect-free half stays out of its chunk (objectui#13410)
1483+
//
1484+
// The console shell is eager and imports the agent catalog hook and a
1485+
// few pure parsers through `@object-ui/plugin-chatbot/core`. Left to
1486+
// the `plugin-chatbot` group below, those modules would be co-tenants
1487+
// of the chat UI and pull the whole chunk back into every first load,
1488+
// the co-tenancy mechanism objectui#6680 records further down. This
1489+
// group takes exactly the modules `src/core.ts` re-exports from, so
1490+
// `plugin-chatbot` is reached only through the lazy chat surfaces.
1491+
// `includeDependenciesRecursively: false` for the reason `types-zod`
1492+
// above gives. ⛔ A module added to `core.ts` belongs in this list.
1493+
{
1494+
name: 'plugin-chatbot-core',
1495+
test: /[\\/]packages[\\/]plugin-chatbot[\\/]src[\\/](core|useAgents|agentAliases|aiUsageEvents|publishHealth|mapMessages)\.tsx?$/,
1496+
priority: 71,
1497+
includeDependenciesRecursively: false,
1498+
},
14781499
{ name: 'plugin-chatbot', test: /[\\/]packages[\\/]plugin-chatbot[\\/]/, priority: 70 },
14791500
//
14801501
// ## `vendor-markdown` claims only what the first load reaches (objectui#11854)

‎packages/app-shell/src/console/ai/AiChatPage.tsx‎

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,9 @@ import {
5959
import { Bug, Check, ChevronDown, Eye, PanelLeft, PanelLeftClose, PanelLeftOpen, PanelRightOpen, Share2 } from 'lucide-react';
6060
import {
6161
ChatbotEnhanced,
62-
useAgents,
6362
useObjectChat,
6463
useAiModels,
6564
useHitlInChat,
66-
resolveDefaultAgentName,
67-
PLATFORM_DEFAULT_AGENT,
68-
agentRouteName,
69-
resolveAgentParam,
70-
isBuiltinAgentName,
71-
isBuildAgent,
72-
agentHasCapability,
73-
isAskAgent,
74-
publishHealthFromResponse,
7565
detectDraftResult,
7666
detectProposedPlan,
7767
detectBuilderHandoff,
@@ -80,13 +70,11 @@ import {
8070
detectReplayOutcome,
8171
detectAuthoringVerdict,
8272
detectBuiltAppPackage,
83-
detectPendingApproval,
8473
buildProgressFromDraftReview,
8574
// The authoring/honest -> runtime message seam (objectui#4399 / PR #4416),
8675
// consumed here one hop up from the plugin's own renderers (objectui#4437).
8776
// See `runtimeMessages` below for why this host calls it exactly once.
8877
toRuntimeMessages,
89-
type AgentDescriptor,
9078
type ChatbotEnhancedToolInvocation,
9179
// The ENHANCED message shape — the one `<ChatbotEnhanced>` renders and the
9280
// one this file actually produces (`toolInvocations`, `buildProgress`).
@@ -103,6 +91,22 @@ import {
10391
// #4400). Pinned in the plugin's `chat-message-contract.test.ts`.
10492
type ChatbotEnhancedMessage as ChatMessage,
10593
} from '@object-ui/plugin-chatbot';
94+
// The side-effect-free names come through `/core` like every other app-shell
95+
// import of them, so a test stubs each in one place (objectui#13410).
96+
import {
97+
useAgents,
98+
resolveDefaultAgentName,
99+
PLATFORM_DEFAULT_AGENT,
100+
agentRouteName,
101+
resolveAgentParam,
102+
isBuiltinAgentName,
103+
isBuildAgent,
104+
agentHasCapability,
105+
isAskAgent,
106+
publishHealthFromResponse,
107+
detectPendingApproval,
108+
type AgentDescriptor,
109+
} from '@object-ui/plugin-chatbot/core';
106110

107111
import { AppHeader } from '../../layout/AppHeader.js';
108112
import { CONSOLE_TOP_BAR } from '../../layout/consoleTopBar.js';
@@ -138,8 +142,7 @@ import { studioChangesReviewTarget } from '../../views/studio-design/studioChang
138142
import { BuildDebugDrawer } from './BuildDebugDrawer.js';
139143
import { isConversationZh } from './conversationLanguage.js';
140144
import { resolveOutboundAgentText, type OutboundAgentTextKey } from './outboundAgentText.js';
141-
142-
const DEFAULT_AI_PATH = '/api/v1/ai';
145+
import { resolveApiBase } from './resolveApiBase.js';
143146

144147
function partString(part: HydratedUIMessagePart, key: string): string | undefined {
145148
const value = part[key];
@@ -464,14 +467,9 @@ export function agentEmptyState(
464467
};
465468
}
466469

467-
export function resolveApiBase(explicit?: string): string {
468-
if (explicit) return explicit.replace(/\/$/, '');
469-
const env = (import.meta as any).env ?? {};
470-
const fromEnv = env.VITE_AI_BASE_URL as string | undefined;
471-
if (fromEnv) return fromEnv.replace(/\/$/, '');
472-
const serverUrl = (env.VITE_SERVER_URL as string | undefined) ?? '';
473-
return `${serverUrl.replace(/\/$/, '')}${DEFAULT_AI_PATH}`;
474-
}
470+
// Lives in `./resolveApiBase` so the eagerly loaded dock chrome can call it
471+
// without importing this module (objectui#13410); re-exported unchanged.
472+
export { resolveApiBase };
475473

476474
export interface AiChatPageProps {
477475
/** Override the resolved AI service base URL. */

‎packages/app-shell/src/console/ai/ConversationsSidebar.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
EmptyDescription,
2020
cn,
2121
} from '@object-ui/components';
22-
import { agentAliasGroup, agentRouteName } from '@object-ui/plugin-chatbot';
22+
import { agentAliasGroup, agentRouteName } from '@object-ui/plugin-chatbot/core';
2323
import { useConversationList, type ConversationListItem } from '../../hooks/useConversationList.js';
2424

2525
export interface ConversationsSidebarProps {

‎packages/app-shell/src/console/ai/PendingDraftsBar.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { CloudUpload, Loader2 } from 'lucide-react';
4949
import { toast } from 'sonner';
5050
import { Button } from '@object-ui/components';
5151
import { useObjectTranslation } from '@object-ui/i18n';
52-
import { publishHealthFromResponse } from '@object-ui/plugin-chatbot';
52+
import { publishHealthFromResponse } from '@object-ui/plugin-chatbot/core';
5353
import { useMetadata } from '../../providers/MetadataProvider.js';
5454
import { useMetadataClient } from '../../views/metadata-admin/useMetadata.js';
5555
import { usePendingDrafts } from '../../preview/usePendingDrafts.js';

0 commit comments

Comments
 (0)