@@ -12,6 +12,7 @@ import { getApp } from '../../helpers/app'
1212import { processSQLWithCtesOrModels } from '../../helpers/catalogAsModels'
1313import { getAllTemplateTagsInQuery , replaceLLMFriendlyIdentifiersInSqlWithModels } from 'apps'
1414import type { MetabaseModel } from 'apps/types'
15+ import type { EmbedConfigs } from '../../state/settings/reducer'
1516import { Badge } from "@chakra-ui/react" ;
1617import { CodeBlock } from './CodeBlock' ;
1718import { BiChevronDown , BiChevronRight } from 'react-icons/bi' ;
@@ -166,10 +167,11 @@ function ImageComponent(props: any) {
166167 return < ZoomableImage src = { props . src } alt = { props . alt } />
167168}
168169
169- function generateMetabaseQuestionURL ( origin : string , sql : string , databaseId : number | null = null ) {
170- // Get all template tags in the query (we don't have access to snippets here, so pass undefined)
170+ function generateMetabaseQuestionURL ( sql : string , databaseId : number | null = null , embedConfigs : EmbedConfigs = { } ) {
171+ // Get Metabase origin from embed_configs if available, otherwise use iframe info
171172 const templateTags = getAllTemplateTagsInQuery ( sql ) ;
172173
174+ // Get all template tags in the query (we don't have access to snippets here, so pass undefined)
173175 const cardData = {
174176 "dataset_query" : {
175177 "database" : databaseId ,
@@ -186,7 +188,11 @@ function generateMetabaseQuestionURL(origin: string, sql: string, databaseId: nu
186188 } ;
187189
188190 const hash = btoa ( JSON . stringify ( cardData ) ) ;
189- return `${ origin } /question#${ hash } ` ;
191+ const origin = embedConfigs . embed_host ;
192+ if ( ! origin ) {
193+ return `${ getOrigin ( ) } /question#${ hash } ` ;
194+ }
195+ return `${ origin } /question?hash=${ hash } ` ;
190196}
191197
192198function extractLastSQLFromMessages ( messages : any [ ] , currentMessageIndex : number ) : string | null {
@@ -232,7 +238,8 @@ export function Markdown({content, messageIndex}: {content: string, messageIndex
232238 const settings = useSelector ( ( state : RootState ) => ( {
233239 selectedCatalog : state . settings . selectedCatalog ,
234240 availableCatalogs : state . settings . availableCatalogs ,
235- modelsMode : state . settings . modelsMode
241+ modelsMode : state . settings . modelsMode ,
242+ embed_configs : state . settings . embed_configs
236243 } ) ) ;
237244 const mxModels = useSelector ( ( state : RootState ) => state . cache . mxModels ) ;
238245
@@ -250,13 +257,10 @@ export function Markdown({content, messageIndex}: {content: string, messageIndex
250257 }
251258
252259 if ( lastSQL ) {
253- // Get Metabase origin from iframe info
254- const metabaseOrigin = getOrigin ( ) ;
255-
256260 // Get current database ID from app state
257261 const databaseId = toolContext ?. dbId || null ;
258262
259- const questionURL = generateMetabaseQuestionURL ( metabaseOrigin , lastSQL , databaseId ) ;
263+ const questionURL = generateMetabaseQuestionURL ( lastSQL , databaseId , settings . embed_configs ) ;
260264
261265 return renderString ( content , {
262266 'MX_LAST_SQL_URL' : `\n\n --- \n\n Continue your analysis [here](${ questionURL } )`
0 commit comments