@flamingo-stack/openframe-frontend-core 0.0.646 → 0.0.647-snapshot.20260917173248

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/dist/chat-protocol/index.cjs.map +1 -1
  2. package/dist/chat-protocol/index.js.map +1 -1
  3. package/dist/{chunk-ETEM2ZD4.js → chunk-2A4RLR7R.js} +3 -3
  4. package/dist/{chunk-JFBUXYDK.cjs → chunk-2ENDIKKP.cjs} +15 -15
  5. package/dist/{chunk-JFBUXYDK.cjs.map → chunk-2ENDIKKP.cjs.map} +1 -1
  6. package/dist/{chunk-QS55P2TA.js → chunk-2ULLNHL3.js} +6 -6
  7. package/dist/chunk-2ULLNHL3.js.map +1 -0
  8. package/dist/{chunk-DULSS7R6.js → chunk-3ORBE27K.js} +832 -547
  9. package/dist/chunk-3ORBE27K.js.map +1 -0
  10. package/dist/{chunk-ZW2BEEX2.cjs → chunk-4JRBRMKO.cjs} +25 -25
  11. package/dist/{chunk-ZW2BEEX2.cjs.map → chunk-4JRBRMKO.cjs.map} +1 -1
  12. package/dist/{chunk-7UWJMWDH.cjs → chunk-EFPAKLT5.cjs} +784 -499
  13. package/dist/chunk-EFPAKLT5.cjs.map +1 -0
  14. package/dist/{chunk-5C7GMRJU.js → chunk-EKLOXVG2.js} +5 -5
  15. package/dist/{chunk-AYAZU3BO.cjs → chunk-EW3EIPT5.cjs} +5 -5
  16. package/dist/{chunk-AYAZU3BO.cjs.map → chunk-EW3EIPT5.cjs.map} +1 -1
  17. package/dist/{chunk-NKMXFBV5.js → chunk-FQ4TZP6K.js} +4 -4
  18. package/dist/{chunk-5JVN3EVT.cjs → chunk-HN4DLGKP.cjs} +71 -71
  19. package/dist/{chunk-5JVN3EVT.cjs.map → chunk-HN4DLGKP.cjs.map} +1 -1
  20. package/dist/{chunk-WJ7PDBPK.cjs → chunk-HXQWGZYG.cjs} +4 -4
  21. package/dist/{chunk-WJ7PDBPK.cjs.map → chunk-HXQWGZYG.cjs.map} +1 -1
  22. package/dist/{chunk-5MZZFTME.js → chunk-IUHU5BC2.js} +5 -5
  23. package/dist/{chunk-ZGWXD2S3.js → chunk-IWEJCDCB.js} +3 -3
  24. package/dist/{chunk-N2E26OD6.cjs → chunk-LFCMKMHR.cjs} +45 -45
  25. package/dist/{chunk-N2E26OD6.cjs.map → chunk-LFCMKMHR.cjs.map} +1 -1
  26. package/dist/{chunk-XJH5M2B7.js → chunk-M6QCADAT.js} +6 -6
  27. package/dist/{chunk-NWYSHZG7.cjs → chunk-N7AJUG4C.cjs} +22 -22
  28. package/dist/{chunk-NWYSHZG7.cjs.map → chunk-N7AJUG4C.cjs.map} +1 -1
  29. package/dist/{chunk-LDJ4TIDC.cjs → chunk-ODXVLFAQ.cjs} +13 -24
  30. package/dist/chunk-ODXVLFAQ.cjs.map +1 -0
  31. package/dist/{chunk-4GOJFHJY.js → chunk-OLPU5IVF.js} +2 -2
  32. package/dist/{chunk-PD47DDHS.js → chunk-PYAFHT6B.js} +7 -18
  33. package/dist/chunk-PYAFHT6B.js.map +1 -0
  34. package/dist/{chunk-H4FQRA5O.cjs → chunk-RM5MF2N3.cjs} +3 -3
  35. package/dist/{chunk-H4FQRA5O.cjs.map → chunk-RM5MF2N3.cjs.map} +1 -1
  36. package/dist/{chunk-ZDIDA4QG.js → chunk-SBKNMSQR.js} +2 -2
  37. package/dist/{chunk-GBZ3IR3S.js → chunk-SNQ5KWLP.js} +2 -2
  38. package/dist/{chunk-LLT5XMP2.js → chunk-UW7XUQFP.js} +3 -3
  39. package/dist/{chunk-RRSR2XHJ.cjs → chunk-VPEETTUS.cjs} +167 -167
  40. package/dist/chunk-VPEETTUS.cjs.map +1 -0
  41. package/dist/{chunk-UR7BC74V.js → chunk-VTLDEZ5D.js} +3 -3
  42. package/dist/{chunk-XPPGI7SD.js → chunk-WBRO3MX2.js} +2 -2
  43. package/dist/{chunk-NZ66W56D.cjs → chunk-WMKXHOOD.cjs} +10 -10
  44. package/dist/{chunk-NZ66W56D.cjs.map → chunk-WMKXHOOD.cjs.map} +1 -1
  45. package/dist/{chunk-TZO743LD.cjs → chunk-WPNY4XEL.cjs} +3 -3
  46. package/dist/{chunk-TZO743LD.cjs.map → chunk-WPNY4XEL.cjs.map} +1 -1
  47. package/dist/{chunk-XATBOM3X.js → chunk-XE5DNWOR.js} +5 -5
  48. package/dist/{chunk-C6QUB6IS.cjs → chunk-XI3QJD3N.cjs} +22 -22
  49. package/dist/{chunk-C6QUB6IS.cjs.map → chunk-XI3QJD3N.cjs.map} +1 -1
  50. package/dist/{chunk-2V7SCIOG.cjs → chunk-YTOUGDPY.cjs} +33 -33
  51. package/dist/{chunk-2V7SCIOG.cjs.map → chunk-YTOUGDPY.cjs.map} +1 -1
  52. package/dist/{chunk-X2VTQ3TL.cjs → chunk-YUXFHVC2.cjs} +10 -10
  53. package/dist/{chunk-X2VTQ3TL.cjs.map → chunk-YUXFHVC2.cjs.map} +1 -1
  54. package/dist/components/case-studies/index.cjs +14 -14
  55. package/dist/components/case-studies/index.js +3 -3
  56. package/dist/components/chat/embeddable-chat.d.ts.map +1 -1
  57. package/dist/components/chat/index.cjs +2 -2
  58. package/dist/components/chat/index.js +1 -1
  59. package/dist/components/chat/types/message.types.d.ts +5 -0
  60. package/dist/components/chat/types/message.types.d.ts.map +1 -1
  61. package/dist/components/chat/utils/cited-sources.d.ts +5 -0
  62. package/dist/components/chat/utils/cited-sources.d.ts.map +1 -1
  63. package/dist/components/chat/utils/source-row-cta.d.ts +2 -7
  64. package/dist/components/chat/utils/source-row-cta.d.ts.map +1 -1
  65. package/dist/components/contact/index.cjs +4 -4
  66. package/dist/components/contact/index.js +3 -3
  67. package/dist/components/docs/index.cjs +7 -7
  68. package/dist/components/docs/index.js +6 -6
  69. package/dist/components/embeds/index.cjs +4 -4
  70. package/dist/components/embeds/index.js +3 -3
  71. package/dist/components/faq/index.cjs +4 -4
  72. package/dist/components/faq/index.js +3 -3
  73. package/dist/components/features/index.cjs +3 -3
  74. package/dist/components/features/index.js +2 -2
  75. package/dist/components/help-center-pages/index.cjs +23 -23
  76. package/dist/components/help-center-pages/index.js +14 -14
  77. package/dist/components/index.cjs +39 -39
  78. package/dist/components/index.js +13 -13
  79. package/dist/components/meeting-scheduler/index.cjs +24 -24
  80. package/dist/components/meeting-scheduler/index.js +2 -2
  81. package/dist/components/navigation/index.cjs +6 -6
  82. package/dist/components/navigation/index.js +5 -5
  83. package/dist/components/onboarding-guides/index.cjs +6 -6
  84. package/dist/components/onboarding-guides/index.js +5 -5
  85. package/dist/components/shared/doc-search/map-doc-search-results.d.ts.map +1 -1
  86. package/dist/components/tickets/index.cjs +7 -7
  87. package/dist/components/tickets/index.js +6 -6
  88. package/dist/components/ui/data-table/data-table-skeleton.d.ts.map +1 -1
  89. package/dist/components/ui/index.cjs +3 -3
  90. package/dist/components/ui/index.js +2 -2
  91. package/dist/components/ui/markdown/mermaid-diagram.d.ts +31 -9
  92. package/dist/components/ui/markdown/mermaid-diagram.d.ts.map +1 -1
  93. package/dist/index.cjs +19 -7
  94. package/dist/index.cjs.map +1 -1
  95. package/dist/index.js +18 -6
  96. package/dist/index.js.map +1 -1
  97. package/dist/utils/index.cjs +163 -0
  98. package/dist/utils/index.cjs.map +1 -1
  99. package/dist/utils/index.d.ts +1 -0
  100. package/dist/utils/index.d.ts.map +1 -1
  101. package/dist/utils/index.js +158 -1
  102. package/dist/utils/index.js.map +1 -1
  103. package/dist/utils/source-grouping.d.ts +86 -0
  104. package/dist/utils/source-grouping.d.ts.map +1 -0
  105. package/dist/utils/source-icons.d.ts +7 -0
  106. package/dist/utils/source-icons.d.ts.map +1 -1
  107. package/package.json +1 -1
  108. package/src/components/chat/embeddable-chat.tsx +10 -2
  109. package/src/components/chat/types/message.types.ts +5 -0
  110. package/src/components/chat/utils/cited-sources.ts +7 -1
  111. package/src/components/chat/utils/source-row-cta.ts +4 -7
  112. package/src/components/shared/doc-search/__tests__/map-doc-search-results.test.ts +48 -0
  113. package/src/components/shared/doc-search/map-doc-search-results.ts +6 -16
  114. package/src/components/ui/data-table/data-table-skeleton.tsx +15 -7
  115. package/src/components/ui/markdown/__tests__/mermaid-zoom.test.tsx +117 -0
  116. package/src/components/ui/markdown/mermaid-diagram.tsx +279 -59
  117. package/src/utils/__tests__/source-grouping.test.ts +240 -0
  118. package/src/utils/index.ts +11 -0
  119. package/src/utils/source-grouping.ts +215 -0
  120. package/src/utils/source-icons.ts +13 -0
  121. package/dist/chunk-7UWJMWDH.cjs.map +0 -1
  122. package/dist/chunk-DULSS7R6.js.map +0 -1
  123. package/dist/chunk-LDJ4TIDC.cjs.map +0 -1
  124. package/dist/chunk-PD47DDHS.js.map +0 -1
  125. package/dist/chunk-QS55P2TA.js.map +0 -1
  126. package/dist/chunk-RRSR2XHJ.cjs.map +0 -1
  127. /package/dist/{chunk-ETEM2ZD4.js.map → chunk-2A4RLR7R.js.map} +0 -0
  128. /package/dist/{chunk-5C7GMRJU.js.map → chunk-EKLOXVG2.js.map} +0 -0
  129. /package/dist/{chunk-NKMXFBV5.js.map → chunk-FQ4TZP6K.js.map} +0 -0
  130. /package/dist/{chunk-5MZZFTME.js.map → chunk-IUHU5BC2.js.map} +0 -0
  131. /package/dist/{chunk-ZGWXD2S3.js.map → chunk-IWEJCDCB.js.map} +0 -0
  132. /package/dist/{chunk-XJH5M2B7.js.map → chunk-M6QCADAT.js.map} +0 -0
  133. /package/dist/{chunk-4GOJFHJY.js.map → chunk-OLPU5IVF.js.map} +0 -0
  134. /package/dist/{chunk-ZDIDA4QG.js.map → chunk-SBKNMSQR.js.map} +0 -0
  135. /package/dist/{chunk-GBZ3IR3S.js.map → chunk-SNQ5KWLP.js.map} +0 -0
  136. /package/dist/{chunk-LLT5XMP2.js.map → chunk-UW7XUQFP.js.map} +0 -0
  137. /package/dist/{chunk-UR7BC74V.js.map → chunk-VTLDEZ5D.js.map} +0 -0
  138. /package/dist/{chunk-XPPGI7SD.js.map → chunk-WBRO3MX2.js.map} +0 -0
  139. /package/dist/{chunk-XATBOM3X.js.map → chunk-XE5DNWOR.js.map} +0 -0
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Grouped source chips: THE one owner, for every producer.
3
+ *
4
+ * "ClickUp Tasks (14 records)" with a per-row dropdown is built in exactly one
5
+ * place, `buildGroupedSource`, and WHICH rows group is decided in exactly one
6
+ * place, `groupsByTable`. Three producers call them:
7
+ *
8
+ * 1. the hub's web chat (`buildSourcesMeta`), server-side, over the rows it
9
+ * retrieved;
10
+ * 2. the hub's side-channel chips (my-tickets / my-tasks), server-side, over
11
+ * rows a strategy injected;
12
+ * 3. this chat's strip, client-side, over the FLAT sources a remote MCP tool
13
+ * returns (`groupSourcesByTable`).
14
+ *
15
+ * Why the third one is client-side: an MCP tool result is one self-describing
16
+ * citation per record, which is what a citation contract should be, and a turn
17
+ * that calls several tools yields several flat lists only the client ever sees
18
+ * merged. Grouping is presentation. It is the SAME presentation everywhere
19
+ * because it is the same two functions everywhere.
20
+ *
21
+ * Server-safe: no React, no browser APIs. The hub imports it from the `utils`
22
+ * barrel next to `getSourceLabel`.
23
+ */
24
+ import type { ChatSource } from '../components/chat/types/message.types';
25
+ /**
26
+ * Doc-table documentTypes: whole documents with their own viewer (markdown =
27
+ * product docs, data_room_doc = data room). They carry an in-app `path`, an
28
+ * embedder keys `docPlatformTargets` by them, and they NEVER group: one chip
29
+ * per document. The hub's per-source contract test pins this list to its
30
+ * doc-table configs.
31
+ */
32
+ export declare const DOC_TABLE_TYPES: readonly ["markdown", "data_room_doc"];
33
+ /** THE rule: rows of a knowledge table share one chip unless they are whole
34
+ * documents. Decided by `documentType`, the one fact every producer has. */
35
+ export declare function groupsByTable(documentType: string | null | undefined): boolean;
36
+ /** `(1 record)` / `(14 records)`: the count every grouped chip states. */
37
+ export declare function recordCountLabel(count: number): string;
38
+ type GroupedItem = NonNullable<ChatSource['items']>[number];
39
+ /** One row of a group. `index` is set only when the row was cited on its own
40
+ * (a flat MCP source); a server-grouped row shares the group's number. */
41
+ export type GroupedSourceRow = GroupedItem;
42
+ /**
43
+ * THE grouped-chip constructor. Order-preserving: a producer that wants its
44
+ * dropdown by date sorts `rows` first.
45
+ *
46
+ * `items` is ALWAYS populated, rows without a public URL included: per-row
47
+ * `id` + `documentType` is what gives every dropdown row its Ask action, and a
48
+ * chip with `items` never navigates to `path`, which for an entity table is
49
+ * mapper bookkeeping and not a route.
50
+ */
51
+ export declare function buildGroupedSource(spec: {
52
+ /** The chip's citation number (and React key). */
53
+ index: number;
54
+ sourceRepo: string;
55
+ rows: GroupedSourceRow[];
56
+ /** Chip-level link, when it is not the first row's own. */
57
+ externalUrl?: string;
58
+ targetPlatform?: string | null;
59
+ }): ChatSource;
60
+ /**
61
+ * Flat sources in, the strip's chips out: ONE chip per table.
62
+ *
63
+ * Every row that names its table joins that table's chip, a lone record and a
64
+ * row missing its `id` or `documentType` included, exactly as the hub's web chat draws it. Each flat row
65
+ * keeps the citation number it was given, so `[3]` in the answer still
66
+ * resolves inside the group. The chip sits where its table first appeared and
67
+ * takes that source's `index` (unique, members are disjoint), so the strip
68
+ * keeps the order it was handed: reading order for cited sources.
69
+ *
70
+ * A chip the server already grouped passes through UNTOUCHED when it is its
71
+ * table's only source. When flat rows of the same table arrive beside it (a
72
+ * hub-injected chip plus MCP-cited rows in one answer), they merge into it:
73
+ * its rows first, its chip-level link kept, the count restated. Whole
74
+ * documents and rows naming no table pass through as their own chips.
75
+ */
76
+ export declare function groupSourcesByTable(sources: ChatSource[]): ChatSource[];
77
+ /**
78
+ * The citation numbers a chip answers to, as compact text: `1-3, 7`.
79
+ *
80
+ * A chip grouped from flat sources stands for several `[N]` markers, so it
81
+ * shows all of them. Consecutive numbers fold into a range, which keeps a
82
+ * 25-row group readable.
83
+ */
84
+ export declare function formatCitationIndices(indices: number[]): string;
85
+ export {};
86
+ //# sourceMappingURL=source-grouping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-grouping.d.ts","sourceRoot":"","sources":["../../src/utils/source-grouping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAGzE;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,wCAAyC,CAAC;AAEtE;6EAC6E;AAC7E,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAE9E;AAED,0EAA0E;AAC1E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,KAAK,WAAW,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5D;2EAC2E;AAC3E,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAE3C;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACvC,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,gBAAgB,EAAE,CAAC;IACzB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,GAAG,UAAU,CAcb;AA0DD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAqCvE;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAU/D"}
@@ -75,4 +75,11 @@ export declare const DEFAULT_DOCUMENT_TYPE_TO_TABLE_ID: Record<string, string>;
75
75
  * still short-circuits gracefully on stale or custom types.
76
76
  */
77
77
  export declare function defaultTableIdForDocumentType(documentType: string): string | null;
78
+ /**
79
+ * The reverse lookup: a table's canonical `documentType`. The map above is
80
+ * 1:1 (the hub's per-source contract test pins one type per table), so a row
81
+ * that names its table but arrived with no type still has one. `null` for a
82
+ * table the map does not list.
83
+ */
84
+ export declare function defaultDocumentTypeForTableId(tableId: string): string | null;
78
85
  //# sourceMappingURL=source-icons.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"source-icons.d.ts","sourceRoot":"","sources":["../../src/utils/source-icons.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAsDpD,CAAC;AAEF;;6DAE6D;AAC7D,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAGxF;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA4DzD,CAAC;AAEF;;kEAEkE;AAClE,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,iCAAiC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAsDpE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEjF"}
1
+ {"version":3,"file":"source-icons.d.ts","sourceRoot":"","sources":["../../src/utils/source-icons.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAsDpD,CAAC;AAEF;;6DAE6D;AAC7D,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAGxF;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA4DzD,CAAC;AAEF;;kEAEkE;AAClE,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,iCAAiC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAsDpE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEjF;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK5E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flamingo-stack/openframe-frontend-core",
3
- "version": "0.0.646",
3
+ "version": "0.0.647-snapshot.20260917173248",
4
4
  "description": "Shared design system and components for all Flamingo platforms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -41,6 +41,7 @@ import { useRequiredChatRuntime } from '../../contexts/chat-runtime-context';
41
41
  import { useRouter } from '../../embed-shims/next-navigation';
42
42
  import { useIsHydrated } from '../../hooks/ui/use-is-hydrated';
43
43
  import { cn } from '../../utils/cn';
44
+ import { formatCitationIndices } from '../../utils/source-grouping';
44
45
  import { EntityIcon } from '../icon-display';
45
46
  import { MingoIcon } from '../icons';
46
47
  import {
@@ -668,7 +669,9 @@ function SourceChip({
668
669
  // value is what keeps the handler assertion-free.
669
670
  const itemChatRef = itemCta.chatRef;
670
671
  return {
671
- label: item.name,
672
+ // A client-built group keeps each row's own citation number, so the
673
+ // `[3]` in the answer is findable inside the dropdown.
674
+ label: item.index === undefined ? item.name : `[${item.index}] ${item.name}`,
672
675
  icon: <ItemIcon className="h-3.5 w-3.5" />,
673
676
  href: itemCta.href ?? undefined,
674
677
  targetPlatform: itemCta.targetPlatform,
@@ -684,6 +687,11 @@ function SourceChip({
684
687
  };
685
688
  });
686
689
 
690
+ // A server-grouped chip answers to one number; a client-built one answers
691
+ // to every number its rows were cited by.
692
+ const itemIndices = src.items.flatMap(item => (item.index === undefined ? [] : [item.index]));
693
+ const groupIndices = itemIndices.length > 0 ? formatCitationIndices(itemIndices) : `${src.index}`;
694
+
687
695
  return (
688
696
  <HoverDropdown
689
697
  items={dropdownItems}
@@ -701,7 +709,7 @@ function SourceChip({
701
709
  <span className={`${chipClass} cursor-pointer`}>
702
710
  {icon}
703
711
  <span className="max-w-[160px] truncate">
704
- [{src.index}] {src.name}
712
+ [{groupIndices}] {src.name}
705
713
  </span>
706
714
  </span>
707
715
  </HoverDropdown>
@@ -424,6 +424,11 @@ export interface ChatSource {
424
424
  id?: string;
425
425
  /** Per-row items for grouped chips. */
426
426
  items?: Array<{
427
+ /** The row's own citation number. Present when the group was built
428
+ * client-side from flat sources (`groupSourcesByTable`), so `[N]` in the
429
+ * answer still resolves to a row; absent on a server-grouped chip, whose
430
+ * rows share the group's one number. */
431
+ index?: number;
427
432
  id: string;
428
433
  documentType: string;
429
434
  name: string;
@@ -1,3 +1,4 @@
1
+ import { groupSourcesByTable } from '../../../utils/source-grouping';
1
2
  import type { ChatSource } from '../types/message.types';
2
3
 
3
4
  /** How many retrieved sources to show when the answer cited none of them. */
@@ -40,6 +41,11 @@ function withoutCode(content: string): string {
40
41
  * even when the model numbered it `[3]`. A number cited twice is placed once,
41
42
  * at its first mention.
42
43
  *
44
+ * Each half is then grouped by knowledge table (`groupSourcesByTable`): AFTER
45
+ * the split, because cited-ness belongs to a citation number, and a table whose
46
+ * rows were only partly cited is honestly two chips, the cited rows under
47
+ * "Sources" and the rest behind the expander.
48
+ *
43
49
  * `content` is the flat answer text. A segmented message has to be flattened by
44
50
  * the caller — citation markers live in text segments, and this function
45
51
  * deliberately does not know what a segment is.
@@ -57,5 +63,5 @@ export function splitCitedSources(sources: ChatSource[] | undefined, content: st
57
63
  .filter(source => firstMentionAt.has(source.index))
58
64
  .sort((a, b) => (firstMentionAt.get(a.index) ?? 0) - (firstMentionAt.get(b.index) ?? 0));
59
65
  const uncited = sources.filter(source => !firstMentionAt.has(source.index));
60
- return { cited, uncited };
66
+ return { cited: groupSourcesByTable(cited), uncited: groupSourcesByTable(uncited) };
61
67
  }
@@ -26,6 +26,7 @@ import type React from 'react';
26
26
  import { getPlatformUrl } from '../../../platform-domains';
27
27
  import type { ComposeContentUrl } from '../../../utils/content-href';
28
28
  import { canonicalContentRefType } from '../../../utils/list-url';
29
+ import { DOC_TABLE_TYPES } from '../../../utils/source-grouping';
29
30
  import type { ChatRef } from '../chat-ref.types';
30
31
  import { safeHref } from './compact-card-classes';
31
32
  import { getIconComponent } from './icon-registry';
@@ -154,13 +155,9 @@ function pickSourceIcon(sourceRepo: string | null, documentType: string | null |
154
155
  return { icon, iconLabel };
155
156
  }
156
157
 
157
- /**
158
- * Doc-table documentTypes — rows that carry an in-app `path` (not an entity
159
- * `externalUrl`) and resolve to a doc viewer. The SAME set an embedder keys its
160
- * `docPlatformTargets` map by (markdown = product docs, data_room_doc = data room),
161
- * declared once so the two can't silently diverge.
162
- */
163
- export const DOC_TABLE_TYPES = ['markdown', 'data_room_doc'] as const;
158
+ // Declared once in `utils/source-grouping`; re-exported so embedders that key
159
+ // `docPlatformTargets` by it keep their import.
160
+ export { DOC_TABLE_TYPES };
164
161
 
165
162
  /**
166
163
  * Only doc-table rows (DOC_TABLE_TYPES) fall back to doc-viewer navigation when no
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The search bar folds the financial tables into one row each, titled with the
3
+ * SHARED table label and count (the same owners the chat's grouped chip uses).
4
+ * It used to carry its own label map; this pins that every table it folds has a
5
+ * real label in the shared one, so a title can never decay to a raw table slug.
6
+ */
7
+
8
+ import { describe, expect, it } from 'vitest';
9
+
10
+ import { SOURCE_LABELS_BY_TABLE } from '../../../../utils/source-icons';
11
+ import { mapDocSearchResults } from '../map-doc-search-results';
12
+ import type { DocSearchResult } from '../types';
13
+
14
+ const FOLDED_TABLES = [
15
+ 'financial-cap-table',
16
+ 'financial-kpis',
17
+ 'financial-pnl',
18
+ 'financial-balance-sheet',
19
+ 'financial-cash-flow',
20
+ ];
21
+
22
+ const row = (sourceRepo: string, n: number): DocSearchResult =>
23
+ ({
24
+ path: `${sourceRepo}/${n}`,
25
+ name: `Row ${n}`,
26
+ snippet: '',
27
+ type: 'file',
28
+ matchType: 'content',
29
+ documentType: 'cap_table',
30
+ sourceRepo,
31
+ entityId: `${n}`,
32
+ }) as DocSearchResult;
33
+
34
+ describe('mapDocSearchResults', () => {
35
+ it.each(FOLDED_TABLES)('titles the folded %s row with its shared label and count', table => {
36
+ expect(SOURCE_LABELS_BY_TABLE[table]).toEqual(expect.any(String));
37
+
38
+ const [group, ...rest] = mapDocSearchResults([row(table, 1), row(table, 2)]);
39
+ expect(rest).toEqual([]);
40
+ expect(group.title).toBe(`${SOURCE_LABELS_BY_TABLE[table]} (2 records)`);
41
+ expect(group.title.startsWith(table)).toBe(false);
42
+ });
43
+
44
+ it('leaves every other table as one row per result', () => {
45
+ const results = mapDocSearchResults([row('blog-posts', 1), row('blog-posts', 2)]);
46
+ expect(results.map(result => result.title)).toEqual(['Row 1', 'Row 2']);
47
+ });
48
+ });
@@ -10,10 +10,14 @@
10
10
  * dropped — callers that want logging can wrap this helper).
11
11
  */
12
12
 
13
+ import { recordCountLabel } from '../../../utils/source-grouping';
14
+ import { getSourceLabel } from '../../../utils/source-icons';
13
15
  import type { SearchResult } from '../../ui/search-input';
14
16
  import type { DocSearchResult } from './types';
15
17
 
16
18
  /** Source repos that should be collapsed into grouped results in the search bar.
19
+ * A SEARCH rule, deliberately narrower than the chat strip's `groupsByTable`:
20
+ * a search result is a destination, so only rows that share one are folded.
17
21
  * Only financial tables (all rows link to the same admin page).
18
22
  * Content tables (blog, webinar, podcast, etc.) stay individual since each has a unique URL. */
19
23
  const SEARCH_GROUP_REPOS = new Set([
@@ -24,20 +28,6 @@ const SEARCH_GROUP_REPOS = new Set([
24
28
  'financial-cash-flow',
25
29
  ]);
26
30
 
27
- const ENTITY_LABELS: Record<string, string> = {
28
- 'financial-cap-table': 'Cap Table',
29
- 'financial-kpis': 'Financial KPIs',
30
- 'financial-pnl': 'Profit & Loss',
31
- 'financial-balance-sheet': 'Balance Sheets',
32
- 'financial-cash-flow': 'Cash Flow',
33
- 'blog-posts': 'Blog Posts',
34
- 'product-releases': 'Product Releases',
35
- 'case-studies': 'Case Studies',
36
- webinars: 'Webinars',
37
- events: 'Events',
38
- podcasts: 'Podcasts',
39
- };
40
-
41
31
  export function mapDocSearchResults(docs: DocSearchResult[]): SearchResult[] {
42
32
  const entityGroups = new Map<string, DocSearchResult[]>();
43
33
  // Track insertion order — groups appear where the FIRST row of that
@@ -67,10 +57,10 @@ export function mapDocSearchResults(docs: DocSearchResult[]): SearchResult[] {
67
57
  // whole search dropdown if that ever stops holding.
68
58
  const rows = entityGroups.get(entry.repo);
69
59
  if (!rows || rows.length === 0) continue;
70
- const label = ENTITY_LABELS[entry.repo] || entry.repo;
71
60
  results.push({
72
61
  id: `group-${entry.repo}`,
73
- title: `${label} (${rows.length} ${rows.length === 1 ? 'record' : 'records'})`,
62
+ // Same table label and count as the chat's grouped chip: one owner each.
63
+ title: `${getSourceLabel(entry.repo)} ${recordCountLabel(rows.length)}`,
74
64
  path: rows[0].path,
75
65
  type: 'file',
76
66
  metadata: {
@@ -128,19 +128,27 @@ export function ReservedEmptyState({
128
128
  innerHeightClassName?: string;
129
129
  children: ReactNode;
130
130
  }) {
131
+ // ONE grid cell holds both layers, so the box is as tall as the TALLER of
132
+ // the two: a short reservation (three compact rows) never clips the empty
133
+ // state, and a tall one still reserves its slots. The former absolute
134
+ // overlay took no height of its own, so a message taller than the slots
135
+ // spilled out of the host's horizontal scroller and grew it a vertical
136
+ // scrollbar — the header scrolled away inside a section.
131
137
  return (
132
- <div className={cn('relative flex w-full flex-col', gapClassName)}>
133
- <PlaceholderRows
134
- count={count}
135
- rowHeightClassName={rowHeightClassName}
136
- innerHeightClassName={innerHeightClassName}
137
- />
138
+ <div className="grid w-full">
139
+ <div className={cn('flex w-full flex-col [grid-area:1/1]', gapClassName)}>
140
+ <PlaceholderRows
141
+ count={count}
142
+ rowHeightClassName={rowHeightClassName}
143
+ innerHeightClassName={innerHeightClassName}
144
+ />
145
+ </div>
138
146
  {/* `sticky left-0` + `w-screen max-w-full`: hosts wrap tables in a
139
147
  horizontal scroller with a forced min-width, and an overlay centred on
140
148
  that CANVAS puts the message off-screen on a phone. This centres it on
141
149
  the visible area instead, and collapses to plain centring when the
142
150
  table is not wider than its container. */}
143
- <div className="absolute inset-0 flex items-center">
151
+ <div className="flex items-center [grid-area:1/1]">
144
152
  <div className="sticky left-0 flex w-screen max-w-full justify-center">{children}</div>
145
153
  </div>
146
154
  </div>
@@ -0,0 +1,117 @@
1
+ /**
2
+ * The zoom toolbar lives in the ONE MermaidDiagram, so every diagram (a
3
+ * markdown fence, a server-rendered admin chart) zooms the same way. Pins:
4
+ * the buttons change the container's CSS `zoom`, the bounds hold, reset
5
+ * returns to 100%, and `zoomable={false}` renders no toolbar.
6
+ */
7
+ import { render, act, screen, fireEvent } from '@testing-library/react';
8
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
9
+
10
+ const renders: Array<{ resolve: (value: { svg: string }) => void }> = [];
11
+
12
+ vi.mock('mermaid', () => ({
13
+ default: {
14
+ initialize: vi.fn(),
15
+ render: vi.fn(
16
+ () =>
17
+ new Promise<{ svg: string }>(resolve => {
18
+ renders.push({ resolve });
19
+ }),
20
+ ),
21
+ },
22
+ }));
23
+
24
+ import { MERMAID_ZOOM_MAX, MERMAID_ZOOM_MIN, MermaidDiagram } from '../mermaid-diagram';
25
+
26
+ const flushUntil = async (done: () => boolean, what: string) => {
27
+ for (let i = 0; i < 50; i++) {
28
+ await act(async () => {
29
+ await new Promise(resolve => setTimeout(resolve, 0));
30
+ });
31
+ if (done()) return;
32
+ }
33
+ throw new Error(`timed out waiting for ${what}`);
34
+ };
35
+
36
+ const mountRendered = async (props: { zoomable?: boolean } = {}) => {
37
+ render(<MermaidDiagram chart="flowchart LR; a-->b" {...props} />);
38
+ await flushUntil(() => renders.length >= 1, 'a mermaid.render call');
39
+ await act(async () => {
40
+ renders[0].resolve({ svg: '<svg width="10" height="10"><g/></svg>' });
41
+ // Let the resolved render settle inside `act` (and give the async callback its await).
42
+ await Promise.resolve();
43
+ });
44
+ await flushUntil(() => !!screen.queryByTestId('mermaid-svg-container'), 'the rendered diagram');
45
+ };
46
+
47
+ const zoomOf = () => Number(screen.getByTestId('mermaid-svg-container').getAttribute('data-zoom'));
48
+
49
+ describe('MermaidDiagram zoom', () => {
50
+ beforeEach(() => {
51
+ renders.length = 0;
52
+ });
53
+
54
+ it('zooms in and out from the toolbar and resets to 100%', async () => {
55
+ await mountRendered();
56
+ expect(zoomOf()).toBe(1);
57
+ fireEvent.click(screen.getByRole('button', { name: 'Zoom in' }));
58
+ expect(zoomOf()).toBe(1.25);
59
+ fireEvent.click(screen.getByRole('button', { name: 'Zoom in' }));
60
+ expect(zoomOf()).toBeCloseTo(1.56, 2);
61
+ fireEvent.click(screen.getByRole('button', { name: 'Reset zoom' }));
62
+ expect(zoomOf()).toBe(1);
63
+ fireEvent.click(screen.getByRole('button', { name: 'Zoom out' }));
64
+ expect(zoomOf()).toBe(0.8);
65
+ });
66
+
67
+ it('stays inside the bounds and disables the button at each end', async () => {
68
+ await mountRendered();
69
+ const zoomIn = screen.getByRole('button', { name: 'Zoom in' });
70
+ for (let i = 0; i < 20; i++) fireEvent.click(zoomIn);
71
+ expect(zoomOf()).toBe(MERMAID_ZOOM_MAX);
72
+ expect(zoomIn).toBeDisabled();
73
+ const zoomOut = screen.getByRole('button', { name: 'Zoom out' });
74
+ for (let i = 0; i < 40; i++) fireEvent.click(zoomOut);
75
+ expect(zoomOf()).toBe(MERMAID_ZOOM_MIN);
76
+ expect(zoomOut).toBeDisabled();
77
+ });
78
+
79
+ it('holds the skeleton for an empty chart instead of asking mermaid to parse it', async () => {
80
+ const { rerender } = render(<MermaidDiagram chart="" frame="fold" />);
81
+ await act(async () => {
82
+ await new Promise(resolve => setTimeout(resolve, 20));
83
+ });
84
+ expect(renders).toHaveLength(0);
85
+ expect(screen.getByTestId('mermaid-frame').getAttribute('data-frame')).toBe('fold');
86
+ expect(screen.queryByTestId('mermaid-svg-container')).toBeNull();
87
+ rerender(<MermaidDiagram chart="flowchart LR; a-->b" frame="fold" />);
88
+ await flushUntil(() => renders.length >= 1, 'the first real render');
89
+ });
90
+
91
+ it('pans by dragging the frame, and zooms from the keyboard and a ⌘/Ctrl wheel', async () => {
92
+ await mountRendered();
93
+ const frame = screen.getByTestId('mermaid-frame');
94
+ fireEvent.pointerDown(frame, { button: 0, pointerType: 'mouse', clientX: 100, clientY: 100, pointerId: 1 });
95
+ fireEvent.pointerMove(frame, { clientX: 60, clientY: 75, pointerId: 1 });
96
+ expect(frame.scrollLeft).toBe(40);
97
+ expect(frame.scrollTop).toBe(25);
98
+ fireEvent.pointerUp(frame, { pointerId: 1 });
99
+ fireEvent.pointerMove(frame, { clientX: 0, clientY: 0, pointerId: 1 });
100
+ expect(frame.scrollLeft).toBe(40);
101
+
102
+ fireEvent.keyDown(frame, { key: '+' });
103
+ expect(zoomOf()).toBe(1.25);
104
+ fireEvent.keyDown(frame, { key: '0' });
105
+ expect(zoomOf()).toBe(1);
106
+ fireEvent.wheel(frame, { deltaY: -400, ctrlKey: true, clientX: 10, clientY: 10 });
107
+ expect(zoomOf()).toBeGreaterThan(1);
108
+ fireEvent.wheel(frame, { deltaY: 400 });
109
+ expect(zoomOf()).toBeGreaterThan(1); // a plain wheel scrolls, it never zooms
110
+ });
111
+
112
+ it('renders no toolbar when zoom is turned off', async () => {
113
+ await mountRendered({ zoomable: false });
114
+ expect(screen.queryByRole('group', { name: 'Diagram zoom' })).toBeNull();
115
+ expect(zoomOf()).toBe(1);
116
+ });
117
+ });