graphlit-client 1.0.20250612007 ā 1.0.20250612008
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.js +45 -7
- package/dist/streaming/ui-event-adapter.js +20 -4
- package/package.json +1 -1
package/dist/client.js
CHANGED
@@ -1678,11 +1678,20 @@ class Graphlit {
|
|
1678
1678
|
// Format conversation once at the beginning
|
1679
1679
|
const formatResponse = await this.formatConversation(prompt, conversationId, { id: specification.id }, tools, true, correlationId);
|
1680
1680
|
const formattedMessage = formatResponse.formatConversation?.message;
|
1681
|
+
const conversationHistory = formatResponse.formatConversation?.details?.messages;
|
1681
1682
|
if (!formattedMessage?.message) {
|
1682
1683
|
throw new Error("Failed to format conversation");
|
1683
1684
|
}
|
1684
1685
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
1685
|
-
console.log("\nš [formatConversation]
|
1686
|
+
console.log("\nš [formatConversation] Full response:", JSON.stringify(formatResponse, null, 2));
|
1687
|
+
console.log("\nš [formatConversation] Response - current message:", formattedMessage.message);
|
1688
|
+
console.log(`š [formatConversation] Conversation history: ${conversationHistory?.length || 0} messages`);
|
1689
|
+
if (conversationHistory && conversationHistory.length > 0) {
|
1690
|
+
console.log("š [formatConversation] History messages:");
|
1691
|
+
conversationHistory.forEach((msg, i) => {
|
1692
|
+
console.log(` ${i + 1}. [${msg?.role}] ${msg?.message?.substring(0, 100)}...`);
|
1693
|
+
});
|
1694
|
+
}
|
1686
1695
|
}
|
1687
1696
|
// Build message array with conversation history
|
1688
1697
|
const messages = [];
|
@@ -1695,9 +1704,41 @@ class Graphlit {
|
|
1695
1704
|
timestamp: new Date().toISOString(),
|
1696
1705
|
});
|
1697
1706
|
}
|
1698
|
-
// Use the
|
1699
|
-
|
1700
|
-
|
1707
|
+
// Use the full conversation history from formatConversation if available
|
1708
|
+
if (conversationHistory && conversationHistory.length > 0) {
|
1709
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
1710
|
+
console.log(`š [formatConversation] Using full conversation history with ${conversationHistory.length} messages`);
|
1711
|
+
}
|
1712
|
+
for (const historyMessage of conversationHistory) {
|
1713
|
+
if (historyMessage) {
|
1714
|
+
const messageToAdd = {
|
1715
|
+
__typename: "ConversationMessage",
|
1716
|
+
role: historyMessage.role || Types.ConversationRoleTypes.User,
|
1717
|
+
message: historyMessage.message || "",
|
1718
|
+
timestamp: historyMessage.timestamp || new Date().toISOString(),
|
1719
|
+
};
|
1720
|
+
// Add optional fields if present
|
1721
|
+
if (historyMessage.author)
|
1722
|
+
messageToAdd.author = historyMessage.author;
|
1723
|
+
if (historyMessage.data)
|
1724
|
+
messageToAdd.data = historyMessage.data;
|
1725
|
+
if (historyMessage.mimeType)
|
1726
|
+
messageToAdd.mimeType = historyMessage.mimeType;
|
1727
|
+
if (historyMessage.toolCalls)
|
1728
|
+
messageToAdd.toolCalls = historyMessage.toolCalls;
|
1729
|
+
if (historyMessage.toolCallId)
|
1730
|
+
messageToAdd.toolCallId = historyMessage.toolCallId;
|
1731
|
+
if (historyMessage.toolCallResponse)
|
1732
|
+
messageToAdd.toolCallResponse = historyMessage.toolCallResponse;
|
1733
|
+
messages.push(messageToAdd);
|
1734
|
+
}
|
1735
|
+
}
|
1736
|
+
}
|
1737
|
+
else {
|
1738
|
+
// Fallback to single formatted message (for backward compatibility)
|
1739
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
1740
|
+
console.log("ā ļø [formatConversation] No conversation history available, using single formatted message");
|
1741
|
+
}
|
1701
1742
|
const messageToAdd = {
|
1702
1743
|
__typename: "ConversationMessage",
|
1703
1744
|
role: formattedMessage.role || Types.ConversationRoleTypes.User,
|
@@ -1714,9 +1755,6 @@ class Graphlit {
|
|
1714
1755
|
}
|
1715
1756
|
messages.push(messageToAdd);
|
1716
1757
|
}
|
1717
|
-
else {
|
1718
|
-
throw new Error("No formatted message returned from formatConversation");
|
1719
|
-
}
|
1720
1758
|
const serviceType = getServiceType(specification);
|
1721
1759
|
// Handle tool calling loop locally
|
1722
1760
|
while (currentRound < maxRounds) {
|
@@ -155,12 +155,28 @@ export class UIEventAdapter {
|
|
155
155
|
globalThis.clearTimeout(this.updateTimer);
|
156
156
|
this.updateTimer = undefined;
|
157
157
|
}
|
158
|
-
//
|
159
|
-
|
158
|
+
// Process any remaining chunks before completing
|
159
|
+
if (this.chunkQueue.length > 0) {
|
160
|
+
// Add all remaining chunks to current message
|
161
|
+
const remainingChunks = this.chunkQueue.join('');
|
162
|
+
const chunkCount = this.chunkQueue.length;
|
163
|
+
this.currentMessage += remainingChunks;
|
164
|
+
this.chunkQueue.length = 0; // Clear the queue after processing
|
165
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
166
|
+
console.log(`š [UIEventAdapter] Processed ${chunkCount} remaining chunks: "${remainingChunks}"`);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
// Flush any remaining content from the buffer
|
160
170
|
if (this.chunkBuffer) {
|
161
|
-
this.chunkBuffer.flush();
|
171
|
+
const finalChunks = this.chunkBuffer.flush();
|
172
|
+
if (finalChunks.length > 0) {
|
173
|
+
const finalContent = finalChunks.join('');
|
174
|
+
this.currentMessage += finalContent;
|
175
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
176
|
+
console.log(`š [UIEventAdapter] Flushed buffer with ${finalChunks.length} chunks: "${finalContent}"`);
|
177
|
+
}
|
178
|
+
}
|
162
179
|
}
|
163
|
-
this.chunkQueue.length = 0; // Clear any remaining queue
|
164
180
|
this.isStreaming = false;
|
165
181
|
// Create final message
|
166
182
|
const finalMessage = {
|