@redocly/theme 0.70.0-next.5 → 0.70.0-next.7

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 (99) hide show
  1. package/lib/components/Buttons/ConnectMCPButton.js +8 -13
  2. package/lib/components/Catalog/CatalogEntity/CatalogEntityGraph/CatalogEntityRelationsGraph.lazy.js +1 -1
  3. package/lib/components/Catalog/CatalogFilter/CatalogFilterDateRange.js +2 -1
  4. package/lib/components/Dropdown/Dropdown.d.ts +4 -2
  5. package/lib/components/Dropdown/Dropdown.js +28 -8
  6. package/lib/components/Filter/FilterDateRange.js +36 -2
  7. package/lib/components/Portal/Portal.js +37 -5
  8. package/lib/components/Search/SearchAiActionButtons.js +8 -3
  9. package/lib/components/Search/SearchAiActivity.d.ts +10 -0
  10. package/lib/components/Search/SearchAiActivity.js +278 -0
  11. package/lib/components/Search/SearchAiDialog.js +5 -1
  12. package/lib/components/Search/SearchAiMessage.d.ts +2 -1
  13. package/lib/components/Search/SearchAiMessage.js +20 -108
  14. package/lib/components/Search/SearchDialog.js +10 -0
  15. package/lib/components/Search/SearchItem.js +1 -8
  16. package/lib/components/Search/variables.js +15 -2
  17. package/lib/components/Select/SelectInput.js +2 -8
  18. package/lib/components/SplitButton/SplitButton.js +37 -3
  19. package/lib/core/constants/mcp.d.ts +2 -2
  20. package/lib/core/constants/mcp.js +3 -8
  21. package/lib/core/constants/search.js +5 -1
  22. package/lib/core/contexts/PortalContainerContext.d.ts +2 -0
  23. package/lib/core/contexts/PortalContainerContext.js +7 -0
  24. package/lib/core/hooks/index.d.ts +2 -0
  25. package/lib/core/hooks/index.js +2 -0
  26. package/lib/core/hooks/menu/use-collapse.js +1 -1
  27. package/lib/core/hooks/search/use-persisted-quick-filter.d.ts +21 -0
  28. package/lib/core/hooks/search/use-persisted-quick-filter.js +92 -0
  29. package/lib/core/hooks/search/use-search-ai-activity.d.ts +11 -0
  30. package/lib/core/hooks/search/use-search-ai-activity.js +15 -0
  31. package/lib/core/hooks/use-connect-mcp-button.js +2 -1
  32. package/lib/core/hooks/use-full-height.d.ts +1 -1
  33. package/lib/core/hooks/use-full-height.js +8 -8
  34. package/lib/core/styles/global.d.ts +2 -0
  35. package/lib/core/styles/global.js +80 -76
  36. package/lib/core/styles/index.d.ts +1 -0
  37. package/lib/core/styles/index.js +3 -1
  38. package/lib/core/styles/search-ai-appear.d.ts +1 -0
  39. package/lib/core/styles/search-ai-appear.js +18 -0
  40. package/lib/core/types/dropdown.d.ts +1 -0
  41. package/lib/core/types/dropdown.js +3 -0
  42. package/lib/core/types/index.d.ts +1 -0
  43. package/lib/core/types/l10n.d.ts +1 -1
  44. package/lib/core/types/mcp.d.ts +2 -1
  45. package/lib/core/types/search.d.ts +23 -0
  46. package/lib/core/utils/assign-ref.d.ts +2 -0
  47. package/lib/core/utils/assign-ref.js +12 -0
  48. package/lib/core/utils/content-segments.d.ts +12 -1
  49. package/lib/core/utils/content-segments.js +90 -5
  50. package/lib/core/utils/dropdown.d.ts +2 -0
  51. package/lib/core/utils/dropdown.js +12 -0
  52. package/lib/core/utils/index.d.ts +2 -0
  53. package/lib/core/utils/index.js +2 -0
  54. package/lib/core/utils/mcp.d.ts +2 -1
  55. package/lib/core/utils/mcp.js +5 -0
  56. package/lib/core/utils/search-ai-activity.d.ts +4 -0
  57. package/lib/core/utils/search-ai-activity.js +83 -0
  58. package/lib/markdoc/tags/connect-mcp.js +15 -0
  59. package/package.json +3 -2
  60. package/src/components/Buttons/ConnectMCPButton.tsx +8 -14
  61. package/src/components/Catalog/CatalogEntity/CatalogEntityGraph/CatalogEntityRelationsGraph.lazy.tsx +3 -1
  62. package/src/components/Catalog/CatalogFilter/CatalogFilterDateRange.tsx +3 -2
  63. package/src/components/Dropdown/Dropdown.tsx +28 -6
  64. package/src/components/Filter/FilterDateRange.tsx +3 -2
  65. package/src/components/Portal/Portal.tsx +4 -2
  66. package/src/components/Search/SearchAiActionButtons.tsx +31 -19
  67. package/src/components/Search/SearchAiActivity.tsx +318 -0
  68. package/src/components/Search/SearchAiDialog.tsx +4 -3
  69. package/src/components/Search/SearchAiMessage.tsx +27 -135
  70. package/src/components/Search/SearchDialog.tsx +11 -0
  71. package/src/components/Search/SearchItem.tsx +2 -9
  72. package/src/components/Search/variables.ts +15 -2
  73. package/src/components/Select/SelectInput.tsx +2 -8
  74. package/src/components/SplitButton/SplitButton.tsx +8 -2
  75. package/src/core/constants/mcp.ts +3 -9
  76. package/src/core/constants/search.ts +5 -1
  77. package/src/core/contexts/PortalContainerContext.tsx +4 -0
  78. package/src/core/hooks/__mocks__/index.ts +2 -0
  79. package/src/core/hooks/index.ts +2 -0
  80. package/src/core/hooks/menu/use-collapse.ts +1 -1
  81. package/src/core/hooks/search/use-persisted-quick-filter.ts +125 -0
  82. package/src/core/hooks/search/use-search-ai-activity.ts +31 -0
  83. package/src/core/hooks/use-connect-mcp-button.ts +7 -2
  84. package/src/core/hooks/use-full-height.ts +8 -8
  85. package/src/core/styles/global.ts +80 -75
  86. package/src/core/styles/index.ts +2 -1
  87. package/src/core/styles/search-ai-appear.ts +16 -0
  88. package/src/core/types/dropdown.ts +1 -0
  89. package/src/core/types/index.ts +1 -0
  90. package/src/core/types/l10n.ts +4 -1
  91. package/src/core/types/mcp.ts +3 -1
  92. package/src/core/types/search.ts +21 -0
  93. package/src/core/utils/assign-ref.ts +9 -0
  94. package/src/core/utils/content-segments.ts +98 -6
  95. package/src/core/utils/dropdown.ts +14 -0
  96. package/src/core/utils/index.ts +2 -0
  97. package/src/core/utils/mcp.ts +7 -1
  98. package/src/core/utils/search-ai-activity.ts +110 -0
  99. package/src/markdoc/tags/connect-mcp.ts +16 -1
@@ -1,5 +1,13 @@
1
- import type { ToolCall, ContentSegment } from '../types/search';
1
+ import type { ToolCall, ContentSegment, GroupedContentSegment } from '../types/search';
2
2
 
3
+ const SENTENCE_END_MARKS = '.!?:;';
4
+ const CLOSING_MARKS = `"')]*_\``;
5
+ const CODE_FENCE = /^[ \t]*(```|~~~)/gm;
6
+
7
+ /**
8
+ * Splits an answer at its tool calls. A call made in the middle of a sentence or a code block is
9
+ * placed at the end of that paragraph, so the sentence reads as one piece.
10
+ */
3
11
  export function splitContentByToolCalls(
4
12
  content: string | undefined,
5
13
  toolCalls: ToolCall[] | undefined,
@@ -8,20 +16,104 @@ export function splitContentByToolCalls(
8
16
  return [{ type: 'text', text: content || '' }];
9
17
  }
10
18
 
19
+ const text = content ?? '';
20
+ const fences = Array.from(text.matchAll(CODE_FENCE), (match) => match.index);
11
21
  const segments: ContentSegment[] = [];
12
22
  let lastPos = 0;
13
23
 
14
24
  for (const toolCall of toolCalls) {
15
- if (content && toolCall.position > lastPos) {
16
- segments.push({ type: 'text', text: content.substring(lastPos, toolCall.position) });
25
+ const position = Math.max(lastPos, getBlockBoundary(text, toolCall.position, fences));
26
+ if (position > lastPos) {
27
+ segments.push({ type: 'text', text: text.substring(lastPos, position) });
17
28
  }
18
29
  segments.push({ type: 'tool', toolCall });
19
- lastPos = toolCall.position;
30
+ lastPos = position;
20
31
  }
21
32
 
22
- if (content && lastPos < content.length) {
23
- segments.push({ type: 'text', text: content.substring(lastPos) });
33
+ if (lastPos < text.length) {
34
+ segments.push({ type: 'text', text: text.substring(lastPos) });
24
35
  }
25
36
 
26
37
  return segments;
27
38
  }
39
+
40
+ function getBlockBoundary(content: string, position: number, fences: number[]): number {
41
+ if (position <= 0 || position >= content.length) {
42
+ return position;
43
+ }
44
+ const isInsideCodeFence = (index: number) => {
45
+ let count = 0;
46
+ while (count < fences.length && fences[count] < index) count++;
47
+ return count % 2 === 1;
48
+ };
49
+ if (!isInsideCodeFence(position) && endsBlockOrSentence(content, position)) {
50
+ return position;
51
+ }
52
+ for (
53
+ let boundary = content.indexOf('\n\n', position);
54
+ boundary !== -1;
55
+ boundary = content.indexOf('\n\n', boundary + 2)
56
+ ) {
57
+ if (!isInsideCodeFence(boundary)) {
58
+ return boundary;
59
+ }
60
+ }
61
+ return content.length;
62
+ }
63
+
64
+ function endsBlockOrSentence(content: string, position: number): boolean {
65
+ let index = position - 1;
66
+ while (index >= 0 && /\s/.test(content[index])) {
67
+ if (content[index] === '\n') return true;
68
+ index--;
69
+ }
70
+ while (index >= 0 && CLOSING_MARKS.includes(content[index])) index--;
71
+ return index >= 0 && SENTENCE_END_MARKS.includes(content[index]);
72
+ }
73
+
74
+ /**
75
+ * Groups consecutive tool calls and drops text that is only whitespace. While the answer is
76
+ * generated, an answer with nothing to show yet is one empty active group (the thinking status),
77
+ * and the last group is active until text that is not whitespace follows it.
78
+ */
79
+ export function groupToolCallSegments(
80
+ segments: ContentSegment[],
81
+ isGenerating?: boolean,
82
+ ): GroupedContentSegment[] {
83
+ const grouped: GroupedContentSegment[] = [];
84
+ let text = '';
85
+
86
+ for (const segment of segments) {
87
+ if (segment.type === 'text') {
88
+ text += segment.text;
89
+ if (segment.text.trim()) {
90
+ grouped.push(segment);
91
+ }
92
+ continue;
93
+ }
94
+ const previous = grouped.at(-1);
95
+ if (previous?.type === 'tools') {
96
+ previous.toolCalls.push(segment.toolCall);
97
+ } else {
98
+ grouped.push({ type: 'tools', toolCalls: [segment.toolCall], isActive: false });
99
+ }
100
+ }
101
+
102
+ if (!isGenerating) {
103
+ return grouped;
104
+ }
105
+ const last = grouped.at(-1);
106
+ if (last?.type === 'tools') {
107
+ last.isActive = !text.slice(last.toolCalls.at(-1)?.position ?? 0).trim();
108
+ } else if (grouped.length === 0) {
109
+ return [{ type: 'tools', toolCalls: [], isActive: true }];
110
+ }
111
+ return grouped;
112
+ }
113
+
114
+ export function hasToolCallsAndText(segments: ContentSegment[]): boolean {
115
+ return (
116
+ segments.some((segment) => segment.type === 'tool') &&
117
+ segments.some((segment) => segment.type === 'text' && segment.text.trim().length > 0)
118
+ );
119
+ }
@@ -0,0 +1,14 @@
1
+ import type { DropdownAlignment } from '../types/dropdown';
2
+
3
+ export function fitDropdownAlignment(
4
+ anchor: DOMRect,
5
+ menuWidth: number,
6
+ alignment: DropdownAlignment = 'start',
7
+ ): DropdownAlignment {
8
+ const fits: Record<DropdownAlignment, boolean> = {
9
+ start: anchor.left + menuWidth <= window.innerWidth,
10
+ end: anchor.right - menuWidth >= 0,
11
+ };
12
+ const other: DropdownAlignment = alignment === 'end' ? 'start' : 'end';
13
+ return fits[alignment] || !fits[other] ? alignment : other;
14
+ }
@@ -51,3 +51,5 @@ export * from './telemetry/get-base-data-attributes';
51
51
  export * from './telemetry/generate-before-after-context';
52
52
  export * from './RenderWithLink';
53
53
  export * from './consent-settings-link-placement';
54
+ export * from './assign-ref';
55
+ export * from './dropdown';
@@ -1,4 +1,10 @@
1
- import type { MCPClientType, McpConnectionParams } from '../types';
1
+ import type { MCPClientType, McpConnectionParams, MCPOption } from '../types';
2
+
3
+ import { MCP_OPTIONS } from '../constants/mcp';
4
+
5
+ export function isMCPOption(value: unknown): value is MCPOption {
6
+ return (MCP_OPTIONS as readonly unknown[]).includes(value);
7
+ }
2
8
 
3
9
  function generateCursorMCPDeepLink(config: McpConnectionParams): string {
4
10
  const cursorConfig = {
@@ -0,0 +1,110 @@
1
+ import type { TFunction } from '../types/l10n';
2
+
3
+ import {
4
+ ToolCallName,
5
+ type SearchAiActivityStatus,
6
+ type SearchAiActivityStep,
7
+ type ToolCall,
8
+ type SearchAiActivityKind,
9
+ } from '../types/search';
10
+ import { TOOL_CALL_DISPLAY_TEXT } from '../constants/search';
11
+ import { isObject } from './type-guards';
12
+
13
+ export function getSearchAiActivityStatus(
14
+ toolCalls: ToolCall[],
15
+ isActive: boolean,
16
+ runningToolCall: ToolCall | undefined,
17
+ translate: TFunction,
18
+ ): SearchAiActivityStatus {
19
+ const latestToolCall = toolCalls.at(-1);
20
+ if (!latestToolCall) {
21
+ return {
22
+ label: translate('search.ai.thinkingText', 'Thinking...'),
23
+ kind: 'thinking',
24
+ isRunning: true,
25
+ };
26
+ }
27
+
28
+ if (isActive || toolCalls.length === 1) {
29
+ const toolCall = runningToolCall ?? latestToolCall;
30
+ return {
31
+ ...getToolCallLabel(toolCall, !isActive, translate),
32
+ kind: getSearchAiActivityKind(toolCall.name),
33
+ isRunning: isActive,
34
+ };
35
+ }
36
+
37
+ const isSameTool = toolCalls.every((toolCall) => toolCall.name === latestToolCall.name);
38
+ const sharedText = isSameTool
39
+ ? TOOL_CALL_DISPLAY_TEXT[latestToolCall.name]?.completedText
40
+ : undefined;
41
+ return {
42
+ label: sharedText ?? translate('search.ai.toolCall.usedTools', 'Used tools'),
43
+ kind: isSameTool ? getSearchAiActivityKind(latestToolCall.name) : 'code',
44
+ isRunning: false,
45
+ };
46
+ }
47
+
48
+ export function getSearchAiActivityStep(
49
+ toolCall: ToolCall,
50
+ isRunning: boolean,
51
+ translate: TFunction,
52
+ ): SearchAiActivityStep {
53
+ const detail = getToolCallDetail(toolCall);
54
+ const kind = getSearchAiActivityKind(toolCall.name);
55
+
56
+ if (toolCall.name === ToolCallName.SearchDocumentation && detail) {
57
+ return { id: toolCall.id, label: `“${detail}”`, kind, isRunning };
58
+ }
59
+ const { label } = getToolCallLabel(toolCall, !isRunning, translate);
60
+ return { id: toolCall.id, label: detail ? label : stripEllipsis(label), kind, isRunning };
61
+ }
62
+
63
+ function getToolCallLabel(
64
+ toolCall: ToolCall,
65
+ isCompleted: boolean,
66
+ translate: TFunction,
67
+ ): { label: string; detail?: string } {
68
+ const detail = getToolCallDetail(toolCall);
69
+ if (toolCall.name === ToolCallName.Execute && detail) {
70
+ return { label: detail };
71
+ }
72
+ const builtInText = TOOL_CALL_DISPLAY_TEXT[toolCall.name];
73
+ if (builtInText) {
74
+ const text = isCompleted ? builtInText.completedText : builtInText.inProgressText;
75
+ return detail ? { label: stripEllipsis(text), detail } : { label: text };
76
+ }
77
+ const prefix = isCompleted
78
+ ? translate('search.ai.toolCall.executed', 'Executed')
79
+ : translate('search.ai.toolCall.executing', 'Executing');
80
+ return { label: `${prefix} ${toolCall.name}` };
81
+ }
82
+
83
+ function getSearchAiActivityKind(name: string): SearchAiActivityKind {
84
+ if (name === ToolCallName.SearchDocumentation) return 'search';
85
+ if (name === ToolCallName.ContactSupport) return 'support';
86
+ return 'code';
87
+ }
88
+
89
+ function getToolCallDetail(toolCall: ToolCall): string | undefined {
90
+ switch (toolCall.name) {
91
+ case ToolCallName.SearchDocumentation:
92
+ return getStringArg(toolCall.args, 'query');
93
+ case ToolCallName.Execute:
94
+ return getStringArg(toolCall.args, 'description');
95
+ default:
96
+ return undefined;
97
+ }
98
+ }
99
+
100
+ function getStringArg(args: unknown, name: string): string | undefined {
101
+ if (!isObject(args) || !(name in args)) {
102
+ return undefined;
103
+ }
104
+ const value: unknown = Reflect.get(args, name);
105
+ return typeof value === 'string' && value.trim().length > 0 ? value.trim() : undefined;
106
+ }
107
+
108
+ function stripEllipsis(text: string): string {
109
+ return text.replace(/(\.{3}|…)$/, '');
110
+ }
@@ -1,6 +1,7 @@
1
1
  import type { MarkdocSchemaWrapper } from '@redocly/theme/markdoc/tags/types';
2
2
 
3
- import { DEFAULT_MCP_OPTIONS } from '@redocly/theme/core/constants';
3
+ import { DEFAULT_MCP_OPTIONS, MCP_OPTIONS } from '@redocly/theme/core/constants';
4
+ import { isMCPOption } from '@redocly/theme/core/utils';
4
5
 
5
6
  export const connectMcp: MarkdocSchemaWrapper = {
6
7
  schema: {
@@ -19,6 +20,20 @@ export const connectMcp: MarkdocSchemaWrapper = {
19
20
  options: {
20
21
  type: Array,
21
22
  default: DEFAULT_MCP_OPTIONS,
23
+ validate(value) {
24
+ if (!Array.isArray(value)) return [];
25
+
26
+ const unknownOptions = value.filter((option) => !isMCPOption(option));
27
+ if (unknownOptions.length === 0) return [];
28
+
29
+ return [
30
+ {
31
+ id: 'invalid-connect-mcp-options',
32
+ level: 'error',
33
+ message: `Invalid connect-mcp options: ${unknownOptions.join(', ')}. Must be one of: ${MCP_OPTIONS.join(', ')}`,
34
+ },
35
+ ];
36
+ },
22
37
  },
23
38
  },
24
39
  selfClosing: true,