Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 90 additions & 21 deletions mcp/python-react-agent-simple-ui/README.md

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions mcp/python-react-agent-simple-ui/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mcp/python-react-agent-simple-ui/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"typecheck": "tsc -p tsconfig.json"
},
"dependencies": {
"@thoughtspot/visual-embed-sdk": "1.53.0",
"@thoughtspot/visual-embed-sdk": "1.54.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-markdown": "^10.1.0",
Expand Down
46 changes: 34 additions & 12 deletions mcp/python-react-agent-simple-ui/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ interface Answer {
query?: string | null;
iframe_url?: string | null;
frame_params?: FrameParams | null;
/** Position in the conversation; set on stored answers only. */
/**
* The ThoughtSpot analytical session that produced this answer. One chat can span
* several (a session belongs to the Org it was created in), so a stored answer is
* resolved from its own session, not the chat's latest one.
*/
analytical_session_id?: string | null;
/** Position in its session; set on stored answers only. */
answer_index?: number | null;
}

Expand All @@ -66,6 +72,8 @@ interface Message {
work?: WorkStep[];
/** Stored turns only: ThoughtSpot's id for each Show work query, in order. */
workAnswerIds?: string[];
/** Stored turns only: the session those Show work queries belong to. */
sessionId?: string | null;
isError?: boolean;
}

Expand All @@ -83,6 +91,7 @@ interface ConversationDetail {
answers?: Answer[];
work?: WorkStep[];
work_answer_ids?: string[];
analytical_session_id?: string | null;
}[];
}

Expand Down Expand Up @@ -311,6 +320,8 @@ const stepIcon = (text: string): keyof typeof ICON_PATHS => {
/** Where a stored turn's thinking answers are loaded from. */
interface WorkSource {
conversationId: string | null;
/** The ThoughtSpot session the stored turn came from. */
sessionId: string | null;
answerIds: string[];
}

Expand All @@ -321,12 +332,17 @@ interface WorkSource {
*/
const workAnswerLoads = new Map<string, Promise<FrameParams>>();

const loadWorkAnswer = (conversationId: string, answerId: string) => {
const key = `${conversationId}/${answerId}`;
const loadWorkAnswer = (
conversationId: string,
answerId: string,
sessionId: string | null,
) => {
const key = `${conversationId}/${sessionId ?? ""}/${answerId}`;
let load = workAnswerLoads.get(key);
if (!load) {
const query = sessionId ? `?session_id=${encodeURIComponent(sessionId)}` : "";
load = fetch(
`${HISTORY_URL}/${conversationId}/work-answers/${encodeURIComponent(answerId)}`,
`${HISTORY_URL}/${conversationId}/work-answers/${encodeURIComponent(answerId)}${query}`,
).then(async (response) => {
if (!response.ok) throw new Error(String(response.status));
return ((await response.json()) as { frame_params: FrameParams }).frame_params;
Expand Down Expand Up @@ -357,6 +373,7 @@ function WorkQueryChart({
const liveSrc = answerSrc(step, null);
const answerId = source.answerIds[index];
const conversationId = source.conversationId;
const sessionId = source.sessionId;
const [resolved, setResolved] = useState<FrameParams | null>(null);
const [failed, setFailed] = useState(false);
// Bumped by Retry to run the load again; the failed load is already evicted.
Expand All @@ -366,15 +383,15 @@ function WorkQueryChart({
if (liveSrc || !conversationId || !answerId) return;
let cancelled = false;
setFailed(false);
loadWorkAnswer(conversationId, answerId)
loadWorkAnswer(conversationId, answerId, sessionId)
.then((frame_params) => {
if (!cancelled) setResolved(frame_params);
})
.catch(() => !cancelled && setFailed(true));
return () => {
cancelled = true;
};
}, [liveSrc, conversationId, answerId, step, attempt]);
}, [liveSrc, conversationId, sessionId, answerId, step, attempt]);

const html = liveSrc
? answerHtml(step, null, theme)
Expand Down Expand Up @@ -501,9 +518,11 @@ const escapeAttr = (value: unknown) =>
*
* A live answer carries the `iframe_url` the MCP server just produced. A stored
* one does not: those URLs embed a session that expires in about 8 hours, so the
* server never persists them. Instead we point the renderer at the conversation
* and the answer's position in it, and it resolves a current URL - re-running the
* chart against today's data, which is why it also gets the stale-data notice.
* server never persists them. Instead we point the renderer at the answer's
* session and its position in that session, and it resolves a current URL -
* re-running the chart against today's data, which is why it also gets the
* stale-data notice. The answer's own session wins over the chat's: after an Org
* switch, one chat holds answers from more than one session.
*/
const answerSrc = (
answer: Answer,
Expand All @@ -527,9 +546,10 @@ const answerSrc = (
return `${url.toString()}#/embed/conv-assist-answer?${hash.toString()}`;
}

// A stored answer has neither - the SDK resolves it from the conversation.
if (!conversationSessionId || answer.answer_index == null) return null;
url.searchParams.set("tsmcpConversationId", conversationSessionId);
// A stored answer has neither - the SDK resolves it from its session.
const sessionId = answer.analytical_session_id || conversationSessionId;
if (!sessionId || answer.answer_index == null) return null;
url.searchParams.set("tsmcpConversationId", sessionId);
url.searchParams.set("tsmcpAnswerIndex", String(answer.answer_index));
return url.toString();
};
Expand Down Expand Up @@ -682,6 +702,7 @@ function App() {
answers: turn.answers || [],
work: turn.work || [],
workAnswerIds: turn.work_answer_ids || [],
sessionId: turn.analytical_session_id || null,
})),
);
setResponseId(data.id);
Expand Down Expand Up @@ -990,6 +1011,7 @@ function App() {
finished={!(isLoading && i === messages.length - 1)}
source={{
conversationId: responseId,
sessionId: msg.sessionId || null,
answerIds: msg.workAnswerIds || [],
}}
/>
Expand Down
Loading
Loading