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
17 changes: 17 additions & 0 deletions .changeset/38551-dataset-term-names-field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@objectstack/service-analytics': patch
'@objectstack/runtime': patch
'@objectstack/mcp': patch
'@objectstack/spec': patch
---

feat(service-analytics): a word that names the field a filtered measure candidate sums is answered from that field, not asked about

Clause-②: no
Metadata-protocol: none

`list_datasets` no longer offers, as a candidate to ask back about, a measure that carries a `filter` and whose aggregated base field the word names: the word equals, or is inside, that field's label or its name (ADR-0149 D3, the amendment note of 2026-12-01). "hours" beside a measure "Billable hours" that sums the field `hours` under a filter is now answered from the field: `nextStep.note` names the field (object and field name), says to answer it with the object query tools labelled as not from a governed metric, and mentions the measure as a narrower declared metric. The measure stays listed in its dataset's entry; it is only absent from `candidates` for that word.

The decision values are unchanged and read as declared: a word left with no candidate is `no_measure`; a word left with dimension candidates stays `candidates_only`, with the field named and no question; a word left with another measure candidate is still asked about, and the field answers only if that question settles nothing. Unchanged, and still asked about: a measure with no `filter` over the named field, a measure over a relationship path, and a word that names different fields through different measures. The take-out runs before the per-word cap of candidates, so a measure taken out uses no slot.

Field labels are read by a new optional `DatasetToolsDeps.readFieldLabel` (the authored label and the translation-bundle label for the answer's locale). Both MCP doors (HTTP and stdio) wire it from the object `describe_object` serves; a host that does not tests the field's name only, as the `list_datasets` description says. The `list_datasets` description and the MCP `initialize` selection rule carry the rule in the same sentence, and the `candidates` and `nextStep.note` descriptions in `@objectstack/spec` say it.
10 changes: 10 additions & 0 deletions content/docs/data-modeling/analytics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ not certain:
list is capped for each word.
- A word whose candidates are all dimensions is read as a possible grouping,
and is not asked about.
- A word that names the field a filtered measure sums is not asked about for
that measure. "Names" means the word equals, or is inside, the field's label
or its name; where the deployment translates field labels, the label in the
person's language counts too. The AI answers from the field itself, says the
answer is not from a governed metric, and mentions the measure as a narrower
declared metric: "hours" over a `hours` field labelled "Hours" is answered
from that field, with "Billable hours" (`sum` of `hours` filtered to billable
entries) mentioned. A measure with no `filter`, a measure over a relationship
path, and a word that names two different fields through different measures
keep the question.

The AI chooses which words of a question to look up. When it looks up a longer
phrase ("overdue deliverables") or Chinese text without word breaks
Expand Down
6 changes: 3 additions & 3 deletions content/docs/references/ai/dataset-tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const result = DatasetNextStepSchema.parse(data);
| :--- | :--- | :--- | :--- |
| **decision** | `Enum<'one_measure' \| 'several_measures' \| 'candidates_only' \| 'no_measure'>` | ✅ | Which case of the ADR-0149 D3 selection rule each term in `terms` is in, computed by the platform from this answer's `matches` and `candidates`. `one_measure`: the term equals exactly one measure. `several_measures`: it equals more than one measure, in one dataset or in several. `candidates_only`: it matched no member and has entries in `candidates`. `no_measure`: it equals no measure and has no entry in `candidates`. A dimension the term equals is not counted |
| **terms** | `string[]` | ✅ | The caller's terms the decision is about, each as sent in the tool's `terms` input. This is the reference to the members the decision rests on, which `nextStep` does not list: they are the entries carrying one of these terms in the same answer, in a dataset's `matches` (those whose `member` is a measure) for `one_measure` and `several_measures`, and in `candidates` for `candidates_only`. `no_measure` rests on no member |
| **note** | `string` | ✅ | The decision in words: finished text in the caller's locale, composed by the tool from this answer and never typed by the model. The wording is the executor's; the schema declares the slot and fixes no text (ADR-0149 M1) |
| **note** | `string` | ✅ | The decision in words: finished text in the caller's locale, composed by the tool from this answer and never typed by the model. Besides this answer's members it may name, for a term, the field that term names which a filtered measure listed here aggregates and which answers it (ADR-0149 D3, the note of 2026-12-01). The wording is the executor's; the schema declares the slot and fixes no text (ADR-0149 M1) |


---
Expand Down Expand Up @@ -256,7 +256,7 @@ const result = DatasetNextStepSchema.parse(data);
| **datasets** | `{ name: string; label: string; description?: string; object: string; … }[]` | ✅ | The datasets this caller may query. A dataset the caller may not query is absent, the same answer as one that does not exist |
| **partial** | `true` | optional | Present, and `true`, when the dataset read was degraded and `datasets` may be incomplete; `warning` says why. Absent on a complete answer |
| **warning** | `string` | optional | Why the answer is partial; present exactly when `partial` is |
| **candidates** | `{ term: string; dataset: string; member: string }[]` | optional | Members offered as possible readings of a term that matched no member of any listed dataset: for a clarifying question when a measure is among the term's candidates. A term whose candidates are all dimensions is offered them as a possible grouping, not for a question, and does not stop a matched measure. A candidate is not a match: its term has no entry in any dataset's `matches`. The platform selects none: the list carries no score, and its order is the listing order stated here, not a ranking. Every candidate is a member this caller may read, listed in `datasets`. Terms in the order sent; for one term, datasets in the order listed, and each dataset's measures before its dimensions, as its entry lists them; at most 5 per term, the first in that order. Present only when `terms` were sent and a term that matched nothing has a candidate; absent otherwise, never an empty list. A term with a match has no candidate |
| **candidates** | `{ term: string; dataset: string; member: string }[]` | optional | Members offered as possible readings of a term that matched no member of any listed dataset: for a clarifying question when a measure is among the term's candidates. A term whose candidates are all dimensions is offered them as a possible grouping, not for a question, and does not stop a matched measure. A measure that carries a filter and whose aggregated field the term names (the term equals, or is inside, that field's label or name) is not offered for that term: the field answers it, labelled as not from a governed metric, and `nextStep.note` names the field and mentions the measure as a narrower declared metric; its dataset's entry still lists it. Such a measure is still offered when the term names different fields through different candidates, and a measure with no filter is offered as before; with another measure candidate left for the term, that one is asked about first and the field answers only if the question settles nothing. A candidate is not a match: its term has no entry in any dataset's `matches`. The platform selects none: the list carries no score, and its order is the listing order stated here, not a ranking. Every candidate is a member this caller may read, listed in `datasets`. Terms in the order sent; for one term, datasets in the order listed, and each dataset's measures before its dimensions, as its entry lists them; at most 5 per term, the first in that order. Present only when `terms` were sent and a term that matched nothing has a candidate; absent otherwise, never an empty list. A term with a match has no candidate |
| **nextStep** | `{ decision: Enum<'one_measure' \| 'several_measures' \| 'candidates_only' \| 'no_measure'>; terms: string[]; note: string }` | optional | Which case of the ADR-0149 D3 selection rule the caller's `terms` are in, as the platform computed it from this answer's own `matches` and `candidates`: the case, the terms it is about and the case in words. It adds no match and no candidate and lists no member: the members it rests on are read from `matches` and `candidates` under its `terms`. Present only when `terms` were sent |

### Nested Shape: `ListDatasetsOutput.datasets[number]`
Expand Down Expand Up @@ -286,7 +286,7 @@ const result = DatasetNextStepSchema.parse(data);
| :--- | :--- | :--- | :--- |
| **decision** | `Enum<'one_measure' \| 'several_measures' \| 'candidates_only' \| 'no_measure'>` | ✅ | Which case of the ADR-0149 D3 selection rule each term in `terms` is in, computed by the platform from this answer's `matches` and `candidates`. `one_measure`: the term equals exactly one measure. `several_measures`: it equals more than one measure, in one dataset or in several. `candidates_only`: it matched no member and has entries in `candidates`. `no_measure`: it equals no measure and has no entry in `candidates`. A dimension the term equals is not counted |
| **terms** | `string[]` | ✅ | The caller's terms the decision is about, each as sent in the tool's `terms` input. This is the reference to the members the decision rests on, which `nextStep` does not list: they are the entries carrying one of these terms in the same answer, in a dataset's `matches` (those whose `member` is a measure) for `one_measure` and `several_measures`, and in `candidates` for `candidates_only`. `no_measure` rests on no member |
| **note** | `string` | ✅ | The decision in words: finished text in the caller's locale, composed by the tool from this answer and never typed by the model. The wording is the executor's; the schema declares the slot and fixes no text (ADR-0149 M1) |
| **note** | `string` | ✅ | The decision in words: finished text in the caller's locale, composed by the tool from this answer and never typed by the model. Besides this answer's members it may name, for a term, the field that term names which a filtered measure listed here aggregates and which answers it (ADR-0149 D3, the note of 2026-12-01). The wording is the executor's; the schema declares the slot and fixes no text (ADR-0149 M1) |


---
Expand Down
20 changes: 20 additions & 0 deletions packages/mcp/src/initialize-selection-rule-34686.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,26 @@ describe('[#34919] initialize instructions — follow nextStep, cite sourceLine'
* description (the real one, read from the executor's package), so the two
* doors cannot drift apart.
*/
/**
* [ADR-0149 D3, amendment note of 2026-12-01] A word that names the field a
* filtered measure candidate aggregates is answered from that field and not
* asked about for that measure: both doors say it in the same words.
*/
describe('[ADR-0149 D3 note of 2026-12-01] initialize instructions — the field a word names, in the same words as list_datasets', () => {
const FIELD_TERM =
'A word that names the field a filtered candidate measure aggregates (it equals or is inside that field\'s '
+ 'label or name) is not asked about for that measure: the field answers it through the object query tools, '
+ 'labelled as not from a governed metric, and the measure is mentioned as a narrower declared metric.';

it('both doors carry the sentence', async () => {
const runtime = new MCPServerRuntime({ name: 't', version: '1.0.0' });
const text = await instructionsOf(runtime, makeBridge());
const list = getDatasetToolDefinitions().find((d) => d.name === LIST_DATASETS_TOOL_NAME)!;
expect(text).toContain(FIELD_TERM);
expect(list.description).toContain(FIELD_TERM);
});
});

describe('[#35005] initialize instructions — the ask-back is scoped in the same words as list_datasets', () => {
const SCOPED =
'A word whose candidates are all dimensions is at most a possible grouping: never ask about it, and it never '
Expand Down
10 changes: 8 additions & 2 deletions packages/mcp/src/mcp-server-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,10 @@ const AUTHORING_CONTRACT_LINE: string | undefined = (() => {
* [#35005] that question is owed only for a word with a measure among its
* candidates: a word whose candidates are all dimensions is at most a possible
* grouping, never asked about and never a stop for a matched measure, in the
* same words as `list_datasets`' description;
* same words as `list_datasets`' description; [ADR-0149 D3, note of
* 2026-12-01] a word that names the field a filtered measure candidate
* aggregates is answered from that field, labelled, the measure mentioned as a
* narrower declared metric, again in `list_datasets`' own words;
* only a word with no match and no candidate falls back to the object tools,
* with the answer labelled. [#34919] The answer itself then states the
* case (`list_datasets` `nextStep`, composed by the service-analytics
Expand All @@ -1912,7 +1915,10 @@ const DATASET_SELECTION_RULE =
+ 'Only the user\'s own word is asked about: one you cut out of a longer phrase of the question, or reworded, '
+ 'is sent to list_datasets once more as the user wrote it instead, never the whole question. '
+ 'A word whose candidates are all dimensions is at most a possible grouping: never ask about it, and it never '
+ 'stops a matched measure. No match '
+ 'stops a matched measure. '
+ 'A word that names the field a filtered candidate measure aggregates (it equals or is inside that field\'s '
+ 'label or name) is not asked about for that measure: the field answers it through the object query tools, '
+ 'labelled as not from a governed metric, and the measure is mentioned as a narrower declared metric. No match '
+ 'and no candidates: fall back to query_records / aggregate_records and say the answer is not from a governed '
+ 'metric. The list_datasets answer states which of these cases your words are in as nextStep: follow its note, '
+ 'which reports the first of several_measures, one_measure, candidates_only, no_measure when words differ. Cite '
Expand Down
101 changes: 101 additions & 0 deletions packages/mcp/src/stdio-data-bridge.dataset-locale.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,104 @@ describe('[ADR-0149 D2] stdio dataset tools when the i18n service resolves but i
expect(en.query.sourceLine).not.toBe(zh.query.sourceLine);
});
});

/**
* [ADR-0149 D3, amendment note of 2026-12-01] The stdio bridge hands the
* executor a field-label read over the object `describe_object` serves on
* this transport, localized for the i18n service's default locale: the
* authored label and the bundle label. The card's case over the REAL executor:
* 「工时」 is the zh-CN bundle label of the field `hours`, authored "Hours",
* which a filtered measure 「计费工时」 sums, so the term is answered from the
* field and not asked about; with an `en` default the bundle label is not the
* answer's, and the term is still asked about.
*/
describe('[ADR-0149 D3] stdio dataset tools read a field\'s label for the term-names-field test', () => {
const TIMESHEET = {
name: 'timesheet',
label: 'Timesheet',
fields: { id: { type: 'text', label: 'Id' }, hours: { type: 'number', label: 'Hours' }, billable: { type: 'boolean', label: 'Billable' } },
};
const TIMESHEETS = {
name: 'timesheets',
label: 'Timesheets',
object: 'timesheet',
dimensions: [],
measures: [{ name: 'billable_hours', label: '计费工时', aggregate: 'sum', field: 'hours', filter: { billable: true } }],
};
const ZH_FIELD = { objects: { timesheet: { fields: { hours: { label: '工时' } } } } };

async function wiredAnalytics(): Promise<AnalyticsService> {
const engine = {
execute: async () => ({ rows: [] }),
hasObjectMiddleware: () => false,
getObject: (name: string) => (name === 'timesheet' ? TIMESHEET : undefined),
resolveEffectiveDatasource: () => undefined,
};
const security = {
getReadFilter: async () => undefined,
canReadObject: () => true,
getReadableFields: async () => Object.keys(TIMESHEET.fields),
getQueryableFields: async () => Object.keys(TIMESHEET.fields),
};
const registered: Record<string, unknown> = { data: engine, security };
const ctx = {
getService: (name: string) => registered[name],
registerService: (name: string, svc: unknown) => { registered[name] = svc; },
replaceService: (name: string, svc: unknown) => { registered[name] = svc; },
logger: { info() {}, warn() {}, error() {}, debug() {} },
};
await new AnalyticsServicePlugin({ queryCapabilities: () => ({ nativeSql: true, objectqlAggregate: false, inMemory: false }) }).init(ctx as never);
return registered.analytics as AnalyticsService;
}

async function bridgeWithDefault(defaultLocale: string) {
const analytics = await wiredAnalytics();
const bound: Array<Parameters<StdioDatasetToolsService['datasetTools']>[0]> = [];
const spy: StdioDatasetToolsService = {
datasetTools: (deps) => {
bound.push(deps);
return analytics.datasetTools(deps as never);
},
};
const bridge = createStdioDataBridge({
engine: {} as any,
metadataService: { list: async () => [] } as any,
protocol: () => ({
getMetaItems: async ({ type }: { type: string }) => ({ items: type === 'dataset' ? [TIMESHEETS] : type === 'object' ? [TIMESHEET] : [] }),
}) as any,
resolvePrincipal: async () => PRINCIPAL as any,
datasetTools: spy,
i18n: () => ({
getLocales: () => ['zh-CN', 'en'],
getTranslations: (locale: string) => (locale === 'zh-CN' ? ZH_FIELD : {}),
getDefaultLocale: () => defaultLocale,
}),
});
return { bridge, bound };
}

it('the read answers the authored label and the bundle label for the default locale, from the object describe_object serves', async () => {
const { bridge, bound } = await bridgeWithDefault('zh-CN');
bridge.datasetToolDefinitions!();
const read = bound[0].readFieldLabel!;
expect(await read('timesheet', 'hours', undefined)).toEqual({ authored: 'Hours', translated: '工时' });
expect(await read('timesheet', 'no_such_field', undefined)).toEqual({ authored: undefined, translated: undefined });
expect(await read('no_such_object', 'hours', undefined)).toBeUndefined();
});

it('工时, the bundle label of the field a filtered measure sums ⇒ no_measure, no candidate, the field named', async () => {
const { bridge } = await bridgeWithDefault('zh-CN');
const answer = (await bridge.listDatasets!({ terms: ['工时'] })) as ListDatasetsOutput;
expect(answer.nextStep!.decision).toBe('no_measure');
expect(answer.candidates).toBeUndefined();
expect(answer.nextStep!.note).toContain('「工时」指的是字段 工时(对象 "timesheet"、字段 "hours")');
});

it('control: an en default, so the bundle label is not the answer\'s, and 工时 is still a candidate and asked about', async () => {
const { bridge } = await bridgeWithDefault('en');
const answer = (await bridge.listDatasets!({ terms: ['工时'] })) as ListDatasetsOutput;
expect(answer.nextStep!.decision).toBe('candidates_only');
expect(answer.candidates).toEqual([{ term: '工时', dataset: 'timesheets', member: 'measures.billable_hours' }]);
expect(answer.nextStep!.note).toContain('ask the user which one they mean');
});
});
Loading
Loading