Skip to content

Commit 9acde6e

Browse files
committed
clean up code
1 parent 19d429b commit 9acde6e

2 files changed

Lines changed: 15 additions & 43 deletions

File tree

packages/sdk/src/index.ts

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -345,38 +345,19 @@ export class MermaidChart {
345345
public async diagramChat(request: DiagramChatRequest): Promise<DiagramChatResponse> {
346346
const { message, documentID, code = '', documentChatThreadID } = request;
347347

348-
// Send only the current user message. The backend will prepend the stored
349-
// conversation history when autoFetchHistory is true (see AIChatRequestData).
350-
const messages = [
351-
{
352-
id: uuid(),
353-
role: 'user' as const,
354-
content: message,
355-
experimental_attachments: [] as [],
356-
},
357-
];
358-
359-
const requestBody = {
360-
messages,
361-
code,
362-
documentID,
363-
documentChatThreadID,
364-
// parentID null: the backend already handles finding the correct parent
365-
parentID: null,
366-
// Tell the backend to fetch DB history and prepend it before calling the AI.
367-
autoFetchHistory: true,
368-
};
369-
370348
try {
371-
const response = await this.axios.post<{
372-
text: string;
373-
documentChatThreadID?: string;
374-
documentID: string;
375-
}>(URLS.rest.openai.chat, requestBody);
349+
const { data } = await this.axios.post<DiagramChatResponse>(URLS.rest.openai.chat, {
350+
messages: [{ id: uuid(), role: 'user' as const, content: message, experimental_attachments: [] }],
351+
code,
352+
documentID,
353+
documentChatThreadID,
354+
parentID: null,
355+
autoFetchHistory: true,
356+
});
376357

377358
return {
378-
text: response.data.text,
379-
documentChatThreadID: response.data.documentChatThreadID ?? documentChatThreadID,
359+
text: data.text,
360+
documentChatThreadID: data.documentChatThreadID ?? documentChatThreadID,
380361
documentID,
381362
};
382363
} catch (error: unknown) {

packages/sdk/src/types.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,11 @@ export interface RepairDiagramRequest {
100100
* Request parameters for chatting with the Mermaid AI about a diagram.
101101
*/
102102
export interface DiagramChatRequest {
103-
/** The user's chat message / question */
103+
/** The user's chat message / question. */
104104
message: string;
105-
/**
106-
* MermaidChart document ID to associate the chat thread with.
107-
*/
105+
/** The MermaidChart document ID to associate the chat thread with. */
108106
documentID: string;
109-
/**
110-
* Optional Mermaid diagram code to use as context.
111-
* Pass the current diagram code when the user wants to modify or discuss a specific
112-
* diagram. Leave empty (or omit) for general Mermaid questions.
113-
* Defaults to an empty string.
114-
*/
107+
/** Mermaid diagram code for context. Defaults to an empty string. */
115108
code?: string;
116109
/**
117110
* Existing chat thread ID to continue a conversation.
@@ -126,11 +119,9 @@ export interface DiagramChatRequest {
126119
* Response from chatting with the Mermaid AI.
127120
*/
128121
export interface DiagramChatResponse {
129-
/** The full AI-generated response text (may contain Mermaid code blocks) */
122+
/** The AI response text, which may contain Mermaid code blocks. */
130123
text: string;
131-
/**
132-
* The document ID used for this conversation. Same as the one passed in the request.
133-
*/
124+
/** Same as the document ID passed in the request. */
134125
documentID: string;
135126
/**
136127
* The chat thread ID created or used for this conversation.

0 commit comments

Comments
 (0)