graphlit-client 1.0.20250701002 → 1.0.20250702001

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.d.ts CHANGED
@@ -461,10 +461,6 @@ declare class Graphlit {
461
461
  * Execute tools during streaming with proper event emission
462
462
  */
463
463
  private executeToolsInStream;
464
- /**
465
- * Format tool results for API
466
- */
467
- private formatToolResults;
468
464
  /**
469
465
  * Fallback to non-streaming when streaming is not available
470
466
  */
package/dist/client.js CHANGED
@@ -2737,36 +2737,6 @@ class Graphlit {
2737
2737
  });
2738
2738
  await Promise.all(toolPromises);
2739
2739
  }
2740
- /**
2741
- * Format tool results for API
2742
- */
2743
- async formatToolResults(toolCalls, toolHandlers) {
2744
- const results = [];
2745
- for (const toolCall of toolCalls) {
2746
- const handler = toolHandlers[toolCall.name];
2747
- if (handler) {
2748
- try {
2749
- const args = toolCall.arguments ? JSON.parse(toolCall.arguments) : {};
2750
- const result = await handler(args);
2751
- results.push({
2752
- id: toolCall.id,
2753
- content: JSON.stringify(result),
2754
- });
2755
- }
2756
- catch (error) {
2757
- results.push({
2758
- id: toolCall.id,
2759
- content: JSON.stringify({
2760
- error: error instanceof Error
2761
- ? error.message
2762
- : "Tool execution failed",
2763
- }),
2764
- });
2765
- }
2766
- }
2767
- }
2768
- return results;
2769
- }
2770
2740
  /**
2771
2741
  * Fallback to non-streaming when streaming is not available
2772
2742
  */
@@ -110,7 +110,7 @@ export function formatMessagesForAnthropic(messages) {
110
110
  case ConversationRoleTypes.Assistant:
111
111
  const content = []; // Use any[] to allow thinking blocks
112
112
  // Handle thinking blocks for extended thinking preservation
113
- if (trimmedMessage && trimmedMessage.includes('<thinking')) {
113
+ if (trimmedMessage && trimmedMessage.includes("<thinking")) {
114
114
  // Extract thinking content and signature if present
115
115
  const thinkingMatch = trimmedMessage.match(/<thinking(?:\s+signature="([^"]*)")?>([\s\S]*?)<\/thinking>/);
116
116
  if (thinkingMatch) {
@@ -133,7 +133,9 @@ export function formatMessagesForAnthropic(messages) {
133
133
  content.push(thinkingBlock);
134
134
  }
135
135
  // Remove thinking tags from the main text and add remaining content
136
- const textWithoutThinking = trimmedMessage.replace(/<thinking(?:\s+[^>]*)?>[\s\S]*?<\/thinking>/g, '').trim();
136
+ const textWithoutThinking = trimmedMessage
137
+ .replace(/<thinking(?:\s+[^>]*)?>[\s\S]*?<\/thinking>/g, "")
138
+ .trim();
137
139
  if (textWithoutThinking) {
138
140
  content.push({
139
141
  type: "text",
@@ -2162,6 +2162,8 @@ onEvent, onComplete, abortSignal) {
2162
2162
  let currentContent = "";
2163
2163
  const THINKING_START = "<thinking>";
2164
2164
  const THINKING_END = "</thinking>";
2165
+ // Bedrock delta tracking - Some Bedrock models send accumulated text instead of deltas
2166
+ let accumulatedText = "";
2165
2167
  try {
2166
2168
  if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
2167
2169
  console.log(`🔍 [Bedrock] Specification object:`, JSON.stringify(specification, null, 2));
@@ -2242,7 +2244,22 @@ onEvent, onComplete, abortSignal) {
2242
2244
  const delta = event.contentBlockDelta.delta;
2243
2245
  const contentIndex = event.contentBlockDelta.contentBlockIndex;
2244
2246
  if (delta?.text) {
2245
- const text = delta.text;
2247
+ let text = delta.text;
2248
+ // Bedrock models (especially Nova) may send accumulated text instead of deltas
2249
+ // Check if this delta contains all previously accumulated text
2250
+ if (accumulatedText.length > 0 &&
2251
+ delta.text.startsWith(accumulatedText)) {
2252
+ // This is accumulated text - extract only the new part
2253
+ text = delta.text.substring(accumulatedText.length);
2254
+ if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
2255
+ console.log(`🔍 [Bedrock] Extracted delta from accumulated text: "${text}" (total: ${delta.text.length}, prev: ${accumulatedText.length})`);
2256
+ }
2257
+ }
2258
+ else if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
2259
+ console.log(`🔍 [Bedrock] Using text as delta: "${text}"`);
2260
+ }
2261
+ // Update accumulated text
2262
+ accumulatedText = accumulatedText + text;
2246
2263
  tokenCount++;
2247
2264
  if (firstTokenTime === 0) {
2248
2265
  firstTokenTime = Date.now() - startTime;
@@ -2331,6 +2348,11 @@ onEvent, onComplete, abortSignal) {
2331
2348
  }
2332
2349
  }
2333
2350
  else if (event.contentBlockStart) {
2351
+ // Reset Bedrock tracking for new content blocks
2352
+ accumulatedText = "";
2353
+ if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
2354
+ console.log(`🔍 [Bedrock] Reset accumulated text tracking for new content block`);
2355
+ }
2334
2356
  // Handle tool use start
2335
2357
  const start = event.contentBlockStart.start;
2336
2358
  const startIndex = event.contentBlockStart.contentBlockIndex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphlit-client",
3
- "version": "1.0.20250701002",
3
+ "version": "1.0.20250702001",
4
4
  "description": "Graphlit API Client for TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/client.js",