Skip to content

Commit 571c775

Browse files
committed
Use embed host for tracing cards as well
1 parent 070d531 commit 571c775

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

web/src/components/common/ActionStack.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const ActionStack: React.FC<{status: string, actions: Array<ActionStatusV
5858
const origin = url ? new URL(url).origin : '';
5959
const thread = useSelector((state: RootState) => state.chat.activeThread)
6060
const totalThreads = useSelector((state: RootState) => state.chat.threads.length)
61+
const embedConfigs = useSelector((state: RootState) => state.configs.embed);
6162

6263
const lastThread = (thread === totalThreads - 1)
6364

@@ -83,7 +84,7 @@ export const ActionStack: React.FC<{status: string, actions: Array<ActionStatusV
8384
}
8485
const preExpanderTextArr = actions.map(action => {
8586
const { text } = action.renderInfo || {}
86-
return processModelToUIText(text || '', origin)
87+
return processModelToUIText(text || '', origin, embedConfigs)
8788
}).filter(text => text !== '')
8889

8990
// const preExpanderText = preExpanderTextArr.length > 1

web/src/components/common/ChatContent.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import React from 'react';
2+
import { useSelector } from 'react-redux';
23
import { ChatMessageContent } from '../../state/chat/reducer'
34
import { Markdown } from './Markdown';
45
import { processModelToUIText } from '../../helpers/utils';
56
import { getApp } from '../../helpers/app';
7+
import { RootState } from '../../state/store';
8+
import { getOrigin, getParsedIframeInfo } from '../../helpers/origin';
69

710

811
const useAppStore = getApp().useStore()
@@ -12,16 +15,19 @@ export const ChatContent: React.FC<{content: ChatMessageContent, messageIndex?:
1215
messageIndex,
1316
role
1417
}) => {
15-
const url = useAppStore((state) => state.toolContext)?.url || ''
18+
// const url = useAppStore((state) => state.toolContext)?.url || ''
19+
const origin = getOrigin()
1620
const pageType = useAppStore((state) => state.toolContext)?.pageType || ''
21+
const embedConfigs = useSelector((state: RootState) => state.configs.embed);
22+
1723
if (content.type == 'DEFAULT') {
1824
const contentText = ((pageType === 'dashboard' || pageType === 'unknown') && role === 'assistant') ? `${content.text} {{MX_LAST_SQL_URL}}` : content.text;
1925
return (
2026
<div>
2127
{content.images.map(image => (
2228
<img src={image.url} key={image.url} />
2329
))}
24-
<Markdown content={processModelToUIText(contentText, url)} messageIndex={messageIndex} />
30+
<Markdown content={processModelToUIText(contentText, origin, embedConfigs)} messageIndex={messageIndex} />
2531
</div>
2632
)
2733
} else {

web/src/helpers/utils.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { isEqual, some } from "lodash";
22
import { getApp } from "./app";
3+
import { EmbedConfigs } from "../state/configs/reducer";
4+
import { getParsedIframeInfo } from "./origin";
35

46
export async function sleep(ms: number = 0) {
57
return new Promise((resolve) => setTimeout(resolve, ms));
@@ -84,7 +86,7 @@ export const getActionTaskLiteLabels = (action: string) => {
8486
}
8587

8688

87-
export const processModelToUIText = (text: string, origin: string): string => {
89+
export const processModelToUIText = (text: string, origin: string, embedConfigs: EmbedConfigs = {}): string => {
8890
if (text === ''){
8991
return ''
9092
}
@@ -96,9 +98,21 @@ export const processModelToUIText = (text: string, origin: string): string => {
9698
}
9799
if (text.includes("card_id:") && (origin != '')) {
98100
//Replace [card_id:<id>] with link
99-
// Replace [card_id:<id>] with markdown link
101+
// Replace [card_id:<id>] with markdown link using embed URL logic
100102
text = text.replace(/\[card_id:(\d+)\]/g, (match, id) => {
101-
return `[Card ID: ${id}](${origin}/question/${id})`;
103+
const isEmbedded = getParsedIframeInfo().isEmbedded as unknown === 'true';
104+
const embedHost = embedConfigs.embed_host;
105+
106+
let questionUrl;
107+
if (embedHost && isEmbedded) {
108+
// Use embed host for embedded mode
109+
questionUrl = `${embedHost}/question/${id}`;
110+
} else {
111+
// Use regular origin
112+
questionUrl = `${origin}/question/${id}`;
113+
}
114+
115+
return `[Card ID: ${id}](${questionUrl})`;
102116
});
103117
}
104118
return text

0 commit comments

Comments
 (0)