Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .changeset/33933-knowledge-settings-with-service.md
Original file line number Diff line number Diff line change
@@ -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.

<!-- adr-0087: not-required (no-migration-prescription) No schema key, accepted value or metadata type is added, removed, renamed or re-shaped: settings manifests are runtime registrations, not authorable metadata. The moved answers are settings doors that a deployment without the knowledge service no longer serves; a deployment that mounts it serves them exactly as before, and stored rows are untouched, so there is nothing for a migration to rewrite. -->

**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.
29 changes: 20 additions & 9 deletions docs/qa/platform-checklist/areas/platform-core.json

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions packages/cli/test/connect-agent-both-halves-wire.pin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -280,20 +280,24 @@ 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');
expect(allowedIds).toContain('nav_work_calendars');
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');
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] },
Expand Down
2 changes: 2 additions & 0 deletions packages/services/service-knowledge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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<void> {
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<SettingsService>('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<Record<string, unknown>> {
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<string, RouteHandler>();
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');
});
});
Loading
Loading