diff --git a/.changeset/33933-knowledge-settings-with-service.md b/.changeset/33933-knowledge-settings-with-service.md new file mode 100644 index 00000000000..64fe6de0daa --- /dev/null +++ b/.changeset/33933-knowledge-settings-with-service.md @@ -0,0 +1,23 @@ +--- +'@objectstack/service-settings': patch +'@objectstack/service-knowledge': patch +'@objectstack/platform-objects': patch +--- + +fix(settings)!: the knowledge settings page and the AI page's embedder section appear only where the knowledge service is mounted + +Clause-②: no (narrowing) — narrowed: on a deployment that does not mount `KnowledgeServicePlugin` (every stock boot), `GET` / `PUT /api/settings/knowledge` and `POST /api/settings/knowledge/test` now answer `404 UNKNOWN_NAMESPACE`, where they served the Knowledge page; a write of an `ai.embedder_*` key (`embedder_provider`, `embedder_api_key`, `embedder_model`, `embedder_base_url`, `embedder_dimensions`, `embedder_batch_size`) now answers `400 UNKNOWN_KEY`, and `POST /api/settings/ai/test_embedder` answers that no handler is registered; the hub list no longer carries `knowledge`, and the Setup sidebar no longer carries `nav_settings_knowledge`. `builtinSettingsManifests` drops `knowledgeSettingsManifest`, and `aiSettingsManifest` drops its embedder section. +Metadata-protocol: none +Skills-docs: none — no skill under `skills/**` teaches the knowledge settings page or the `ai.embedder_*` keys; `skills/objectstack-ai` teaches wiring `KnowledgeServicePlugin`, which is unchanged. + + + +**BREAKING** for a deployment that does not mount the knowledge service: the knowledge base is not a default capability, so its settings are no longer offered by default. The Knowledge page, the AI page's Embedder section, their "Test connection" / "Test embedder" buttons and the Setup entry are now contributed by `@objectstack/service-knowledge` when `KnowledgeServicePlugin` is mounted beside `SettingsServicePlugin`, and only then. Values already stored under `knowledge.*` or `ai.embedder_*` stay in the database and are served again as soon as the service is mounted. + +The AI page's description no longer names the knowledge base, in every bundled locale. + +`@objectstack/service-settings` now exports `knowledgeSettingsManifest`, `knowledgeTestActionHandler`, `aiSettingsManifest`, `aiEmbedderSettingsSpecifiers`, `withAiEmbedderSection` and `aiTestEmbedderActionHandler` from its package entry, and its default `actionHandlers` map no longer registers `knowledge.test` or `ai.test_embedder`. `@objectstack/service-knowledge` depends on `@objectstack/service-settings` and declares the settings plugin in `optionalDependencies`, so the kernel inits it first. + +What to do: nothing, unless you configure an embedder or a knowledge backend from Setup. Then mount `KnowledgeServicePlugin` from `@objectstack/service-knowledge` (with a knowledge adapter plugin) beside `SettingsServicePlugin`; the page, the embedder section and the Setup entry come back with it. A host that passed its own `ai` manifest to `SettingsServicePlugin({ manifests })` adds `aiEmbedderSettingsSpecifiers` to it (or wraps it with `withAiEmbedderSection`) to keep the embedder keys. The embedder section joins only the bundled `ai` page, recognised as that very declaration; a host's own `ai` page (or one served through an option source) is left as it is, and the plugin logs a warning saying so. A host that passes its own `actionHandlers` to `SettingsServicePlugin` keeps a `knowledge` entry there only beside the knowledge manifest: without it the settings plugin refuses to register the handler for an unknown namespace at boot. + +Stored credentials: on a deployment that does not mount the knowledge service, `ai.embedder_api_key`, `knowledge.turso_auth_token` and `knowledge.ragflow_api_key` stay stored (as `sys_secret` handles) but no settings door serves, edits or clears them, and the AI page's reset clears declared keys only. To remove them, mount `KnowledgeServicePlugin` once and clear the keys from Setup, or delete their rows from `sys_platform_setting` (the `knowledge` namespace and the `ai.embedder_*` keys) and the `sys_secret` rows whose `id` those rows hold in `value_enc` (a `sec_` handle); until then the `sys_secret` orphan report may list them. diff --git a/docs/qa/platform-checklist/areas/platform-core.json b/docs/qa/platform-checklist/areas/platform-core.json index b43c584dd76..0b1d4ce3caa 100644 --- a/docs/qa/platform-checklist/areas/platform-core.json +++ b/docs/qa/platform-checklist/areas/platform-core.json @@ -640,7 +640,7 @@ "title": "The built-in apps a stock boot REGISTERS (Setup / Account) render every merged-nav destination; app-level and entry-level gates are enforced, not errored — and Studio's deliberate absence is asserted, never hunted", "since": "v15", "status": "active", - "revision": 19, + "revision": 20, "priority": "P0", "surface": "browser", "personas": [ @@ -663,9 +663,9 @@ "as admin, GET /api/v1/meta/app?id=setup and extract every merged nav destination — Setup is a SHELL of empty group anchors (packages/platform-objects/src/apps/setup.app.ts: group_overview/apps/people_org/access_control/approvals/configuration/diagnostics/integrations/advanced) filled by SETUP_NAV_CONTRIBUTIONS (setup-nav.contributions.ts) plus capability-plugin contributions (plugin-security Positions/Permission Sets, plugin-sharing Sharing Rules/Record Shares, plugin-approvals, plugin-webhooks)", "GET /api/v1/meta/app with NO query first and record the names actually served — a stock boot answers exactly showcase_app, setup, account. Then GET /api/v1/meta/app?id=account (account.app.ts — Profile + Inbox/Security/Developer groups). ⚠️ GET /api/v1/meta/app?id=studio answers 200 {\"items\":[]} on every stock boot and that is the expected result (knownGap): record the absence as an assertion and move on — do NOT install @objectstack/studio to make the step runnable", "as admin, hand-walk each destination in each app. At a window narrower than 1280 px a browser with no choice kept opens Setup and Account with the sidebar collapsed, and from 1280 px expanded (ui/packages/app-shell/src/layout/consoleSidebarRail.ts CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH, ruling 7069868269 on objectstack#36112); a reader's own collapse or expand is kept per browser, on each side of that width. Collapsed, the sidebar is hidden, with no icon column (ruling 6973617688 on objectstack#35062): press the expand button at the page header's left edge, or press Ctrl/⌘+B, which does the same (ruling 7074574380 on objectstack#36112), to put it back beside the page before expanding any group — or rest the pointer on the window's left edge to float the full menu over the page; the float folds back after each chosen entry, so float it again for the next destination. EXPAND every nav group first: some render collapsed by default — Setup's Advanced group and Account's Developer group declare `expanded: false` (packages/platform-objects/src/apps/setup.app.ts, account.app.ts), and QA run #24557 found Setup's Configuration group collapsed as well — so a walk that never expands them never reaches their entries. Then navigate, wait for render, SCREENSHOT FIRST, then read the DOM — assert no pageerror, no 'failed to load', no blank
, no 'no actions configured' placeholder", - "Setup detail: confirm each settings URL entry (nav_settings_* → /apps/setup/system/settings/) opens the settings namespace form — the 11 namespaces of a stock single-posture boot, localization/company/branding/auth/access_policy/mail/sms/storage/ai/knowledge/lifecycle: the nav_settings_* entries of packages/platform-objects/src/apps/setup-nav.contributions.ts, plus nav_settings_branding, which packages/services/service-settings/src/settings-service-plugin.ts contributes only where no organization wall stands, and Users / Organization / Business Units / Teams / Sessions / OAuth Applications render. User preferences and identity links are not Setup destinations: open a user's record page, /_console/apps/setup/sys_user/record/ID (a row click on the Users list opens a side panel at ?recordId=, which is not that page: take the id from the row or the panel), and confirm the user page's Preferences and Linked Accounts tabs (packages/platform-objects/src/pages/sys-user.page.ts#SysUserDetailPage) render that user's rows", + "Setup detail: confirm each settings URL entry (nav_settings_* → /apps/setup/system/settings/) opens the settings namespace form — the 10 namespaces of a stock single-posture boot, localization/company/branding/auth/access_policy/mail/sms/storage/ai/lifecycle: the nav_settings_* entries of packages/platform-objects/src/apps/setup-nav.contributions.ts, plus nav_settings_branding, which packages/services/service-settings/src/settings-service-plugin.ts contributes only where no organization wall stands (Knowledge, nav_settings_knowledge, is contributed by packages/services/service-knowledge/src/knowledge-settings-contribution.ts only where the knowledge service is mounted, which no stock app does), and Users / Organization / Business Units / Teams / Sessions / OAuth Applications render. User preferences and identity links are not Setup destinations: open a user's record page, /_console/apps/setup/sys_user/record/ID (a row click on the Users list opens a side panel at ?recordId=, which is not that page: take the id from the row or the panel), and confirm the user page's Preferences and Linked Accounts tabs (packages/platform-objects/src/pages/sys-user.page.ts#SysUserDetailPage) render that user's rows", "Studio detail is NOT walked from here — the app is not registered on a stock boot (knownGap), so there is no merged nav to render. Its metadata:resource lists and component surfaces (App Builder, All Metadata Types, Packages, API Console, Flow Runs, Public Forms) are reached through the console surface at /_console/studio// and are covered by area studio-authoring. What THIS item asserts about Studio is the absence itself, per clause 6", - "Account detail: confirm Profile (account:profile_card), Notifications (sys_inbox_message/mine), Approvals (nav_account_approvals, the approvals:inbox component, served as …/component/approvals/inbox — the Approvals Inbox, not the sys_approval_request grid; account.app.ts), Linked Accounts (sys_account), Active Sessions (sys_session/mine), API Keys (sys_api_key/mine), OAuth Applications (sys_oauth_application/mine) and Connect an Agent (nav_connect_agent) each render — 8 Account destinations and 47 Setup destinations for the admin on a stock single-org showcase boot, read from source after objectstack#34724 retired Setup › Packaged Actions (nav_packaged_actions; its switch moved onto the action in Studio); QA runs #32953 (at 5fb79bc0) and #33087 (at 8e3d4a54) read 48 before it (GET /api/v1/meta/app leaves, which match the nav source minus its gates). QA run #29877 read 46 at 589049b0, before Access policy (nav_settings_access_policy, the access_policy namespace) joined the Configuration group. Since QA run #28545's reading Setup's Packaged automation page retired under ADR-0146 D11, leaving Packaged Actions (nav_packaged_actions, automation:packaged-actions; #28785, itself retired by objectstack#34724), and its unfiltered Packages entry moved to Studio (#29547) (47 for #28927, 50 at eeec88d1 for QA run #28545, 48 re-measured at 3fd80337 for #28338, QA run #27481 read 44 and 8, QA run #24557 read 42 at 5b14b7f3, 45 on 2026-10-01, and #9453 recorded 43 and 7). Recount from the payload each run", + "Account detail: confirm Profile (account:profile_card), Notifications (sys_inbox_message/mine), Approvals (nav_account_approvals, the approvals:inbox component, served as …/component/approvals/inbox — the Approvals Inbox, not the sys_approval_request grid; account.app.ts), Linked Accounts (sys_account), Active Sessions (sys_session/mine), API Keys (sys_api_key/mine), OAuth Applications (sys_oauth_application/mine) and Connect an Agent (nav_connect_agent) each render — 8 Account destinations and 46 Setup destinations for the admin on a stock single-org showcase boot, read from source after #33933 took Knowledge (nav_settings_knowledge) out of the stock Setup tree (47 before it, after objectstack#34724 retired Setup › Packaged Actions, nav_packaged_actions, whose switch moved onto the action in Studio); QA runs #32953 (at 5fb79bc0) and #33087 (at 8e3d4a54) read 48 before objectstack#34724 (GET /api/v1/meta/app leaves, which match the nav source minus its gates). QA run #29877 read 46 at 589049b0, before Access policy (nav_settings_access_policy, the access_policy namespace) joined the Configuration group. Since QA run #28545's reading Setup's Packaged automation page retired under ADR-0146 D11, leaving Packaged Actions (nav_packaged_actions, automation:packaged-actions; #28785, itself retired by objectstack#34724), and its unfiltered Packages entry moved to Studio (#29547) (47 for #28927, 50 at eeec88d1 for QA run #28545, 48 re-measured at 3fd80337 for #28338, QA run #27481 read 44 and 8, QA run #24557 read 42 at 5b14b7f3, 45 on 2026-10-01, and #9453 recorded 43 and 7). Recount from the payload each run", "confirm the gated entries resolve to ABSENT-not-erroring for the admin: nav_organizations (requiresService org-scoping) is absent in single-org mode; nav_jwks Signing Keys is ABSENT for EVERY persona, admin included — the entry was removed in #7544 because sys_jwks declares apiEnabled:false, so its list answers OBJECT_API_DISABLED (404) for all callers and no permission gate could prune it; SSO Providers is absent unless OS_SSO_ENABLED (knownGap)", "sign in as the plain member: attempt to open Setup (app name setup) — capture the app-level refusal (App.requiredPermissions setup.access); open Account (declares no requiredPermissions) — capture it opening. Studio is not part of this comparison: it is absent for EVERY persona including the admin, so a member failing to reach it proves nothing about the gate (the same reasoning #7544 applied to nav_jwks)", "as the member, GET /api/v1/meta/app for a reachable app and confirm every manage_platform_settings-gated entry (API Keys, the manage_platform_settings settings URLs) is ABSENT from the member's payload — the server prunes, the client does not merely hide. JWKS is deliberately NOT in this list any more: it is absent for admins too, so finding it absent for a member proves nothing about the gate (#7544)", @@ -834,6 +834,12 @@ "date": "2026-11-22", "change": "steps[2]: Ctrl/⌘+B is a press on the expand / collapse button (ruling 7074574380 on #36112, which replaces the words '⌘B unchanged' of ruling 7069868269): it docks the collapsed sidebar beside the page as the reader's choice, a float included, and collapses a docked one; it no longer floats the menu, which floats only from the window's left edge. The walk is unchanged in substance. No clause changed. Read from source; not yet re-run by a QA run.", "ref": "#36347" + }, + { + "revision": 20, + "date": "2026-11-24", + "change": "steps[3] and steps[5] follow #33933: the knowledge settings page left the stock Setup tree. steps[3] lists the 10 namespaces of a stock single-posture boot (knowledge removed) and names where nav_settings_knowledge comes from now (packages/services/service-knowledge/src/knowledge-settings-contribution.ts, only where the knowledge service is mounted); steps[5] counts 46 Setup destinations, one fewer. No clause weakened. Read from source, not driven live", + "ref": "#33933" } ] }, @@ -842,7 +848,7 @@ "title": "Settings hub round-trip: a value saves, PERSISTS, reaches an observable consumer, audits, env-locks, tests honestly, and stores secrets as handles served MASKED — anonymous denied", "since": "v15", "status": "active", - "revision": 8, + "revision": 9, "priority": "P1", "surface": "mixed", "personas": [ @@ -852,7 +858,7 @@ "fixtures": { "app": "showcase", "requires": [ - "the 11 open-framework settings namespaces a stock boot serves: the 10 in builtinSettingsManifests (packages/services/service-settings/src/manifests: localization, company, branding, auth, access_policy, mail, sms, storage, ai, knowledge; access_policy is tenant-scoped, ADR-0069) PLUS lifecycle (5 specifiers), which is NOT in that aggregate — ObjectQLPlugin registers it at kernel:ready whenever a SettingsService is present (packages/objectql/src/lifecycle/lifecycle-settings.ts). Enumerating only the manifests directory undercounts by one. The stock showcase also env-pins one key: examples/app-showcase/.env sets OS_LOCALIZATION_CURRENCY=USD, so on every stock boot localization.currency reads source 'env', locked, the console shows Locked by env on Default currency, and a PUT of currency answers 409 SETTINGS_LOCKED. That is the env lock working (steps' env-lock leg), not leakage from the runner's shell; keep currency out of the round-trip and source-badge legs", + "the 10 open-framework settings namespaces a stock boot serves: the 9 in builtinSettingsManifests (packages/services/service-settings/src/manifests: localization, company, branding, auth, access_policy, mail, sms, storage, ai; access_policy is tenant-scoped, ADR-0069) PLUS lifecycle (5 specifiers), which is NOT in that aggregate — ObjectQLPlugin registers it at kernel:ready whenever a SettingsService is present (packages/objectql/src/lifecycle/lifecycle-settings.ts). Enumerating only the manifests directory undercounts by one. The stock showcase also env-pins one key: examples/app-showcase/.env sets OS_LOCALIZATION_CURRENCY=USD, so on every stock boot localization.currency reads source 'env', locked, the console shows Locked by env on Default currency, and a PUT of currency answers 409 SETTINGS_LOCKED. That is the env lock working (steps' env-lock leg), not leakage from the runner's shell; keep currency out of the round-trip and source-badge legs", "the settings service wired with a data engine so it swaps from in-memory to the sys_setting table, and with the sys_secret store + auditWriter (SettingsServicePlugin binds these on kernel:ready; the showcase stack mounts the engine)" ], "knownGaps": [ @@ -860,7 +866,7 @@ ] }, "steps": [ - "as admin, GET /api/settings — capture the visible manifests (the 11 open-framework namespaces above; the route is the SettingsService REST surface in settings-routes.ts)", + "as admin, GET /api/settings — capture the visible manifests (the 10 open-framework namespaces above, and no knowledge namespace: service-knowledge contributes it, with the ai embedder_* keys, only where it is mounted; the route is the SettingsService REST surface in settings-routes.ts)", "pick localization (an OBSERVABLE-CONSUMER namespace — packages/core/src/security/resolve-authz-context.ts reads localization.timezone/locale/currency onto ExecutionContext). GET /api/settings/localization — capture {manifest, values}; note the timezone value and its source. On an `os dev --seed-admin` boot the dev seed has ALREADY written the host's zone (UTC in these containers) at tenant scope (packages/plugins/plugin-auth/src/auth-plugin.ts, #23175), so source reads 'tenant' before any PUT; only a boot without the dev seed starts at 'default'", "change it: PUT /api/settings/localization { timezone: 'Asia/Tokyo' }; re-read GET /api/settings/localization and confirm the value persists and source is the scope, 'tenant' (localization scope is 'tenant'): on a dev-seeded boot the source already read 'tenant', so the value is what round-trips; on an unseeded boot the source flips from 'default'. For the console badge (steps[5]) pick a localization key the dev seed did NOT write (e.g. default_country), so its source starts at 'default'", "prove EFFECT (not just the saved form): re-derive an ExecutionContext-dependent output and confirm it now resolves against the saved zone, not UTC. Two stock consumers serve: GET /api/v1/auth/me/localization (the resolved timezone the session carries), and a datetime the console renders — e.g. showcase_field_zoo's f_datetime on its record page, which shifts by exactly the zone offset. ⛔ The analytics date bucket has no stock observable (the only date-typed time dimension is due_date, and the seeded admin holds no export grant), so do not reach for it. If no localization effect is observable at all, fall back to branding.workspace_name visible in the console shell — but never tick effect off the form alone", @@ -919,7 +925,7 @@ "evidence": "the action response" }, { - "clause": "an encrypted specifier's value lands in sys_secret as a handle, never plaintext: the settings row's value_enc holds a 'sec_' handle id and sys_secret holds the ciphertext. Which settings table holds the row follows the namespace's scope: a GLOBAL-scope namespace (mail, ai, sms, storage, auth, knowledge) lands in sys_platform_setting, a tenant- or user-scope one in sys_setting", + "clause": "an encrypted specifier's value lands in sys_secret as a handle, never plaintext: the settings row's value_enc holds a 'sec_' handle id and sys_secret holds the ciphertext. Which settings table holds the row follows the namespace's scope: a GLOBAL-scope namespace (mail, ai, sms, storage, auth) lands in sys_platform_setting, a tenant- or user-scope one in sys_setting", "oracle": "api", "verify": "the sys_secret row (id starts 'sec_', ciphertext present) + the settings row's value_enc = that handle, value null (materialiseRow dereferences through sys_secret) — read it from sys_platform_setting for mail.smtp_password / ai.*_api_key (global scope), never from sys_setting, which holds tenant/user rows only", "evidence": "the sys_secret row + sys_setting.value_enc" @@ -949,7 +955,7 @@ "evidence": "the two 401 bodies" }, { - "clause": "each of the 11 open-framework namespaces resolves GET /api/settings/:ns with its manifest + values — no namespace 500s or serves an empty manifest", + "clause": "each of the 10 open-framework namespaces resolves GET /api/settings/:ns with its manifest + values — no namespace 500s or serves an empty manifest", "oracle": "api", "verify": "one GET per variant in variants[]; each returns {manifest, values} with the manifest's specifiers", "evidence": "the per-namespace responses" @@ -975,7 +981,6 @@ "sms", "storage", "ai", - "knowledge", "lifecycle" ], "traps": ["stale-console-bundle", "dispatcher-vs-hono-route"], @@ -1013,6 +1018,12 @@ "date": "2026-11-14", "change": "fixtures.requires[0], steps[0], acceptance[12] and variants recounted (stale count, card #33330, row 143 of the #32908 close-out ledger; QA run #33048 comment 6846028996 on #32908). builtinSettingsManifests (packages/services/service-settings/src/manifests/index.ts) now holds 10 manifests, access_policy (tenant scope) among them, so a stock boot serves 11 namespaces with lifecycle. variants gains access_policy and lifecycle, so acceptance[12]'s one-GET-per-variant reads all 11 (lifecycle was counted but missing from the list before). The fixture also names the showcase's own env pin, OS_LOCALIZATION_CURRENCY=USD in examples/app-showcase/.env, whose Locked by env badge and 409 SETTINGS_LOCKED #33048 met. No clause weakened: acceptance[12] now binds one more namespace. Read from source at base 87330e89, not driven live", "ref": "#33330" + }, + { + "revision": 9, + "date": "2026-11-15", + "change": "fixtures.requires[0], steps[0], acceptance[7], acceptance[12] and variants recounted for #33933: knowledgeSettingsManifest left builtinSettingsManifests (9 manifests, so a stock boot serves 10 namespaces with lifecycle), and service-knowledge contributes the knowledge namespace and the ai embedder_* keys only where it is mounted. variants drops knowledge; acceptance[7]'s global-scope list drops it. No clause weakened: every namespace a stock boot still serves is still read. Read from source, not driven live", + "ref": "#33933" } ] }, diff --git a/packages/cli/test/connect-agent-both-halves-wire.pin.test.ts b/packages/cli/test/connect-agent-both-halves-wire.pin.test.ts index b56d1a5b46c..9996c4fc2b3 100644 --- a/packages/cli/test/connect-agent-both-halves-wire.pin.test.ts +++ b/packages/cli/test/connect-agent-both-halves-wire.pin.test.ts @@ -264,7 +264,7 @@ describe('#17647 — Connect-an-Agent visibility: BOTH halves, over the wire', ( // The Setup tree the platform admin is served BY THIS COMPOSITION: 9 // authored groups less `group_approvals` and `group_integrations`, // which nothing in it contributes into and the filter collapses, plus - // the 29 entries `SETUP_NAV_CONTRIBUTIONS` carries, plus the MCP one. + // the 28 entries `SETUP_NAV_CONTRIBUTIONS` carries, plus the MCP one. // (25 until #25098 moved the unfiltered Packages entry to Studio; 24 // until #30204 removed the Feature Flags entry with its namespace; 32 // until #30895 moved the MCP entry out of `group_integrations`, the @@ -280,13 +280,16 @@ describe('#17647 — Connect-an-Agent visibility: BOTH halves, over the wire', ( // the public forms entry, `nav_public_forms`, joined it, #36444; 35 // until objectstack#36834 gave Setup its Packages entry, // `nav_packages`, in `group_apps`, so that group is served again: - // +2, `group_apps` and `nav_packages`.) + // +2, `group_apps` and `nav_packages`; 37 until #33933 moved the + // Knowledge entry, `nav_settings_knowledge`, to + // `@objectstack/service-knowledge`, which contributes it only where the + // knowledge service is mounted.) // `nav_settings_branding` is not among them, and not because of a // tenancy wall (this harness boots none): since #24766 it is // contributed by `@objectstack/service-settings` together with the // `branding` namespace, offered only where no organization wall stands, // and this harness composes platform-objects and the MCP bundle alone. - expect(allowedIds).toHaveLength(37); + expect(allowedIds).toHaveLength(36); expect(allowedIds).toContain('nav_packages'); expect(groupChildren(setupAllowed.body?.item, 'group_apps')).toEqual(['nav_packages']); expect(allowedIds).toContain('nav_public_forms'); @@ -294,6 +297,7 @@ describe('#17647 — Connect-an-Agent visibility: BOTH halves, over the wire', ( expect(allowedIds).toContain('nav_work_calendar_exceptions'); expect(allowedIds).not.toContain('nav_packaged_actions'); expect(allowedIds).toContain('nav_settings_access_policy'); + expect(allowedIds).not.toContain('nav_settings_knowledge'); expect(allowedIds).toContain('nav_recycle_bin'); expect(allowedIds).toContain('nav_units_of_measure'); expect(allowedIds).not.toContain('nav_settings_branding'); @@ -318,8 +322,8 @@ describe('#17647 — Connect-an-Agent visibility: BOTH halves, over the wire', ( expect(withAccountHalf.statusCode).toBe(200); expect(withoutAccountHalf.statusCode).toBe(200); expect(navIds(withAccountHalf.body?.item)).toEqual(navIds(withoutAccountHalf.body?.item)); - // 37: the composition the count in the test above states. - expect(navIds(withAccountHalf.body?.item)).toHaveLength(37); + // 36: the composition the count in the test above states. + expect(navIds(withAccountHalf.body?.item)).toHaveLength(36); // The mechanism behind the invariance, asserted rather than assumed: // the bundle aims exactly one contribution at `setup` and one at diff --git a/packages/platform-objects/src/apps/setup-nav.contributions.ts b/packages/platform-objects/src/apps/setup-nav.contributions.ts index 93932683e26..8ef743efa10 100644 --- a/packages/platform-objects/src/apps/setup-nav.contributions.ts +++ b/packages/platform-objects/src/apps/setup-nav.contributions.ts @@ -190,7 +190,9 @@ export const SETUP_NAV_CONTRIBUTIONS: NavigationContribution[] = [ // entry is not drawn. `features` is a root every nav entry binds. { id: 'nav_settings_storage', type: 'url', label: 'File Storage', url: '/apps/setup/system/settings/storage', icon: 'hard-drive', requiredPermissions: ['manage_platform_settings'], visible: 'features.cloudManaged != true' }, { id: 'nav_settings_ai', type: 'url', label: 'AI & Embedder', url: '/apps/setup/system/settings/ai', icon: 'sparkles', requiredPermissions: ['manage_platform_settings'] }, - { id: 'nav_settings_knowledge', type: 'url', label: 'Knowledge', url: '/apps/setup/system/settings/knowledge', icon: 'book-open', requiredPermissions: ['manage_platform_settings'] }, + // `nav_settings_knowledge` is contributed by `@objectstack/service-knowledge` + // with the `knowledge` namespace, which is offered only where that + // service is mounted — so the entry lives and dies with it. // `lifecycle` is `@objectstack/objectql`'s manifest (ADR-0057), offered // wherever a settings service is mounted, like the entries above. { id: 'nav_settings_lifecycle', type: 'url', label: 'Data Lifecycle', url: '/apps/setup/system/settings/lifecycle', icon: 'timer', requiredPermissions: ['manage_platform_settings'] }, diff --git a/packages/services/service-knowledge/package.json b/packages/services/service-knowledge/package.json index 7733366ab64..135ce83fc86 100644 --- a/packages/services/service-knowledge/package.json +++ b/packages/services/service-knowledge/package.json @@ -27,10 +27,12 @@ }, "dependencies": { "@objectstack/core": "workspace:*", + "@objectstack/service-settings": "workspace:*", "@objectstack/spec": "workspace:*" }, "devDependencies": { "@objectstack/objectql": "workspace:*", + "@objectstack/platform-objects": "workspace:*", "@types/node": "^26.6.5", "tsx": "^4.23.15", "typescript": "^6.0.3", diff --git a/packages/services/service-knowledge/src/__tests__/knowledge-settings-contribution.test.ts b/packages/services/service-knowledge/src/__tests__/knowledge-settings-contribution.test.ts new file mode 100644 index 00000000000..56952b8b07e --- /dev/null +++ b/packages/services/service-knowledge/src/__tests__/knowledge-settings-contribution.test.ts @@ -0,0 +1,195 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The knowledge settings live and die with the knowledge service (#33933). + * + * A kernel that mounts `KnowledgeServicePlugin` beside `SettingsServicePlugin` + * offers the knowledge page, the `ai` embedder section, both test actions and + * the Setup entry; the same kernel without it offers none of them. This kernel + * stands in for an app that mounts the service (none in this repository does): + * the knowledge plugin is `use`d BEFORE the settings plugin on purpose, so the + * pins also prove that its `optionalDependencies` declaration orders the + * settings plugin ahead rather than the `use` order doing it by luck. + * + * The Setup entry is judged on the merged Setup tree the console reads (the + * stock contributions plus every bundle registered through the `manifest` + * service, folded by the ObjectQL registry), and against the hub list: the + * knowledge page has exactly one sidebar entry exactly when the hub lists it. + */ + +import { describe, it, expect } from 'vitest'; +import { LiteKernel } from '@objectstack/core'; +import type { Plugin, PluginContext } from '@objectstack/core'; +import { ObjectQL } from '@objectstack/objectql'; +import { SETUP_APP, SETUP_NAV_CONTRIBUTIONS } from '@objectstack/platform-objects'; +import type { IHttpRequest, IHttpResponse, IHttpServer, RouteHandler } from '@objectstack/spec/contracts'; +import { + SettingsServicePlugin, + registerSettingsRoutes, + aiEmbedderSettingsSpecifiers, + aiTestEmbedderActionHandler, + knowledgeTestActionHandler, + type SettingsService, +} from '@objectstack/service-settings'; +import { KnowledgeServicePlugin } from '../knowledge-service-plugin.js'; + +const EMBEDDER_KEYS = aiEmbedderSettingsSpecifiers.map((s) => s.key).filter((k): k is string => !!k); +const SETTINGS_PAGE = /^\/apps\/setup\/system\/settings\/([a-z_]+)$/; + +interface NavItem { id?: string; type?: string; url?: string; children?: NavItem[] } + +/** The `manifest` service ObjectQL provides, reduced to a recorder. */ +class FakeManifestPlugin implements Plugin { + name = 'test.fake.manifest'; + version = '1.0.0'; + type = 'standard' as const; + providesServices = ['manifest']; + constructor(private readonly registered: unknown[]) {} + async init(ctx: PluginContext): Promise { + ctx.registerService('manifest', { register: (m: unknown) => { this.registered.push(m); } }); + } +} + +async function boot(withKnowledge: boolean) { + const registered: unknown[] = []; + const kernel = new LiteKernel(); + kernel.use(new FakeManifestPlugin(registered)); + if (withKnowledge) kernel.use(new KnowledgeServicePlugin({ enableEventSync: false })); + kernel.use(new SettingsServicePlugin({ env: {}, registerRoutes: false })); + await kernel.bootstrap(); + const settings = kernel.getService('settings'); + return { kernel, settings, registered }; +} + +/** The Configuration group of the merged Setup tree. */ +function configurationEntries(registered: unknown[]): NavItem[] { + const engine = new ObjectQL(); + engine.registry.logLevel = 'silent'; + engine.registerApp({ + id: 'com.objectstack.test.setup-shell', namespace: 'sys', version: '0.0.0', type: 'plugin', scope: 'system', + name: 'Setup shell (fixture)', apps: [SETUP_APP], navigationContributions: SETUP_NAV_CONTRIBUTIONS, + } as any); + for (const m of registered) engine.registerApp(m as any); + const navigation = (engine.registry.getApp('setup') as { navigation?: NavItem[] } | undefined)?.navigation ?? []; + return navigation.find((item) => item.id === 'group_configuration')?.children ?? []; +} + +const knowledgeEntries = (registered: unknown[]) => + configurationEntries(registered).filter((i) => i.type === 'url' && SETTINGS_PAGE.exec(i.url ?? '')?.[1] === 'knowledge'); + +async function namespaceValues(settings: SettingsService, ns: string): Promise> { + const payload = await settings.getNamespace(ns); + return Object.fromEntries(Object.entries(payload.values).map(([k, v]) => [k, (v as { value?: unknown }).value])); +} + +describe('#33933 — knowledge settings are contributed by the mounted knowledge service', async () => { + const mounted = await boot(true); + const bare = await boot(false); + + it('reads two real hubs: both serve the default slate', () => { + for (const { settings } of [mounted, bare]) { + expect(settings.listManifests().map((m) => m.namespace)).toEqual(expect.arrayContaining(['ai', 'storage', 'mail'])); + } + }); + + it('the knowledge page is offered with the service, and only with it', () => { + expect(mounted.settings.listManifests().map((m) => m.namespace)).toContain('knowledge'); + expect(bare.settings.listManifests().map((m) => m.namespace)).not.toContain('knowledge'); + }); + + it('the ai page carries the embedder section with the service, and only with it', () => { + const keysOf = (s: SettingsService) => + (s.getManifest('ai').specifiers as Array<{ key?: string; id?: string }>).map((x) => x.key ?? x.id); + expect(EMBEDDER_KEYS.length).toBeGreaterThanOrEqual(6); + expect(keysOf(mounted.settings)).toEqual(expect.arrayContaining([...EMBEDDER_KEYS, 'embedder', 'test_embedder'])); + const bareKeys = keysOf(bare.settings); + expect(bareKeys).toContain('provider'); + for (const key of [...EMBEDDER_KEYS, 'embedder', 'test_embedder']) expect(bareKeys, key).not.toContain(key); + }); + + it('both test buttons reach their handlers when the service is mounted', async () => { + // "Reached" is judged by the handler's own answer for the same inputs, + // never by message text: the no-handler answer is a different result. + const knowledgeValues = await namespaceValues(mounted.settings, 'knowledge'); + expect(await mounted.settings.runAction('knowledge', 'test', {})).toEqual( + await knowledgeTestActionHandler({ namespace: 'knowledge', actionId: 'test', values: knowledgeValues, payload: {}, ctx: {} }), + ); + const aiValues = await namespaceValues(mounted.settings, 'ai'); + const embedder = await mounted.settings.runAction('ai', 'test_embedder', {}); + expect(embedder).toEqual( + await aiTestEmbedderActionHandler({ namespace: 'ai', actionId: 'test_embedder', values: aiValues, payload: {}, ctx: {} }), + ); + expect(embedder.severity).toBe('warning'); + }); + + it('the Setup sidebar opens the knowledge page exactly once with the service, and never without it', () => { + const entries = knowledgeEntries(mounted.registered); + expect(entries).toHaveLength(1); + expect(entries[0].id).toBe('nav_settings_knowledge'); + expect(knowledgeEntries(bare.registered)).toHaveLength(0); + // Non-vacuity: the bare tree is a real Setup tree with its AI entry. + expect(configurationEntries(bare.registered).some((i) => i.id === 'nav_settings_ai')).toBe(true); + }); +}); + +class MockHttp implements IHttpServer { + routes = new Map(); + private add(method: string, path: string, handler: RouteHandler) { + this.routes.set(`${method} ${path}`, handler); + } + get(path: string, h: RouteHandler) { this.add('GET', path, h); return this as any; } + post(path: string, h: RouteHandler) { this.add('POST', path, h); return this as any; } + put(path: string, h: RouteHandler) { this.add('PUT', path, h); return this as any; } + delete(path: string, h: RouteHandler) { this.add('DELETE', path, h); return this as any; } + patch(path: string, h: RouteHandler) { this.add('PATCH', path, h); return this as any; } + use() { return this as any; } + listen() { return Promise.resolve(); } + close() { return Promise.resolve(); } + getInstance() { return null; } +} + +async function post(http: MockHttp, namespace: string, actionId: string, body: unknown) { + const req = { params: { namespace, actionId }, query: {}, body, headers: {}, method: 'POST', path: '/' } as IHttpRequest; + const state: { status: number; body?: any } = { status: 200 }; + const res = { + json: (data: unknown) => { state.body = data; }, + send: () => {}, + status: (code: number) => { state.status = code; return res; }, + header: () => res, + } as unknown as IHttpResponse; + await http.routes.get('POST /api/settings/:namespace/:actionId')!(req, res); + return state; +} + +/** + * The two buttons #24769 measured, at the HTTP door — moved here from + * `@objectstack/service-settings`' `settings-default-action-handlers.pin.test.ts` + * with #33933, because the composition that serves them is now the one that + * mounts the knowledge service. + */ +describe('[#24769] the two buttons the knowledge service contributes, at the HTTP door', async () => { + // A platform admin: both namespaces gate reads and writes (and so actions) on + // `manage_platform_settings`. + const admin = () => ({ enforced: true, permissions: ['manage_platform_settings'], userId: 'usr_admin' }); + const { settings } = await boot(true); + const http = new MockHttp(); + registerSettingsRoutes(http, settings, { contextFromRequest: admin }); + + it('POST /api/settings/ai/test_embedder is answered by the embedder check (200, not 400)', async () => { + const answer = await post(http, 'ai', 'test_embedder', { + values: { embedder_provider: 'openai', embedder_api_key: 'sk-test', embedder_model: 'text-embedding-3-small' }, + }); + expect(answer.status).toBe(200); + expect(answer.body?.data?.ok).toBe(true); + expect(answer.body?.data?.message).toContain('text-embedding-3-small'); + }); + + it('POST /api/settings/knowledge/test is answered by the adapter check (200, not 400)', async () => { + const answer = await post(http, 'knowledge', 'test', { + values: { adapter: 'ragflow', ragflow_base_url: 'http://localhost:9380', ragflow_api_key: 'k' }, + }); + expect(answer.status).toBe(200); + expect(answer.body?.data?.ok).toBe(true); + expect(answer.body?.data?.message).toContain('localhost:9380'); + }); +}); diff --git a/packages/services/service-knowledge/src/__tests__/knowledge-settings-host-ai.test.ts b/packages/services/service-knowledge/src/__tests__/knowledge-settings-host-ai.test.ts new file mode 100644 index 00000000000..05fb395092a --- /dev/null +++ b/packages/services/service-knowledge/src/__tests__/knowledge-settings-host-ai.test.ts @@ -0,0 +1,120 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The embedder section joins the bundled `ai` page only (#33933). + * + * `contributeKnowledgeSettings` must leave a host's own `ai` manifest exactly + * as the host wrote it, even when it carries the bundled keys: the bundled page + * is recognised as that very declaration, never by its key set. A host page + * that already declares the embedder keys keeps its declaration and gets the + * test button's handler. Each case runs on a real `SettingsService`, with a + * plugin context reduced to the two services the contribution reads. + */ + +import { describe, it, expect, vi } from 'vitest'; +import type { PluginContext } from '@objectstack/core'; +import { + SettingsService, + aiSettingsManifest, + aiEmbedderSettingsSpecifiers, + aiTestEmbedderActionHandler, + withAiEmbedderSection, +} from '@objectstack/service-settings'; +import { contributeKnowledgeSettings, isBundledAiManifest } from '../knowledge-settings-contribution.js'; + +const EMBEDDER_KEYS = aiEmbedderSettingsSpecifiers.map((s) => s.key).filter((k): k is string => !!k); + +function contextFor(settings: SettingsService | undefined) { + const warn = vi.fn(); + const ctx = { + getService: (name: string) => { + if (name === 'settings' && settings) return settings; + throw new Error(`no service ${name}`); + }, + logger: { warn, info: vi.fn(), debug: vi.fn(), error: vi.fn() }, + } as unknown as PluginContext; + return { ctx, warn }; +} + +function hubWith(ai: typeof aiSettingsManifest): SettingsService { + const settings = new SettingsService({ env: {} }); + settings.registerManifest(ai); + return settings; +} + +const keysOf = (s: SettingsService) => + (s.getManifest('ai').specifiers as Array<{ key?: string }>).map((x) => x.key).filter(Boolean); + +describe('#33933 — the embedder section joins the bundled ai page only', () => { + it('the bundled page is joined: embedder keys and the test button are offered', () => { + const settings = hubWith(aiSettingsManifest); + const { ctx, warn } = contextFor(settings); + expect(contributeKnowledgeSettings(ctx, '0.0.0').embedder).toBe(true); + expect(keysOf(settings)).toEqual(expect.arrayContaining(EMBEDDER_KEYS)); + expect(warn).not.toHaveBeenCalled(); + }); + + it('a page served through an option source is not taken as bundled: no join, and the host is told why', () => { + // The served copy cannot be told apart from a host page that narrowed an + // option table, so it is left alone (no `ai` key has a source today). + const settings = new SettingsService({ env: {} }); + settings.registerOptionSource('ai', 'provider', () => ({ options: [{ value: 'openai', label: 'OpenAI' }], admits: () => true }) as any); + settings.registerManifest(aiSettingsManifest); + expect(settings.getManifest('ai')).not.toBe(aiSettingsManifest); + const { ctx, warn } = contextFor(settings); + expect(contributeKnowledgeSettings(ctx, '0.0.0').embedder).toBe(false); + for (const key of EMBEDDER_KEYS) expect(keysOf(settings), key).not.toContain(key); + expect(warn).toHaveBeenCalledTimes(1); + }); + + for (const [what, host] of [ + ['a different scope', { ...aiSettingsManifest, scope: 'tenant' as const }], + ['a different read permission', { ...aiSettingsManifest, readPermission: 'host.ai.read' }], + [ + 'a narrowed option table on one key', + { + ...aiSettingsManifest, + specifiers: aiSettingsManifest.specifiers.map((s) => + s.key === 'provider' ? { ...s, options: (s as { options?: unknown[] }).options?.slice(0, 2) } : s, + ), + }, + ], + [ + 'a different default on one key', + { + ...aiSettingsManifest, + specifiers: aiSettingsManifest.specifiers.map((s) => (s.key === 'temperature' ? { ...s, default: 0.1 } : s)), + }, + ], + ] as const) { + it(`a host ai page with the bundled keys and ${what} is left untouched, and the host is told why`, () => { + const settings = hubWith(host as typeof aiSettingsManifest); + const { ctx, warn } = contextFor(settings); + expect(isBundledAiManifest(settings.getManifest('ai'))).toBe(false); + expect(contributeKnowledgeSettings(ctx, '0.0.0').embedder).toBe(false); + expect(settings.getManifest('ai')).toBe(host); + for (const key of EMBEDDER_KEYS) expect(keysOf(settings), key).not.toContain(key); + expect(warn).toHaveBeenCalledTimes(1); + expect(String(warn.mock.calls[0][0])).toContain('not the bundled one'); + }); + } + + it('a host ai page that already declares the embedder keys keeps its declaration and gets the button handler', async () => { + const host = withAiEmbedderSection({ ...aiSettingsManifest, scope: 'global' as const, label: 'Host AI' }); + const settings = hubWith(host); + const { ctx, warn } = contextFor(settings); + expect(contributeKnowledgeSettings(ctx, '0.0.0').embedder).toBe(true); + expect(settings.getManifest('ai')).toBe(host); + expect(warn).not.toHaveBeenCalled(); + const payload = await settings.getNamespace('ai'); + const values = Object.fromEntries(Object.entries(payload.values).map(([k, v]) => [k, (v as { value?: unknown }).value])); + expect(await settings.runAction('ai', 'test_embedder', {})).toEqual( + await aiTestEmbedderActionHandler({ namespace: 'ai', actionId: 'test_embedder', values, payload: {}, ctx: {} }), + ); + }); + + it('a composition with no settings service is offered nothing and does not throw', () => { + const { ctx } = contextFor(undefined); + expect(contributeKnowledgeSettings(ctx, '0.0.0')).toEqual({ knowledge: false, embedder: false, nav: false }); + }); +}); diff --git a/packages/services/service-knowledge/src/index.ts b/packages/services/service-knowledge/src/index.ts index 4076e926bb9..e8ed3459e67 100644 --- a/packages/services/service-knowledge/src/index.ts +++ b/packages/services/service-knowledge/src/index.ts @@ -7,3 +7,9 @@ export type { } from './knowledge-service.js'; export { KnowledgeServicePlugin } from './knowledge-service-plugin.js'; export type { KnowledgeServicePluginOptions } from './knowledge-service-plugin.js'; +export { + contributeKnowledgeSettings, + knowledgeSetupNavItem, + KNOWLEDGE_SETUP_NAV_BUNDLE_ID, +} from './knowledge-settings-contribution.js'; +export type { KnowledgeSettingsContribution } from './knowledge-settings-contribution.js'; diff --git a/packages/services/service-knowledge/src/knowledge-service-plugin.ts b/packages/services/service-knowledge/src/knowledge-service-plugin.ts index 2b206a6b6e2..ad0d8a8c14d 100644 --- a/packages/services/service-knowledge/src/knowledge-service-plugin.ts +++ b/packages/services/service-knowledge/src/knowledge-service-plugin.ts @@ -10,6 +10,7 @@ import { KNOWLEDGE_SERVICE } from '@objectstack/spec/contracts'; import { KnowledgeService } from './knowledge-service.js'; import type { KnowledgeLogger } from './knowledge-service.js'; import { createKnowledgeReapGuard, guardedObjectsFor } from './knowledge-reap-guard.js'; +import { contributeKnowledgeSettings } from './knowledge-settings-contribution.js'; /** * Configuration options for the `KnowledgeServicePlugin`. @@ -69,8 +70,14 @@ export class KnowledgeServicePlugin implements Plugin { * order-if-present so the resolution is deterministic (ADR-0116, #4471). * Soft, not hard: without an engine the service degrades on purpose * (pure-search mode with conservative RLS). + * + * The settings plugin is ordered ahead the same way: init() contributes the + * knowledge settings to its `settings` service (`contributeKnowledgeSettings`), + * so its absence there is a fact about the composition, never a guess. */ - optionalDependencies = ['com.objectstack.engine.objectql']; + // Literal ids: the boot-order gates read this array statically. The second + // is `SETTINGS_PLUGIN_ID` from `@objectstack/service-settings`. + optionalDependencies = ['com.objectstack.engine.objectql', 'com.objectstack.service.settings']; private service: KnowledgeService | null = null; private subscriptionId: string | undefined; @@ -124,6 +131,11 @@ export class KnowledgeServicePlugin implements Plugin { } ctx.registerService(KNOWLEDGE_SERVICE, this.service); + + // The knowledge settings page, the `ai` embedder section, both test + // actions and the Setup entry are offered only where this service is + // mounted — never by default (`@objectstack/service-settings`). + contributeKnowledgeSettings(ctx, this.version); ctx.logger.info?.( `KnowledgeServicePlugin: registered '${KNOWLEDGE_SERVICE}' service (eventSync=${ this.options.enableEventSync !== false diff --git a/packages/services/service-knowledge/src/knowledge-settings-contribution.ts b/packages/services/service-knowledge/src/knowledge-settings-contribution.ts new file mode 100644 index 00000000000..93a75f8b38c --- /dev/null +++ b/packages/services/service-knowledge/src/knowledge-settings-contribution.ts @@ -0,0 +1,161 @@ +// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The knowledge base's settings surface, contributed WITH the service. + * + * The knowledge base is not a default capability: no deployment loads + * `KnowledgeServicePlugin` unless its host mounts it. Its settings used to be + * registered by `@objectstack/service-settings` on every boot all the same — + * the `knowledge` namespace, the `ai` namespace's embedder section, both + * "Test" buttons and the Setup entry — so every deployment showed a Knowledge + * page, an "Embedder" section and a test button with no service behind them. + * They now live and die with the service, the way the branding entry lives + * with its namespace and the "Connect an AI Assistant" page with the MCP + * capability: a deployment without this plugin serves none of them (a read or + * write of `knowledge` answers `404 UNKNOWN_NAMESPACE`, a write of an + * `embedder_*` key `400 UNKNOWN_KEY`), and one with it serves all of them. + * + * Called from `KnowledgeServicePlugin.init()`, which declares the settings + * plugin in `optionalDependencies`: the kernel inits that plugin first when it + * is present, so "no `settings` service" here is a fact about the composition, + * not a guess taken while the registry is still filling. + */ + +import type { PluginContext } from '@objectstack/core'; +import { + knowledgeSettingsManifest, + knowledgeTestActionHandler, + aiSettingsManifest, + withAiEmbedderSection, + aiEmbedderSettingsSpecifiers, + aiTestEmbedderActionHandler, + type SettingsService, +} from '@objectstack/service-settings'; + +/** The Setup bundle this contribution registers under. */ +export const KNOWLEDGE_SETUP_NAV_BUNDLE_ID = 'com.objectstack.service.knowledge.setup-nav'; + +/** + * The Setup entry for the `knowledge` namespace. Its label stays keyed + * `apps.setup.navigation.nav_settings_knowledge` in `@objectstack/platform-objects`' + * bundles, where the console resolves every Setup entry, contributed or static. + * A factory, not a shared literal: the nav fold pushes contributed items into + * the merged tree by reference. + */ +export function knowledgeSetupNavItem(): Record { + return { + id: 'nav_settings_knowledge', + type: 'url', + label: 'Knowledge', + url: '/apps/setup/system/settings/knowledge', + icon: 'book-open', + requiredPermissions: ['manage_platform_settings'], + }; +} + +type SettingsSlot = Pick; + +function keysOf(manifest: { specifiers: ReadonlyArray<{ key?: string }> }): Set { + return new Set(manifest.specifiers.map((s) => s.key).filter((k): k is string => typeof k === 'string')); +} + +/** + * Whether the served `ai` manifest IS the bundled declaration (#33933). + * + * Judged by identity, never by its key set: a host may register its own `ai` + * manifest with the bundled keys and a different scope, permission, default or + * option table, and that manifest must be left as the host wrote it. With no + * option source on an `ai` key the hub serves the registered declaration + * itself, so the bundled page is that very object. A page served through an + * option source is a copy whose sourced specifiers carry other options, which + * cannot be told apart from a host page that narrowed an option table; it is + * therefore NOT taken as bundled, and the caller warns. No `ai` key has an + * option source today. + */ +export function isBundledAiManifest(served: unknown): boolean { + return served === aiSettingsManifest; +} + +function embedderKeys(): string[] { + return aiEmbedderSettingsSpecifiers.map((s) => s.key).filter((k): k is string => typeof k === 'string'); +} + +/** What {@link contributeKnowledgeSettings} offered on this boot. */ +export interface KnowledgeSettingsContribution { + knowledge: boolean; + embedder: boolean; + nav: boolean; +} + +/** + * Register the knowledge settings surface on the composition's settings + * service, and its Setup entry on the manifest service. A composition with no + * settings service gets none of it, Setup entry included: the entry would open + * a page the server does not serve. + */ +export function contributeKnowledgeSettings(ctx: PluginContext, version: string): KnowledgeSettingsContribution { + const offered: KnowledgeSettingsContribution = { knowledge: false, embedder: false, nav: false }; + let settings: SettingsSlot | undefined; + try { + settings = ctx.getService('settings'); + } catch { + // No settings service: nothing claims a settings UI for the knowledge base. + return offered; + } + if (!settings || typeof settings.registerManifest !== 'function') return offered; + + settings.registerManifest(knowledgeSettingsManifest); + settings.registerAction('knowledge', 'test', knowledgeTestActionHandler); + offered.knowledge = true; + + // The embedder section joins the `ai` namespace — the bundled one only, + // recognised as that very declaration (`isBundledAiManifest`), and registered from its DECLARATION + // (`aiSettingsManifest`), never from the served copy `getManifest` returns + // (that copy carries option-source tables in place of declared ones). A host + // that registered its own `ai` manifest keeps it untouched and is told why + // it has no embedder keys; one whose `ai` already declares them keeps those. + let ai: ReturnType | undefined; + try { + ai = settings.getManifest('ai'); + } catch { + ai = undefined; + } + const served = ai ? keysOf(ai) : new Set(); + const declaresEmbedder = aiEmbedderSettingsSpecifiers.some((s) => s.key !== undefined && served.has(s.key)); + const isBundled = isBundledAiManifest(ai); + if (ai && (declaresEmbedder || isBundled)) { + if (!declaresEmbedder) settings.registerManifest(withAiEmbedderSection(aiSettingsManifest)); + settings.registerAction('ai', 'test_embedder', aiTestEmbedderActionHandler); + offered.embedder = true; + } else { + ctx.logger?.warn?.( + `KnowledgeServicePlugin: ${ai ? "the registered 'ai' settings namespace is not the bundled one" : "no 'ai' settings namespace is registered"}, ` + + `so the embedder settings (${embedderKeys().join(', ')}) are not offered. ` + + "Declare them in the host's 'ai' manifest (aiEmbedderSettingsSpecifiers) to configure an embedder from Setup.", + ); + } + + let manifestService: { register?(m: unknown): void } | undefined; + try { + manifestService = ctx.getService<{ register?(m: unknown): void }>('manifest'); + } catch { + // No manifest service (lean kernels, tests): no app registry to contribute to. + return offered; + } + if (typeof manifestService?.register !== 'function') return offered; + manifestService.register({ + id: KNOWLEDGE_SETUP_NAV_BUNDLE_ID, + namespace: 'sys', + version, + type: 'plugin', + scope: 'system', + name: 'Knowledge Service — Setup entries', + description: 'Setup navigation for the knowledge settings, offered only where the knowledge service is mounted.', + navigationContributions: [ + // After platform-objects' Configuration entries (priority 100). + { app: 'setup', group: 'group_configuration', priority: 110, items: [knowledgeSetupNavItem()] }, + ], + }); + offered.nav = true; + return offered; +} diff --git a/packages/services/service-knowledge/vitest.config.ts b/packages/services/service-knowledge/vitest.config.ts index 4bfc71ed08b..f6c5c9e6363 100644 --- a/packages/services/service-knowledge/vitest.config.ts +++ b/packages/services/service-knowledge/vitest.config.ts @@ -25,6 +25,21 @@ export default defineConfig({ // One rule for all namespaces cannot go stale that way. alias: [ { find: /^@objectstack\/core$/, replacement: path.resolve(__dirname, '../../core/src/index.ts') }, + // The settings contribution (`knowledge-settings-contribution.ts`) imports + // `@objectstack/service-settings`; its source, and the source of every + // workspace package that source reaches, like every sibling here. + // `platform-objects` takes explicit subpaths: its export map is not uniform. + { find: /^@objectstack\/service-settings$/, replacement: path.resolve(__dirname, '../service-settings/src/index.ts') }, + { find: /^@objectstack\/types$/, replacement: path.resolve(__dirname, '../../types/src/index.ts') }, + { + find: /^@objectstack\/platform-objects\/system$/, + replacement: path.resolve(__dirname, '../../platform-objects/src/system/index.ts'), + }, + { + find: /^@objectstack\/platform-objects\/identity$/, + replacement: path.resolve(__dirname, '../../platform-objects/src/identity/index.ts'), + }, + { find: /^@objectstack\/platform-objects$/, replacement: path.resolve(__dirname, '../../platform-objects/src/index.ts') }, { find: /^@objectstack\/spec\/([a-z-]+)$/, replacement: `${path.resolve(__dirname, '../../spec/src')}/$1/index.ts`, diff --git a/packages/services/service-settings/src/cloud-managed-settings.pin.test.ts b/packages/services/service-settings/src/cloud-managed-settings.pin.test.ts index f32f89ee44f..a36a4e29e94 100644 --- a/packages/services/service-settings/src/cloud-managed-settings.pin.test.ts +++ b/packages/services/service-settings/src/cloud-managed-settings.pin.test.ts @@ -21,7 +21,7 @@ import type { IHttpRequest, IHttpResponse } from '@objectstack/spec/contracts'; import { SettingsService } from './settings-service.js'; import { registerSettingsRoutes } from './settings-routes.js'; import { MockHttp } from './__tests__/settings-door.testkit.js'; -import { aiSettingsManifest, builtinSettingsManifests } from './manifests/index.js'; +import { aiSettingsManifest, builtinSettingsManifests, withAiEmbedderSection } from './manifests/index.js'; import { CLOUD_MANAGED_HIDDEN_SETTINGS, CLOUD_MANAGED_SERVED_AI_KEYS, @@ -37,7 +37,12 @@ function hosted(on: boolean): void { async function boot(): Promise<{ service: SettingsService; http: MockHttp }> { const service = new SettingsService({ env: {} }); - for (const m of builtinSettingsManifests) service.registerManifest(m as any); + // The `ai` page as a deployment that mounts the knowledge service serves it: + // the embedder section joined (#33933), so the hosted projection is judged + // over every key it can hide, the embedder ones included. + for (const m of builtinSettingsManifests) { + service.registerManifest((m.namespace === 'ai' ? withAiEmbedderSection(m) : m) as any); + } const http = new MockHttp(); registerSettingsRoutes(http, service, { contextFromRequest: () => ({ enforced: true, permissions: ['manage_platform_settings', 'setup.access'], userId: 'usr_admin' }), @@ -85,7 +90,8 @@ const idsOf = (manifest: any, type: string): string[] => describe('#33891 — the hosted projection table', () => { it('classifies every ai key: hidden, or served — none both, none neither', () => { - const declared = keysOf(aiSettingsManifest); + // The page with its knowledge-mounted embedder section joined (#33933). + const declared = keysOf(withAiEmbedderSection(aiSettingsManifest)); const served = new Set(CLOUD_MANAGED_SERVED_AI_KEYS); for (const key of declared) expect(HIDDEN_AI.includes(key) !== served.has(key), key).toBe(true); for (const key of served) expect(declared, key).toContain(key); diff --git a/packages/services/service-settings/src/index.ts b/packages/services/service-settings/src/index.ts index 895cb8ff4a6..d736fb3c825 100644 --- a/packages/services/service-settings/src/index.ts +++ b/packages/services/service-settings/src/index.ts @@ -181,6 +181,14 @@ export { smsTestActionHandler, storageSettingsManifest, storageTestActionHandler, + // What `@objectstack/service-knowledge` contributes when it is mounted — + // never registered by default (`builtinSettingsManifests`). + knowledgeSettingsManifest, + knowledgeTestActionHandler, + aiSettingsManifest, + aiEmbedderSettingsSpecifiers, + withAiEmbedderSection, + aiTestEmbedderActionHandler, } from './manifests/index.js'; // Re-export the spec types for convenience so plugin authors only need diff --git a/packages/services/service-settings/src/knowledge-settings-default-absent.pin.test.ts b/packages/services/service-settings/src/knowledge-settings-default-absent.pin.test.ts new file mode 100644 index 00000000000..ca02fe3fd9e --- /dev/null +++ b/packages/services/service-settings/src/knowledge-settings-default-absent.pin.test.ts @@ -0,0 +1,155 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * A deployment that does not mount the knowledge service offers no knowledge + * settings (#33933). + * + * The knowledge base is not a default capability, and its settings used to be + * registered on every boot regardless: the `knowledge` namespace, the `ai` + * namespace's embedder section, the "Test connection" and "Test embedder" + * buttons, and the Setup entry. `@objectstack/service-knowledge` now + * contributes all of them when it is mounted (its own suite pins that half); + * this file pins the other half on the composition a host gets by default — + * `new SettingsServicePlugin()` beside the stock Setup navigation: + * + * - no `knowledge` manifest in the hub list, and its doors refuse; + * - no `embedder_*` key and no `test_embedder` button on the `ai` page, and a + * write of an embedder key is refused like any undeclared key; + * - neither test button's door reaches a handler; + * - no Setup entry opening the knowledge page; + * - the AI page's description names no knowledge base, in any locale. + * + * The refusals are pinned by envelope (status + `error.code`), which is what a + * console or API caller reads. + */ + +import { describe, expect, it, vi } from 'vitest'; +import { ObjectKernel } from '@objectstack/core'; +import { SETUP_NAV_CONTRIBUTIONS } from '@objectstack/platform-objects'; +import type { IHttpRequest, IHttpResponse } from '@objectstack/spec/contracts'; +import { SettingsServicePlugin } from './settings-service-plugin.js'; +import type { SettingsService } from './settings-service.js'; +import { registerSettingsRoutes } from './settings-routes.js'; +import { MockHttp } from './__tests__/settings-door.testkit.js'; +import { aiEmbedderSettingsSpecifiers, aiSettingsManifest, builtinSettingsManifests } from './manifests/index.js'; +import { settingsBuiltinTranslations } from './translations/index.js'; +import { settingsActionCopy } from './settings-action-copy.js'; + +const EMBEDDER_KEYS = aiEmbedderSettingsSpecifiers.map((s) => s.key).filter((k): k is string => !!k); + +/** The default composition: `new SettingsServicePlugin()` with no options but an empty env. */ +async function bootDefault(): Promise<{ service: SettingsService; http: MockHttp }> { + const kernel = new ObjectKernel({ skipSystemValidation: true, gracefulShutdown: false } as any); + let readyHook: (() => Promise) | undefined; + const ctx: any = { + logger: { info: () => {}, warn: () => {}, error: () => {}, debug: () => {} }, + registerService: kernel.registerService.bind(kernel), + getService: kernel.getService.bind(kernel), + hook: (event: string, fn: () => Promise) => { if (event === 'kernel:ready') readyHook = fn; }, + getKernel: () => kernel, + }; + const plugin = new SettingsServicePlugin({ env: {}, registerRoutes: false }); + await plugin.init(ctx); + await plugin.start(ctx); + await readyHook!(); + const service = ctx.getService('settings') as SettingsService; + const http = new MockHttp(); + registerSettingsRoutes(http, service, { + contextFromRequest: () => ({ enforced: true, permissions: ['manage_platform_settings', 'setup.access'], userId: 'usr_admin' }), + }); + return { service, http }; +} + +async function call( + http: MockHttp, + route: string, + params: Record, + body?: Record, +): Promise<{ status: number; body?: any }> { + const handler = http.routes.get(route); + if (!handler) throw new Error(`route not registered: ${route}`); + const [method] = route.split(' '); + const req: IHttpRequest = { params, query: {}, body: body ?? {}, headers: {}, method, path: '/' } as IHttpRequest; + const state: { status: number; body?: any } = { status: 200 }; + const res: IHttpResponse = { + json: vi.fn((d) => { state.body = d; }) as any, + send: vi.fn() as any, + status: vi.fn((c: number) => { state.status = c; return res; }) as any, + header: vi.fn(() => res) as any, + }; + await handler(req, res); + return state; +} + +describe('#33933 — no knowledge settings on a default boot', async () => { + const { service, http } = await bootDefault(); + + it('reads a real hub: the default slate is registered, AI included', () => { + // Non-vacuity: the namespaces around the absent one are there. + const namespaces = service.listManifests().map((m) => m.namespace); + expect(namespaces).toEqual(expect.arrayContaining(['ai', 'storage', 'mail'])); + }); + + it('the bundled aggregate and the hub list carry no knowledge namespace', () => { + expect(builtinSettingsManifests.map((m) => m.namespace)).not.toContain('knowledge'); + expect(service.listManifests().map((m) => m.namespace)).not.toContain('knowledge'); + }); + + it('a direct read of the knowledge page is refused, not served as a form', async () => { + const read = await call(http, 'GET /api/settings/:namespace', { namespace: 'knowledge' }); + expect(read.status).toBe(404); + expect(read.body?.error?.code).toBe('UNKNOWN_NAMESPACE'); + }); + + it('the ai page declares no embedder key and no Test embedder button', () => { + const served = service.getManifest('ai').specifiers as Array<{ key?: string; id?: string; type: string }>; + // Non-vacuity: the provider section the page keeps is there. + expect(served.some((s) => s.key === 'provider')).toBe(true); + expect(EMBEDDER_KEYS.length).toBeGreaterThanOrEqual(6); + for (const key of EMBEDDER_KEYS) expect(served.some((s) => s.key === key), key).toBe(false); + expect(served.some((s) => s.id === 'embedder' || s.id === 'test_embedder')).toBe(false); + expect(aiSettingsManifest.specifiers.some((s) => s.key !== undefined && EMBEDDER_KEYS.includes(s.key))).toBe(false); + }); + + it('a write of an embedder key is refused as an undeclared key', async () => { + const write = await call(http, 'PUT /api/settings/:namespace', { namespace: 'ai' }, { embedder_provider: 'openai' }); + expect(write.status).toBe(400); + expect(write.body?.error?.code).toBe('UNKNOWN_KEY'); + }); + + it('neither test button reaches a handler at its door', async () => { + const route = 'POST /api/settings/:namespace/:actionId'; + const embedder = await call(http, route, { namespace: 'ai', actionId: 'test_embedder' }, { + values: { embedder_provider: 'openai', embedder_api_key: 'sk-test', embedder_model: 'text-embedding-3-small' }, + }); + expect(embedder.status).toBe(400); + expect(embedder.body?.error?.code).toBe('SETTINGS_ACTION_FAILED'); + // "Not reached" is judged against the hub's own no-handler answer for this + // id, never against a copy of its wording. + expect(embedder.body?.error?.details?.message).toBe(settingsActionCopy(undefined).noHandler('test_embedder', 'ai')); + const knowledge = await call(http, route, { namespace: 'knowledge', actionId: 'test' }, { values: { adapter: 'ragflow' } }); + expect(knowledge.status).toBe(404); + expect(knowledge.body?.error?.code).toBe('UNKNOWN_NAMESPACE'); + }); + + it('the stock Setup navigation opens no knowledge page', () => { + const items = SETUP_NAV_CONTRIBUTIONS.flatMap((c) => (c.items ?? []) as Array<{ id?: string; url?: string }>); + // Non-vacuity: the AI entry beside it is there. + expect(items.some((i) => i.id === 'nav_settings_ai')).toBe(true); + expect(items.some((i) => i.id === 'nav_settings_knowledge' || /\/settings\/knowledge$/.test(i.url ?? ''))).toBe(false); + }); + + it('the AI page description names no knowledge base in any locale', () => { + expect(aiSettingsManifest.description).not.toMatch(/knowledge/i); + const bundles = settingsBuiltinTranslations as Record; + const words: Record = { + en: /knowledge/i, 'zh-CN': /知识/, 'zh-Hant': /知識/, 'ja-JP': /ナレッジ/, ko: /지식/, + de: /Wissen/, 'es-ES': /conocimiento/i, fr: /connaissance/i, 'pt-BR': /conhecimento/i, ru: /знани/i, ar: /المعرفة/, + }; + for (const [locale, word] of Object.entries(words)) { + const description = bundles[locale]?.settings?.ai?.description; + expect(typeof description, locale).toBe('string'); + expect(description, locale).not.toMatch(word); + } + }); +}); diff --git a/packages/services/service-settings/src/manifests/ai.manifest.test.ts b/packages/services/service-settings/src/manifests/ai.manifest.test.ts index 16f018b9ff7..5198a1b13ad 100644 --- a/packages/services/service-settings/src/manifests/ai.manifest.test.ts +++ b/packages/services/service-settings/src/manifests/ai.manifest.test.ts @@ -5,7 +5,13 @@ import { SettingsManifestSchema } from '@objectstack/spec/system'; import { PLATFORM_CAPABILITY_PROVIDERS } from '@objectstack/spec/kernel'; import { SettingsService } from '../settings-service.js'; import type { CryptoAdapter } from '../crypto-adapter.js'; -import { aiSettingsManifest, aiTestActionHandler, aiTestEmbedderActionHandler } from './ai.manifest.js'; +import { + aiSettingsManifest, + aiEmbedderSettingsSpecifiers, + withAiEmbedderSection, + aiTestActionHandler, + aiTestEmbedderActionHandler, +} from './ai.manifest.js'; /** * #8026 — the write-door cases below save a complete `openai` provider config, @@ -258,9 +264,9 @@ describe('aiSettingsManifest — the log_prompts PII warning is an info_banner', }); }); -describe('aiSettingsManifest — embedder section', () => { +describe('aiEmbedderSettingsSpecifiers — the embedder section the knowledge service contributes', () => { it('exposes embedder_provider select with 10 options incl. none + 5 Chinese providers', () => { - const f = (aiSettingsManifest.specifiers as any[]).find( + const f = (aiEmbedderSettingsSpecifiers as any[]).find( (s) => s.key === 'embedder_provider' && s.type === 'select', ); expect(f).toBeDefined(); @@ -275,14 +281,14 @@ describe('aiSettingsManifest — embedder section', () => { }); it('marks embedder_api_key as encrypted password', () => { - const f = (aiSettingsManifest.specifiers as any[]).find((s) => s.key === 'embedder_api_key'); + const f = (aiEmbedderSettingsSpecifiers as any[]).find((s) => s.key === 'embedder_api_key'); expect(f).toBeDefined(); expect(f.type).toBe('password'); expect(f.encrypted).toBe(true); }); it('exposes embedder test action wired to /api/settings/ai/test_embedder', () => { - const f = (aiSettingsManifest.specifiers as any[]).find( + const f = (aiEmbedderSettingsSpecifiers as any[]).find( (s) => s.type === 'action_button' && s.id === 'test_embedder', ); expect(f).toBeDefined(); @@ -292,6 +298,13 @@ describe('aiSettingsManifest — embedder section', () => { url: '/api/settings/ai/test_embedder', }); }); + + it('parses inside the ai manifest it joins, and only joins it once', () => { + const joined = withAiEmbedderSection(aiSettingsManifest); + expect(() => SettingsManifestSchema.parse(joined)).not.toThrow(); + expect(joined.specifiers).toHaveLength(aiSettingsManifest.specifiers.length + aiEmbedderSettingsSpecifiers.length); + expect(withAiEmbedderSection(joined)).toBe(joined); + }); }); /** @@ -363,8 +376,9 @@ describe('aiTestActionHandler — live-call hint carries the cloud boundary (#11 }); /** - * #24769 — "Test embedder" is now answered (the handler is in the plugin's - * default map), and what it answers is a form check: no embedding request is + * #24769 — "Test embedder" is now answered (the knowledge service registers + * the handler with the embedder section it contributes, #33933), and what it + * answers is a form check: no embedding request is * sent and no package in this repo replaces it with a live probe. A green * answer must say so, and must not name a package whose mounting would make the * check live. @@ -398,13 +412,15 @@ describe('aiTestEmbedderActionHandler — a form check says it is one (#24769)', describe('aiSettingsManifest — no provider is presented until one is configured (#31960)', () => { const providerSpec = () => (aiSettingsManifest.specifiers as any[]).find((s) => s.key === 'provider' && s.type === 'select'); - const aiSvc = (env: Record = {}, errors: string[] = []) => { + // `withEmbedder` registers the page as a deployment that mounts the + // knowledge service serves it (`withAiEmbedderSection`, #33933). + const aiSvc = (env: Record = {}, errors: string[] = [], withEmbedder = false) => { const svc = new SettingsService({ env, crypto: new ConfidentialTestAdapter(), logger: { error: (m: string) => void errors.push(m) }, }); - svc.registerManifest(aiSettingsManifest); + svc.registerManifest(withEmbedder ? withAiEmbedderSection(aiSettingsManifest) : aiSettingsManifest); return svc; }; @@ -497,7 +513,7 @@ describe('aiSettingsManifest — no provider is presented until one is configure expect(providerSpec().required).toBe(false); const parsed = SettingsManifestSchema.parse(aiSettingsManifest) as any; expect(parsed.specifiers.find((s: any) => s.key === 'provider').required).toBe(false); - const svc = aiSvc(); + const svc = aiSvc({}, [], true); await expect( svc.setMany('ai', { embedder_provider: 'openai', embedder_api_key: 'k', embedder_model: 'text-embedding-3-small' }), ).resolves.toBeDefined(); diff --git a/packages/services/service-settings/src/manifests/ai.manifest.ts b/packages/services/service-settings/src/manifests/ai.manifest.ts index a4388dcce9e..49545782a36 100644 --- a/packages/services/service-settings/src/manifests/ai.manifest.ts +++ b/packages/services/service-settings/src/manifests/ai.manifest.ts @@ -21,11 +21,13 @@ const manifest = { version: 1, label: 'AI', icon: 'Sparkles', + // No knowledge-base wording: the embedder section that serves the knowledge + // service is contributed only where that service is mounted + // (`aiEmbedderSettingsSpecifiers` below). description: - 'LLM provider, model, credentials, and embedder configuration used by ' + - 'the platform AI and knowledge services. Provider SDK packages (e.g. ' + - '@ai-sdk/openai for chat, @objectstack/embedder-openai for embeddings) ' + - 'must be installed on the host for the chosen provider to be loadable at runtime.', + 'LLM provider, model and credentials used by the platform AI service. ' + + 'The provider SDK package (e.g. @ai-sdk/openai) must be installed on the ' + + 'host for the chosen provider to be loadable at runtime.', scope: 'global', readPermission: 'manage_platform_settings', writePermission: 'manage_platform_settings', @@ -252,72 +254,96 @@ const manifest = { { type: 'action_button', id: 'reset', label: 'Reset to environment defaults', required: false, icon: 'RotateCcw', handler: { kind: 'http', method: 'POST', url: '/api/settings/ai/reset' } }, - - // ════════════════════════════════════════════════════════════════ - // Embedder — text → vector provider used by knowledge / RAG. - // Decoupled from the chat provider above so an organisation can - // mix-and-match (e.g. OpenAI for chat + 阿里通义 for embeddings). - // - // The preset list mirrors @objectstack/embedder-openai's - // OPENAI_COMPATIBLE_PRESETS so a UI dropdown maps 1:1 to a - // runtime baseUrl. The "none" choice is the explicit opt-out - // for instances that disable knowledge / RAG entirely. - // ════════════════════════════════════════════════════════════════ - { type: 'group', id: 'embedder', label: 'Embedder', required: false, - description: - 'Text → vector provider used by knowledge sources and RAG. ' + - 'Independent from the chat provider above — mix providers freely ' + - '(e.g. OpenAI for chat + 阿里通义 for embeddings).' }, - { type: 'select', key: 'embedder_provider', label: 'Provider', - required: false, default: 'none', - options: [ - { value: 'none', label: 'Disabled (no embeddings)' }, - { value: 'openai', label: 'OpenAI' }, - { value: 'azure', label: 'Azure OpenAI' }, - { value: 'dashscope', label: '阿里通义 DashScope' }, - { value: 'zhipu', label: '智谱 BigModel' }, - { value: 'siliconflow', label: '硅基流动 SiliconFlow' }, - { value: 'doubao', label: '火山引擎 Doubao' }, - { value: 'minimax', label: 'MiniMax' }, - { value: 'ollama', label: 'Ollama (local)' }, - { value: 'custom', label: 'Custom (OpenAI-compatible)' }, - ], - }, - { type: 'password', key: 'embedder_api_key', label: 'Embedder API key', - required: false, encrypted: true, - description: 'Bearer token sent as Authorization header. For Ollama any non-empty value works.', - visible: "${data.embedder_provider && data.embedder_provider !== 'none'}" }, - { type: 'text', key: 'embedder_model', label: 'Model', - required: false, - description: - 'Examples — OpenAI: text-embedding-3-small · 阿里通义: text-embedding-v3 · ' + - '智谱: embedding-3 · 硅基流动: BAAI/bge-m3 · Ollama: bge-m3', - visible: "${data.embedder_provider && data.embedder_provider !== 'none'}" }, - { type: 'text', key: 'embedder_base_url', label: 'Base URL', - required: false, - description: - 'Endpoint root (without /embeddings). Auto-filled from preset; ' + - 'override for proxies or self-hosted gateways.', - visible: "${data.embedder_provider === 'custom' || data.embedder_provider === 'azure'}" }, - { type: 'number', key: 'embedder_dimensions', label: 'Dimensions', - required: false, min: 1, max: 8192, - description: - 'Override output dimensionality (Matryoshka models only — OpenAI v3, 智谱 embedding-3, BGE-m3 dense). ' + - 'Leave blank to use the model default.', - visible: "${data.embedder_provider && data.embedder_provider !== 'none'}" }, - { type: 'number', key: 'embedder_batch_size', label: 'Batch size', - required: false, default: 64, min: 1, max: 2048, - description: 'Chunks sent to the embedding provider in one request. Reduce if hitting provider rate / size limits.', - visible: "${data.embedder_provider && data.embedder_provider !== 'none'}" }, - { type: 'action_button', id: 'test_embedder', label: 'Test embedder', - required: false, icon: 'Plug', - handler: { kind: 'http', method: 'POST', url: '/api/settings/ai/test_embedder' } }, ], }; -/** AI — provider / model / credentials configuration. */ +/** + * AI — provider / model / credentials configuration. + * + * It carries no embedder section. The embedder keys (`embedder_*`) and the + * "Test embedder" button configure the text-to-vector provider that only the + * knowledge service uses, so they are offered only where that service is + * mounted: `@objectstack/service-knowledge` appends + * {@link aiEmbedderSettingsSpecifiers} to this namespace when it starts beside + * a settings service ({@link withAiEmbedderSection}). A deployment without it + * serves no embedder key: a read or write of one is refused like any key the + * manifest does not declare. + */ export const aiSettingsManifest = manifest as unknown as SettingsManifest; +/** + * The embedder section of the `ai` namespace — the text-to-vector provider the + * knowledge service uses — contributed by `@objectstack/service-knowledge` + * when it is mounted, never by default ({@link aiSettingsManifest}). + * + * The preset list mirrors @objectstack/embedder-openai's + * OPENAI_COMPATIBLE_PRESETS so a UI dropdown maps 1:1 to a runtime baseUrl. + * The "none" choice is the explicit opt-out for an instance that mounts the + * knowledge service and still wants no embeddings. + */ +export const aiEmbedderSettingsSpecifiers: SettingsManifest['specifiers'] = [ + { type: 'group', id: 'embedder', label: 'Embedder', required: false, + description: + 'Text → vector provider used by knowledge sources and RAG. ' + + 'Independent from the chat provider above — mix providers freely ' + + '(e.g. OpenAI for chat + 阿里通义 for embeddings).' }, + { type: 'select', key: 'embedder_provider', label: 'Provider', + required: false, default: 'none', + options: [ + { value: 'none', label: 'Disabled (no embeddings)' }, + { value: 'openai', label: 'OpenAI' }, + { value: 'azure', label: 'Azure OpenAI' }, + { value: 'dashscope', label: '阿里通义 DashScope' }, + { value: 'zhipu', label: '智谱 BigModel' }, + { value: 'siliconflow', label: '硅基流动 SiliconFlow' }, + { value: 'doubao', label: '火山引擎 Doubao' }, + { value: 'minimax', label: 'MiniMax' }, + { value: 'ollama', label: 'Ollama (local)' }, + { value: 'custom', label: 'Custom (OpenAI-compatible)' }, + ], + }, + { type: 'password', key: 'embedder_api_key', label: 'Embedder API key', + required: false, encrypted: true, + description: 'Bearer token sent as Authorization header. For Ollama any non-empty value works.', + visible: "${data.embedder_provider && data.embedder_provider !== 'none'}" }, + { type: 'text', key: 'embedder_model', label: 'Model', + required: false, + description: + 'Examples — OpenAI: text-embedding-3-small · 阿里通义: text-embedding-v3 · ' + + '智谱: embedding-3 · 硅基流动: BAAI/bge-m3 · Ollama: bge-m3', + visible: "${data.embedder_provider && data.embedder_provider !== 'none'}" }, + { type: 'text', key: 'embedder_base_url', label: 'Base URL', + required: false, + description: + 'Endpoint root (without /embeddings). Auto-filled from preset; ' + + 'override for proxies or self-hosted gateways.', + visible: "${data.embedder_provider === 'custom' || data.embedder_provider === 'azure'}" }, + { type: 'number', key: 'embedder_dimensions', label: 'Dimensions', + required: false, min: 1, max: 8192, + description: + 'Override output dimensionality (Matryoshka models only — OpenAI v3, 智谱 embedding-3, BGE-m3 dense). ' + + 'Leave blank to use the model default.', + visible: "${data.embedder_provider && data.embedder_provider !== 'none'}" }, + { type: 'number', key: 'embedder_batch_size', label: 'Batch size', + required: false, default: 64, min: 1, max: 2048, + description: 'Chunks sent to the embedding provider in one request. Reduce if hitting provider rate / size limits.', + visible: "${data.embedder_provider && data.embedder_provider !== 'none'}" }, + { type: 'action_button', id: 'test_embedder', label: 'Test embedder', + required: false, icon: 'Plug', + handler: { kind: 'http', method: 'POST', url: '/api/settings/ai/test_embedder' } }, +] as unknown as SettingsManifest['specifiers']; + +/** + * `manifest` with the embedder section appended, or `manifest` itself when it + * already declares it. The knowledge service registers the result over the + * `ai` namespace it found registered. + */ +export function withAiEmbedderSection(manifest: SettingsManifest): SettingsManifest { + const keys = new Set(manifest.specifiers.map((s) => s.key ?? s.id)); + if (aiEmbedderSettingsSpecifiers.some((s) => keys.has(s.key ?? s.id))) return manifest; + return { ...manifest, specifiers: [...manifest.specifiers, ...aiEmbedderSettingsSpecifiers] }; +} + /** * The live-call hint the three real-provider branches of `ai/test` end with. * @@ -434,18 +460,18 @@ export const aiTestActionHandler: SettingsActionHandler = async ({ values, paylo }; /** - * Handler for `ai/test_embedder` ("Test embedder"), registered by - * `SettingsServicePlugin`'s default `actionHandlers` map (#24769). + * Handler for `ai/test_embedder` ("Test embedder"). Registered by + * `@objectstack/service-knowledge` together with the embedder section it + * contributes ({@link aiEmbedderSettingsSpecifiers}); a deployment without the + * knowledge service has neither the button nor this handler. * * It checks form completeness only — a provider is chosen, an API key is * present (Ollama excepted), a Base URL is present for `custom` / `azure` — * and sends NO embedding request. Nothing in this repository replaces it with - * a live probe: neither `@objectstack/embedder-openai` nor - * `@objectstack/service-knowledge` registers `ai/test_embedder` (a plugin that - * did would call `SettingsService.registerAction`, which replaces this - * handler). So its success message says what was checked and that no request - * was sent, and names no package whose mounting would make this check live — - * none does. + * a live probe (a plugin that did would call `SettingsService.registerAction`, + * which replaces this handler). So its success message says what was checked + * and that no request was sent, and names no package whose mounting would make + * this check live — none does. */ export const aiTestEmbedderActionHandler: SettingsActionHandler = async ({ values, payload }) => { const overrides = extractOverrides(payload); diff --git a/packages/services/service-settings/src/manifests/index.ts b/packages/services/service-settings/src/manifests/index.ts index ee80e77530a..5688b68be7e 100644 --- a/packages/services/service-settings/src/manifests/index.ts +++ b/packages/services/service-settings/src/manifests/index.ts @@ -9,6 +9,8 @@ export { brandingSettingsManifest } from './branding.manifest.js'; export { storageSettingsManifest, storageTestActionHandler } from './storage.manifest.js'; export { aiSettingsManifest, + aiEmbedderSettingsSpecifiers, + withAiEmbedderSection, aiTestActionHandler, aiTestEmbedderActionHandler, } from './ai.manifest.js'; @@ -23,11 +25,18 @@ import { smsSettingsManifest } from './sms.manifest.js'; import { brandingSettingsManifest } from './branding.manifest.js'; import { storageSettingsManifest } from './storage.manifest.js'; import { aiSettingsManifest } from './ai.manifest.js'; -import { knowledgeSettingsManifest } from './knowledge.manifest.js'; import { localizationSettingsManifest } from './localization.manifest.js'; import { companySettingsManifest } from './company.manifest.js'; -/** Convenience aggregate — pass to `SettingsServicePlugin({ manifests })`. */ +/** + * Convenience aggregate — pass to `SettingsServicePlugin({ manifests })`. + * + * The knowledge base is not here, and neither is the `ai` namespace's embedder + * section: both configure `@objectstack/service-knowledge`, which contributes + * them (with their Setup entry and their two actions) when it is mounted, so a + * deployment without that service offers no knowledge settings at all. + * `knowledgeSettingsManifest` stays exported for that contribution. + */ export const builtinSettingsManifests = [ brandingSettingsManifest, companySettingsManifest, @@ -38,5 +47,4 @@ export const builtinSettingsManifests = [ smsSettingsManifest, storageSettingsManifest, aiSettingsManifest, - knowledgeSettingsManifest, ]; diff --git a/packages/services/service-settings/src/manifests/knowledge.manifest.ts b/packages/services/service-settings/src/manifests/knowledge.manifest.ts index 42b8e249d23..5d2a533605e 100644 --- a/packages/services/service-settings/src/manifests/knowledge.manifest.ts +++ b/packages/services/service-settings/src/manifests/knowledge.manifest.ts @@ -133,7 +133,12 @@ const manifest = { ], }; -/** Knowledge — RAG vector-store backend configuration. */ +/** + * Knowledge — RAG vector-store backend configuration. Not in + * `builtinSettingsManifests`: `@objectstack/service-knowledge` registers it + * when it is mounted, so a deployment without the knowledge service offers no + * Knowledge page (#33933). + */ export const knowledgeSettingsManifest = manifest as unknown as SettingsManifest; /** @@ -144,14 +149,14 @@ const FORM_CHECK_ONLY = 'This checks the form only — no connection was attempt /** * Handler for `knowledge/test` ("Test connection"), registered by - * `SettingsServicePlugin`'s default `actionHandlers` map (#24769). + * `@objectstack/service-knowledge` with the manifest it contributes (#33933). * * It checks form completeness only — a Turso auth token beside a managed * `libsql://` URL, a RAGFlow Base URL and API key — and opens NO connection. * Nothing in this repository replaces it with a live probe: - * `@objectstack/service-knowledge`, `@objectstack/knowledge-memory` and - * `@objectstack/knowledge-ragflow` neither read this namespace nor register - * `knowledge/test` (a plugin that did would call + * `@objectstack/service-knowledge` registers exactly this handler, and + * `@objectstack/knowledge-memory` and `@objectstack/knowledge-ragflow` neither + * read this namespace nor register `knowledge/test` (a plugin that did would call * `SettingsService.registerAction`, which replaces this handler). So every * answer on a remote adapter says no connection was attempted, and none names * a package whose mounting would make this check live — none does. diff --git a/packages/services/service-settings/src/settings-default-action-handlers.pin.test.ts b/packages/services/service-settings/src/settings-default-action-handlers.pin.test.ts index 7e6f128e63f..ffdca15b142 100644 --- a/packages/services/service-settings/src/settings-default-action-handlers.pin.test.ts +++ b/packages/services/service-settings/src/settings-default-action-handlers.pin.test.ts @@ -18,6 +18,11 @@ * package are plugin-email (`mail`), service-sms (`sms`) and service-storage * (`storage`). * + * Since #33933 neither of those two buttons is in the bundled slate: the + * knowledge service contributes both, with their handlers, when it is mounted + * (`@objectstack/service-knowledge`, `knowledge-settings-contribution.test.ts`), + * so this default composition declares neither and registers neither. + * * ## What is pinned * * The CLASS, not the two instances: each bundled manifest's `http`-kind @@ -34,11 +39,9 @@ import { afterEach, describe, expect, it, vi } from 'vitest'; import type { PluginContext } from '@objectstack/core'; -import type { IHttpRequest, IHttpResponse, IHttpServer, RouteHandler } from '@objectstack/spec/contracts'; import { SettingsServicePlugin } from './settings-service-plugin.js'; import { SettingsService } from './settings-service.js'; import type { SettingsActionHandler } from './settings-service.types.js'; -import { registerSettingsRoutes } from './settings-routes.js'; import { builtinSettingsManifests } from './manifests/index.js'; /** The settings action route under the plugin's default base path. */ @@ -104,19 +107,16 @@ afterEach(() => { }); describe('[#24769] the default composition answers every declared settings action button', () => { - it('enumerates the declared population — the two buttons this card is about among it', () => { + it('enumerates the declared population — and the two buttons this card was about are not in it', () => { const declared = declaredRouteActions().map((a) => `${a.namespace}/${a.actionId}`); expect(declared).toEqual( - expect.arrayContaining([ - 'ai/test', - 'ai/reset', - 'ai/test_embedder', - 'knowledge/test', - 'mail/test', - 'sms/test', - 'storage/test', - ]), + expect.arrayContaining(['ai/test', 'ai/reset', 'mail/test', 'sms/test', 'storage/test']), ); + // #33933: `ai/test_embedder` and `knowledge/test` arrive with the knowledge + // service, which registers their handlers; its suite drives both at the + // HTTP door (`knowledge-settings-contribution.test.ts`). + expect(declared).not.toContain('ai/test_embedder'); + expect(declared).not.toContain('knowledge/test'); }); it('each button targets its own namespace and its own id on the route', () => { @@ -136,62 +136,3 @@ describe('[#24769] the default composition answers every declared settings actio expect(unanswered).toEqual([]); }); }); - -class MockHttp implements IHttpServer { - routes = new Map(); - private add(method: string, path: string, handler: RouteHandler) { - this.routes.set(`${method} ${path}`, handler); - } - get(path: string, h: RouteHandler) { this.add('GET', path, h); return this as any; } - post(path: string, h: RouteHandler) { this.add('POST', path, h); return this as any; } - put(path: string, h: RouteHandler) { this.add('PUT', path, h); return this as any; } - delete(path: string, h: RouteHandler) { this.add('DELETE', path, h); return this as any; } - patch(path: string, h: RouteHandler) { this.add('PATCH', path, h); return this as any; } - use() { return this as any; } - listen() { return Promise.resolve(); } - close() { return Promise.resolve(); } - getInstance() { return null; } -} - -async function post(http: MockHttp, namespace: string, actionId: string, body: unknown) { - const req = { params: { namespace, actionId }, query: {}, body, headers: {}, method: 'POST', path: '/' } as IHttpRequest; - const state: { status: number; body?: any } = { status: 200 }; - const res = { - json: (data: unknown) => { state.body = data; }, - send: () => {}, - status: (code: number) => { state.status = code; return res; }, - header: () => res, - } as unknown as IHttpResponse; - await http.routes.get('POST /api/settings/:namespace/:actionId')!(req, res); - return state; -} - -describe('[#24769] the two buttons the card measured, at the HTTP door', () => { - // A platform admin: both namespaces gate reads and writes (and so actions) on - // `manage_platform_settings`. - const admin = () => ({ enforced: true, permissions: ['manage_platform_settings'], userId: 'usr_admin' }); - - it('POST /api/settings/ai/test_embedder is answered by the embedder check (200, not 400)', async () => { - const { service } = await bootDefaultPlugin(); - const http = new MockHttp(); - registerSettingsRoutes(http, service, { contextFromRequest: admin }); - const answer = await post(http, 'ai', 'test_embedder', { - values: { embedder_provider: 'openai', embedder_api_key: 'sk-test', embedder_model: 'text-embedding-3-small' }, - }); - expect(answer.status).toBe(200); - expect(answer.body?.data?.ok).toBe(true); - expect(answer.body?.data?.message).toContain('text-embedding-3-small'); - }); - - it('POST /api/settings/knowledge/test is answered by the adapter check (200, not 400)', async () => { - const { service } = await bootDefaultPlugin(); - const http = new MockHttp(); - registerSettingsRoutes(http, service, { contextFromRequest: admin }); - const answer = await post(http, 'knowledge', 'test', { - values: { adapter: 'ragflow', ragflow_base_url: 'http://localhost:9380', ragflow_api_key: 'k' }, - }); - expect(answer.status).toBe(200); - expect(answer.body?.data?.ok).toBe(true); - expect(answer.body?.data?.message).toContain('localhost:9380'); - }); -}); diff --git a/packages/services/service-settings/src/settings-service-plugin.ts b/packages/services/service-settings/src/settings-service-plugin.ts index e21cdfbb3fa..66311f1bc1b 100644 --- a/packages/services/service-settings/src/settings-service-plugin.ts +++ b/packages/services/service-settings/src/settings-service-plugin.ts @@ -56,8 +56,6 @@ import { smsTestActionHandler, storageTestActionHandler, aiTestActionHandler, - aiTestEmbedderActionHandler, - knowledgeTestActionHandler, } from './manifests/index.js'; import { settingsBuiltinTranslations } from './translations/index.js'; @@ -152,8 +150,9 @@ export interface SettingsServicePluginOptions { * Action handlers to register at boot, keyed by namespace and action * id. When omitted, the bundled handler of every `action_button` the * builtin manifests declare is registered (`mail.test`, `sms.test`, - * `storage.test`, `ai.test`, `ai.test_embedder`, `knowledge.test`; - * `reset` is served by the service for every namespace). Providing this + * `storage.test`, `ai.test`; `reset` is served by the service for every + * namespace). `ai.test_embedder` and `knowledge.test` arrive with the + * knowledge service, which contributes their buttons. Providing this * object replaces that whole default map. A plugin may still replace any * one handler later with `SettingsService.registerAction`. */ @@ -209,8 +208,11 @@ export class SettingsServicePlugin implements Plugin { mail: { test: mailTestActionHandler }, sms: { test: smsTestActionHandler }, storage: { test: storageTestActionHandler }, - ai: { test: aiTestActionHandler, test_embedder: aiTestEmbedderActionHandler }, - knowledge: { test: knowledgeTestActionHandler }, + // `ai.test_embedder` and `knowledge.test` are not here: their buttons + // are contributed by `@objectstack/service-knowledge`, which registers + // both handlers with them. `registerAction` refuses a namespace that is + // not registered, so a default entry for `knowledge` would stop the boot. + ai: { test: aiTestActionHandler }, }, }; } diff --git a/packages/services/service-settings/src/settings-visibility-declaration.pin.test.ts b/packages/services/service-settings/src/settings-visibility-declaration.pin.test.ts index a32edb60449..9aaf25fed0f 100644 --- a/packages/services/service-settings/src/settings-visibility-declaration.pin.test.ts +++ b/packages/services/service-settings/src/settings-visibility-declaration.pin.test.ts @@ -27,7 +27,7 @@ import { describe, it, expect } from 'vitest'; import { SettingsManifestSchema, SpecifierSchema } from '@objectstack/spec/system'; -import { builtinSettingsManifests } from './manifests/index.js'; +import { builtinSettingsManifests, knowledgeSettingsManifest, withAiEmbedderSection } from './manifests/index.js'; import { evaluateVisibility, visibilitySource } from './visibility-eval.js'; /** Wrap a predicate in the smallest specifier that carries one. */ @@ -50,11 +50,22 @@ const evaluatorParses = (visible: unknown): boolean => { } }; +/** + * The bundled corpus: every manifest declaration this package ships. #33933 + * took the `knowledge` manifest and the `ai` embedder section out of the + * default aggregate; `@objectstack/service-knowledge` registers them from these + * same declarations, so they stay in the corpus the ruling measured. + */ +const corpus = [ + ...builtinSettingsManifests.map((m) => (m.namespace === 'ai' ? withAiEmbedderSection(m) : m)), + knowledgeSettingsManifest, +]; + describe('settings `visible` — declaration ⇄ evaluator', () => { it('the corpus: every bundled manifest parses against the narrowed declaration', () => { // The #7169 corpus, on the declaration side. Expected refusals: 0. const refusals: string[] = []; - for (const manifest of builtinSettingsManifests as Array>) { + for (const manifest of corpus as Array>) { const parsed = SettingsManifestSchema.safeParse(manifest); if (!parsed.success) { refusals.push(`${manifest.namespace}: ${parsed.error.issues.map((i) => `${i.path.join('.')} — ${i.message}`).join(' | ')}`); @@ -68,7 +79,7 @@ describe('settings `visible` — declaration ⇄ evaluator', () => { // the reader is sent back to the measurement rather than trusting a stale // one. It is a tripwire on the premise, not a rule about how many // predicates a manifest may have — move it deliberately. - const predicates = (builtinSettingsManifests as Array>).flatMap((m) => [ + const predicates = (corpus as Array>).flatMap((m) => [ ...(typeof m.visible === 'undefined' ? [] : [m.visible]), ...(m.specifiers ?? []).filter((s: any) => typeof s.visible !== 'undefined').map((s: any) => s.visible), ]); @@ -78,7 +89,10 @@ describe('settings `visible` — declaration ⇄ evaluator', () => { // policy, ADR-0069 TL;DR 6); it declares no `visible`, so the predicate // count does not move. `auth.mfa_grace_period_days` keeps its one // predicate, now over the three-level `mfa_required`. - expect(builtinSettingsManifests).toHaveLength(10); + // #33933: the aggregate is 9 now, and the corpus is still 10 with the + // `knowledge` manifest the knowledge service registers. + expect(builtinSettingsManifests).toHaveLength(9); + expect(corpus).toHaveLength(10); // 94 -> 96 at #11768: the `audience` group added two gated fields // (`audience_allowed_email_domains`, `audience_self_registration_permission_set`), // each with one `visible` predicate over `data.audience_posture`. @@ -90,7 +104,7 @@ describe('settings `visible` — declaration ⇄ evaluator', () => { }); it('every bundled predicate is accepted by BOTH sides', () => { - for (const manifest of builtinSettingsManifests as Array>) { + for (const manifest of corpus as Array>) { for (const spec of manifest.specifiers ?? []) { if (typeof spec.visible === 'undefined') continue; const where = `${manifest.namespace}.${spec.key ?? '(layout)'}: ${visibilitySource(spec.visible)}`; diff --git a/packages/services/service-settings/src/translations/ar.ts b/packages/services/service-settings/src/translations/ar.ts index ee6825869d0..1a4f5b7b1bd 100644 --- a/packages/services/service-settings/src/translations/ar.ts +++ b/packages/services/service-settings/src/translations/ar.ts @@ -463,7 +463,7 @@ export const ar: PlatformTranslationData = { }, ai: { title: 'الذكاء الاصطناعي والتضمين (Embedder)', - description: 'مزوّد LLM والنموذج وبيانات الاعتماد وإعداد التضمين التي تستخدمها خدمات الذكاء الاصطناعي والمعرفة في المنصة.', + description: 'مزوّد LLM والنموذج وبيانات الاعتماد التي تستخدمها خدمة الذكاء الاصطناعي في المنصة.', groups: { provider: { title: 'المزوّد', diff --git a/packages/services/service-settings/src/translations/de.ts b/packages/services/service-settings/src/translations/de.ts index 5aa3189b628..0e6304e5c00 100644 --- a/packages/services/service-settings/src/translations/de.ts +++ b/packages/services/service-settings/src/translations/de.ts @@ -490,7 +490,7 @@ export const de: PlatformTranslationData = { }, ai: { title: 'KI und Embedder', - description: 'LLM-Anbieter, Modell, Anmeldedaten und Embedder-Konfiguration für die KI- und Wissensdienste der Plattform.', + description: 'LLM-Anbieter, Modell und Anmeldedaten für den KI-Dienst der Plattform.', groups: { provider: { title: 'Anbieter', diff --git a/packages/services/service-settings/src/translations/en.ts b/packages/services/service-settings/src/translations/en.ts index 7760052fd84..089e4ba0949 100644 --- a/packages/services/service-settings/src/translations/en.ts +++ b/packages/services/service-settings/src/translations/en.ts @@ -291,8 +291,7 @@ export const en: PlatformTranslationData = { ai: { title: 'AI & Embedder', description: - 'LLM provider, model, credentials, and embedder configuration used by ' + - 'the platform AI and knowledge services.', + 'LLM provider, model and credentials used by the platform AI service.', groups: { provider: { title: 'Provider', description: 'Choose the LLM backend.' }, diff --git a/packages/services/service-settings/src/translations/es-ES.ts b/packages/services/service-settings/src/translations/es-ES.ts index 148d99114e4..80577c81c4e 100644 --- a/packages/services/service-settings/src/translations/es-ES.ts +++ b/packages/services/service-settings/src/translations/es-ES.ts @@ -429,8 +429,7 @@ export const esES: PlatformTranslationData = { ai: { title: 'IA y Embedder', description: - 'Proveedor de LLM, modelo, credenciales y configuración del embedder usados por ' + - 'los servicios de IA y de conocimiento de la plataforma.', + 'Proveedor de LLM, modelo y credenciales usados por el servicio de IA de la plataforma.', groups: { provider: { title: 'Proveedor', description: 'Elige el backend de LLM.' }, diff --git a/packages/services/service-settings/src/translations/fr.ts b/packages/services/service-settings/src/translations/fr.ts index 234cfb5af12..d39d320b4ec 100644 --- a/packages/services/service-settings/src/translations/fr.ts +++ b/packages/services/service-settings/src/translations/fr.ts @@ -499,7 +499,7 @@ export const fr: PlatformTranslationData = { }, ai: { title: 'IA et Embedder', - description: 'Fournisseur LLM, modèle, identifiants et configuration de l’Embedder utilisés par les services d’IA et de connaissances de la plateforme.', + description: 'Fournisseur LLM, modèle et identifiants utilisés par le service d’IA de la plateforme.', groups: { provider: { title: 'Fournisseur', diff --git a/packages/services/service-settings/src/translations/ja-JP.ts b/packages/services/service-settings/src/translations/ja-JP.ts index a2fb4bcb6fd..d61f2e61127 100644 --- a/packages/services/service-settings/src/translations/ja-JP.ts +++ b/packages/services/service-settings/src/translations/ja-JP.ts @@ -428,7 +428,7 @@ export const jaJP: PlatformTranslationData = { ai: { title: 'AI と Embedder', description: - 'プラットフォームの AI およびナレッジサービスが使用する LLM プロバイダー、モデル、認証情報、Embedder 設定。', + 'プラットフォームの AI サービスが使用する LLM プロバイダー、モデル、認証情報。', groups: { provider: { title: 'プロバイダー', description: 'LLM バックエンドを選択します。' }, diff --git a/packages/services/service-settings/src/translations/ko.ts b/packages/services/service-settings/src/translations/ko.ts index 9f5f2c7f9b2..3f7c94ed01a 100644 --- a/packages/services/service-settings/src/translations/ko.ts +++ b/packages/services/service-settings/src/translations/ko.ts @@ -387,7 +387,7 @@ export const ko: PlatformTranslationData = { }, ai: { title: 'AI 및 Embedder', - description: '플랫폼 AI 및 지식 서비스가 쓰는 LLM 공급자, 모델, 자격 증명, Embedder 설정입니다.', + description: '플랫폼 AI 서비스가 쓰는 LLM 공급자, 모델, 자격 증명입니다.', groups: { provider: { title: '공급자', diff --git a/packages/services/service-settings/src/translations/pt-BR.ts b/packages/services/service-settings/src/translations/pt-BR.ts index 1686c311d6f..64c57f378c2 100644 --- a/packages/services/service-settings/src/translations/pt-BR.ts +++ b/packages/services/service-settings/src/translations/pt-BR.ts @@ -486,7 +486,7 @@ export const ptBR: PlatformTranslationData = { }, ai: { title: 'IA e Embedder', - description: 'Provedor de LLM, modelo, credenciais e configuração do Embedder usados pelos serviços de IA e de conhecimento da plataforma.', + description: 'Provedor de LLM, modelo e credenciais usados pelo serviço de IA da plataforma.', groups: { provider: { title: 'Provedor', diff --git a/packages/services/service-settings/src/translations/ru.ts b/packages/services/service-settings/src/translations/ru.ts index c4c2d4ecfd4..1579aff467d 100644 --- a/packages/services/service-settings/src/translations/ru.ts +++ b/packages/services/service-settings/src/translations/ru.ts @@ -499,7 +499,7 @@ export const ru: PlatformTranslationData = { }, ai: { title: 'ИИ и Embedder', - description: 'Провайдер LLM, модель, учётные данные и настройка Embedder для служб ИИ и знаний платформы.', + description: 'Провайдер LLM, модель и учётные данные для службы ИИ платформы.', groups: { provider: { title: 'Провайдер', diff --git a/packages/services/service-settings/src/translations/settings-translation-coverage.test.ts b/packages/services/service-settings/src/translations/settings-translation-coverage.test.ts index 2e1f2886f2a..a2d70c7e9ae 100644 --- a/packages/services/service-settings/src/translations/settings-translation-coverage.test.ts +++ b/packages/services/service-settings/src/translations/settings-translation-coverage.test.ts @@ -30,13 +30,18 @@ import { en, zhCN, jaJP, esES, zhHant, ar, fr, ptBR, ru, de, ko } from './index. // The manifests barrel also exports action handlers and the aggregate array; // keep only the manifest objects. -const bundledManifests = Object.values(manifestsModule).filter( - (v): v is SettingsManifest => - !!v && - typeof v === 'object' && - 'namespace' in v && - Array.isArray((v as SettingsManifest).specifiers), -); +// The `ai` manifest is held here WITH its embedder section: since #33933 +// `@objectstack/service-knowledge` adds that section when it is mounted, and +// its copy lives in this bundle beside the rest of the page. +const bundledManifests = Object.values(manifestsModule) + .filter( + (v): v is SettingsManifest => + !!v && + typeof v === 'object' && + 'namespace' in v && + Array.isArray((v as SettingsManifest).specifiers), + ) + .map((m) => (m.namespace === 'ai' ? manifestsModule.withAiEmbedderSection(m) : m)); /** * Platform manifests another package registers into the same settings hub, diff --git a/packages/services/service-settings/src/translations/zh-CN.ts b/packages/services/service-settings/src/translations/zh-CN.ts index cd502448eda..d7872bc0f17 100644 --- a/packages/services/service-settings/src/translations/zh-CN.ts +++ b/packages/services/service-settings/src/translations/zh-CN.ts @@ -482,7 +482,7 @@ export const zhCN: PlatformTranslationData = { ai: { title: 'AI 与向量化', - description: '平台 AI 与知识库服务使用的 LLM 提供商、模型、凭据与向量化配置。', + description: '平台 AI 服务使用的 LLM 提供商、模型与凭据。', groups: { provider: { title: '提供商', description: '选择 LLM 后端。' }, gateway: { title: 'Vercel AI Gateway', description: '多提供商路由器。模型写作 provider/model,例如 openai/gpt-4o。' }, diff --git a/packages/services/service-settings/src/translations/zh-Hant.ts b/packages/services/service-settings/src/translations/zh-Hant.ts index bead8431110..bd6e4998aef 100644 --- a/packages/services/service-settings/src/translations/zh-Hant.ts +++ b/packages/services/service-settings/src/translations/zh-Hant.ts @@ -347,7 +347,7 @@ export const zhHant: PlatformTranslationData = { }, ai: { title: 'AI 與 Embedder', - description: '平台 AI 與知識庫服務使用的 LLM 提供者、模型、憑證與 Embedder 設定。', + description: '平台 AI 服務使用的 LLM 提供者、模型與憑證。', groups: { provider: { title: '提供者', description: '選擇 LLM 後端。' }, gateway: { title: 'Vercel AI Gateway', description: '多提供者路由器。模型寫成 provider/model,例如 openai/gpt-4o。' }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6aac79eeae4..1703c4edb3c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3129,6 +3129,9 @@ importers: '@objectstack/core': specifier: workspace:* version: link:../../core + '@objectstack/service-settings': + specifier: workspace:* + version: link:../service-settings '@objectstack/spec': specifier: workspace:* version: link:../../spec @@ -3136,6 +3139,9 @@ importers: '@objectstack/objectql': specifier: workspace:* version: link:../../objectql + '@objectstack/platform-objects': + specifier: workspace:* + version: link:../../platform-objects '@types/node': specifier: ^26.6.5 version: 26.6.5