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
20 changes: 20 additions & 0 deletions .changeset/34761-list-datasets-candidates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@objectstack/spec': minor
---

feat(spec): the `list_datasets` output declares `candidates`, the members offered for a clarifying question when a term matched nothing (ADR-0149 D3)

Clause-②: yes (widening — an optional output field on a published schema)
Metadata-protocol: added
Skills-docs: follow-up owed — skills/objectstack-ask/SKILL.md (zero-match row reads candidates once #34763 lands)

`ListDatasetsOutputSchema` (`@objectstack/spec/ai`) gains one optional member, `candidates`, with its entry schema `DatasetTermCandidateSchema` (type `DatasetTermCandidate`) and the per-term cap `LIST_DATASETS_MAX_CANDIDATES_PER_TERM` (5). Nothing is removed or renamed, and an answer without the key parses as it did.

- **What it is.** For a term the caller sent that matched no member of any listed dataset, the members the platform offers as possible readings. Each entry is a pointer `{ term, dataset, member }` to a member listed in the same answer: `dataset` is a `datasets[].name`, `member` is `measures.<name>` or `dimensions.<name>`. Only members the caller may read are offered. The label, dataset label and description a clarifying question lists are read from that `datasets` entry.
- **What it is not.** A candidate is not a match. `matches`, and what counts as a match (equality after normalization, ADR-0149 D3 rule 1), are unchanged, and an entry carries no `matchedOn`. The platform selects none of them. The list carries no score, and its order is the listing order: terms as sent, datasets as listed, a dataset's measures before its dimensions, at most five per term.
- **When it is present.** Only when `terms` were sent and a term that matched nothing has a candidate. No candidates is the key's absence: an empty list does not parse. A term with a match has none.
- **Who fills it.** This change declares the shape only, and the tool's `outputSchema` (`getDatasetToolJsonSchemas().list_datasets.outputSchema`) lists the member from it. Filling the list is the `list_datasets` executor's change in `@objectstack/service-analytics`, which ships under its own entry; an answer carries `candidates` only from a release that has both.

ADR-0149 D3 gains an add-only amendment note recording the ruling: a term with no match and with candidates is asked about in rule 3's form and none is acted on; with no candidate, rule 4's fallback is unchanged.

Level: `minor` for `@objectstack/spec`, the level `Metadata-protocol: added` takes. The `authorable-surface/ai.json` baseline records the new keys: `ai/ListDatasetsOutput:candidates` and the three `ai/DatasetTermCandidate` members.
32 changes: 28 additions & 4 deletions content/docs/references/ai/dataset-tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Dataset AI tools — the inputs and outputs of `list_datasets` and
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, and which of the caller's words matched which member),
business vocabulary, which of the caller's words matched which member, and,
for a word that matched nothing, the members offered as `candidates`),
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
Expand All @@ -27,7 +28,8 @@ inline `dataset` and no `previewDrafts` on this tool, because an AI that could
author a dataset inline could author its own 口径.

Only the shapes are spec. The executor, the catalogue builder with its
admission and member withholding, the term matcher and the row cap
admission and member withholding, the term matcher, the rule that finds a
zero-match term's candidates and the row cap
(`selection.limit` held to the bridge's `maxQueryLimit`) belong to
`@objectstack/service-analytics` (card #31589); the MCP registration under
`data:read` to `@objectstack/mcp` (card #31590). The tool descriptions, which
Expand All @@ -41,8 +43,8 @@ executor: AI guidance text does not enter the spec (ADR-0149 M1, ruled A).
## TypeScript Usage

```typescript
import { DatasetProvenanceSchema, DatasetTermMatchSchema, DatasetTermMatchedOn, DatasetToolCatalogDimensionSchema, DatasetToolCatalogEntrySchema, DatasetToolCatalogMeasureSchema, ListDatasetsInputSchema, ListDatasetsOutputSchema, QueryDatasetInputSchema, QueryDatasetOutputSchema } from '@objectstack/spec/ai';
import type { DatasetProvenance, DatasetTermMatch, DatasetTermMatchedOn, DatasetToolCatalogDimension, DatasetToolCatalogEntry, DatasetToolCatalogMeasure, ListDatasetsInput, ListDatasetsOutput, QueryDatasetInput, QueryDatasetOutput } from '@objectstack/spec/ai';
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';

// Validate data
const result = DatasetProvenanceSchema.parse(data);
Expand Down Expand Up @@ -85,6 +87,19 @@ const result = DatasetProvenanceSchema.parse(data);
| **label** | `string` | ✅ | Dimension label at the caller's locale |


---

## DatasetTermCandidate

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **term** | `string` | ✅ | The caller's term, as sent in `terms`: one that matched no member of any listed dataset |
| **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.<name>` or `dimensions.<name>`: a member that dataset's entry lists. The term does not equal any of its words after normalization |


---

## DatasetTermMatch
Expand Down Expand Up @@ -211,6 +226,7 @@ const result = DatasetProvenanceSchema.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. 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 |

### Nested Shape: `ListDatasetsOutput.datasets[number]`

Expand All @@ -225,6 +241,14 @@ const result = DatasetProvenanceSchema.parse(data);
| **measures** | `{ name: string; label: string; description?: string; aggregate?: Enum<'count' \| 'sum' \| 'avg' \| 'min' \| 'max' \| 'count_distinct'>; … }[]` | ✅ | The measures this caller may read |
| **matches** | `{ term: string; member: string; matchedOn: Enum<'name' \| 'label' \| 'synonym'> }[]` | optional | Each of the caller's `terms` that matched a member of this dataset, computed by the platform under the same normalization the dataset's own validation uses. Absent when no `terms` were sent |

### Nested Shape: `ListDatasetsOutput.candidates[number]`

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **term** | `string` | ✅ | The caller's term, as sent in `terms`: one that matched no member of any listed dataset |
| **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.<name>` or `dimensions.<name>`: a member that dataset's entry lists. The term does not equal any of its words after normalization |


---

Expand Down
10 changes: 5 additions & 5 deletions content/docs/references/index.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Protocol reference — every schema by module
navTitle: Protocol Reference
description: Every schema published by @objectstack/spec — 1669 schemas across 14 protocol modules
description: Every schema published by @objectstack/spec — 1670 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/. */}
Expand All @@ -20,7 +20,7 @@ counts are sums of the rows they head. Regenerate with

| Module | Pages | Schemas | Description |
| :--- | ---: | ---: | :--- |
| [AI Protocol](/docs/references/ai) | 14 | 81 | Agents, tools, skills, RAG and knowledge sources, model registry, conversations. |
| [AI Protocol](/docs/references/ai) | 14 | 82 | 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. |
Expand All @@ -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** | **1669** | 14 protocol modules |
| **Total** | **218** | **1670** | 14 protocol modules |

---

## AI Protocol

**Source:** `packages/spec/src/ai/` · **Import:** `@objectstack/spec/ai` · **14 pages, 81 schemas**
**Source:** `packages/spec/src/ai/` · **Import:** `@objectstack/spec/ai` · **14 pages, 82 schemas**

Agents, tools, skills, RAG and knowledge sources, model registry, conversations.

Expand All @@ -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`, `DatasetTermMatch`, `DatasetTermMatchedOn`, `DatasetToolCatalogDimension`, `DatasetToolCatalogEntry`, `DatasetToolCatalogMeasure`, `ListDatasetsInput`, `ListDatasetsOutput`, `QueryDatasetInput`, `QueryDatasetOutput` |
| [`dataset-tools.zod.ts`](/docs/references/ai/dataset-tools) | `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` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ The rule is stated once here and carried in three places: the tool descriptions

Why the platform computes `matches` instead of leaving the whole rule to the model: 防 AI 犯错. The model still decides what the question's terms are; whether a term equals a synonym is a string comparison, and a string comparison belongs where it can be unit-tested and where every consumer gets the same answer.

> **Amendment note (2026-11-17, [#34761](https://github.com/objectstack-ai/objectstack/issues/34761) — this PR): a term with no hit is answered with `candidates`, offered for a question and never selected.**
> Ruled by the maintainer on [#34691](https://github.com/objectstack-ai/objectstack/issues/34691), fork F1, option B, option text verbatim 「B 零命中返回候选」 — 「现在就改服务器,list_datasets 零命中时返回候选数据集。专题席的新推荐。」 (ruling record [`6943126855`](https://github.com/objectstack-ai/objectstack/issues/34691#issuecomment-6943126855), relayed to #34659 as `6943149235`). It re-rules point E2 of #34659's record `6940528935`, where `list_datasets` stayed exact-match with no candidates list on a named premise, to that point's option A. The contract is `packages/spec/src/ai/dataset-tools.zod.ts#ListDatasetsOutputSchema` (its `candidates` member) with `packages/spec/src/ai/dataset-tools.zod.ts#DatasetTermCandidateSchema`; this note points at it without restating every case.
>
> - **What counts as a hit does not change.** This note changes no word of rule 1: equality after normalization is a hit, and a substring, a stem or an embedding neighbour is not. `matches` is computed as before, and rules 2, 3 and 5 read it as before.
> - **A term with no hit in any listed dataset gets `candidates`.** The `list_datasets` output of [D2](#d2--two-tools-one-definition-one-executor-two-transports) gains one optional member beside the ones D2 lists, which stand as written. For such a term it names the members the platform offers as possible readings, each a pointer `{ term, dataset, member }` to a member listed in the same answer, so only a member this caller may read is ever offered. This is rule 1's parenthesis as a platform answer: a non-hit "may be offered in rule 3's question, never acted on". The list carries no score. Its order is the listing order: terms as sent, datasets as listed, a dataset's measures before its dimensions (rule 5: a dimension alone is not an answer), held to `LIST_DATASETS_MAX_CANDIDATES_PER_TERM` per term. A term with a hit has no candidates and an answer with none to offer carries no `candidates` key, so an answer in which every term sent has a hit, like an answer to a call that sent no `terms`, is what it was. Which members are near enough to offer is the executor's rule; this record and the spec say what a candidate is, not how it is found.
> - **With candidates, the AI asks in rule 3's form and acts on none.** The question lists each candidate's label, dataset label and description, as rule 3 lists several hits. The AI does not pick one, does not prefer the first, and does not treat a candidate as a hit under rule 2: the choice is the person's.
> - **With no candidate, rule 4 is unchanged.** No hit and nothing offered is the labelled fallback to the object query, as written; [M2](#m2--what-the-ai-does-when-no-dataset-covers-the-question) stays ruled A.
> - **Rule 4 is named here because its path changes and its matching does not.** A term with no hit used to go straight to the fallback; a clarifying question may now come first. The term still has no hit, so rule 4 still governs it when the question settles nothing.
> - **Why the platform offers them, and not only the client's wording.** A tool result is read by every client that made the call; a tool description is read only after the client chose the tool, and a skill only when it is installed and triggered (the grounds of fork F1 on #34691). It is the reason given above for `matches`: every consumer gets the same answer.
> - **State on `main`.** This PR declares the shape and changes no executor. The executor that fills `candidates`, and the tool descriptions that carry this branch to the model, land with [#34763](https://github.com/objectstack-ai/objectstack/issues/34763); until then no answer carries the key. 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.

### D4 — Permissions: the tools add no gate and bypass none

Measured in [Context](#the-executor-and-its-gate-chain-measured-on-originmain). The binding statements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ hand-patch a number here** — fix the code or the verdict and regenerate.

| Dir | Sites |
|---|---|
| `ai/` | 96 |
| `ai/` | 97 |
3 changes: 3 additions & 0 deletions packages/spec/api-surface/ai.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"ConversationSummarySchema (const)",
"DatasetProvenance (type)",
"DatasetProvenanceSchema (const)",
"DatasetTermCandidate (type)",
"DatasetTermCandidateSchema (const)",
"DatasetTermMatch (type)",
"DatasetTermMatchSchema (const)",
"DatasetTermMatchedOn (const)",
Expand Down Expand Up @@ -95,6 +97,7 @@
"KnowledgeSourceKindSchema (const)",
"KnowledgeSourceParsed (type)",
"KnowledgeSourceSchema (const)",
"LIST_DATASETS_MAX_CANDIDATES_PER_TERM (const)",
"LIST_DATASETS_TOOL_NAME (const)",
"ListDatasetsInput (type)",
"ListDatasetsInputSchema (const)",
Expand Down
4 changes: 4 additions & 0 deletions packages/spec/authorable-surface/ai.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@
"ai/DatasetProvenance:kind",
"ai/DatasetProvenance:measures",
"ai/DatasetProvenance:runtimeFilter",
"ai/DatasetTermCandidate:dataset",
"ai/DatasetTermCandidate:member",
"ai/DatasetTermCandidate:term",
"ai/DatasetTermMatch:matchedOn",
"ai/DatasetTermMatch:member",
"ai/DatasetTermMatch:term",
Expand Down Expand Up @@ -242,6 +245,7 @@
"ai/KnowledgeSource:source",
"ai/KnowledgeSource:vectorStore",
"ai/ListDatasetsInput:terms",
"ai/ListDatasetsOutput:candidates",
"ai/ListDatasetsOutput:datasets",
"ai/ListDatasetsOutput:partial",
"ai/ListDatasetsOutput:warning",
Expand Down
2 changes: 2 additions & 0 deletions packages/spec/declaration-map/ai.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"ConversationSummarySchema": "ai/ConversationSummary",
"DatasetProvenance": "ai/DatasetProvenance",
"DatasetProvenanceSchema": "ai/DatasetProvenance",
"DatasetTermCandidate": "ai/DatasetTermCandidate",
"DatasetTermCandidateSchema": "ai/DatasetTermCandidate",
"DatasetTermMatch": "ai/DatasetTermMatch",
"DatasetTermMatchSchema": "ai/DatasetTermMatch",
"DatasetTermMatchedOn": "ai/DatasetTermMatchedOn",
Expand Down
Loading
Loading