Skip to content

Commit b5730e0

Browse files
committed
support dashboard tag parsing and rendering
1 parent 64e8c55 commit b5730e0

File tree

4 files changed

+259
-97
lines changed

4 files changed

+259
-97
lines changed

x-pack/platform/packages/shared/onechat/onechat-common/tools/tool_result.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ export const isErrorResult = (result: ToolResult): result is ErrorResult => {
115115
return result.type === ToolResultType.error;
116116
};
117117

118+
export const isDashboardResult = (result: ToolResult): result is DashboardResult => {
119+
return result.type === ToolResultType.dashboard;
120+
};
121+
118122
export interface VisualizationElementAttributes {
119123
toolResultId?: string;
120124
chartType?: ChartType;
@@ -127,3 +131,14 @@ export const visualizationElement = {
127131
chartType: 'chart-type',
128132
},
129133
};
134+
135+
export interface DashboardElementAttributes {
136+
toolResultId?: string;
137+
}
138+
139+
export const dashboardElement = {
140+
tagName: 'dashboard',
141+
attributes: {
142+
toolResultId: 'tool-result-id',
143+
},
144+
};

x-pack/platform/plugins/shared/dashboard_agent/server/register_agent.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import { ToolResultType, platformCoreTools } from '@kbn/onechat-common';
9+
import { dashboardElement } from '@kbn/onechat-common/tools/tool_result';
910
import type { OnechatPluginSetup } from '@kbn/onechat-plugin/server';
1011
import { dashboardTools } from '../common';
1112

@@ -108,17 +109,22 @@ General Guidelines:
108109

109110
function renderDashboardResultPrompt() {
110111
const { dashboard } = ToolResultType;
112+
const { tagName, attributes } = dashboardElement;
111113

112-
return `#### Handling Dashboard Results
113-
When a tool call returns a result of type "${dashboard}", you should inform the user that a dashboard has been created and provide relevant information about it.
114+
return `#### Rendering Dashboards
115+
When a tool call returns a result of type "${dashboard}", you should render the dashboard in the UI by emitting a custom XML element:
116+
117+
<${tagName} ${attributes.toolResultId}="TOOL_RESULT_ID_HERE" />
114118
115119
**Rules**
116-
* When you receive a tool result with \`"type": "${dashboard}"\`, extract the \`id\`, \`title\`, and other relevant data from the result.
117-
* Provide a clickable link if a URL is available in \`content.url\`.
120+
* The \`<${tagName}>\` element must only be used to render tool results of type \`${dashboard}\`.
121+
* You must copy the \`tool_result_id\` from the tool's response into the \`${attributes.toolResultId}\` element attribute verbatim.
122+
* Do not invent, alter, or guess \`tool_result_id\`. You must use the exact id provided in the tool response.
123+
* You must not include any other attributes or content within the \`<${tagName}>\` element.
118124
119-
**Example for Dashboard:**
125+
**Example Usage:**
120126
121-
Tool response:
127+
Tool response includes:
122128
{
123129
"tool_result_id": "abc123",
124130
"type": "${dashboard}",
@@ -133,6 +139,10 @@ function renderDashboardResultPrompt() {
133139
}
134140
}
135141
136-
Your response to the user should include:
137-
Dashboard "My Dashboard" created successfully. You can view it at: [/app/dashboards#/view/dashboard-123](/app/dashboards#/view/dashboard-123)`;
142+
To render this dashboard your reply should include:
143+
<${tagName} ${attributes.toolResultId}="abc123" />
144+
145+
You may also add a brief message about the dashboard creation, for example:
146+
"I've created a dashboard for you:"
147+
<${tagName} ${attributes.toolResultId}="abc123" />`;
138148
}

x-pack/platform/plugins/shared/onechat/public/application/components/conversations/conversation_rounds/round_response/chat_message_text.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ import {
2222
} from '@elastic/eui';
2323
import { type PluggableList } from 'unified';
2424
import type { ConversationRoundStep } from '@kbn/onechat-common';
25-
import { visualizationElement } from '@kbn/onechat-common/tools/tool_result';
25+
import { visualizationElement, dashboardElement } from '@kbn/onechat-common/tools/tool_result';
2626
import { useOnechatServices } from '../../../../hooks/use_onechat_service';
2727
import {
2828
Cursor,
2929
esqlLanguagePlugin,
3030
createVisualizationRenderer,
31+
createDashboardRenderer,
3132
loadingCursorPlugin,
3233
visualizationTagParser,
34+
dashboardTagParser,
3335
} from './markdown_plugins';
3436
import { useStepsFromPrevRounds } from '../../../../hooks/use_conversation';
3537

@@ -125,13 +127,18 @@ export function ChatMessageText({ content, steps: stepsFromCurrentRound }: Props
125127
stepsFromCurrentRound,
126128
stepsFromPrevRounds,
127129
}),
130+
[dashboardElement.tagName]: createDashboardRenderer({
131+
stepsFromCurrentRound,
132+
stepsFromPrevRounds,
133+
}),
128134
};
129135

130136
return {
131137
parsingPluginList: [
132138
loadingCursorPlugin,
133139
esqlLanguagePlugin,
134140
visualizationTagParser,
141+
dashboardTagParser,
135142
...parsingPlugins,
136143
],
137144
processingPluginList: processingPlugins,

0 commit comments

Comments
 (0)