graphlit-client 1.0.20250713002 → 1.0.20250716001
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
@@ -2454,6 +2454,8 @@ class Graphlit {
|
|
2454
2454
|
// ALWAYS log when there's a tool-related issue for debugging
|
2455
2455
|
const hasToolCalls = mistralMessages.some((m) => m.tool_calls?.length > 0);
|
2456
2456
|
const hasToolResponses = mistralMessages.some((m) => m.role === "tool");
|
2457
|
+
// Count tool responses to determine if we should pass tools
|
2458
|
+
const toolResponseCount = mistralMessages.filter((m) => m.role === "tool").length;
|
2457
2459
|
if (hasToolCalls ||
|
2458
2460
|
hasToolResponses ||
|
2459
2461
|
process.env.DEBUG_GRAPHLIT_SDK_STREAMING_MESSAGES) {
|
@@ -2461,13 +2463,17 @@ class Graphlit {
|
|
2461
2463
|
console.log(JSON.stringify(mistralMessages, null, 2));
|
2462
2464
|
// Count tool calls and responses
|
2463
2465
|
const toolCallCount = mistralMessages.reduce((count, m) => count + (m.tool_calls?.length || 0), 0);
|
2464
|
-
const toolResponseCount = mistralMessages.filter((m) => m.role === "tool").length;
|
2465
2466
|
console.log(`🔍 [Mistral] Tool calls: ${toolCallCount}, Tool responses: ${toolResponseCount}`);
|
2466
2467
|
if (toolResponseCount > 0) {
|
2467
2468
|
console.log(`🔍 [Mistral] IMPORTANT: We have tool responses, should we still pass tools?`);
|
2468
2469
|
}
|
2469
2470
|
}
|
2470
|
-
|
2471
|
+
// Mistral API requires that we don't pass tools when sending tool results
|
2472
|
+
const shouldPassTools = toolResponseCount === 0 ? tools : undefined;
|
2473
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2474
|
+
console.log(`🔍 [Mistral] Passing tools: ${shouldPassTools ? 'YES' : 'NO'} (tool responses in messages: ${toolResponseCount})`);
|
2475
|
+
}
|
2476
|
+
await this.streamWithMistral(specification, mistralMessages, shouldPassTools, uiAdapter, (message, calls, usage) => {
|
2471
2477
|
roundMessage = message;
|
2472
2478
|
toolCalls = calls;
|
2473
2479
|
if (usage) {
|
@@ -2860,6 +2866,8 @@ class Graphlit {
|
|
2860
2866
|
(OpenAI
|
2861
2867
|
? new OpenAI({
|
2862
2868
|
apiKey: process.env.OPENAI_API_KEY || "",
|
2869
|
+
maxRetries: 3,
|
2870
|
+
timeout: 60000, // 60 seconds
|
2863
2871
|
})
|
2864
2872
|
: (() => {
|
2865
2873
|
throw new Error("OpenAI module not available");
|
@@ -2882,6 +2890,8 @@ class Graphlit {
|
|
2882
2890
|
(Anthropic
|
2883
2891
|
? new Anthropic({
|
2884
2892
|
apiKey: process.env.ANTHROPIC_API_KEY || "",
|
2893
|
+
maxRetries: 3,
|
2894
|
+
timeout: 60000, // 60 seconds
|
2885
2895
|
})
|
2886
2896
|
: (() => {
|
2887
2897
|
throw new Error("Anthropic module not available");
|
@@ -2976,6 +2986,8 @@ class Graphlit {
|
|
2976
2986
|
? new OpenAI({
|
2977
2987
|
apiKey: process.env.CEREBRAS_API_KEY || "",
|
2978
2988
|
baseURL: "https://api.cerebras.ai/v1",
|
2989
|
+
maxRetries: 3,
|
2990
|
+
timeout: 60000, // 60 seconds
|
2979
2991
|
})
|
2980
2992
|
: (() => {
|
2981
2993
|
throw new Error("OpenAI module not available for Cerebras");
|
@@ -3023,7 +3035,19 @@ class Graphlit {
|
|
3023
3035
|
if (!apiKey) {
|
3024
3036
|
throw new Error("MISTRAL_API_KEY environment variable is required for Mistral streaming");
|
3025
3037
|
}
|
3026
|
-
return new Mistral({
|
3038
|
+
return new Mistral({
|
3039
|
+
apiKey,
|
3040
|
+
retryConfig: {
|
3041
|
+
strategy: "backoff",
|
3042
|
+
backoff: {
|
3043
|
+
initialInterval: 1000,
|
3044
|
+
maxInterval: 60000,
|
3045
|
+
exponent: 2,
|
3046
|
+
maxElapsedTime: 300000, // 5 minutes
|
3047
|
+
},
|
3048
|
+
retryConnectionErrors: true,
|
3049
|
+
},
|
3050
|
+
});
|
3027
3051
|
})()
|
3028
3052
|
: (() => {
|
3029
3053
|
throw new Error("Mistral module not available");
|
@@ -3069,6 +3093,8 @@ class Graphlit {
|
|
3069
3093
|
? new OpenAI({
|
3070
3094
|
baseURL: "https://api.deepseek.com",
|
3071
3095
|
apiKey: process.env.DEEPSEEK_API_KEY || "",
|
3096
|
+
maxRetries: 3,
|
3097
|
+
timeout: 60000, // 60 seconds
|
3072
3098
|
})
|
3073
3099
|
: null);
|
3074
3100
|
if (!deepseekClient) {
|
@@ -3090,6 +3116,8 @@ class Graphlit {
|
|
3090
3116
|
? new OpenAI({
|
3091
3117
|
baseURL: "https://api.x.ai/v1",
|
3092
3118
|
apiKey: process.env.XAI_API_KEY || "",
|
3119
|
+
maxRetries: 3,
|
3120
|
+
timeout: 60000, // 60 seconds
|
3093
3121
|
})
|
3094
3122
|
: null);
|
3095
3123
|
if (!xaiClient) {
|
@@ -1505,7 +1505,11 @@ export declare enum CerebrasModels {
|
|
1505
1505
|
/** LLaMA 3.1 8b */
|
1506
1506
|
Llama_3_1_8B = "LLAMA_3_1_8B",
|
1507
1507
|
/** LLaMA 3.3 70b */
|
1508
|
-
Llama_3_3_70B = "LLAMA_3_3_70B"
|
1508
|
+
Llama_3_3_70B = "LLAMA_3_3_70B",
|
1509
|
+
/** LLaMA 4 Scout 17b */
|
1510
|
+
Llama_4Scout_17B = "LLAMA_4_SCOUT_17B",
|
1511
|
+
/** Qwen 3 32b */
|
1512
|
+
Qwen_3_32B = "QWEN_3_32B"
|
1509
1513
|
}
|
1510
1514
|
/** Represents a classification workflow job. */
|
1511
1515
|
export type ClassificationWorkflowJob = {
|
@@ -4471,10 +4475,7 @@ export declare enum FeedTypes {
|
|
4471
4475
|
Twitter = "TWITTER",
|
4472
4476
|
/** Web feed */
|
4473
4477
|
Web = "WEB",
|
4474
|
-
/**
|
4475
|
-
* YouTube audio feed
|
4476
|
-
* @deprecated No longer supported. We suggest using your own YouTube downloader and then ingest the video or audio files.
|
4477
|
-
*/
|
4478
|
+
/** YouTube audio feed */
|
4478
4479
|
YouTube = "YOU_TUBE",
|
4479
4480
|
/** Zendesk articles feed */
|
4480
4481
|
Zendesk = "ZENDESK"
|
@@ -5290,6 +5291,8 @@ export declare enum GroqModels {
|
|
5290
5291
|
Custom = "CUSTOM",
|
5291
5292
|
/** Deepseek R1 Distill Llama 70b Preview */
|
5292
5293
|
DeepseekR1Llama_70BPreview = "DEEPSEEK_R1_LLAMA_70B_PREVIEW",
|
5294
|
+
/** Kimi K2 32b */
|
5295
|
+
KimiK2_32B = "KIMI_K2_32B",
|
5293
5296
|
/** LLaMA 3.1 8b */
|
5294
5297
|
Llama_3_1_8B = "LLAMA_3_1_8B",
|
5295
5298
|
/**
|
@@ -5323,7 +5326,9 @@ export declare enum GroqModels {
|
|
5323
5326
|
/** LLaMA 4 Scout 17b */
|
5324
5327
|
Llama_4Scout_17B = "LLAMA_4_SCOUT_17B",
|
5325
5328
|
/** Mixtral 8x7b Instruct */
|
5326
|
-
Mixtral_8X7BInstruct = "MIXTRAL_8X7B_INSTRUCT"
|
5329
|
+
Mixtral_8X7BInstruct = "MIXTRAL_8X7B_INSTRUCT",
|
5330
|
+
/** Qwen 3 32b */
|
5331
|
+
Qwen_3_32B = "QWEN_3_32B"
|
5327
5332
|
}
|
5328
5333
|
/** Represents an H3 index. */
|
5329
5334
|
export type H3 = {
|
@@ -279,6 +279,10 @@ export var CerebrasModels;
|
|
279
279
|
CerebrasModels["Llama_3_1_8B"] = "LLAMA_3_1_8B";
|
280
280
|
/** LLaMA 3.3 70b */
|
281
281
|
CerebrasModels["Llama_3_3_70B"] = "LLAMA_3_3_70B";
|
282
|
+
/** LLaMA 4 Scout 17b */
|
283
|
+
CerebrasModels["Llama_4Scout_17B"] = "LLAMA_4_SCOUT_17B";
|
284
|
+
/** Qwen 3 32b */
|
285
|
+
CerebrasModels["Qwen_3_32B"] = "QWEN_3_32B";
|
282
286
|
})(CerebrasModels || (CerebrasModels = {}));
|
283
287
|
/** Cohere model type */
|
284
288
|
export var CohereModels;
|
@@ -917,10 +921,7 @@ export var FeedTypes;
|
|
917
921
|
FeedTypes["Twitter"] = "TWITTER";
|
918
922
|
/** Web feed */
|
919
923
|
FeedTypes["Web"] = "WEB";
|
920
|
-
/**
|
921
|
-
* YouTube audio feed
|
922
|
-
* @deprecated No longer supported. We suggest using your own YouTube downloader and then ingest the video or audio files.
|
923
|
-
*/
|
924
|
+
/** YouTube audio feed */
|
924
925
|
FeedTypes["YouTube"] = "YOU_TUBE";
|
925
926
|
/** Zendesk articles feed */
|
926
927
|
FeedTypes["Zendesk"] = "ZENDESK";
|
@@ -1082,6 +1083,8 @@ export var GroqModels;
|
|
1082
1083
|
GroqModels["Custom"] = "CUSTOM";
|
1083
1084
|
/** Deepseek R1 Distill Llama 70b Preview */
|
1084
1085
|
GroqModels["DeepseekR1Llama_70BPreview"] = "DEEPSEEK_R1_LLAMA_70B_PREVIEW";
|
1086
|
+
/** Kimi K2 32b */
|
1087
|
+
GroqModels["KimiK2_32B"] = "KIMI_K2_32B";
|
1085
1088
|
/** LLaMA 3.1 8b */
|
1086
1089
|
GroqModels["Llama_3_1_8B"] = "LLAMA_3_1_8B";
|
1087
1090
|
/**
|
@@ -1116,6 +1119,8 @@ export var GroqModels;
|
|
1116
1119
|
GroqModels["Llama_4Scout_17B"] = "LLAMA_4_SCOUT_17B";
|
1117
1120
|
/** Mixtral 8x7b Instruct */
|
1118
1121
|
GroqModels["Mixtral_8X7BInstruct"] = "MIXTRAL_8X7B_INSTRUCT";
|
1122
|
+
/** Qwen 3 32b */
|
1123
|
+
GroqModels["Qwen_3_32B"] = "QWEN_3_32B";
|
1119
1124
|
})(GroqModels || (GroqModels = {}));
|
1120
1125
|
/** H3 index resolution types */
|
1121
1126
|
export var H3ResolutionTypes;
|
@@ -962,13 +962,6 @@ onEvent, onComplete, abortSignal) {
|
|
962
962
|
const result = await chat.sendMessageStream(prompt);
|
963
963
|
for await (const chunk of result.stream) {
|
964
964
|
const text = chunk.text();
|
965
|
-
// Debug log chunk details
|
966
|
-
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
967
|
-
console.log(`[Google] Raw chunk:`, JSON.stringify(chunk, null, 2));
|
968
|
-
if (text) {
|
969
|
-
console.log(`[Google] Text delta: "${text}" (${text.length} chars)`);
|
970
|
-
}
|
971
|
-
}
|
972
965
|
if (text) {
|
973
966
|
fullMessage += text;
|
974
967
|
tokenCount++;
|
@@ -1094,11 +1087,15 @@ onEvent, onComplete, abortSignal) {
|
|
1094
1087
|
// Check for any final text we might have missed
|
1095
1088
|
if (part.text) {
|
1096
1089
|
const finalText = part.text;
|
1097
|
-
//
|
1098
|
-
if (
|
1090
|
+
// Skip if this is just the complete message we already have
|
1091
|
+
if (finalText === fullMessage) {
|
1099
1092
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
1100
|
-
console.log(`[Google]
|
1093
|
+
console.log(`[Google] Skipping duplicate final text (matches fullMessage exactly)`);
|
1101
1094
|
}
|
1095
|
+
continue;
|
1096
|
+
}
|
1097
|
+
// Only add if it's not already included in fullMessage
|
1098
|
+
if (!fullMessage.includes(finalText) && !fullMessage.endsWith(finalText)) {
|
1102
1099
|
fullMessage += finalText;
|
1103
1100
|
onEvent({
|
1104
1101
|
type: "token",
|
@@ -2008,6 +2005,7 @@ onEvent, onComplete, abortSignal) {
|
|
2008
2005
|
};
|
2009
2006
|
// Add tools if provided
|
2010
2007
|
if (tools && tools.length > 0) {
|
2008
|
+
console.log(`[Mistral] Adding ${tools.length} tools to stream config`);
|
2011
2009
|
streamConfig.tools = tools.map((tool) => ({
|
2012
2010
|
type: "function",
|
2013
2011
|
function: {
|
@@ -2017,6 +2015,9 @@ onEvent, onComplete, abortSignal) {
|
|
2017
2015
|
},
|
2018
2016
|
}));
|
2019
2017
|
}
|
2018
|
+
else {
|
2019
|
+
console.log(`[Mistral] No tools provided - tools parameter is ${tools === undefined ? 'undefined' : 'empty array'}`);
|
2020
|
+
}
|
2020
2021
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2021
2022
|
console.log(`[Mistral] Stream config:`, JSON.stringify({
|
2022
2023
|
...streamConfig,
|
@@ -2058,9 +2059,24 @@ onEvent, onComplete, abortSignal) {
|
|
2058
2059
|
});
|
2059
2060
|
}
|
2060
2061
|
}
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2062
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2063
|
+
console.log(`[Mistral] Attempting to create stream with retry configuration`);
|
2064
|
+
}
|
2065
|
+
// Log final config being sent
|
2066
|
+
console.log(`[Mistral] Sending request with tools: ${streamConfig.tools ? 'YES' : 'NO'}`);
|
2067
|
+
stream = await mistralClient.chat.stream(streamConfig, {
|
2068
|
+
retries: {
|
2069
|
+
strategy: "backoff",
|
2070
|
+
backoff: {
|
2071
|
+
initialInterval: 1000,
|
2072
|
+
maxInterval: 60000,
|
2073
|
+
exponent: 2,
|
2074
|
+
maxElapsedTime: 300000, // 5 minutes
|
2075
|
+
},
|
2076
|
+
retryConnectionErrors: true,
|
2077
|
+
},
|
2078
|
+
retryCodes: ["429", "500", "502", "503", "504"],
|
2079
|
+
...(abortSignal && { fetchOptions: { signal: abortSignal } }),
|
2064
2080
|
});
|
2065
2081
|
}
|
2066
2082
|
catch (error) {
|
@@ -2218,6 +2234,13 @@ onEvent, onComplete, abortSignal) {
|
|
2218
2234
|
rateLimitError.statusCode = 429;
|
2219
2235
|
throw rateLimitError;
|
2220
2236
|
}
|
2237
|
+
if (error.message?.includes("500") ||
|
2238
|
+
error.message?.includes("Service unavailable") ||
|
2239
|
+
error.message?.includes("INTERNAL_SERVER_ERROR")) {
|
2240
|
+
const serviceError = new Error("Mistral API service is temporarily unavailable (500). This is a temporary issue with Mistral's servers. Please try again later.");
|
2241
|
+
serviceError.statusCode = 500;
|
2242
|
+
throw serviceError;
|
2243
|
+
}
|
2221
2244
|
// Re-throw with more context
|
2222
2245
|
throw new Error(`Mistral streaming failed: ${error.message || "Unknown error"}`);
|
2223
2246
|
}
|