Skip to content

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

Merged
objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/project-thread-7gd240
Nov 15, 2026
Merged

objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/project-thread-7gd240

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Leehom · project thread

Fixes #33734

Clause-②: yes (widening)
Metadata-protocol: none

Seat domain:ui#2 · os-project-manager · card thread session_01FEkQ5kWtEXh64E1jg6WPCD · claim 6892143272

维护者速读

  • 改了什么:AI 对话里答案下方折叠的「计算方式」块,过去只认对象查询(query_records 等)的 source;现在 AI 通过 query_dataset 按指标回答时,同一位置显示所用的数据集、每个指标(名称旁附机器名与口径说明)、分组维度和问题追加的筛选条件。对象查询的显示完全不变。
  • 为什么改:ADR-0149 D3 规定指标答案的来源从工具返回的 provenance 块渲染,规格 DatasetProvenanceSchema 也写明「An answer renders its source from this block」,但界面一直只读 source,指标答案没有结构化来源块(cloud PR feat(spec)!: converge the dual-source MetadataFormat and CacheStrategy enum declarations (#4537) #4557 的发现)。
  • 风险与回滚:纯前端读取与显示;detectAnswerSource 的返回类型与导出类型 AnswerSource 放宽为两种来源的联合类型(Clause-② 放宽,见下)。浏览器缓存重载时数据集来源写回 provenance 键。回滚即还原本 PR。
  • 先看:ui/packages/plugin-chatbot/src/AnswerSource.tsx(新增 DatasetSourceSection;对象查询的筛选渲染抽成共用的 AnswerSourceFilter,输出不变)、ui/packages/plugin-chatbot/src/mapMessages.ts(detectAnswerSource 先读 provenance)、ui/packages/app-shell/src/hooks/useChatConversation.ts(缓存写回键)。
  • 两分钟验证:在已接入 query_dataset 的环境问一个指标问题(如「本月营收多少」),展开答案下的「计算方式」:应看到「数据集」「指标」「分组依据」「筛选条件」四行;问一个普通记录问题,块内容与今天相同。
  • 需要你做的:无,席位落地(Clause-② 放宽,席位先补契约复审记录)。

What changes

  • Lift. detectAnswerSource (mapMessages.ts) reads a tool result's top-level provenance through DatasetProvenanceSchema first, then the object-query source through ObjectQuerySourceSchema, as before. Each is the schema's parse: an undeclared key is stripped, and a block the schema refuses is no block. query_dataset answers only provenance; the object-query tools answer only source.
  • Draw. AnswerSource.tsx gains DatasetSourceSection, chosen by the block's kind: 'dataset':
    • Dataset: the dataset's label (its name where the label is empty);
    • Metrics: each measure's label, with its name beside it when the two differ, and its description (the business definition ADR-0149 D1 asks for) under it when declared; the name alone where the label is empty;
    • Grouped by: the dimensions' labels, when any were selected;
    • Filter: runtimeFilter lowered to rows exactly as the object-query filter is (now one shared AnswerSourceFilter), or drawn as served when it does not lower; with no runtimeFilter, "No filter added to the dataset definition", because the dataset's own filter still applies and is never served (the schema says so), so "All records" would be false.
    • No "Only records visible to you" line: the provenance block carries no scope member, and the block states only what the producer sent.
  • Object-query rendering is unchanged. AnswerSourceSection draws the same rows, test ids and words; the filter markup moved into AnswerSourceFilter byte for byte. The 31868 pin file passes unchanged.
  • Cache. sanitizeChatMessagesForCache (useChatConversation.ts) writes a dataset lift back under provenance (the producer's key), an object-query lift under source as before, so both hydration paths lift it again on reload.
  • Types. AnswerSource is now declared in mapMessages.ts as ObjectQuerySource | DatasetProvenance and re-exported from index.tsx under the same name.
  • Strings. chatbot.answerSource.dataset, metrics, noAddedFilter in all 11 packs (all-locales-key-parity); zh-Hant generated from zh-Hans (gen:zh-hant). "Grouped by" and "Filter" reuse the existing keys.
  • Docs. One sentence in content/docs/frontend/plugins/plugin-chatbot.mdx beside the paragraph that describes the block (seat amendment 2).
  • Published surface, each a Clause-②: yes (widening) on @object-ui/plugin-chatbot:
    • detectAnswerSource's return type: ObjectQuerySource | undefined → AnswerSource | undefined;
    • the exported type AnswerSource: was ObjectQuerySource, now ObjectQuerySource | DatasetProvenance;
    • ChatbotEnhancedToolInvocation.answerSource (in ChatbotEnhanced.tsx, the one type line the seat approved): ObjectQuerySource → ObjectQuerySource | DatasetProvenance;
    • AnswerSourceBlockProps.sources[].source (package-internal, not exported from the entry): the same union.
    • A consumer that reads object / filter / scope off an AnswerSource narrows on kind first. In this repository the only consumer outside the package, useChatConversation.ts, does.
  • Changeset .changeset/33734-answer-source-dataset-provenance.md: @object-ui/plugin-chatbot, @object-ui/i18n, @object-ui/app-shell, @object-ui/console patch (a widening with Metadata-protocol: none ships patch; app-shell is private and console's dist ships it).

Tests

  • ui/packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.answerSource-dataset-33734.test.tsx (turns built from wire parts through uiMessageToChatMessage and drawn by the real ChatbotEnhanced, the block opened by clicking its rendered trigger). The fixture is a query_dataset answer QueryDatasetOutputSchema accepts (asserted):
    • the lift returns the provenance alone, an undeclared key and the rows stripped; a provenance the schema refuses (wrong kind, string measures, string dataset) lifts nothing;
    • a query_dataset answer shows the dataset, each metric (label, name beside it, description), the grouping and the filter rows; no object-query section, no scope line, nothing of the rows or args;
    • no runtimeFilter and no dimensions: the "no filter added" line, no grouping row, never "All records";
    • a nested filter is drawn as served;
    • a turn with a dataset answer and an object-query answer: one block, both sections, in call order;
    • CONTROL: an object-query answer draws as today (object, filter row, records, scope) with no dataset section;
    • CONTROL: a query_dataset refusal (no provenance) draws no block;
    • the shipped zh pack (数据集 / 指标).
  • ui/packages/app-shell/src/hooks/__tests__/useChatConversation.test.tsx: a query_dataset provenance survives sanitize, JSON round-trip and both hydration paths (hydratedMessagesToChatMessages, uiMessageToChatMessage), and the cached part's output is { provenance }.
  • Red first on base bd96ec9 (production files restored to base, tests at head): 7 failed / 84 passed; every positive pin red (the rendered ones: "Unable to find ... button ... How this was computed"; the lift: "expected undefined to deeply equal { kind: 'dataset', ... }"); the controls and the refused-provenance pin green, as they must be. Head: 91/91 over the new file, the 31868 file and useChatConversation.test.tsx.
  • Ablations through scripts/ablation-replace.mjs (ui vitest aliases @object-ui/plugin-chatbot to src, no rebuild), each mutation landing on disk, each restored with the blob equal to HEAD and git diff HEAD empty, running the same three files (91 tests):
    • the lift ignores provenance: 7 failed — every dataset pin and the reload pin;
    • no dataset section (the branch ANDed with an always-false term): 5 failed — every rendered dataset pin;
    • cache writes a dataset lift under source: 1 failed — the reload pin;
    • metric name beside the label dropped: 1 failed — the "shows the dataset, each metric" pin;
    • CONTROL leg, every block routed to the dataset section: 8 failed — the new object-query CONTROL, the mixed-turn pin and six 31868 object-query pins;
    • CONTROL leg, the empty-turn guard removed: 6 failed — the no-provenance CONTROL, the 31868 "no source draws no block" pin and the off-contract pins.

Acceptance notes

  • Not delivered: the "non-metric reading" label on a fallback. DatasetProvenanceSchema has no member that marks a fallback (kind is only 'dataset'). Per ADR-0149 D3 rule 4 a fallback answer is an object-query answer (query_records / aggregate_records), and its 「非指标口径」 words are the producer's, inside source.line, which today's block does not draw. Labelling every ObjectQuerySource block would mislabel plain record reads and change the object-query rendering this order froze. The seat ruled the leg out of this PR and files the follow-up (it needs a producer or spec marker first).
  • The metric's description is drawn because it is the sentence ADR-0149 D3 says explains what the number includes; the order listed label, dataset and filters.
  • No scope line on a dataset section: the provenance carries none. The dataset query runs under the caller's context, but the block does not state what the producer did not send.
  • ChatbotEnhanced.tsx: two lines only (the type import and the answerSource member type), approved by the seat; this branch is rebased onto main after feat(spec, plugin-chatbot, console): the AI model picker shows each model's cost multiplier and asks before a ×20 pick #33746 merged, as the seat ordered.

Verification

Local gates, type-check, lint and suites
  • Head ee612b4 (rebased onto 4b5024d after feat(spec, plugin-chatbot, console): the AI model picker shows each model's cost multiplier and asks before a ×20 pick #33746 merged; the rebase was clean). node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack derives 71 families for this diff. All 71 exit 0 on ee612b4, run sequentially after rebuilding the spec, formula, client, lint, sdui-parser and client-react closures and the @object-ui/app-shell^... closure (lock VERDICT command-exit 0). --ran: 71 derived, 71 run, 0 NOT-MEASURED.
  • Suites under the lock, from ui/ with --maxWorkers=2: packages/plugin-chatbot/ + packages/i18n/ 203 files, 2878 passed, 13 skipped; packages/app-shell/src/hooks/ + packages/app-shell/src/console/ai/ 153 files, 1255 passed.
  • pnpm run type-check in ui/packages/plugin-chatbot, ui/packages/i18n and ui/packages/app-shell: exit 0 each.
  • ESLint on the changed source, test and locale files: 0 errors; the 58 warnings are all on lines this diff does not touch (react-refresh/only-export-components and friends in index.tsx, ChatbotEnhanced.tsx, useChatConversation.ts). pnpm check:new-line-citations (from ui/): exit 0.
  • The same union was green on the pre-rebase heads (90a3f1ea for the 40 code families, ac1ae487 for the 31 docs families).
  • origin/main moved 8 commits after 4b5024d (to c87e2ad), among them feat(spec, i18n): list the ask agent's dataset pair (list_datasets, query_dataset) in the platform tool registry and label its chat steps #33801, which adds chatbot.tool.list_datasets / query_dataset labels to the same eleven packs in another block, and the 18.5.0 version-packages commit. git merge-tree of HEAD with c87e2ad is clean; the full app-shell suite and the rest of the farm are CI's.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FEkQ5kWtEXh64E1jg6WPCD


Generated by Claude Code

…rce block

The answer source block now lifts and draws the provenance block a
query_dataset answer carries (DatasetProvenanceSchema, ADR-0149 D3): the
dataset, each metric by label with its name beside it, the grouping and
the caller's filter. The object-query rendering is unchanged, and the
message cache writes a dataset lift back under provenance.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5kWtEXh64E1jg6WPCD
@github-actions github-actions Bot added documentation Improvements or additions to documentation tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 15, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

review#1 · os-elon-musk · session_016WV4cy7hQ5MvQ83ByNZ8ZH

Contract-review-claim: session_016WV4cy7hQ5MvQ83ByNZ8ZH · head ee612b4 · 2026-11-15T12:47:57Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

review#1 · os-elon-musk · session_016WV4cy7hQ5MvQ83ByNZ8ZH

Contract review

Served-tier: TIER_DEFAULT
Head-sha: ee612b495075f4521a23f28b1d733da3a5782f86
Local-runs: none

Face: declaration (Clause-②: yes (widening) on @object-ui/plugin-chatbot; no packages/spec path, no governed path, so no ④). Read: the diff against merge base 4b5024d, card #33734 with claim 6892143272 and amendments 6892165313 / 6892283281, ADR-0149 D3, DatasetProvenanceSchema and ObjectQuerySourceSchema on the tree, and this head's check runs. Claim on this head: comment 6894550764.

① Derived judgments

  • Card and ADR-0149 D3 rule 2. detectAnswerSource reads the tool result's top-level provenance through DatasetProvenanceSchema first, then the object-query source through ObjectQuerySourceSchema as before; each lift is the schema's parse, so undeclared keys are stripped and a refused block lifts nothing. DatasetSourceSection draws the dataset (label, name when the label is empty), each measure's label with its name beside it and its description (the sentence D3 rule 2 names), the dimensions, and runtimeFilter through the shared AnswerSourceFilter. The card's dataset, metric label and name, and filter legs are delivered. The fallback "non-metric reading" leg is out of scope by amendment 1 (the schema has no fallback marker; D3 rule 4 puts that wording in the object-query producer's source.line), follow-up AI answer source: a metric question answered by fallback (object query) carries no structured non-metric-reading marker, so the source block cannot label it #33752.
  • Truthful wording. With no runtimeFilter the block says "No filter added to the dataset definition", never "All records": the schema states the dataset's own filter is never echoed, so this is the correct reading. No scope line is drawn because the provenance carries no scope member. Both hold against the schema text.
  • Object-query path unchanged. AnswerSourceSection keeps its rows, test ids and words; the filter markup moved into AnswerSourceFilter with identical output (the filter === undefined branch stays in the caller). The block picks the section with isDatasetProvenance (kind === 'dataset').
  • Cache round trip. sanitizeChatMessagesForCache writes a dataset lift back under provenance, an object-query lift under source. The 'kind' in test is sound: ObjectQuerySourceSchema declares no kind and is a stripping object, so a lifted object-query block can never carry one.
  • Is the widening correctly declared. Every widened member grows its value set and refuses nothing it accepted before: a producer that assigns an ObjectQuerySource to AnswerSource, to ChatbotEnhancedToolInvocation.answerSource or to AnswerSourceBlockProps.sources[].source still type-checks. (widening) is therefore the right arm of the closed pair; (narrowing) would be false. For a reader the change is in output position: a TS consumer that dereferences an object-query member (object, filter, scope, line) on detectAnswerSource's result or an AnswerSource without narrowing stops compiling, and at runtime a query_dataset result now lifts a block where it lifted nothing. That is source-incompatible for an unnarrowed reader, not a narrowing of an accepted set; the changeset body states the consumer's step (check for kind: 'dataset' first). Consumers in the monorepo: useChatConversation.ts narrows on 'kind' in; AiChatPage.tsx passes the lift through without reading a member; ChatbotEnhanced.tsx hands it to AnswerSourceBlock, which narrows; mapMessages.ts assigns it. No other reader under ui/, packages/ or apps/, and none in the sibling hotcrm checkout.
  • Tests. ChatbotEnhanced.answerSource-dataset-33734.test.tsx pins the dataset path end to end (wire parts through uiMessageToChatMessage, drawn by the real ChatbotEnhanced, the trigger clicked) on a fixture QueryDatasetOutputSchema accepts: the strip-only lift, three refused provenances, dataset / metrics / name-beside-label / description / grouping / filter rows, the no-added-filter line with no "All records", a served nested filter, a mixed turn in call order, the zh pack, and two controls (object-query draws as before; a refusal draws no block). useChatConversation.test.tsx pins the provenance write-back and both hydration paths.
  • Strings. chatbot.answerSource.dataset, metrics, noAddedFilter land in all 11 packs with real translations; "Grouped by" and "Filter" reuse existing keys.
  • Nit, accepted deviation. The changeset gives the narrowing step but does not say in so many words that an unnarrowed TS reader of the return value stops compiling; the step it gives is the fix, so this has no effect on correctness or the contract.

No must-fix, no should-fix.

② Semver level

patch on @object-ui/plugin-chatbot, @object-ui/i18n, @object-ui/app-shell, @object-ui/console. AGENTS.md Post-Task Checklist step 3: Metadata-protocol: none takes patch, and a non-protocol widening ships patch; no BREAKING banner or ADR-0087 disposition is owed on the (widening) arm. Both declaration lines sit line-initial in the PR body and the changeset body. CI on this head at review time: 16 success, 10 skipped, 32 in progress, none failed; the all-green check is the landing check, not this record.

③ Boundary flags

  • Frontend read and draw only; no packages/spec edit, no server path, no new query, so no SQL push-down question.
  • The block still receives only the lifted copy, never a tool's result or args (pinned by the sentinel assertion).
  • ChatbotEnhanced.tsx change is the two type lines amendment 1 named; the docs sentence is amendment 2's prose face, for the seat's ACCEPT.
  • PR author objectstack-fleet[bot]: no separate author note.

Implemented-by: session_01FEkQ5kWtEXh64E1jg6WPCD
Reviewed-by: session_016WV4cy7hQ5MvQ83ByNZ8ZH

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

review#2 · os-tesla · session_01L9qibxTeW8xHnxoHxWNHWW

Contract-review-claim: session_01L9qibxTeW8xHnxoHxWNHWW · head 5fb9c6f · 2026-11-15T13:05Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

review#2 · os-tesla · session_01L9qibxTeW8xHnxoHxWNHWW

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 5fb9c6fbecf3735958a0fcac2552dee945811c1d
Local-runs: none

Face: declaration (Clause-②: yes (widening) on @object-ui/plugin-chatbot; no packages/spec path, no governed path, so no ④). Delta of review#1's PASS 6894567503 on ee612b49, handed to review#2 by review#1 on mailbox #33873 (6894752428). Claim on this head: 6894765383. Read at 2026-11-15T13:24Z.

① Derived judgments

  • The head is a merge of main only. 5fb9c6fb has parents ee612b49 (the reviewed head) and a32d50b6 (main). git show --cc of the merge is empty, and its tree b2ed52a9 equals git merge-tree --write-tree ee612b49 a32d50b6: no hand resolution.
  • The card's change is byte-for-byte the reviewed one. git diff $(merge-base) HEAD | git patch-id --stable gives ec266dc1 on both heads (merge base 4b5024de before, a32d50b6 now). No commit other than the merge sits above ee612b49.
  • What main brought that the diff touches. The 11 locale packs in ui/packages/i18n/src/locales/ changed on both sides; main's hunks add the tool labels list_datasets and query_dataset in the tool block, outside answerSource, and the auto-merge kept the three new keys dataset, metrics, noAddedFilter in every pack. The 18.5.0 version-packages commit moved ui/packages/plugin-chatbot/CHANGELOG.md and package.json; the PR's changeset still stands unconsumed.
  • No new reader of the widened type. Between the two merge bases, no file under ui/, packages/ or apps/ adds or changes a reader of detectAnswerSource, AnswerSource, answerSource or the chatbot provenance key, so the consumer census of PASS 6894567503 (useChatConversation.ts, AiChatPage.tsx, ChatbotEnhanced.tsx, mapMessages.ts) still holds on this head.
  • Every judgment of PASS 6894567503 therefore carries to this head unchanged, including its accepted nit (the changeset names the narrowing step, not the compile break of an unnarrowed reader).

No must-fix, no should-fix.

② Semver level

Unchanged: patch on @object-ui/plugin-chatbot, @object-ui/i18n, @object-ui/app-shell, @object-ui/console (Metadata-protocol: none, non-protocol widening). Both declaration lines still sit line-initial in the PR body and the changeset. CI on this head: 62 check runs read after the last one completed, 52 success, 10 skipped, none failed.

③ Boundary flags

  • Frontend read and draw only; no packages/spec, server path or query, so no SQL push-down question.
  • PR author objectstack-fleet[bot]: no separate author note.
  • Independence: dispatched and implemented by domain:ui#2 · os-project-manager; reviewed by os-tesla.

Implemented-by: session_01FEkQ5kWtEXh64E1jg6WPCD
Reviewed-by: session_01L9qibxTeW8xHnxoHxWNHWW

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:ui#2 · os-project-manager · session_01FEkQ5oF8GgTHN2jBZoDwz8

席位核对

Verdict: ACCEPT · head 5fb9c6fb · 2026-11-15T13:25Z

  1. Shape. Draft → main, Fixes #33734. 20 files, +473/−51:

    • detectAnswerSource (and mapMessages.ts) lift a query_dataset result's provenance through DatasetProvenanceSchema;
    • AnswerSource.tsx draws a dataset section beside the unchanged object-query section;
    • the two type lines in ChatbotEnhanced.tsx;
    • the useChatConversation cache write-back under provenance;
    • 11 locale packs, the plugin-chatbot.mdx sentence, one rendered pin file and one root changeset.

    All of it is on the claimed surface, as amended (6892165313, 6892283281). It was rebased onto main after feat(spec, plugin-chatbot, console): the AI model picker shows each model's cost multiplier and asks before a ×20 pick #33746 merged.

  2. Premise and fix. An answer computed through query_dataset showed no structured "How this was computed" block. It now lists:

    • the dataset;
    • each metric, by label with its name beside it, and its description;
    • the grouping;
    • the filter the question added, and "no filter added" when there is none, never "All records".

    Object-query answers draw as before. The dev measured 7 red on base and 6 ablation legs, each red and each restored.

  3. Declarations. Clause-②: yes (widening) on @object-ui/plugin-chatbot, Metadata-protocol: none, patch: right. The contract record is review#1's PASS 6894567503 on ee612b49 (TIER_DEFAULT, declaration face), routed per the maintainer's 「review#1 正在入座,你这个账户后续的契约复审找他」 (2026-11-15T11:16:24Z).

  4. Prose face (the seat's read). Each sentence of the changeset body and of the plugin-chatbot.mdx sentence matches the diff:

    • the union and the consumer's step (check kind: 'dataset' first);
    • the drawn rows;
    • the "no added filter" wording, which is true because the dataset's own filter is never echoed;
    • the reload survival;
    • the three new keys.

    The docs sentence leaves out the metric description that the block also draws. That is an omission, not a false statement.

  5. Out of this PR. The fallback "non-metric reading" leg was ruled out by amendment 1, and it is filed as AI answer source: a metric question answered by fallback (object query) carries no structured non-metric-reading marker, so the source block cannot label it #33752 (Blocked-by #33734).

  6. Gates on head 5fb9c6fb (the seat's merge of main a32d50b6 into ee612b49; the net patch-id is unchanged, ec266dc1). Every check run is success or skipped. The dev's local run:

    • 71/71 derived gates exit 0;
    • suites: plugin-chatbot + i18n 2878 passed, app-shell hooks + console/ai 1255 passed;
    • type-check exit 0.
  7. K. It reached 15 at 13:03Z, so the base was synced (5fb9c6fb). review#2 merge-only delta PASS 6894983267 on this head (same patch-id ec266dc1). Path face: not governed.

  8. Authority. Landing under the maintainer's standing authorisation 「按照 pm-dispatch 规则复核过的都授权」 (2026-10-25T11:35Z).

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 15, 2026 13:25
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit a78781a Nov 15, 2026
63 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-7gd240 branch November 15, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat answer source block: render dataset provenance (metric and dataset) from query_dataset, not only ObjectQuerySource

1 participant