Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6ee3b96
refactor(service-knowledge): split KnowledgeService into concern face…
claude Nov 30, 2026
525fb38
refactor(service-knowledge): register KnowledgeService in the facade …
claude Nov 30, 2026
4c4a984
refactor(service-knowledge): facets as host-typed functions the censu…
claude Nov 30, 2026
bac87c0
chore(service-knowledge): ceiling row measured on the split head
claude Nov 30, 2026
5fffac6
Merge origin/main into claude/project-thread-e6npb2
claude Nov 30, 2026
1b7a98c
docs(service-knowledge): name the facet modules in the host and top-l…
claude Nov 30, 2026
6829ee1
docs(service-knowledge): a private member with no docblock is named s…
claude Nov 30, 2026
ad4f458
chore(spec): the knowledge_source liveness ledger cites the moved bod…
claude Nov 30, 2026
1ff5857
feat(spec): source.retrieval.mode, AdapterCapabilities.retrieval and …
claude Nov 30, 2026
8dc9af7
chore(spec): regenerate the generated artifacts for source.retrieval
claude Nov 30, 2026
e582d5e
chore(changeset): source.retrieval.mode and the adapter's retrieval r…
claude Nov 30, 2026
9e57639
test(service-knowledge): the vector-mode contract case reads the vect…
claude Nov 30, 2026
0250e69
Merge remote-tracking branch 'origin/claude/project-thread-vj79kz' in…
claude Nov 30, 2026
9c31e44
feat(service-knowledge): read a source's retrieval mode, and refuse a…
claude Nov 30, 2026
e805371
test(spec): pin KnowledgeRetrievalModeSchema as isomorphic (ADR-0122)
claude Nov 30, 2026
b78a7de
Merge branch 'claude/project-thread-vj79kz' of https://github.com/obj…
claude Nov 30, 2026
14b8b7a
docs(knowledge): the adapter contract carries the retrieval mode; nam…
claude Nov 30, 2026
d22f211
Merge branch 'claude/project-thread-vj79kz' of https://github.com/obj…
claude Nov 30, 2026
dc69544
feat(service-knowledge): index_status names the store a source that n…
claude Nov 30, 2026
2369674
feat(studio): the knowledge source retrieval-mode picker offers the m…
claude Nov 30, 2026
0d18717
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 30, 2026
83af1dd
Merge remote-tracking branch 'origin/claude/project-thread-vj79kz-ser…
claude Nov 30, 2026
dd4cf3e
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 30, 2026
08788c6
fix(platform-objects): name the retrieval-mode choices in every local…
claude Nov 30, 2026
662a70c
test(service-knowledge): keep the tracker id out of the contract suit…
claude Nov 30, 2026
6ea2c54
Merge remote-tracking branch 'origin/claude/project-thread-vj79kz' in…
claude Nov 30, 2026
1bf3ba7
Merge remote-tracking branch 'origin/claude/project-thread-vj79kz-ser…
claude Nov 30, 2026
7436d4f
test(platform-objects): count the retrieval-mode rows in the translat…
claude Nov 30, 2026
77c17a5
Merge remote-tracking branch 'origin/claude/project-thread-vj79kz' in…
claude Nov 30, 2026
9436b32
Merge remote-tracking branch 'origin/claude/project-thread-vj79kz-ser…
claude Nov 30, 2026
2cae196
test(app-shell): the retrieval-mode picker joins the failure-arm nami…
claude Nov 30, 2026
43497e0
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 30, 2026
b15ac8d
docs(spec): cite the ADR-0161 note of 2026-11-30 under K8 by its plac…
claude Nov 30, 2026
a76dc2e
chore(changeset): the platform-objects translations of the retrieval-…
claude Nov 30, 2026
75d7437
fix(spec): the retrieval key warns until the service reads it; the co…
claude Nov 30, 2026
fdba258
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 30, 2026
099d019
Merge PR1 head into the service branch
claude Nov 30, 2026
021016b
Merge branch 'claude/project-thread-vj79kz-service' of https://github…
claude Nov 30, 2026
1a7ba24
Take a published knowledge source whatever its mode; restore the pgve…
claude Nov 30, 2026
3e6c9f3
Merge branch 'claude/project-thread-vj79kz-service' of https://github…
claude Nov 30, 2026
b69e471
Merge branch 'main' of https://github.com/objectstack-ai/objectstack …
claude Nov 30, 2026
25a6dee
Name the spec package in the service changeset: its liveness row flip…
claude Nov 30, 2026
7ba3567
Merge branch 'claude/project-thread-vj79kz-service' of https://github…
claude Nov 30, 2026
d651f4e
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 30, 2026
b93333c
fix(studio): say what a host without the retrieval-mode picker draws
claude Nov 30, 2026
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
12 changes: 12 additions & 0 deletions .changeset/38692-studio-retrieval-mode-picker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@objectstack/spec': patch
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

feat(studio): a knowledge source's retrieval-mode picker offers the modes its store runs

Clause-②: no
Metadata-protocol: none

The `source.retrieval.mode` row of the knowledge source form names a new picker, `knowledge-retrieval-mode`. Studio reads the source's store (the one its `adapter` names, else the deployment's) and its modes from the knowledge service's `index_status` answer, offers those modes, and names which mode the blank choice means ("Store default (Hybrid (both))"). A store that reports no modes, such as memory, is said to declare none ("驱动未声明检索方式"), and a mode already written there is kept and flagged. When the store's modes cannot be read (an author who is not a platform administrator, a store not mounted), the picker offers the three modes and the save judges the choice, as before.
11 changes: 9 additions & 2 deletions packages/spec/src/ai/knowledge-source.metadata-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ import { defineMetadataForm } from '../ui/view.zod';
* - `source.affinity` is the JSON editor too: a list of `{ field, caller,
* mode, places? }` entries whose cross-key rules (a `field` listed in
* `metadataFields`, `places` on a `boost` alone) no list widget states.
* - `source.retrieval.mode` is a select of the three modes, blank for the
* store's default; which modes the store runs is judged at save.
* - `source.retrieval.mode` is the `knowledge-retrieval-mode` picker: Studio
* offers the modes the source's store runs and names its default, or says
* the store declares none. A host whose widget registry lacks that picker
* draws its unregistered-widget face for this row (the JSON editor with its
* notice), not a select: the hint is read before `options`. The three
* `options` stay because the form's generated translations carry their
* labels; no renderer reads them while the hint is set. Which modes the
* store runs is judged at save either way.
*
* ADR-0161 K5 and K10 rule 5: embedding is egress, so `content` offers named
* fields only, and its help says beside it what a build sends and to whom.
Expand Down Expand Up @@ -88,6 +94,7 @@ export const knowledgeSourceForm = defineMetadataForm({
{
field: 'mode',
label: 'Retrieval mode',
widget: 'knowledge-retrieval-mode',
options: [
{ label: 'Vector only (by meaning)', value: 'vector' },
{ label: 'Keyword only (by words)', value: 'keyword' },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* objectstack#38692 phase 1a: a knowledge source's `source.retrieval.mode`
* row names the `knowledge-retrieval-mode` picker. It offers the modes the
* source's store runs and names the store's default; a store that reports no
* modes is said to declare none ("驱动未声明"); without the store's answer the
* three modes are offered and the save judges the choice.
*/

// The source under test reaches these through dynamic imports: their first load is paid at collection.
import '@objectstack/formula';
import '@objectstack/lint';
import { describe, it, expect, vi, afterEach, beforeAll } from 'vitest';
import { render, screen, fireEvent, cleanup } from '@testing-library/react';
import { knowledgeSourceForm } from '@objectstack/spec/ai';
import { WIDGETS, WIDGET_LABELLING, type WidgetContext } from './widgets';
import { storeRetrievalOf, type KnowledgeStoreRetrieval } from './knowledgeRetrieval';

afterEach(cleanup);

beforeAll(() => {
// Radix Select reads pointer capture and scrolls the open item into view; jsdom has neither.
for (const m of ['hasPointerCapture', 'setPointerCapture', 'releasePointerCapture'] as const) {
if (!(m in Element.prototype)) {
(Element.prototype as unknown as Record<string, unknown>)[m] = m === 'hasPointerCapture' ? () => false : () => {};
}
}
if (!Element.prototype.scrollIntoView) Element.prototype.scrollIntoView = () => {};
});

const Picker = WIDGETS['knowledge-retrieval-mode'];

function contextOf(store: KnowledgeStoreRetrieval | 'loading' | 'error'): WidgetContext {
return {
conditionScope: 'none',
knowledgeRetrieval:
store === 'loading'
? { status: 'loading' }
: store === 'error'
? { status: 'error', message: 'index_status answered 403' }
: { status: 'loaded', data: store },
};
}

function open() {
fireEvent.pointerDown(screen.getByTestId('knowledge-retrieval-mode'), { button: 0, ctrlKey: false, pointerType: 'mouse' });
}

const optionNames = () => screen.getAllByRole('option').map((o) => o.textContent);

describe('the published retrieval-mode row (objectstack#38692)', () => {
it('names the picker, under source.retrieval', () => {
type Row = { field?: string; widget?: string; fields?: Row[] };
const found: Array<{ path: string; widget?: string }> = [];
const walk = (list: Row[] | undefined, path: string) => {
for (const row of list ?? []) {
const at = path ? `${path}.${row.field}` : String(row.field);
if (row.widget === 'knowledge-retrieval-mode') found.push({ path: at, widget: row.widget });
walk(row.fields, at);
}
};
for (const section of (knowledgeSourceForm as { sections?: Array<{ fields?: Row[] }> }).sections ?? []) walk(section.fields, '');
expect(found).toEqual([{ path: 'source.retrieval.mode', widget: 'knowledge-retrieval-mode' }]);
});

it('declares control labelling, so the host label names the trigger', () => {
expect(WIDGET_LABELLING['knowledge-retrieval-mode']).toBe('control');
});
});

describe('knowledge-retrieval-mode widget (objectstack#38692)', () => {
const turso: KnowledgeStoreRetrieval = { adapter: 'turso', mounted: true, modes: ['vector', 'keyword', 'hybrid'], default: 'hybrid' };

it("offers the store's modes, and names which one its default is", async () => {
render(<Picker value={undefined} onChange={() => {}} schema={{}} context={contextOf(turso)} />);
expect(screen.getByTestId('knowledge-retrieval-mode')).toHaveTextContent('Store default (Hybrid (both))');
open();
await screen.findAllByRole('option');
expect(optionNames()).toEqual([
'Store default (Hybrid (both))',
'Vector only (by meaning)',
'Keyword only (by words)',
'Hybrid (both)',
]);
});

it('offers only the modes a store lists', async () => {
render(
<Picker
value={undefined}
onChange={() => {}}
schema={{}}
context={contextOf({ adapter: 'vec', mounted: true, modes: ['vector'], default: 'vector' })}
/>,
);
open();
await screen.findAllByRole('option');
expect(optionNames()).toEqual(['Store default (Vector only (by meaning))', 'Vector only (by meaning)']);
});

it('a store that reports no modes: the default alone, and the sentence that it declares none', async () => {
render(<Picker value={undefined} onChange={() => {}} schema={{}} context={contextOf({ adapter: 'memory', mounted: true })} />);
expect(screen.getByTestId('knowledge-retrieval-mode-undeclared')).toHaveTextContent(
'The store memory declares no retrieval modes, so leave this blank.',
);
open();
await screen.findAllByRole('option');
expect(optionNames()).toEqual(['Store default']);
});

it('a stored mode the store does not run is kept as its own option, flagged', async () => {
render(<Picker value="keyword" onChange={() => {}} schema={{}} context={contextOf({ adapter: 'memory', mounted: true })} />);
expect(screen.getByTestId('knowledge-retrieval-mode')).toHaveTextContent('Keyword only (by words) (this store does not run it)');
});

it('without the store answer (refused read, unmounted store, no host): the three modes', async () => {
for (const context of [contextOf('error'), contextOf({ adapter: 'pgvector', mounted: false }), undefined]) {
render(<Picker value={undefined} onChange={() => {}} schema={{}} context={context} />);
expect(screen.queryByTestId('knowledge-retrieval-mode-undeclared')).toBeNull();
open();
await screen.findAllByRole('option');
expect(optionNames()).toEqual(['Store default', 'Vector only (by meaning)', 'Keyword only (by words)', 'Hybrid (both)']);
cleanup();
}
});

it('a mode writes its name; the default removes the key', async () => {
const onChange = vi.fn();
render(<Picker value="hybrid" onChange={onChange} schema={{}} context={contextOf(turso)} />);
open();
fireEvent.click(await screen.findByRole('option', { name: 'Keyword only (by words)' }));
expect(onChange).toHaveBeenLastCalledWith('keyword');
cleanup();
render(<Picker value="keyword" onChange={onChange} schema={{}} context={contextOf(turso)} />);
open();
fireEvent.click(await screen.findByRole('option', { name: 'Store default (Hybrid (both))' }));
expect(onChange).toHaveBeenLastCalledWith(undefined);
});

it('is disabled while loading and read-only', () => {
render(<Picker value="vector" onChange={() => {}} schema={{}} context={contextOf('loading')} />);
expect(screen.getByDisplayValue('vector')).toBeDisabled();
cleanup();
render(<Picker value={undefined} onChange={() => {}} schema={{}} readOnly context={contextOf(turso)} />);
expect(screen.getByTestId('knowledge-retrieval-mode')).toBeDisabled();
});
});

describe('storeRetrievalOf — the store a source binds to, from an index_status answer', () => {
const body = {
success: true,
data: {
ok: true,
details: {
sources: [],
adapters: [
{ id: 'turso', retrieval: { modes: ['vector', 'keyword', 'hybrid'], default: 'hybrid' } },
{ id: 'memory' },
],
defaultAdapter: 'turso',
},
},
};

it("the named store, else the deployment's", () => {
expect(storeRetrievalOf(body, 'memory')).toEqual({ adapter: 'memory', mounted: true });
expect(storeRetrievalOf(body, undefined)).toEqual({
adapter: 'turso',
mounted: true,
modes: ['vector', 'keyword', 'hybrid'],
default: 'hybrid',
});
});

it('a store not mounted, or none placed, is not mounted', () => {
expect(storeRetrievalOf(body, 'pgvector')).toEqual({ adapter: 'pgvector', mounted: false });
const unplaced = { success: true, data: { details: { adapters: [] } } };
expect(storeRetrievalOf(unplaced, undefined)).toEqual({ mounted: false });
});

it('a body with no list of stores is a failed read, never an empty one', () => {
expect(() => storeRetrievalOf({ success: true, data: { details: {} } }, undefined)).toThrow(/no list of stores/);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import {
conditionSubjectsForMetadataType,
} from './conditionScope.js';
import { mapLoaded, usePickerLoad } from './loadState.js';
import { fetchStoreRetrieval, type KnowledgeStoreRetrieval } from './knowledgeRetrieval.js';
import { useCapabilityAudienceLoader } from './useCapabilityAudienceLoader.js';
import {
useMetadataClient,
Expand Down Expand Up @@ -1409,6 +1410,26 @@ function MetadataResourceEditPageImpl({
),
);

// objectstack#38692 phase 1a — the store a knowledge source binds to (the
// one its `adapter` names, else the deployment's) and the retrieval modes it
// runs, for the `knowledge-retrieval-mode` picker. Loaded only when the form
// on screen declares that widget, and again when the source names another
// store.
const declaresRetrievalMode = formDeclaresWidget(
createMode && config.createSchema ? undefined : entry?.form,
'knowledge-retrieval-mode',
);
const draftAdapter =
typeof (draft as { adapter?: unknown } | null)?.adapter === 'string' && (draft as { adapter: string }).adapter.trim()
? (draft as { adapter: string }).adapter.trim()
: undefined;
const knowledgeRetrievalState = usePickerLoad<KnowledgeStoreRetrieval>(
React.useMemo(
() => (declaresRetrievalMode ? () => fetchStoreRetrieval(draftAdapter) : null),
[declaresRetrievalMode, draftAdapter],
),
);

// objectstack#34908 — the audience catalog for the `ref-multi:capability`
// picker (a list view's or a dashboard's `requiredPermissions`): the
// capabilities the environment knows, the permission sets granting each and
Expand Down Expand Up @@ -1476,8 +1497,18 @@ function MetadataResourceEditPageImpl({
componentIds,
permissionSets: permissionSetsState,
loadCapabilityAudience,
knowledgeRetrieval: knowledgeRetrievalState,
}),
[type, objectsState, objectCatalogState, objectViewsState, componentIds, permissionSetsState, loadCapabilityAudience],
[
type,
objectsState,
objectCatalogState,
objectViewsState,
componentIds,
permissionSetsState,
loadCapabilityAudience,
knowledgeRetrievalState,
],
);

// Load layered view + initial draft.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const CONTROL_CASES: WidgetCase[] = [
{ widget: 'related-list-entries', control: (c) => c.querySelector('input[type="text"]'), faceName: 'the related-list entry box' },
{ widget: 'secret', control: (c) => c.querySelector('input[type="password"]'), faceName: 'the masked credential box' },
{ widget: 'field-history', control: (c) => c.querySelector('[role="combobox"]'), faceName: 'the Default / On / Off picker' },
{ widget: 'knowledge-retrieval-mode', control: (c) => c.querySelector('[role="combobox"]'), faceName: 'the retrieval-mode picker' },
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ const CASES: Case[] = [
{ key: 'code', schema: { type: 'string', title: TITLE }, spec: { language: 'javascript' }, value: 'x = 1' },
{ key: 'secret', schema: { type: 'string', title: TITLE }, value: 's3cr3t' },
{ key: 'field-history', schema: { type: 'boolean', title: TITLE }, formData: { type: 'json' }, value: false },
{ key: 'knowledge-retrieval-mode', schema: { type: 'string', title: TITLE, enum: ['vector', 'keyword', 'hybrid'] }, value: 'keyword' },
{ key: 'dynamic-config', schema: { type: 'object', title: TITLE }, spec: { dependsOn: 'driver' }, formData: { driver: 'pg' }, ctx: { dynamicSchemas: { pg: { properties: { host: { type: 'string' } } } } }, value: {} },
{ key: 'dynamic-config', variant: 'unconfigured', schema: { type: 'object', title: TITLE }, spec: { dependsOn: 'driver' }, formData: { driver: '' }, value: {} },
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const FAILED_CTX: WidgetContext = {
objectViews: failed('views: HTTP 503'),
objectActions: failed('actions: HTTP 503'),
datasets: failed('datasets: HTTP 503'),
knowledgeRetrieval: failed('index_status: HTTP 403'),
};

const LOADED_CTX: WidgetContext = {
Expand All @@ -118,6 +119,7 @@ const LOADED_CTX: WidgetContext = {
objectViews: loaded([{ name: 'account.all', label: 'All' }]),
objectActions: loaded([{ name: 'approve' }]),
datasets: loaded([{ name: 'sales_metrics', label: 'Sales metrics', dimensions: [], measures: [] }]),
knowledgeRetrieval: loaded({ adapter: 'turso', mounted: true, modes: ['vector', 'keyword', 'hybrid'], default: 'hybrid' }),
};

interface ControlCase {
Expand Down Expand Up @@ -170,6 +172,8 @@ const CASES: ControlCase[] = [
{ key: 'secret', schema: { type: 'string' }, value: 's3cr3t', banner: null },
// No catalog: the one face is the trigger, on every arm.
{ key: 'field-history', schema: { type: 'boolean' }, value: false, banner: null },
// A refused store read offers the three modes and lets the save judge: no block.
{ key: 'knowledge-retrieval-mode', schema: { type: 'string' }, value: 'keyword', banner: null },
];

/**
Expand Down
Loading
Loading