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
16 changes: 16 additions & 0 deletions .changeset/33734-answer-source-dataset-provenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@object-ui/plugin-chatbot': patch
'@object-ui/i18n': patch
'@object-ui/app-shell': patch
'@object-ui/console': patch
---

feat(plugin-chatbot): an AI chat answer computed from a dataset shows which dataset and metrics it used

Clause-②: yes (widening) — `@object-ui/plugin-chatbot` exports `detectAnswerSource`, whose return type grows from `ObjectQuerySource` to `AnswerSource` (`ObjectQuerySource | DatasetProvenance`); the exported `AnswerSource` type, which was `ObjectQuerySource`, is now that union; and a chat tool invocation's `answerSource` member widens to the same union. `AnswerSourceBlock`'s `sources` prop (package-internal) takes the union too. Code that reads an object-query member (`object`, `filter`, `scope`) off an `AnswerSource` first checks it has no `kind: 'dataset'`.
Metadata-protocol: none

- **"How this was computed" now covers dataset answers.** When the AI answers a business question through `query_dataset` (ADR-0149 D3), the collapsed block under the answer lists the dataset, each metric by its label with its name beside it and its business definition when it has one, what the figures were grouped by, and the filter the question added. A filter that cannot be shown as rows is shown as sent. When the question added no filter, the block says so, because the dataset's own definition still applies.
- **Object-query answers draw as before.** The object, filter, grouping, aggregations, record count and "Only records visible to you" lines are unchanged, and a turn whose tools answered neither block shows no block.
- **The block survives a reload.** A conversation restored from the browser cache keeps the dataset block.
- New strings `chatbot.answerSource.dataset`, `chatbot.answerSource.metrics` and `chatbot.answerSource.noAddedFilter` ship in every locale pack.
2 changes: 1 addition & 1 deletion content/docs/frontend/plugins/plugin-chatbot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ Tool messages represent results from tool invocations during AI streaming. They

By default, `ChatbotEnhanced` renders tool invocations as a compact agent activity summary. Repeated calls are grouped, raw tool names are hidden, and reasoning text is not shown. Use `processVisibility="debug"` for developer/admin views that need the full reasoning panel, raw tool names, parameters, and results. Use `processVisibility="hidden"` to suppress non-interactive activity entirely; approval and draft-review actions remain visible.

In every mode, an answer whose data tools returned a `source` block ends with one collapsed "How this was computed" block: per tool, the object, the filter, the grouping, the aggregations, how many records the figures cover, and whether only the reader's visible records were read. It draws that block alone, never the rest of the tool payload.
In every mode, an answer whose data tools returned a `source` block ends with one collapsed "How this was computed" block: per tool, the object, the filter, the grouping, the aggregations, how many records the figures cover, and whether only the reader's visible records were read. An answer computed through `query_dataset` draws that tool's `provenance` block in the same place instead: the dataset, each metric by its label with its name beside it, the grouping, and the filter the question added (a dataset's own filter is never shown, so no added filter reads as such rather than as all records). It draws that block alone, never the rest of the tool payload.

Each step is named by the locale pack's `chatbot.tool.<tool_name>` entry, a
short sentence in the user's language ("List the existing objects"). A tool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,28 @@ describe('sanitizeChatMessagesForCache — the answer source survives a cache ro
expect(tool?.pendingActionId).toBe('pa_31868');
expect(tool?.answerSource).toEqual(answerSource);
});

// objectstack#33734 — `query_dataset`'s `provenance` is written back under
// its own key, so the same reader lifts it on reload.
it('keeps a query_dataset provenance through sanitize → localStorage → hydration', () => {
const provenance: AnswerSource = {
kind: 'dataset',
dataset: { name: 'sales_analysis', label: 'Sales analysis' },
measures: [{ name: 'total_amount', label: 'Revenue', description: 'Closed-won amount' }],
dimensions: [{ name: 'stage', label: 'Stage' }],
runtimeFilter: { region: 'EMEA' },
};
const persisted = roundTrip([
{ toolCallId: 'tc-ds', toolName: 'query_dataset', state: 'output-available', answerSource: provenance },
]);
const toolPart = persisted[0]?.parts.find((p) => p.type === 'tool-query_dataset') as
| { output?: Record<string, unknown> }
| undefined;
expect(toolPart?.output).toEqual({ provenance });

expect(hydratedMessagesToChatMessages(persisted)[0]?.toolInvocations?.[0]?.answerSource).toEqual(provenance);
expect(uiMessageToChatMessage(persisted[0]).toolInvocations?.[0]?.answerSource).toEqual(provenance);
});
});

// The server persists conversations in ModelMessage format, where an assistant
Expand Down
13 changes: 11 additions & 2 deletions ui/packages/app-shell/src/hooks/useChatConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ interface CacheableChatToolInvocation {
pendingActionId?: string;
/**
* objectstack#31868 — the data tool's `source` block ("How this was
* computed"), as `detectAnswerSource` lifted it. It rides INSIDE the cached
* computed"), or `query_dataset`'s `provenance` (objectstack#33734), as
* `detectAnswerSource` lifted it. It rides INSIDE the cached
* `output`, beside whichever envelope took it, because `output` is the one
* carrier both hydration paths re-parse (see `sanitizeChatMessagesForCache`).
*/
Expand Down Expand Up @@ -588,8 +589,16 @@ export function sanitizeChatMessagesForCache(
// carries a pending approval keeps `status` / `pendingActionId` and
// gains `source`, and `detectPendingApproval` and
// `detectAnswerSource` each read their own keys back.
// objectstack#33734 — a `query_dataset` lift (`kind: 'dataset'`)
// goes back under `provenance`, the key that tool answers it under,
// so the same reader lifts it on reload.
const output = tool.answerSource
? { ...(cachedOutput ?? {}), source: tool.answerSource }
? {
...(cachedOutput ?? {}),
...('kind' in tool.answerSource
? { provenance: tool.answerSource }
: { source: tool.answerSource }),
}
: cachedOutput;
parts.push({
type: `tool-${tool.toolName}`,
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4343,6 +4343,9 @@ const ar = {
aggregations: 'التجميعات',
records: 'السجلات',
visibleToYou: 'فقط السجلات التي يمكنك رؤيتها',
dataset: 'مجموعة البيانات',
metrics: 'المقاييس',
noAddedFilter: 'لا يوجد عامل تصفية مضاف إلى تعريف مجموعة البيانات',
},
tool: {
aggregate_data: "تجميع البيانات ذات الصلة",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4006,6 +4006,9 @@ const de = {
aggregations: 'Aggregationen',
records: 'Datensätze',
visibleToYou: 'Nur Datensätze, die Sie sehen können',
dataset: 'Datenset',
metrics: 'Kennzahlen',
noAddedFilter: 'Kein zusätzlicher Filter zur Datenset-Definition',
},
tool: {
aggregate_data: "Die Daten zusammenfassen",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4932,6 +4932,9 @@ const en = {
aggregations: 'Aggregations',
records: 'Records',
visibleToYou: 'Only records visible to you',
dataset: 'Dataset',
metrics: 'Metrics',
noAddedFilter: 'No filter added to the dataset definition',
},
tool: {
aggregate_data: 'Aggregate the data',
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4091,6 +4091,9 @@ const es = {
aggregations: 'Agregaciones',
records: 'Registros',
visibleToYou: 'Solo los registros que puede ver',
dataset: 'Conjunto de datos',
metrics: 'Métricas',
noAddedFilter: 'Sin filtro añadido a la definición del conjunto de datos',
},
tool: {
aggregate_data: "Resumir los datos",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4087,6 +4087,9 @@ const fr = {
aggregations: 'Agrégations',
records: 'Enregistrements',
visibleToYou: 'Uniquement les enregistrements que vous pouvez voir',
dataset: 'Jeu de données',
metrics: 'Indicateurs',
noAddedFilter: 'Aucun filtre ajouté à la définition du jeu de données',
},
tool: {
aggregate_data: "Synthétiser les données",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4008,6 +4008,9 @@ const ja = {
aggregations: '集計',
records: 'レコード',
visibleToYou: 'あなたが閲覧できるレコードのみ',
dataset: 'データセット',
metrics: '指標',
noAddedFilter: 'データセットの定義に追加されたフィルターなし',
},
tool: {
aggregate_data: "関連データを集計する",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4005,6 +4005,9 @@ const ko = {
aggregations: '집계',
records: '레코드',
visibleToYou: '내가 볼 수 있는 레코드만',
dataset: '데이터셋',
metrics: '지표',
noAddedFilter: '데이터셋 정의에 추가된 필터 없음',
},
tool: {
aggregate_data: "관련 데이터 집계하기",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4086,6 +4086,9 @@ const pt = {
aggregations: 'Agregações',
records: 'Registros',
visibleToYou: 'Somente os registros que você pode ver',
dataset: 'Conjunto de dados',
metrics: 'Métricas',
noAddedFilter: 'Nenhum filtro adicionado à definição do conjunto de dados',
},
tool: {
aggregate_data: "Resumir os dados",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4185,6 +4185,9 @@ const ru = {
aggregations: 'Агрегаты',
records: 'Записи',
visibleToYou: 'Только записи, которые вам доступны',
dataset: 'Набор данных',
metrics: 'Метрики',
noAddedFilter: 'Без фильтров сверх определения набора данных',
},
tool: {
aggregate_data: "Агрегировать данные",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/zh-Hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4254,6 +4254,9 @@ const zh = {
aggregations: '汇总',
records: '记录',
visibleToYou: '仅包含你可见的记录',
dataset: '数据集',
metrics: '指标',
noAddedFilter: '未在数据集定义之外添加筛选条件',
},
tool: {
aggregate_data: '汇总相关数据',
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/zh-Hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4254,6 +4254,9 @@ const zhHant = {
aggregations: '彙總',
records: '記錄',
visibleToYou: '僅包含你可見的記錄',
dataset: '資料集',
metrics: '指標',
noAddedFilter: '未在資料集定義之外新增篩選條件',
},
tool: {
aggregate_data: '彙總相關資料',
Expand Down
Loading
Loading