graphlit-client 1.0.20250612006 → 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 CHANGED
@@ -1417,11 +1417,15 @@ class Graphlit {
1417
1417
  if (specification) {
1418
1418
  const serviceType = specification.serviceType;
1419
1419
  if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
1420
- console.log("[supportsStreaming] Checking support for:", {
1420
+ console.log("[supportsStreaming] Checking support for specification:", {
1421
+ specificationName: specification.name,
1421
1422
  serviceType,
1422
- hasOpenAI: OpenAI !== undefined || this.openaiClient !== undefined,
1423
- hasAnthropic: Anthropic !== undefined || this.anthropicClient !== undefined,
1424
- hasGoogle: GoogleGenerativeAI !== undefined || this.googleClient !== undefined,
1423
+ moduleOpenAI: OpenAI !== undefined,
1424
+ instanceOpenAI: this.openaiClient !== undefined,
1425
+ moduleAnthropic: Anthropic !== undefined,
1426
+ instanceAnthropic: this.anthropicClient !== undefined,
1427
+ moduleGoogle: GoogleGenerativeAI !== undefined,
1428
+ instanceGoogle: this.googleClient !== undefined,
1425
1429
  });
1426
1430
  }
1427
1431
  switch (serviceType) {
@@ -1674,11 +1678,20 @@ class Graphlit {
1674
1678
  // Format conversation once at the beginning
1675
1679
  const formatResponse = await this.formatConversation(prompt, conversationId, { id: specification.id }, tools, true, correlationId);
1676
1680
  const formattedMessage = formatResponse.formatConversation?.message;
1681
+ const conversationHistory = formatResponse.formatConversation?.details?.messages;
1677
1682
  if (!formattedMessage?.message) {
1678
1683
  throw new Error("Failed to format conversation");
1679
1684
  }
1680
1685
  if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
1681
- console.log("\nšŸ“‹ [formatConversation] Response", formattedMessage.message);
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
+ }
1682
1695
  }
1683
1696
  // Build message array with conversation history
1684
1697
  const messages = [];
@@ -1691,9 +1704,41 @@ class Graphlit {
1691
1704
  timestamp: new Date().toISOString(),
1692
1705
  });
1693
1706
  }
1694
- // Use the formatted message from formatConversation which already includes
1695
- // all context, RAG results, and conversation history
1696
- if (formattedMessage) {
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
+ }
1697
1742
  const messageToAdd = {
1698
1743
  __typename: "ConversationMessage",
1699
1744
  role: formattedMessage.role || Types.ConversationRoleTypes.User,
@@ -1710,9 +1755,6 @@ class Graphlit {
1710
1755
  }
1711
1756
  messages.push(messageToAdd);
1712
1757
  }
1713
- else {
1714
- throw new Error("No formatted message returned from formatConversation");
1715
- }
1716
1758
  const serviceType = getServiceType(specification);
1717
1759
  // Handle tool calling loop locally
1718
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
- // DO NOT re-process chunks here - they should already be in currentMessage
159
- // Just clear any remaining state
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(); // Clear the buffer but don't use the result
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 = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphlit-client",
3
- "version": "1.0.20250612006",
3
+ "version": "1.0.20250612008",
4
4
  "description": "Graphlit API Client for TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/client.js",