From fe96c22d8439dd6da22f856272cc1ce548b1faf7 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 20:23:29 +0000 Subject: [PATCH 1/4] feat(spec): the dataset tools' output declares nextStep on list_datasets and sourceLine on query_dataset (ADR-0149 M1) ListDatasetsOutputSchema gains optional nextStep: a closed decision enum (one_measure, several_measures, candidates_only, no_measure), the caller's terms it is about, and a note string slot. It holds no member list: the members are read under its terms from the answer's own matches and candidates, so an answer keeps one list of candidates. QueryDatasetOutputSchema gains optional sourceLine, a non-empty string, declared in the tool's own extend so the shared analytics response is not widened. ADR-0149 M1 gains an add-only amendment note: M1 is unchanged, the spec declares two string slots and one closed enum, and the two sentences are written by the executor. Generated artefacts follow in the next commit. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzfR33NbV51QQU6R6bm --- .../34918-dataset-next-step-source-line.md | 23 +++ ...ions-through-the-dataset-semantic-layer.md | 11 ++ packages/spec/src/ai/dataset-tools.test.ts | 157 ++++++++++++++++++ packages/spec/src/ai/dataset-tools.zod.ts | 101 ++++++++++- .../src/type-alias-convention.pin.test.ts | 16 +- 5 files changed, 303 insertions(+), 5 deletions(-) create mode 100644 .changeset/34918-dataset-next-step-source-line.md diff --git a/.changeset/34918-dataset-next-step-source-line.md b/.changeset/34918-dataset-next-step-source-line.md new file mode 100644 index 00000000000..bc3abdd1179 --- /dev/null +++ b/.changeset/34918-dataset-next-step-source-line.md @@ -0,0 +1,23 @@ +--- +'@objectstack/spec': minor +--- + +feat(spec): the dataset tools' output declares `nextStep` on `list_datasets` and `sourceLine` on `query_dataset` (ADR-0149 M1) + +Clause-②: yes (widening: two optional output members on published schemas) +Metadata-protocol: added +Skills-docs: follow-up owed — skills/objectstack-ask/SKILL.md (follows `nextStep` and cites `sourceLine` once the executor fills them) + +`ListDatasetsOutputSchema` (`@objectstack/spec/ai`) gains one optional member, `nextStep`, with its schema `DatasetNextStepSchema` (type `DatasetNextStep`) and the closed enum `DatasetNextStepDecision`. `QueryDatasetOutputSchema` gains one optional member, `sourceLine`. Nothing is removed or renamed, and an answer without either member parses as it did. + +- **`nextStep`: what it is.** The platform's reading of the caller's `terms` under the ADR-0149 D3 selection rule, as three members: `decision`, `terms` and `note`. +- **`decision` is a closed enum of four cases.** `one_measure` (the term equals exactly one measure), `several_measures` (it equals more than one, 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 candidate). A dimension the term equals is not counted: the rule selects a measure. Any other value does not parse. The values name what the platform found, not what a reader then does. +- **`terms` is the reference to the members, and there is one list of candidates.** `nextStep` holds no member list. It names the caller's terms the decision is about, and the members are read under those terms from the same answer: a dataset's `matches` for `one_measure` and `several_measures`, `candidates` for `candidates_only`. No `{ dataset, member }` pointer is declared twice. +- **`note` and `sourceLine` are string slots.** `note` is the decision in words; `sourceLine` is a `query_dataset` answer's source as one finished line, the same source `provenance` carries as structure. Each is a non-empty string, and the spec declares no wording for either: the text is the executor's (ADR-0149 M1). +- **`sourceLine` is the tool's member only.** It is declared on `QueryDatasetOutputSchema`; `AnalyticsResultResponseSchema`, the REST door's answer, is not changed. +- **When they are present.** Both are optional. `nextStep` is present only when `terms` were sent. No `sourceLine` is the key's absence: an empty string does not parse. +- **Who fills them.** This change declares the shapes only, and each tool's `outputSchema` (`getDatasetToolJsonSchemas()`) lists its member from it. Filling them is the dataset tools' executor's change in `@objectstack/service-analytics`, which ships under its own entry; an answer carries `nextStep` or `sourceLine` only from a release that has both. + +ADR-0149 M1 gains an add-only amendment note recording the ruling: M1 is unchanged, the spec gains two string slots and one closed enum and no sentence, and the two sentences are written by the executor. + +Level: `minor` for `@objectstack/spec`, the level `Metadata-protocol: added` takes. The `authorable-surface/ai.json` baseline records the new keys: `ai/ListDatasetsOutput:nextStep`, the three `ai/DatasetNextStep` members and `ai/QueryDatasetOutput:sourceLine`. diff --git a/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md b/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md index 8ebae3485f6..58206891180 100644 --- a/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md +++ b/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md @@ -253,6 +253,17 @@ Recommendation **A**. 长远合理性: the key the whole industry reads, already 自检行:只看①选 A;②③④ 是否翻转:否。 +> **Amendment note (2026-11-17, [#34918](https://github.com/objectstack-ai/objectstack/issues/34918) — this PR): the two dataset tools' answers may carry a finished sentence each, `nextStep.note` and `sourceLine`; the spec declares a string slot for each and the executor writes the text. M1 stands.** +> Ruled by the maintainer on [#34894](https://github.com/objectstack-ai/objectstack/issues/34894), option A, verbatim 「两件都同意:构建提交进仓库,#34894 选 A」 (ruling record [`6953671481`](https://github.com/objectstack-ai/objectstack/issues/34894#issuecomment-6953671481)). The record states what was ruled: the framework's executor returns `nextStep` (a closed decision, the candidates, a sentence) on `list_datasets` and `sourceLine` on `query_dataset`; the spec declares the shapes; the sentence's text is the executor's and does not enter the spec, so M1 stands. The contract is `packages/spec/src/ai/dataset-tools.zod.ts#ListDatasetsOutputSchema` (its `nextStep` member) with `packages/spec/src/ai/dataset-tools.zod.ts#DatasetNextStepSchema` and `packages/spec/src/ai/dataset-tools.zod.ts#DatasetNextStepDecision`, and `packages/spec/src/ai/dataset-tools.zod.ts#QueryDatasetOutputSchema` (its `sourceLine` member); this note points at them without restating every case. +> +> - **M1 is unchanged.** This note changes no word of M1, of its option table or of its **Ruled A** line. A member `description` is still a plain-language business definition and not a prompt, and AI guidance text still does not enter the spec. +> - **The spec gains two string slots and one closed enum, and no sentence.** `nextStep.note` and `sourceLine` are each a string whose description says what the member is. The spec holds no wording for either, in any language, and no template. The enum is `nextStep.decision`: which case of [D3](#d3--the-selection-rule-and-provenance-the-model-cannot-invent)'s selection rule the caller's terms are in. Its four values name what the platform found (one measure, several measures, candidates only, no measure), not what a reader then does: what follows from each case stays D3's to say, in the three places D3 names. +> - **The sentences are the executor's**, as the tool descriptions are. `@objectstack/service-analytics` composes both, in the caller's locale, from the answer it built: `nextStep.note` from that answer's `matches` and `candidates`, `sourceLine` from its `provenance`. The model types neither. The executor lands with [#34919](https://github.com/objectstack-ai/objectstack/issues/34919). +> - **One list of candidates.** The ruling record's "the candidates" is carried by reference. `nextStep` holds no member list: it names the caller's terms it is about, and the members are read under those terms from the same answer's `matches` and `candidates` (the amendment note under D3). No pointer is declared a second time. +> - **Why a sentence in the result, and not only in a description.** It is the ground given under D3 for `matches` and for `candidates`: a tool result is read by every client that made the call, so the product's agent and an MCP client are handed the same next step and the same source line (#34894, option A). +> - **[D2](#d2--two-tools-one-definition-one-executor-two-transports) and D3 stand as written.** Each tool's output gains one optional member beside the ones D2 lists, and an answer without it parses as before. `provenance` is still the structured source a `query_dataset` answer is rendered from (D3 rule 2); `sourceLine` is that source in words. What counts as a hit, and which rule governs each case, are untouched. +> - **State on `main`.** This PR declares the shapes and changes no executor. Until #34919 lands no answer carries either member. In [D6](#d6--enforce-or-remove-every-key-names-its-reader-in-its-first-implementation-card)'s terms the pending half is named here, by card, and not hidden. + ### M2 — What the AI does when no dataset covers the question 维护者速读:用户问「营收」,但没有任何数据集定义过它。是退回按对象查(今天的做法,答案标明「非指标口径」),还是不答、请管理员先定义? diff --git a/packages/spec/src/ai/dataset-tools.test.ts b/packages/spec/src/ai/dataset-tools.test.ts index 41a8a38e13c..b9dcb07121c 100644 --- a/packages/spec/src/ai/dataset-tools.test.ts +++ b/packages/spec/src/ai/dataset-tools.test.ts @@ -14,12 +14,21 @@ * [ADR-0149 D3, amendment note] `list_datasets` answers a term that matched * nothing with `candidates`: pointers to listed members, never a match and * never an empty list, and an answer without the key parses as before. + * + * [ADR-0149 M1, amendment note] `list_datasets` may state `nextStep`: a closed + * `decision`, the caller's `terms` it is about and a `note`, with no member + * list of its own, so an answer keeps one list of candidates. `query_dataset` + * may state `sourceLine`, on the tool's answer only. Each is optional, and an + * answer without it parses as before. The two texts are string slots: no + * wording is pinned here, because none is declared. */ import { describe, expect, it } from 'vitest'; import { AnalyticsResultResponseSchema, DatasetSelectionSchema } from '../api/analytics.zod'; import { DatasetToolCatalogEntrySchema, + DatasetNextStepDecision, + DatasetNextStepSchema, DatasetProvenanceSchema, DatasetTermCandidateSchema, DatasetTermMatchSchema, @@ -217,6 +226,96 @@ describe('list_datasets candidates', () => { }); }); +describe('list_datasets nextStep', () => { + const entry = { + name: 'billing', + label: '开票', + object: 'invoice', + dimensions: [{ name: 'invoice_status', label: '发票状态', type: 'string' as const }], + measures: [ + { name: 'invoice_count', label: '发票数', aggregate: 'count' as const }, + { name: 'invoice_amount', label: '开票金额', aggregate: 'sum' as const, synonyms: ['金额'] }, + ], + matches: [{ term: '金额', member: 'measures.invoice_amount', matchedOn: 'synonym' as const }], + }; + const candidates = [{ term: 'invoice', dataset: 'billing', member: 'measures.invoice_count' }]; + const nextStep = { decision: 'candidates_only' as const, terms: ['invoice'], note: 'a sentence the executor wrote' }; + + it('the decision is one of four cases, and no other value parses', () => { + expect(DatasetNextStepDecision.options).toEqual(['one_measure', 'several_measures', 'candidates_only', 'no_measure']); + for (const decision of DatasetNextStepDecision.options) { + expect(DatasetNextStepSchema.safeParse({ ...nextStep, decision }).success, decision).toBe(true); + } + for (const decision of ['ask', 'one_match', 'ONE_MEASURE', '', 1, null]) { + const parsed = ListDatasetsOutputSchema.safeParse({ datasets: [entry], nextStep: { ...nextStep, decision } }); + expect(parsed.success, String(decision)).toBe(false); + expect(parsed.error?.issues[0]?.path, String(decision)).toEqual(['nextStep', 'decision']); + } + }); + + it('an answer carries it beside the catalogue and the candidates, and the parse keeps it', () => { + const parsed = ListDatasetsOutputSchema.parse({ datasets: [entry], candidates, nextStep }); + expect(parsed.nextStep).toEqual(nextStep); + expect(parsed.candidates).toEqual(candidates); + }); + + it('an answer without the key parses to the same value as before', () => { + const answer = { datasets: [entry], candidates }; + const parsed = ListDatasetsOutputSchema.parse(answer); + expect(parsed).toEqual(answer); + expect(Object.keys(parsed)).not.toContain('nextStep'); + }); + + it('decision, terms and note are each required, and terms and note are never empty', () => { + for (const key of ['decision', 'terms', 'note'] as const) { + const { [key]: _omitted, ...rest } = nextStep; + const parsed = DatasetNextStepSchema.safeParse(rest); + expect(parsed.success, key).toBe(false); + expect(parsed.error?.issues[0]?.path, key).toEqual([key]); + } + const noTerms = DatasetNextStepSchema.safeParse({ ...nextStep, terms: [] }); + expect(noTerms.success).toBe(false); + expect(noTerms.error?.issues[0]?.path).toEqual(['terms']); + const noNote = DatasetNextStepSchema.safeParse({ ...nextStep, note: '' }); + expect(noNote.success).toBe(false); + expect(noNote.error?.issues[0]?.path).toEqual(['note']); + }); + + it('holds no member list: three keys, and a term is a string, never a pointer', () => { + expect(Object.keys(DatasetNextStepSchema.shape).sort()).toEqual(['decision', 'note', 'terms']); + const pointer = DatasetNextStepSchema.safeParse({ ...nextStep, terms: candidates }); + expect(pointer.success).toBe(false); + expect(pointer.error?.issues[0]?.path).toEqual(['terms', 0]); + }); + + it('an answer has one list of candidates: a list written inside nextStep is not part of the answer', () => { + // The one place a candidate pointer is declared is the answer's `candidates`. + expect(ListDatasetsOutputSchema.shape.candidates.unwrap().element).toBe(DatasetTermCandidateSchema); + const other = [{ term: 'invoice', dataset: 'billing', member: 'dimensions.invoice_status' }]; + const parsed = ListDatasetsOutputSchema.parse({ + datasets: [entry], + candidates, + nextStep: { ...nextStep, candidates: other, matches: entry.matches }, + }); + expect(Object.keys(parsed.nextStep ?? {}).sort()).toEqual(['decision', 'note', 'terms']); + expect(parsed.candidates).toEqual(candidates); + }); + + it('refers to the members by term: they are read from the same answer under `terms`', () => { + const offered = ListDatasetsOutputSchema.parse({ datasets: [entry], candidates, nextStep }); + expect((offered.candidates ?? []).filter((c) => offered.nextStep?.terms.includes(c.term))).toEqual(candidates); + + const matched = ListDatasetsOutputSchema.parse({ + datasets: [entry], + nextStep: { decision: 'one_measure', terms: ['金额'], note: 'a sentence the executor wrote' }, + }); + const measures = matched.datasets.flatMap((d) => (d.matches ?? []) + .filter((m) => matched.nextStep?.terms.includes(m.term) && m.member.startsWith('measures.')) + .map((m) => `${d.name}.${m.member}`)); + expect(measures).toEqual(['billing.measures.invoice_amount']); + }); +}); + describe('query_dataset output', () => { const answer = { rows: [{ stage: 'Won', total_amount: 1200 }], @@ -247,6 +346,31 @@ describe('query_dataset output', () => { expect(QueryDatasetOutputSchema.safeParse(narrowed).success).toBe(true); }); + it('carries `sourceLine`, the source as one line: optional, a string, never empty', () => { + const cited = { ...answer, sourceLine: 'a line the executor wrote' }; + expect(QueryDatasetOutputSchema.parse(cited).sourceLine).toBe('a line the executor wrote'); + + const parsed = QueryDatasetOutputSchema.parse(answer); + expect(parsed).toEqual(answer); + expect(Object.keys(parsed)).not.toContain('sourceLine'); + + for (const sourceLine of ['', 1, null, ['a line']]) { + const refused = QueryDatasetOutputSchema.safeParse({ ...answer, sourceLine }); + expect(refused.success, JSON.stringify(sourceLine)).toBe(false); + expect(refused.error?.issues[0]?.path, JSON.stringify(sourceLine)).toEqual(['sourceLine']); + } + }); + + it('`sourceLine` is the tool\'s member: the REST door\'s answer does not gain it', () => { + expect(Object.keys(QueryDatasetOutputSchema.shape)).toContain('sourceLine'); + expect(Object.keys(AnalyticsResultResponseSchema.shape.data.shape)).not.toContain('sourceLine'); + // The door's `data` is a plain object: a `sourceLine` sent there is not kept. + const door = AnalyticsResultResponseSchema.shape.data.parse({ + rows: answer.rows, fields: answer.fields, sourceLine: 'a line the executor wrote', + }); + expect(Object.keys(door)).not.toContain('sourceLine'); + }); + it('provenance is a dataset source, echoing the caller\'s runtime filter only', () => { expect(DatasetProvenanceSchema.safeParse({ ...provenance, runtimeFilter: { stage: 'won' } }).success).toBe(true); expect(DatasetProvenanceSchema.safeParse({ ...provenance, kind: 'object' }).success).toBe(false); @@ -296,4 +420,37 @@ describe('JSON Schema projection', () => { expect(candidates?.minItems).toBe(1); expect([...(candidates?.items?.required ?? [])].sort()).toEqual(['dataset', 'member', 'term']); }); + + it('the `list_datasets` outputSchema carries `nextStep`: optional, a closed decision, terms by name, a note', () => { + const outputSchema = getDatasetToolJsonSchemas().list_datasets.outputSchema as unknown as { + required: string[]; + properties: Record; + }>; + }; + expect(outputSchema.required).not.toContain('nextStep'); + const nextStep = outputSchema.properties.nextStep; + expect(nextStep?.type).toBe('object'); + expect([...(nextStep?.required ?? [])].sort()).toEqual(['decision', 'note', 'terms']); + expect(nextStep?.additionalProperties).toBe(false); + expect(Object.keys(nextStep?.properties ?? {}).sort()).toEqual(['decision', 'note', 'terms']); + expect(nextStep?.properties?.decision?.enum).toEqual(['one_measure', 'several_measures', 'candidates_only', 'no_measure']); + expect(nextStep?.properties?.terms?.type).toBe('array'); + expect(nextStep?.properties?.terms?.minItems).toBe(1); + expect(nextStep?.properties?.terms?.items?.type).toBe('string'); + expect(nextStep?.properties?.note?.type).toBe('string'); + expect(nextStep?.properties?.note?.minLength).toBe(1); + }); + + it('the `query_dataset` outputSchema carries `sourceLine`: optional, a non-empty string', () => { + const outputSchema = getDatasetToolJsonSchemas().query_dataset.outputSchema as unknown as { + required: string[]; properties: Record; + }; + expect(outputSchema.required).not.toContain('sourceLine'); + expect(outputSchema.properties.sourceLine?.type).toBe('string'); + expect(outputSchema.properties.sourceLine?.minLength).toBe(1); + }); }); diff --git a/packages/spec/src/ai/dataset-tools.zod.ts b/packages/spec/src/ai/dataset-tools.zod.ts index bbb4dce7b5b..653aa4288ae 100644 --- a/packages/spec/src/ai/dataset-tools.zod.ts +++ b/packages/spec/src/ai/dataset-tools.zod.ts @@ -17,10 +17,12 @@ import { AnalyticsResultResponseSchema, DatasetSelectionSchema } from '../api/an * through dashboards and reports: `list_datasets` returns the catalogue (the * datasets the caller may query, their dimensions and measures, each member's * business vocabulary, which of the caller's words matched which member, and, - * for a word that matched nothing, the members offered as `candidates`), + * for a word that matched nothing, the members offered as `candidates`; with + * them `nextStep`, which case of the selection rule those words are in), * and `query_dataset` runs a `DatasetSelection` against one saved dataset and * answers rows plus a `provenance` block naming the dataset and the measures - * used. The shapes are declared here once and projected to the JSON Schema an + * used, with `sourceLine`, that source as one finished line. The shapes are + * declared here once and projected to the JSON Schema an * `AIToolDefinition` carries ({@link getDatasetToolJsonSchemas}), so the MCP * registration and the product AI's registration read one definition. * @@ -39,6 +41,9 @@ import { AnalyticsResultResponseSchema, DatasetSelectionSchema } from '../api/an * `data:read` to `@objectstack/mcp` (card #31590). The tool descriptions, which * carry the ADR-0149 D3 selection rule to the model, are written by the * executor: AI guidance text does not enter the spec (ADR-0149 M1, ruled A). + * The two sentences an answer carries, `nextStep.note` and `sourceLine`, are + * the executor's in the same way (card #34919): the spec declares a string + * slot for each and fixes no wording (the amendment note under M1). */ /** The `list_datasets` tool name, in the `list_objects` family's spelling. */ @@ -141,6 +146,79 @@ export const DatasetTermCandidateSchema = lazySchema(() => z.object({ ), })); +/** + * Which case of the ADR-0149 D3 selection rule a term is in: the `decision` + * of {@link DatasetNextStepSchema}. + * + * D3 selects a MEASURE, so the values count measures. A term that equals a + * dimension and no measure is in `no_measure`: a grouping is not a number + * (rule 5). + * + * - `one_measure`: the term equals exactly one measure (rule 2). + * - `several_measures`: it equals more than one measure, in one dataset or in + * several (rule 3). + * - `candidates_only`: it matched no member and has entries in `candidates` + * (the amendment note under the rules). + * - `no_measure`: it equals no measure and has no entry in `candidates` + * (rule 4). + * + * The set is closed: a value outside it does not parse, and a fifth case is a + * change to this enum, never a free string. + * + * Each value names what the platform FOUND, in the words of the members it + * found it in, and none names what a reader then does. What follows from a + * case is D3's to say, and the text that carries it to a model is the + * executor's (M1). Were the rule for a case re-ruled (M2 names its own + * revisits), the four findings would still be these four. + */ +export const DatasetNextStepDecision = z.enum(['one_measure', 'several_measures', 'candidates_only', 'no_measure']); + +/** + * `list_datasets`' reading of the caller's terms under the ADR-0149 D3 + * selection rule: {@link ListDatasetsOutputSchema}'s `nextStep` (ADR-0149 M1, + * the amendment note under it). + * + * Three members: the case (`decision`), the terms it is about (`terms`) and + * the case in words (`note`). + * + * It holds NO member list. The members a decision rests on are already in the + * answer: a match is an entry of a dataset's `matches` + * ({@link DatasetTermMatchSchema}), a candidate is an entry of `candidates` + * ({@link DatasetTermCandidateSchema}), and both carry the caller's `term`. + * `terms` is that same key, so the reference is by term and no + * `{ dataset, member }` pointer is declared a second time: an answer has one + * list of candidates, and `nextStep` holds no second one that could disagree + * with it. + * + * The caller's terms can be in different cases (one equals a measure, another + * has only candidates). Which case one answer reports is the executor's rule; + * the shape says which terms the reported case is about. + * + * What a schema cannot refuse is the executor's to hold, as it is for + * `candidates`: that `decision` is the case the named terms are in, and that + * every term named was sent. + */ +export const DatasetNextStepSchema = lazySchema(() => z.object({ + decision: DatasetNextStepDecision.describe( + '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: z.array(z.string()).min(1).describe( + 'The caller\'s terms the decision is about, each as sent in `terms`. 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: z.string().min(1).describe( + '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)', + ), +})); + /** * A dimension as the catalogue lists it. * @@ -234,6 +312,12 @@ export const ListDatasetsOutputSchema = lazySchema(() => z.object({ + '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: DatasetNextStepSchema.optional().describe( + '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', + ), })); // ========================================== @@ -322,11 +406,22 @@ export const DatasetProvenanceSchema = lazySchema(() => z.object({ * `AnalyticsResultResponseSchema`'s `data`, so a column property the REST door * gains reaches the tool without a second edit. `sql` is left out: the AI is * given no raw SQL (ADR-0021). + * + * `sourceLine` is declared in the `.extend` below, beside `provenance`: a + * member of the tool's answer only. `AnalyticsResultResponseSchema` is not + * edited, so the REST door's answer and every other reader of it are what + * they were. */ export const QueryDatasetOutputSchema = lazySchema(() => AnalyticsResultResponseSchema.shape.data .omit({ sql: true }) .extend({ provenance: DatasetProvenanceSchema.describe('The dataset and members the answer was computed from'), + sourceLine: z.string().min(1).optional().describe( + 'The answer\'s source as one finished line, in the caller\'s locale: composed by the tool from `provenance` ' + + 'after the query ran, never typed by the model. `provenance` stays the structured source and this is the ' + + 'same source in words. The wording is the executor\'s; the schema declares the slot and fixes no text ' + + '(ADR-0149 M1). Absent when the tool composed none, never an empty string', + ), rowCount: z.number().int().nonnegative().describe('How many rows `rows` holds'), truncated: z.boolean().describe( '`true` when more rows existed past the row cap the tool applied and were not returned', @@ -391,6 +486,8 @@ export type ListDatasetsInput = z.input; export type DatasetTermMatchedOn = z.input; export type DatasetTermMatch = z.input; export type DatasetTermCandidate = z.input; +export type DatasetNextStepDecision = z.input; +export type DatasetNextStep = z.input; export type DatasetToolCatalogDimension = z.input; export type DatasetToolCatalogMeasure = z.input; export type DatasetToolCatalogEntry = z.input; diff --git a/packages/spec/src/type-alias-convention.pin.test.ts b/packages/spec/src/type-alias-convention.pin.test.ts index e5533095eb0..15d02f0c037 100644 --- a/packages/spec/src/type-alias-convention.pin.test.ts +++ b/packages/spec/src/type-alias-convention.pin.test.ts @@ -304,7 +304,7 @@ import type * as M204 from './ai/dataset-tools.zod.js'; import type * as M205 from './ai/object-query-source.zod.js'; // --------------------------------------------------------------------------- -// 858 isomorphic aliases: `z.input` === `z.infer`, so no `XParsed` is declared. +// 860 isomorphic aliases: `z.input` === `z.infer`, so no `XParsed` is declared. // // That number is machine-checked, not hand-kept. The runtime companion at the // bottom of this file recomputes the pin count from the source and asserts that @@ -382,6 +382,8 @@ export type Iso_ai_conversation__TextContentSchema = Assert, z.infer< typeof M1.TokenBudgetStrategySchema > >>; // ai/dataset-tools.zod.ts -- [ADR-0149 D2] plain objects, enums and literals, no default and no transform +export type Iso_ai_datasetTools__DatasetNextStepDecision = Assert, z.infer< typeof M204.DatasetNextStepDecision > >>; +export type Iso_ai_datasetTools__DatasetNextStepSchema = Assert, z.infer< typeof M204.DatasetNextStepSchema > >>; export type Iso_ai_datasetTools__DatasetProvenanceSchema = Assert, z.infer< typeof M204.DatasetProvenanceSchema > >>; export type Iso_ai_datasetTools__DatasetTermCandidateSchema = Assert, z.infer< typeof M204.DatasetTermCandidateSchema > >>; export type Iso_ai_datasetTools__DatasetTermMatchSchema = Assert, z.infer< typeof M204.DatasetTermMatchSchema > >>; @@ -1833,7 +1835,7 @@ describe('ADR-0122 type-alias convention', () => { // this title and the section header above the pin list — are now asserted // against the recomputed count below, so neither can go stale without a red // test naming it. - it('still declares all 858 isomorphic pins', () => { + it('still declares all 860 isomorphic pins', () => { // The truth of each pin is proved by tsc, not here — an `Assert>` // that stops holding is a compile error with the alias named. What tsc // cannot notice is a pin that was DELETED: removing the assertion removes @@ -2916,7 +2918,15 @@ describe('ADR-0122 type-alias convention', () => { // (Iso_ai_datasetTools__DatasetTermCandidateSchema). +1 added. The // `candidates` list it fills on `ListDatasetsOutputSchema` is an optional // array of that object, so that schema's own pin still holds. - expect(pins).toHaveLength(858); + // 858 -> 860 is the ADR-0149 M1 amendment note's `nextStep` + // (`ai/dataset-tools.zod.ts`): `DatasetNextStepDecision`, a closed enum of + // four values, and `DatasetNextStepSchema`, a plain object of that enum, a + // non-empty array of strings and a non-empty string, no default and no + // transform in either (Iso_ai_datasetTools__DatasetNextStepDecision, + // Iso_ai_datasetTools__DatasetNextStepSchema). +2 added. `nextStep` on + // `ListDatasetsOutputSchema` and `sourceLine` on `QueryDatasetOutputSchema` + // are optional members with no default, so those two pins still hold. + expect(pins).toHaveLength(860); // The count is stated in PROSE twice as well — this case's title and the // section header above the pin list — and until commit c6b05c76a nothing read either From d10ea09296e107c40685477e157d64ef8746e1a5 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 20:33:44 +0000 Subject: [PATCH 2/4] chore(spec): regenerate the artefacts for nextStep and sourceLine Generator output only, plus one description reworded so the nextStep terms member names the tool's terms input and not itself: api-surface, authorable-surface, declaration-map, export-origins and json-schema.manifest for ai, the dataset-tools reference page, the reference index totals (1670 to 1672, AI 82 to 84) and the strictness ledger count for ai (97 to 98). Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzfR33NbV51QQU6R6bm --- content/docs/references/ai/dataset-tools.mdx | 50 +++++++++++++++++-- content/docs/references/index.mdx | 10 ++-- .../ai.md | 2 +- packages/spec/api-surface/ai.json | 4 ++ packages/spec/authorable-surface/ai.json | 5 ++ packages/spec/declaration-map/ai.json | 3 ++ packages/spec/export-origins/ai.json | 3 ++ packages/spec/json-schema.manifest/ai.json | 2 + packages/spec/src/ai/dataset-tools.zod.ts | 9 ++-- 9 files changed, 73 insertions(+), 15 deletions(-) diff --git a/content/docs/references/ai/dataset-tools.mdx b/content/docs/references/ai/dataset-tools.mdx index a69e3632d2f..efefe0843ae 100644 --- a/content/docs/references/ai/dataset-tools.mdx +++ b/content/docs/references/ai/dataset-tools.mdx @@ -13,10 +13,12 @@ The two tools give an AI the business semantic layer a person already reads through dashboards and reports: `list_datasets` returns the catalogue (the datasets the caller may query, their dimensions and measures, each member's business vocabulary, which of the caller's words matched which member, and, -for a word that matched nothing, the members offered as `candidates`), +for a word that matched nothing, the members offered as `candidates`; with +them `nextStep`, which case of the selection rule those words are in), and `query_dataset` runs a `DatasetSelection` against one saved dataset and answers rows plus a `provenance` block naming the dataset and the measures -used. The shapes are declared here once and projected to the JSON Schema an +used, with `sourceLine`, that source as one finished line. The shapes are +declared here once and projected to the JSON Schema an `AIToolDefinition` carries (`getDatasetToolJsonSchemas`), so the MCP registration and the product AI's registration read one definition. @@ -35,6 +37,9 @@ zero-match term's candidates and the row cap `data:read` to `@objectstack/mcp` (card #31590). The tool descriptions, which carry the ADR-0149 D3 selection rule to the model, are written by the executor: AI guidance text does not enter the spec (ADR-0149 M1, ruled A). +The two sentences an answer carries, `nextStep.note` and `sourceLine`, are +the executor's in the same way (card #34919): the spec declares a string +slot for each and fixes no wording (the amendment note under M1). **Source:** `packages/spec/src/ai/dataset-tools.zod.ts` @@ -43,13 +48,38 @@ executor: AI guidance text does not enter the spec (ADR-0149 M1, ruled A). ## TypeScript Usage ```typescript -import { DatasetProvenanceSchema, DatasetTermCandidateSchema, DatasetTermMatchSchema, DatasetTermMatchedOn, DatasetToolCatalogDimensionSchema, DatasetToolCatalogEntrySchema, DatasetToolCatalogMeasureSchema, ListDatasetsInputSchema, ListDatasetsOutputSchema, QueryDatasetInputSchema, QueryDatasetOutputSchema } from '@objectstack/spec/ai'; -import type { DatasetProvenance, DatasetTermCandidate, DatasetTermMatch, DatasetTermMatchedOn, DatasetToolCatalogDimension, DatasetToolCatalogEntry, DatasetToolCatalogMeasure, ListDatasetsInput, ListDatasetsOutput, QueryDatasetInput, QueryDatasetOutput } from '@objectstack/spec/ai'; +import { DatasetNextStepSchema, DatasetNextStepDecision, DatasetProvenanceSchema, DatasetTermCandidateSchema, DatasetTermMatchSchema, DatasetTermMatchedOn, DatasetToolCatalogDimensionSchema, DatasetToolCatalogEntrySchema, DatasetToolCatalogMeasureSchema, ListDatasetsInputSchema, ListDatasetsOutputSchema, QueryDatasetInputSchema, QueryDatasetOutputSchema } from '@objectstack/spec/ai'; +import type { DatasetNextStep, DatasetNextStepDecision, DatasetProvenance, DatasetTermCandidate, DatasetTermMatch, DatasetTermMatchedOn, DatasetToolCatalogDimension, DatasetToolCatalogEntry, DatasetToolCatalogMeasure, ListDatasetsInput, ListDatasetsOutput, QueryDatasetInput, QueryDatasetOutput } from '@objectstack/spec/ai'; // Validate data -const result = DatasetProvenanceSchema.parse(data); +const result = DatasetNextStepSchema.parse(data); ``` +--- + +## DatasetNextStep + +### Properties + +| Property | Type | Required | Description | +| :--- | :--- | :--- | :--- | +| **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) | + + +--- + +## DatasetNextStepDecision + +### Allowed Values + +* `one_measure` +* `several_measures` +* `candidates_only` +* `no_measure` + + --- ## DatasetProvenance @@ -227,6 +257,7 @@ const result = DatasetProvenanceSchema.parse(data); | **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. 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]` @@ -249,6 +280,14 @@ const result = DatasetProvenanceSchema.parse(data); | **dataset** | `string` | ✅ | The dataset the offered member belongs to, by name: an entry of `datasets` in the same answer, and what `query_dataset` takes as `datasetName` | | **member** | `string` | ✅ | The member offered, as `measures.` or `dimensions.`: a member that dataset's entry lists. The term does not equal any of its words after normalization | +### Nested Shape: `ListDatasetsOutput.nextStep` + +| Property | Type | Required | Description | +| :--- | :--- | :--- | :--- | +| **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) | + --- @@ -296,6 +335,7 @@ const result = DatasetProvenanceSchema.parse(data); | **drillRanges** | `Record[]` | optional | Drill-through sidecar for date ranges, aligned to `rows` by index: date dimension name to the half-open range `[gte, lt)` that row's records fall in on that dimension's field. A time bucket gets the span it covers; a `timeDimensions[].dateRange` window gets the window the query filtered by on every row, or narrows the bucket entry on the same field to the part inside the window. Bounds are `YYYY-MM-DD` calendar days, or ISO-8601 instants when the source field is `datetime` (a bucket's at midnight in the reference timezone); a row whose bucket value is null gets no bucket entry, and a window whose end is an instant or the last supported day gets none. Set only on a dataset answer that has rows and groups by at least one `type: 'date'` dimension with a `field` and a granularity, or carries a `dateRange` on a dimension with a `field`; independent of `dimensionFields`. Absent on a cube query answer. | | **drillScopes** | `Record` | optional | Drill-through sidecar per measure: each selected measure name to the list filter, on the answer's `object`, that selects the records that measure aggregates: the dataset's own `filter`, AND the measure's own `filter`, AND, for a measure over a `field`, that field holding a value (`{ "$null": false }`; both instants for a duration measure), with each `{token}` resolved as the query resolved it; `{}` when none of these applies. A drill lists the clicked bucket (`dimensionFields` / `drillRawRows` / `drillRawTotals`, `drillRanges`) AND the widget's own filter AND this scope. A measure is left out when no list filter on `object` selects its records (a derived measure; a scope that names a relationship path such as `account.region`, as a key or as a `$field` reference), and a measure left out offers no drill. Keyed by measure name: a `__compare` column has no entry. Set on every dataset answer (`POST /analytics/dataset/query`) that has rows; absent on a cube query answer and on a draft-preview answer. | | **provenance** | `{ kind: 'dataset'; dataset: object; measures: object[]; dimensions: object[]; … }` | ✅ | The dataset and members the answer was computed from | +| **sourceLine** | `string` | optional | The answer's source as one finished line, in the caller's locale: composed by the tool from `provenance` after the query ran, never typed by the model. `provenance` stays the structured source and this is the same source in words. The wording is the executor's; the schema declares the slot and fixes no text (ADR-0149 M1). Absent when the tool composed none, never an empty string | | **rowCount** | `integer` | ✅ | How many rows `rows` holds | | **truncated** | `boolean` | ✅ | `true` when more rows existed past the row cap the tool applied and were not returned | | **delegationNarrowed** | `true` | optional | Present, and `true`, when the caller acts as an agent whose authority narrows what it may read on the dataset's object; `warning` states the narrowing (ADR-0090 D10) | diff --git a/content/docs/references/index.mdx b/content/docs/references/index.mdx index 041ab33b738..d84f1198561 100644 --- a/content/docs/references/index.mdx +++ b/content/docs/references/index.mdx @@ -1,7 +1,7 @@ --- title: Protocol reference — every schema by module navTitle: Protocol Reference -description: Every schema published by @objectstack/spec — 1670 schemas across 14 protocol modules +description: Every schema published by @objectstack/spec — 1672 schemas across 14 protocol modules --- {/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */} @@ -20,7 +20,7 @@ counts are sums of the rows they head. Regenerate with | Module | Pages | Schemas | Description | | :--- | ---: | ---: | :--- | -| [AI Protocol](/docs/references/ai) | 14 | 82 | Agents, tools, skills, RAG and knowledge sources, model registry, conversations. | +| [AI Protocol](/docs/references/ai) | 14 | 84 | Agents, tools, skills, RAG and knowledge sources, model registry, conversations. | | [API Protocol](/docs/references/api) | 36 | 496 | REST contracts, endpoints, routing, realtime, batch, discovery. | | [Automation Protocol](/docs/references/automation) | 16 | 82 | Flows and their nodes, approvals, ETL pipelines, webhooks, state machines, execution records. | | [Data Protocol](/docs/references/data) | 35 | 188 | Objects, fields, queries, filters, datasources and drivers — the ObjectQL layer. | @@ -34,13 +34,13 @@ counts are sums of the rows they head. Regenerate with | [Studio Protocol](/docs/references/studio) | 3 | 35 | Studio designer metadata — the authoring surfaces for the protocols above. | | [System Protocol](/docs/references/system) | 40 | 297 | The runtime environment — logging, jobs, cache, metrics, notifications, i18n and compliance. | | [UI Protocol](/docs/references/ui) | 16 | 177 | Apps, pages, views, dashboards, reports, actions and themes — the ObjectUI layer. | -| **Total** | **218** | **1670** | 14 protocol modules | +| **Total** | **218** | **1672** | 14 protocol modules | --- ## AI Protocol -**Source:** `packages/spec/src/ai/` · **Import:** `@objectstack/spec/ai` · **14 pages, 82 schemas** +**Source:** `packages/spec/src/ai/` · **Import:** `@objectstack/spec/ai` · **14 pages, 84 schemas** Agents, tools, skills, RAG and knowledge sources, model registry, conversations. @@ -49,7 +49,7 @@ Agents, tools, skills, RAG and knowledge sources, model registry, conversations. | [`agent.zod.ts`](/docs/references/ai/agent) | `AIModelConfig`, `Agent`, `StructuredOutputConfig`, `StructuredOutputFormat`, `TransformPipelineStep` | | [`build-progress.zod.ts`](/docs/references/ai/build-progress) | `BuildProgressFrame`, `BuildProgressPhase` | | [`conversation.zod.ts`](/docs/references/ai/conversation) | `CodeContent`, `ConversationAnalytics`, `ConversationContext`, `ConversationMessage`, `ConversationSession`, `ConversationSummary`, `FileContent`, `FunctionCall`, `ImageContent`, `MessageContent`, `MessageContentType`, `MessagePruningEvent`, `MessageRole`, `TextContent`, `TokenBudgetConfig`, `TokenBudgetStrategy`, `TokenUsageStats`, `ToolCall` | -| [`dataset-tools.zod.ts`](/docs/references/ai/dataset-tools) | `DatasetProvenance`, `DatasetTermCandidate`, `DatasetTermMatch`, `DatasetTermMatchedOn`, `DatasetToolCatalogDimension`, `DatasetToolCatalogEntry`, `DatasetToolCatalogMeasure`, `ListDatasetsInput`, `ListDatasetsOutput`, `QueryDatasetInput`, `QueryDatasetOutput` | +| [`dataset-tools.zod.ts`](/docs/references/ai/dataset-tools) | `DatasetNextStep`, `DatasetNextStepDecision`, `DatasetProvenance`, `DatasetTermCandidate`, `DatasetTermMatch`, `DatasetTermMatchedOn`, `DatasetToolCatalogDimension`, `DatasetToolCatalogEntry`, `DatasetToolCatalogMeasure`, `ListDatasetsInput`, `ListDatasetsOutput`, `QueryDatasetInput`, `QueryDatasetOutput` | | [`embedding.zod.ts`](/docs/references/ai/embedding) | `EmbeddingModel`, `VectorStore`, `VectorStoreProvider` | | [`knowledge-document.zod.ts`](/docs/references/ai/knowledge-document) | `KnowledgeChunk`, `KnowledgeDocument`, `KnowledgeHit` | | [`knowledge-source.zod.ts`](/docs/references/ai/knowledge-source) | `FileKnowledgeSource`, `HttpKnowledgeSource`, `KnowledgeRefreshPolicy`, `KnowledgeSource`, `KnowledgeSourceKind`, `ObjectKnowledgeSource` | diff --git a/docs/audits/2026-07-unknown-key-strictness-ledger.counts/ai.md b/docs/audits/2026-07-unknown-key-strictness-ledger.counts/ai.md index 8e5ab008a41..f3c5b4c26d1 100644 --- a/docs/audits/2026-07-unknown-key-strictness-ledger.counts/ai.md +++ b/docs/audits/2026-07-unknown-key-strictness-ledger.counts/ai.md @@ -19,4 +19,4 @@ hand-patch a number here** — fix the code or the verdict and regenerate. | Dir | Sites | |---|---| -| `ai/` | 97 | +| `ai/` | 98 | diff --git a/packages/spec/api-surface/ai.json b/packages/spec/api-surface/ai.json index ccd723b8d1a..1210460d916 100644 --- a/packages/spec/api-surface/ai.json +++ b/packages/spec/api-surface/ai.json @@ -56,6 +56,10 @@ "ConversationSessionSchema (const)", "ConversationSummary (type)", "ConversationSummarySchema (const)", + "DatasetNextStep (type)", + "DatasetNextStepDecision (const)", + "DatasetNextStepDecision (type)", + "DatasetNextStepSchema (const)", "DatasetProvenance (type)", "DatasetProvenanceSchema (const)", "DatasetTermCandidate (type)", diff --git a/packages/spec/authorable-surface/ai.json b/packages/spec/authorable-surface/ai.json index f9c51d0e5ec..95b2a780c22 100644 --- a/packages/spec/authorable-surface/ai.json +++ b/packages/spec/authorable-surface/ai.json @@ -158,6 +158,9 @@ "ai/ConversationSummary:summary", "ai/ConversationSummary:summaryTokens", "ai/ConversationSummary:tokensSaved", + "ai/DatasetNextStep:decision", + "ai/DatasetNextStep:note", + "ai/DatasetNextStep:terms", "ai/DatasetProvenance:dataset", "ai/DatasetProvenance:dimensions", "ai/DatasetProvenance:kind", @@ -247,6 +250,7 @@ "ai/ListDatasetsInput:terms", "ai/ListDatasetsOutput:candidates", "ai/ListDatasetsOutput:datasets", + "ai/ListDatasetsOutput:nextStep", "ai/ListDatasetsOutput:partial", "ai/ListDatasetsOutput:warning", "ai/MCPServerRef:active", @@ -369,6 +373,7 @@ "ai/QueryDatasetOutput:provenance", "ai/QueryDatasetOutput:rowCount", "ai/QueryDatasetOutput:rows", + "ai/QueryDatasetOutput:sourceLine", "ai/QueryDatasetOutput:totals", "ai/QueryDatasetOutput:truncated", "ai/QueryDatasetOutput:warning", diff --git a/packages/spec/declaration-map/ai.json b/packages/spec/declaration-map/ai.json index 7bd7960b23f..409e0d78f00 100644 --- a/packages/spec/declaration-map/ai.json +++ b/packages/spec/declaration-map/ai.json @@ -42,6 +42,9 @@ "ConversationSessionSchema": "ai/ConversationSession", "ConversationSummary": "ai/ConversationSummary", "ConversationSummarySchema": "ai/ConversationSummary", + "DatasetNextStep": "ai/DatasetNextStep", + "DatasetNextStepDecision": "ai/DatasetNextStepDecision", + "DatasetNextStepSchema": "ai/DatasetNextStep", "DatasetProvenance": "ai/DatasetProvenance", "DatasetProvenanceSchema": "ai/DatasetProvenance", "DatasetTermCandidate": "ai/DatasetTermCandidate", diff --git a/packages/spec/export-origins/ai.json b/packages/spec/export-origins/ai.json index ec7a0b34718..5aff96e497c 100644 --- a/packages/spec/export-origins/ai.json +++ b/packages/spec/export-origins/ai.json @@ -56,6 +56,9 @@ "ConversationSessionSchema": "src/ai/conversation.zod.ts#ConversationSessionSchema (const)", "ConversationSummary": "src/ai/conversation.zod.ts#ConversationSummary (type)", "ConversationSummarySchema": "src/ai/conversation.zod.ts#ConversationSummarySchema (const)", + "DatasetNextStep": "src/ai/dataset-tools.zod.ts#DatasetNextStep (type)", + "DatasetNextStepDecision": "src/ai/dataset-tools.zod.ts#DatasetNextStepDecision (type)", + "DatasetNextStepSchema": "src/ai/dataset-tools.zod.ts#DatasetNextStepSchema (const)", "DatasetProvenance": "src/ai/dataset-tools.zod.ts#DatasetProvenance (type)", "DatasetProvenanceSchema": "src/ai/dataset-tools.zod.ts#DatasetProvenanceSchema (const)", "DatasetTermCandidate": "src/ai/dataset-tools.zod.ts#DatasetTermCandidate (type)", diff --git a/packages/spec/json-schema.manifest/ai.json b/packages/spec/json-schema.manifest/ai.json index 0bc9bd67872..d719571cf46 100644 --- a/packages/spec/json-schema.manifest/ai.json +++ b/packages/spec/json-schema.manifest/ai.json @@ -23,6 +23,8 @@ "ai/ConversationMessage", "ai/ConversationSession", "ai/ConversationSummary", + "ai/DatasetNextStep", + "ai/DatasetNextStepDecision", "ai/DatasetProvenance", "ai/DatasetTermCandidate", "ai/DatasetTermMatch", diff --git a/packages/spec/src/ai/dataset-tools.zod.ts b/packages/spec/src/ai/dataset-tools.zod.ts index 653aa4288ae..332deaf8eec 100644 --- a/packages/spec/src/ai/dataset-tools.zod.ts +++ b/packages/spec/src/ai/dataset-tools.zod.ts @@ -207,10 +207,11 @@ export const DatasetNextStepSchema = lazySchema(() => z.object({ + '`candidates`. A dimension the term equals is not counted', ), terms: z.array(z.string()).min(1).describe( - 'The caller\'s terms the decision is about, each as sent in `terms`. 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', + '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: z.string().min(1).describe( 'The decision in words: finished text in the caller\'s locale, composed by the tool from this answer and never ' From d304f1b86183c1a484c72b09b62606e0752da39b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 21:55:27 +0000 Subject: [PATCH 3/4] docs(spec): one nextStep reports one case, and the ADR-0149 M1 note names its PR DatasetNextStepSchema's doc comment now says it outright: an answer carries one nextStep and it reports one case, also when the terms sent are in several. The precedence among the cases is the executor's, fixed and documented by card #34919; the spec declares no order, and `terms` says which of the terms sent the reported case covers. No describe text changes, so each tool's outputSchema is what it was and no generated artefact moves. The header of the amendment note under ADR-0149 M1 names PR #34982 in place of "this PR". Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzfR33NbV51QQU6R6bm --- ...usiness-questions-through-the-dataset-semantic-layer.md | 2 +- packages/spec/src/ai/dataset-tools.zod.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md b/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md index 58206891180..0cceca9cf9f 100644 --- a/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md +++ b/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md @@ -253,7 +253,7 @@ Recommendation **A**. 长远合理性: the key the whole industry reads, already 自检行:只看①选 A;②③④ 是否翻转:否。 -> **Amendment note (2026-11-17, [#34918](https://github.com/objectstack-ai/objectstack/issues/34918) — this PR): the two dataset tools' answers may carry a finished sentence each, `nextStep.note` and `sourceLine`; the spec declares a string slot for each and the executor writes the text. M1 stands.** +> **Amendment note (2026-11-17, [#34918](https://github.com/objectstack-ai/objectstack/issues/34918) — PR #34982): the two dataset tools' answers may carry a finished sentence each, `nextStep.note` and `sourceLine`; the spec declares a string slot for each and the executor writes the text. M1 stands.** > Ruled by the maintainer on [#34894](https://github.com/objectstack-ai/objectstack/issues/34894), option A, verbatim 「两件都同意:构建提交进仓库,#34894 选 A」 (ruling record [`6953671481`](https://github.com/objectstack-ai/objectstack/issues/34894#issuecomment-6953671481)). The record states what was ruled: the framework's executor returns `nextStep` (a closed decision, the candidates, a sentence) on `list_datasets` and `sourceLine` on `query_dataset`; the spec declares the shapes; the sentence's text is the executor's and does not enter the spec, so M1 stands. The contract is `packages/spec/src/ai/dataset-tools.zod.ts#ListDatasetsOutputSchema` (its `nextStep` member) with `packages/spec/src/ai/dataset-tools.zod.ts#DatasetNextStepSchema` and `packages/spec/src/ai/dataset-tools.zod.ts#DatasetNextStepDecision`, and `packages/spec/src/ai/dataset-tools.zod.ts#QueryDatasetOutputSchema` (its `sourceLine` member); this note points at them without restating every case. > > - **M1 is unchanged.** This note changes no word of M1, of its option table or of its **Ruled A** line. A member `description` is still a plain-language business definition and not a prompt, and AI guidance text still does not enter the spec. diff --git a/packages/spec/src/ai/dataset-tools.zod.ts b/packages/spec/src/ai/dataset-tools.zod.ts index 332deaf8eec..e9729c3c938 100644 --- a/packages/spec/src/ai/dataset-tools.zod.ts +++ b/packages/spec/src/ai/dataset-tools.zod.ts @@ -191,8 +191,11 @@ export const DatasetNextStepDecision = z.enum(['one_measure', 'several_measures' * with it. * * The caller's terms can be in different cases (one equals a measure, another - * has only candidates). Which case one answer reports is the executor's rule; - * the shape says which terms the reported case is about. + * has only candidates). An answer still carries one `nextStep`, and it reports + * one case. Which case is reported when the terms are in several, the + * precedence among the cases, is the executor's: card #34919 fixes and + * documents it, and the spec declares no order. `terms` says which of the + * terms sent the reported case covers. * * What a schema cannot refuse is the executor's to hold, as it is for * `candidates`: that `decision` is the case the named terms are in, and that From d80b2d888ddfd4ce5285e4157f645732e1955173 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 22:51:22 +0000 Subject: [PATCH 4/4] chore(spec): regenerate the reference index after merging main content/docs/references/index.mdx is generated and was not text-merged in the merge of origin/main. main's side was taken and the page regenerated from the merged tree by `check:generated --fix`: 1673 schemas (main's 1671 plus DatasetNextStep and DatasetNextStepDecision), AI 84, UI 178 with main's ActionRefusal. No other artefact was stale. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzfR33NbV51QQU6R6bm --- content/docs/references/index.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/content/docs/references/index.mdx b/content/docs/references/index.mdx index d84f1198561..cb2deca35bf 100644 --- a/content/docs/references/index.mdx +++ b/content/docs/references/index.mdx @@ -1,7 +1,7 @@ --- title: Protocol reference — every schema by module navTitle: Protocol Reference -description: Every schema published by @objectstack/spec — 1672 schemas across 14 protocol modules +description: Every schema published by @objectstack/spec — 1673 schemas across 14 protocol modules --- {/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */} @@ -33,8 +33,8 @@ counts are sums of the rows they head. Regenerate with | [Shared Protocol](/docs/references/shared) | 10 | 31 | Primitives used across every protocol — identifiers, HTTP, expressions, error maps, enums. | | [Studio Protocol](/docs/references/studio) | 3 | 35 | Studio designer metadata — the authoring surfaces for the protocols above. | | [System Protocol](/docs/references/system) | 40 | 297 | The runtime environment — logging, jobs, cache, metrics, notifications, i18n and compliance. | -| [UI Protocol](/docs/references/ui) | 16 | 177 | Apps, pages, views, dashboards, reports, actions and themes — the ObjectUI layer. | -| **Total** | **218** | **1672** | 14 protocol modules | +| [UI Protocol](/docs/references/ui) | 16 | 178 | Apps, pages, views, dashboards, reports, actions and themes — the ObjectUI layer. | +| **Total** | **218** | **1673** | 14 protocol modules | --- @@ -385,13 +385,13 @@ The runtime environment — logging, jobs, cache, metrics, notifications, i18n a ## UI Protocol -**Source:** `packages/spec/src/ui/` · **Import:** `@objectstack/spec/ui` · **16 pages, 177 schemas** +**Source:** `packages/spec/src/ui/` · **Import:** `@objectstack/spec/ui` · **16 pages, 178 schemas** Apps, pages, views, dashboards, reports, actions and themes — the ObjectUI layer. | File | Schemas | | :--- | :--- | -| [`action.zod.ts`](/docs/references/ui/action) | `Action`, `ActionAi`, `ActionLocation`, `ActionParam`, `ActionType`, `InlineAction` | +| [`action.zod.ts`](/docs/references/ui/action) | `Action`, `ActionAi`, `ActionLocation`, `ActionParam`, `ActionRefusal`, `ActionType`, `InlineAction` | | [`action-params.zod.ts`](/docs/references/ui/action-params) | `ActionSession` | | [`app.zod.ts`](/docs/references/ui/app) | `ActionNavItem`, `App`, `AppBranding`, `AppContextSelector`, `AppLandingEntry`, `ComponentNavItem`, `DashboardNavItem`, `DocNavItem`, `GroupNavItem`, `NavigationArea`, `NavigationContribution`, `NavigationItem`, `ObjectNavItem`, `PageNavItem`, `ReportNavItem`, `UrlNavItem` | | [`bulk-action.zod.ts`](/docs/references/ui/bulk-action) | `BulkActionDef`, `BulkActionExecution`, `BulkActionOperation`, `BulkActionParam`, `BulkActionResult` |