graphlit-client 1.0.20250625001 → 1.0.20250627001
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/README.md +235 -5
- package/dist/client.d.ts +21 -1
- package/dist/client.js +265 -55
- package/dist/generated/graphql-documents.d.ts +16 -0
- package/dist/generated/graphql-documents.js +1116 -0
- package/dist/generated/graphql-types.d.ts +1884 -85
- package/dist/generated/graphql-types.js +51 -0
- package/dist/streaming/llm-formatters.js +68 -5
- package/dist/streaming/providers.d.ts +18 -13
- package/dist/streaming/providers.js +690 -167
- package/dist/streaming/ui-event-adapter.d.ts +7 -0
- package/dist/streaming/ui-event-adapter.js +55 -0
- package/dist/types/internal.d.ts +11 -0
- package/dist/types/ui-events.d.ts +9 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
@@ -8,7 +8,7 @@ import * as Documents from "./generated/graphql-documents.js";
|
|
8
8
|
import * as dotenv from "dotenv";
|
9
9
|
import { getServiceType, getModelName } from "./model-mapping.js";
|
10
10
|
import { UIEventAdapter } from "./streaming/ui-event-adapter.js";
|
11
|
-
import { formatMessagesForOpenAI, formatMessagesForAnthropic, formatMessagesForGoogle,
|
11
|
+
import { formatMessagesForOpenAI, formatMessagesForAnthropic, formatMessagesForGoogle, formatMessagesForMistral, formatMessagesForBedrock, } from "./streaming/llm-formatters.js";
|
12
12
|
import { streamWithOpenAI, streamWithAnthropic, streamWithGoogle, streamWithGroq, streamWithCerebras, streamWithCohere, streamWithMistral, streamWithBedrock, streamWithDeepseek, } from "./streaming/providers.js";
|
13
13
|
// Optional imports for streaming LLM clients
|
14
14
|
// These are peer dependencies and may not be installed
|
@@ -20,6 +20,7 @@ let Anthropic;
|
|
20
20
|
let GoogleGenerativeAI;
|
21
21
|
let Groq;
|
22
22
|
let CohereClient;
|
23
|
+
let CohereClientV2;
|
23
24
|
let Mistral;
|
24
25
|
let BedrockRuntimeClient;
|
25
26
|
try {
|
@@ -74,6 +75,7 @@ catch (e) {
|
|
74
75
|
}
|
75
76
|
try {
|
76
77
|
CohereClient = optionalRequire("cohere-ai").CohereClient;
|
78
|
+
CohereClientV2 = optionalRequire("cohere-ai").CohereClientV2;
|
77
79
|
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
|
78
80
|
console.log("[SDK Loading] Cohere SDK loaded successfully");
|
79
81
|
}
|
@@ -1026,6 +1028,108 @@ class Graphlit {
|
|
1026
1028
|
async queryModels(filter) {
|
1027
1029
|
return this.queryAndCheckError(Documents.QueryModels, { filter: filter });
|
1028
1030
|
}
|
1031
|
+
async createConnector(connector) {
|
1032
|
+
return this.mutateAndCheckError(Documents.CreateConnector, { connector: connector });
|
1033
|
+
}
|
1034
|
+
async updateConnector(connector) {
|
1035
|
+
return this.mutateAndCheckError(Documents.UpdateConnector, { connector: connector });
|
1036
|
+
}
|
1037
|
+
/*
|
1038
|
+
public async upsertConnector(
|
1039
|
+
connector: Types.ConnectorInput
|
1040
|
+
): Promise<Types.UpsertConnectorMutation> {
|
1041
|
+
return this.mutateAndCheckError<
|
1042
|
+
Types.UpsertConnectorMutation,
|
1043
|
+
{ connector: Types.ConnectorInput }
|
1044
|
+
>(Documents.UpsertConnector, { connector: connector });
|
1045
|
+
}
|
1046
|
+
*/
|
1047
|
+
async deleteConnector(id) {
|
1048
|
+
return this.mutateAndCheckError(Documents.DeleteConnector, { id: id });
|
1049
|
+
}
|
1050
|
+
/*
|
1051
|
+
public async deleteConnectors(
|
1052
|
+
ids: string[],
|
1053
|
+
isSynchronous?: boolean
|
1054
|
+
): Promise<Types.DeleteConnectorsMutation> {
|
1055
|
+
return this.mutateAndCheckError<
|
1056
|
+
Types.DeleteConnectorsMutation,
|
1057
|
+
{ ids: string[]; isSynchronous?: boolean }
|
1058
|
+
>(Documents.DeleteConnectors, { ids: ids, isSynchronous: isSynchronous });
|
1059
|
+
}
|
1060
|
+
|
1061
|
+
public async deleteAllConnectors(
|
1062
|
+
filter?: Types.ConnectorFilter,
|
1063
|
+
isSynchronous?: boolean,
|
1064
|
+
correlationId?: string
|
1065
|
+
): Promise<Types.DeleteAllConnectorsMutation> {
|
1066
|
+
return this.mutateAndCheckError<
|
1067
|
+
Types.DeleteAllConnectorsMutation,
|
1068
|
+
{
|
1069
|
+
filter?: Types.ConnectorFilter;
|
1070
|
+
isSynchronous?: boolean;
|
1071
|
+
correlationId?: string;
|
1072
|
+
}
|
1073
|
+
>(Documents.DeleteAllConnectors, {
|
1074
|
+
filter: filter,
|
1075
|
+
isSynchronous: isSynchronous,
|
1076
|
+
correlationId: correlationId,
|
1077
|
+
});
|
1078
|
+
}
|
1079
|
+
*/
|
1080
|
+
async getConnector(id) {
|
1081
|
+
return this.queryAndCheckError(Documents.GetConnector, { id: id });
|
1082
|
+
}
|
1083
|
+
async queryConnectors(filter) {
|
1084
|
+
return this.queryAndCheckError(Documents.QueryConnectors, { filter: filter });
|
1085
|
+
}
|
1086
|
+
async countConnectors(filter) {
|
1087
|
+
return this.queryAndCheckError(Documents.CountConnectors, { filter: filter });
|
1088
|
+
}
|
1089
|
+
/*
|
1090
|
+
public async connectorExists(
|
1091
|
+
filter?: Types.ConnectorFilter
|
1092
|
+
): Promise<Types.ConnectorExistsQuery> {
|
1093
|
+
return this.queryAndCheckError<
|
1094
|
+
Types.QueryConnectorsQuery,
|
1095
|
+
{ filter?: Types.ConnectorFilter }
|
1096
|
+
>(Documents.ConnectorExists, { filter: filter });
|
1097
|
+
}
|
1098
|
+
*/
|
1099
|
+
async createView(view) {
|
1100
|
+
return this.mutateAndCheckError(Documents.CreateView, { view: view });
|
1101
|
+
}
|
1102
|
+
async updateView(view) {
|
1103
|
+
return this.mutateAndCheckError(Documents.UpdateView, { view: view });
|
1104
|
+
}
|
1105
|
+
async upsertView(view) {
|
1106
|
+
return this.mutateAndCheckError(Documents.UpsertView, { view: view });
|
1107
|
+
}
|
1108
|
+
async deleteView(id) {
|
1109
|
+
return this.mutateAndCheckError(Documents.DeleteView, { id: id });
|
1110
|
+
}
|
1111
|
+
async deleteViews(ids, isSynchronous) {
|
1112
|
+
return this.mutateAndCheckError(Documents.DeleteViews, { ids: ids, isSynchronous: isSynchronous });
|
1113
|
+
}
|
1114
|
+
async deleteAllViews(filter, isSynchronous, correlationId) {
|
1115
|
+
return this.mutateAndCheckError(Documents.DeleteAllViews, {
|
1116
|
+
filter: filter,
|
1117
|
+
isSynchronous: isSynchronous,
|
1118
|
+
correlationId: correlationId,
|
1119
|
+
});
|
1120
|
+
}
|
1121
|
+
async getView(id) {
|
1122
|
+
return this.queryAndCheckError(Documents.GetView, { id: id });
|
1123
|
+
}
|
1124
|
+
async queryViews(filter) {
|
1125
|
+
return this.queryAndCheckError(Documents.QueryViews, { filter: filter });
|
1126
|
+
}
|
1127
|
+
async countViews(filter) {
|
1128
|
+
return this.queryAndCheckError(Documents.CountViews, { filter: filter });
|
1129
|
+
}
|
1130
|
+
async viewExists(filter) {
|
1131
|
+
return this.queryAndCheckError(Documents.ViewExists, { filter: filter });
|
1132
|
+
}
|
1029
1133
|
async createWorkflow(workflow) {
|
1030
1134
|
return this.mutateAndCheckError(Documents.CreateWorkflow, { workflow: workflow });
|
1031
1135
|
}
|
@@ -1649,7 +1753,7 @@ class Graphlit {
|
|
1649
1753
|
* @param specification - Optional specification to check compatibility
|
1650
1754
|
* @returns true if streaming is available, false otherwise
|
1651
1755
|
*/
|
1652
|
-
supportsStreaming(specification) {
|
1756
|
+
supportsStreaming(specification, tools) {
|
1653
1757
|
// If we have a full specification, check its service type
|
1654
1758
|
if (specification) {
|
1655
1759
|
const serviceType = specification.serviceType;
|
@@ -1677,12 +1781,26 @@ class Graphlit {
|
|
1677
1781
|
case Types.ModelServiceTypes.Cerebras:
|
1678
1782
|
return OpenAI !== undefined || this.cerebrasClient !== undefined;
|
1679
1783
|
case Types.ModelServiceTypes.Cohere:
|
1680
|
-
return CohereClient !== undefined ||
|
1784
|
+
return (CohereClient !== undefined ||
|
1785
|
+
CohereClientV2 !== undefined ||
|
1786
|
+
this.cohereClient !== undefined);
|
1681
1787
|
case Types.ModelServiceTypes.Mistral:
|
1682
1788
|
return Mistral !== undefined || this.mistralClient !== undefined;
|
1683
1789
|
case Types.ModelServiceTypes.Bedrock:
|
1684
|
-
|
1685
|
-
this.bedrockClient !== undefined
|
1790
|
+
const hasBedrockClient = BedrockRuntimeClient !== undefined ||
|
1791
|
+
this.bedrockClient !== undefined;
|
1792
|
+
// Bedrock Llama models don't support tools in streaming mode
|
1793
|
+
if (hasBedrockClient && tools && tools.length > 0) {
|
1794
|
+
const bedrockModel = specification.bedrock?.model;
|
1795
|
+
if (bedrockModel === Types.BedrockModels.Llama_4Maverick_17B ||
|
1796
|
+
bedrockModel === Types.BedrockModels.Llama_4Scout_17B) {
|
1797
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
1798
|
+
console.log(`⚠️ [supportsStreaming] Bedrock Llama model ${bedrockModel} does not support tools in streaming mode - will fallback to non-streaming`);
|
1799
|
+
}
|
1800
|
+
return false; // Force fallback to promptAgent for tool support
|
1801
|
+
}
|
1802
|
+
}
|
1803
|
+
return hasBedrockClient;
|
1686
1804
|
case Types.ModelServiceTypes.Deepseek:
|
1687
1805
|
return OpenAI !== undefined || this.deepseekClient !== undefined;
|
1688
1806
|
default:
|
@@ -1696,7 +1814,9 @@ class Graphlit {
|
|
1696
1814
|
const hasGoogle = GoogleGenerativeAI !== undefined || this.googleClient !== undefined;
|
1697
1815
|
const hasGroq = Groq !== undefined || this.groqClient !== undefined;
|
1698
1816
|
const hasCerebras = OpenAI !== undefined || this.cerebrasClient !== undefined;
|
1699
|
-
const hasCohere = CohereClient !== undefined ||
|
1817
|
+
const hasCohere = CohereClient !== undefined ||
|
1818
|
+
CohereClientV2 !== undefined ||
|
1819
|
+
this.cohereClient !== undefined;
|
1700
1820
|
const hasMistral = Mistral !== undefined || this.mistralClient !== undefined;
|
1701
1821
|
const hasBedrock = BedrockRuntimeClient !== undefined || this.bedrockClient !== undefined;
|
1702
1822
|
return (hasOpenAI ||
|
@@ -1914,7 +2034,7 @@ class Graphlit {
|
|
1914
2034
|
}
|
1915
2035
|
}
|
1916
2036
|
// Check streaming support - fallback to promptAgent if not supported
|
1917
|
-
if (fullSpec && !this.supportsStreaming(fullSpec)) {
|
2037
|
+
if (fullSpec && !this.supportsStreaming(fullSpec, tools)) {
|
1918
2038
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
1919
2039
|
console.log("\n⚠️ [streamAgent] Streaming not supported, falling back to promptAgent with same conversation");
|
1920
2040
|
}
|
@@ -1929,6 +2049,31 @@ class Graphlit {
|
|
1929
2049
|
conversationId: actualConversationId,
|
1930
2050
|
timestamp: new Date(),
|
1931
2051
|
});
|
2052
|
+
// Debug logging for fallback
|
2053
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2054
|
+
console.log(`📊 [streamAgent fallback] promptAgent result:`, {
|
2055
|
+
hasMessage: !!promptResult.message,
|
2056
|
+
messageLength: promptResult.message?.length,
|
2057
|
+
toolCallsCount: promptResult.toolCalls?.length || 0,
|
2058
|
+
toolResultsCount: promptResult.toolResults?.length || 0,
|
2059
|
+
toolCalls: promptResult.toolCalls,
|
2060
|
+
toolResults: promptResult.toolResults?.map((tr) => ({
|
2061
|
+
name: tr.name,
|
2062
|
+
hasResult: !!tr.result,
|
2063
|
+
hasError: !!tr.error,
|
2064
|
+
})),
|
2065
|
+
});
|
2066
|
+
}
|
2067
|
+
// Emit tool events if there were tool calls
|
2068
|
+
if (promptResult.toolCalls && promptResult.toolCalls.length > 0) {
|
2069
|
+
for (const toolCall of promptResult.toolCalls) {
|
2070
|
+
onEvent({
|
2071
|
+
type: "tool_update",
|
2072
|
+
toolCall: toolCall,
|
2073
|
+
status: "completed",
|
2074
|
+
});
|
2075
|
+
}
|
2076
|
+
}
|
1932
2077
|
// Emit the final message as a single update (simulating streaming)
|
1933
2078
|
onEvent({
|
1934
2079
|
type: "message_update",
|
@@ -1937,7 +2082,7 @@ class Graphlit {
|
|
1937
2082
|
message: promptResult.message,
|
1938
2083
|
role: Types.ConversationRoleTypes.Assistant,
|
1939
2084
|
timestamp: new Date().toISOString(),
|
1940
|
-
toolCalls: [],
|
2085
|
+
toolCalls: promptResult.toolCalls || [],
|
1941
2086
|
},
|
1942
2087
|
isStreaming: false,
|
1943
2088
|
});
|
@@ -1949,7 +2094,7 @@ class Graphlit {
|
|
1949
2094
|
message: promptResult.message,
|
1950
2095
|
role: Types.ConversationRoleTypes.Assistant,
|
1951
2096
|
timestamp: new Date().toISOString(),
|
1952
|
-
toolCalls: [],
|
2097
|
+
toolCalls: promptResult.toolCalls || [],
|
1953
2098
|
},
|
1954
2099
|
});
|
1955
2100
|
return; // Exit early after successful fallback
|
@@ -2132,7 +2277,7 @@ class Graphlit {
|
|
2132
2277
|
await this.streamWithOpenAI(specification, openaiMessages, tools, uiAdapter, (message, calls) => {
|
2133
2278
|
roundMessage = message;
|
2134
2279
|
toolCalls = calls;
|
2135
|
-
});
|
2280
|
+
}, abortSignal);
|
2136
2281
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2137
2282
|
console.log(`\n🏁 [Streaming] OpenAI native streaming completed (Round ${currentRound})`);
|
2138
2283
|
}
|
@@ -2149,7 +2294,7 @@ class Graphlit {
|
|
2149
2294
|
await this.streamWithAnthropic(specification, anthropicMessages, system, tools, uiAdapter, (message, calls) => {
|
2150
2295
|
roundMessage = message;
|
2151
2296
|
toolCalls = calls;
|
2152
|
-
});
|
2297
|
+
}, abortSignal);
|
2153
2298
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2154
2299
|
console.log(`\n🏁 [Streaming] Anthropic native streaming completed (Round ${currentRound})`);
|
2155
2300
|
}
|
@@ -2168,7 +2313,7 @@ class Graphlit {
|
|
2168
2313
|
tools, uiAdapter, (message, calls) => {
|
2169
2314
|
roundMessage = message;
|
2170
2315
|
toolCalls = calls;
|
2171
|
-
});
|
2316
|
+
}, abortSignal);
|
2172
2317
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2173
2318
|
console.log(`\n🏁 [Streaming] Google native streaming completed (Round ${currentRound})`);
|
2174
2319
|
}
|
@@ -2185,7 +2330,7 @@ class Graphlit {
|
|
2185
2330
|
await this.streamWithGroq(specification, groqMessages, tools, uiAdapter, (message, calls) => {
|
2186
2331
|
roundMessage = message;
|
2187
2332
|
toolCalls = calls;
|
2188
|
-
});
|
2333
|
+
}, abortSignal);
|
2189
2334
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2190
2335
|
console.log(`\n🏁 [Streaming] Groq native streaming completed (Round ${currentRound})`);
|
2191
2336
|
}
|
@@ -2202,24 +2347,24 @@ class Graphlit {
|
|
2202
2347
|
await this.streamWithCerebras(specification, cerebrasMessages, tools, uiAdapter, (message, calls) => {
|
2203
2348
|
roundMessage = message;
|
2204
2349
|
toolCalls = calls;
|
2205
|
-
});
|
2350
|
+
}, abortSignal);
|
2206
2351
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2207
2352
|
console.log(`\n🏁 [Streaming] Cerebras native streaming completed (Round ${currentRound})`);
|
2208
2353
|
}
|
2209
2354
|
}
|
2210
2355
|
else if (serviceType === Types.ModelServiceTypes.Cohere &&
|
2211
|
-
(CohereClient || this.cohereClient)) {
|
2356
|
+
(CohereClient || CohereClientV2 || this.cohereClient)) {
|
2212
2357
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2213
2358
|
console.log(`\n✅ [Streaming] Using Cohere native streaming (Round ${currentRound})`);
|
2214
2359
|
}
|
2215
|
-
|
2360
|
+
// V2 API uses raw messages, not formatted
|
2216
2361
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING_MESSAGES) {
|
2217
|
-
console.log(`🔍 [Cohere] Sending ${
|
2362
|
+
console.log(`🔍 [Cohere] Sending ${messages.length} messages to LLM`);
|
2218
2363
|
}
|
2219
|
-
await this.streamWithCohere(specification,
|
2364
|
+
await this.streamWithCohere(specification, messages, tools, uiAdapter, (message, calls) => {
|
2220
2365
|
roundMessage = message;
|
2221
2366
|
toolCalls = calls;
|
2222
|
-
});
|
2367
|
+
}, abortSignal);
|
2223
2368
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2224
2369
|
console.log(`\n🏁 [Streaming] Cohere native streaming completed (Round ${currentRound})`);
|
2225
2370
|
}
|
@@ -2230,13 +2375,26 @@ class Graphlit {
|
|
2230
2375
|
console.log(`\n✅ [Streaming] Using Mistral native streaming (Round ${currentRound})`);
|
2231
2376
|
}
|
2232
2377
|
const mistralMessages = formatMessagesForMistral(messages);
|
2233
|
-
|
2234
|
-
|
2378
|
+
// ALWAYS log when there's a tool-related issue for debugging
|
2379
|
+
const hasToolCalls = mistralMessages.some((m) => m.tool_calls?.length > 0);
|
2380
|
+
const hasToolResponses = mistralMessages.some((m) => m.role === "tool");
|
2381
|
+
if (hasToolCalls ||
|
2382
|
+
hasToolResponses ||
|
2383
|
+
process.env.DEBUG_GRAPHLIT_SDK_STREAMING_MESSAGES) {
|
2384
|
+
console.log(`🔍 [Mistral] Sending ${mistralMessages.length} messages to LLM:`);
|
2385
|
+
console.log(JSON.stringify(mistralMessages, null, 2));
|
2386
|
+
// Count tool calls and responses
|
2387
|
+
const toolCallCount = mistralMessages.reduce((count, m) => count + (m.tool_calls?.length || 0), 0);
|
2388
|
+
const toolResponseCount = mistralMessages.filter((m) => m.role === "tool").length;
|
2389
|
+
console.log(`🔍 [Mistral] Tool calls: ${toolCallCount}, Tool responses: ${toolResponseCount}`);
|
2390
|
+
if (toolResponseCount > 0) {
|
2391
|
+
console.log(`🔍 [Mistral] IMPORTANT: We have tool responses, should we still pass tools?`);
|
2392
|
+
}
|
2235
2393
|
}
|
2236
2394
|
await this.streamWithMistral(specification, mistralMessages, tools, uiAdapter, (message, calls) => {
|
2237
2395
|
roundMessage = message;
|
2238
2396
|
toolCalls = calls;
|
2239
|
-
});
|
2397
|
+
}, abortSignal);
|
2240
2398
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2241
2399
|
console.log(`\n🏁 [Streaming] Mistral native streaming completed (Round ${currentRound})`);
|
2242
2400
|
}
|
@@ -2253,7 +2411,7 @@ class Graphlit {
|
|
2253
2411
|
await this.streamWithBedrock(specification, bedrockMessages, system, tools, uiAdapter, (message, calls) => {
|
2254
2412
|
roundMessage = message;
|
2255
2413
|
toolCalls = calls;
|
2256
|
-
});
|
2414
|
+
}, abortSignal);
|
2257
2415
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2258
2416
|
console.log(`\n🏁 [Streaming] Bedrock native streaming completed (Round ${currentRound})`);
|
2259
2417
|
}
|
@@ -2270,7 +2428,7 @@ class Graphlit {
|
|
2270
2428
|
await this.streamWithDeepseek(specification, deepseekMessages, tools, uiAdapter, (message, calls) => {
|
2271
2429
|
roundMessage = message;
|
2272
2430
|
toolCalls = calls;
|
2273
|
-
});
|
2431
|
+
}, abortSignal);
|
2274
2432
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2275
2433
|
console.log(`\n🏁 [Streaming] Deepseek native streaming completed (Round ${currentRound})`);
|
2276
2434
|
}
|
@@ -2408,13 +2566,16 @@ class Graphlit {
|
|
2408
2566
|
result: result,
|
2409
2567
|
});
|
2410
2568
|
// Add tool response to messages
|
2411
|
-
|
2569
|
+
const toolMessage = {
|
2412
2570
|
__typename: "ConversationMessage",
|
2413
2571
|
role: Types.ConversationRoleTypes.Tool,
|
2414
2572
|
message: typeof result === "string" ? result : JSON.stringify(result),
|
2415
2573
|
toolCallId: toolCall.id,
|
2416
2574
|
timestamp: new Date().toISOString(),
|
2417
|
-
}
|
2575
|
+
};
|
2576
|
+
// Add tool name for Mistral compatibility
|
2577
|
+
toolMessage.toolName = toolCall.name;
|
2578
|
+
messages.push(toolMessage);
|
2418
2579
|
}
|
2419
2580
|
catch (error) {
|
2420
2581
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
@@ -2430,13 +2591,16 @@ class Graphlit {
|
|
2430
2591
|
error: errorMessage,
|
2431
2592
|
});
|
2432
2593
|
// Add error response
|
2433
|
-
|
2594
|
+
const errorToolMessage = {
|
2434
2595
|
__typename: "ConversationMessage",
|
2435
2596
|
role: Types.ConversationRoleTypes.Tool,
|
2436
2597
|
message: `Error: ${errorMessage}`,
|
2437
2598
|
toolCallId: toolCall.id,
|
2438
2599
|
timestamp: new Date().toISOString(),
|
2439
|
-
}
|
2600
|
+
};
|
2601
|
+
// Add tool name for Mistral compatibility
|
2602
|
+
errorToolMessage.toolName = toolCall.name;
|
2603
|
+
messages.push(errorToolMessage);
|
2440
2604
|
}
|
2441
2605
|
}
|
2442
2606
|
}
|
@@ -2450,7 +2614,14 @@ class Graphlit {
|
|
2450
2614
|
const completionTime = uiAdapter.getCompletionTime(); // Total time in milliseconds
|
2451
2615
|
const ttft = uiAdapter.getTTFT(); // Time to first token in milliseconds
|
2452
2616
|
const throughput = uiAdapter.getThroughput(); // Tokens per second
|
2453
|
-
|
2617
|
+
// Convert milliseconds to ISO 8601 duration format (e.g., "PT1.5S")
|
2618
|
+
const millisecondsToTimeSpan = (ms) => {
|
2619
|
+
if (ms === undefined)
|
2620
|
+
return undefined;
|
2621
|
+
const seconds = ms / 1000;
|
2622
|
+
return `PT${seconds}S`;
|
2623
|
+
};
|
2624
|
+
const completeResponse = await this.completeConversation(trimmedMessage, conversationId, millisecondsToTimeSpan(completionTime), millisecondsToTimeSpan(ttft), throughput, correlationId);
|
2454
2625
|
// Extract token count from the response
|
2455
2626
|
finalTokens =
|
2456
2627
|
completeResponse.completeConversation?.message?.tokens ?? undefined;
|
@@ -2604,7 +2775,7 @@ class Graphlit {
|
|
2604
2775
|
/**
|
2605
2776
|
* Stream with OpenAI client
|
2606
2777
|
*/
|
2607
|
-
async streamWithOpenAI(specification, messages, tools, uiAdapter, onComplete) {
|
2778
|
+
async streamWithOpenAI(specification, messages, tools, uiAdapter, onComplete, abortSignal) {
|
2608
2779
|
// Check if we have either the OpenAI module or a provided client
|
2609
2780
|
if (!OpenAI && !this.openaiClient) {
|
2610
2781
|
throw new Error("OpenAI client not available");
|
@@ -2621,12 +2792,12 @@ class Graphlit {
|
|
2621
2792
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2622
2793
|
console.log(`🚀 [Graphlit SDK] Routing to OpenAI streaming provider | Spec: ${specification.name} (${specification.id}) | Messages: ${messages.length} | Tools: ${tools?.length || 0}`);
|
2623
2794
|
}
|
2624
|
-
await streamWithOpenAI(specification, messages, tools, openaiClient, (event) => uiAdapter.handleEvent(event), onComplete);
|
2795
|
+
await streamWithOpenAI(specification, messages, tools, openaiClient, (event) => uiAdapter.handleEvent(event), onComplete, abortSignal);
|
2625
2796
|
}
|
2626
2797
|
/**
|
2627
2798
|
* Stream with Anthropic client
|
2628
2799
|
*/
|
2629
|
-
async streamWithAnthropic(specification, messages, systemPrompt, tools, uiAdapter, onComplete) {
|
2800
|
+
async streamWithAnthropic(specification, messages, systemPrompt, tools, uiAdapter, onComplete, abortSignal) {
|
2630
2801
|
// Check if we have either the Anthropic module or a provided client
|
2631
2802
|
if (!Anthropic && !this.anthropicClient) {
|
2632
2803
|
throw new Error("Anthropic client not available");
|
@@ -2643,12 +2814,43 @@ class Graphlit {
|
|
2643
2814
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2644
2815
|
console.log(`🚀 [Graphlit SDK] Routing to Anthropic streaming provider | Spec: ${specification.name} (${specification.id}) | Messages: ${messages.length} | Tools: ${tools?.length || 0} | SystemPrompt: ${systemPrompt ? "Yes" : "No"}`);
|
2645
2816
|
}
|
2646
|
-
|
2817
|
+
// Get thinking configuration from specification
|
2818
|
+
const thinkingConfig = this.getThinkingConfig(specification);
|
2819
|
+
if (thinkingConfig && process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2820
|
+
console.log(`🧠 [Graphlit SDK] Anthropic thinking enabled | Budget: ${thinkingConfig.budget_tokens} tokens`);
|
2821
|
+
}
|
2822
|
+
await streamWithAnthropic(specification, messages, systemPrompt, tools, anthropicClient, (event) => uiAdapter.handleEvent(event), onComplete, abortSignal, thinkingConfig);
|
2823
|
+
}
|
2824
|
+
/**
|
2825
|
+
* Extract thinking configuration from specification
|
2826
|
+
*/
|
2827
|
+
getThinkingConfig(specification) {
|
2828
|
+
// Check Anthropic specifications
|
2829
|
+
if (specification.serviceType === Types.ModelServiceTypes.Anthropic) {
|
2830
|
+
const anthropic = specification.anthropic;
|
2831
|
+
if (anthropic?.enableThinking) {
|
2832
|
+
return {
|
2833
|
+
type: "enabled",
|
2834
|
+
budget_tokens: anthropic.thinkingTokenLimit || 10000,
|
2835
|
+
};
|
2836
|
+
}
|
2837
|
+
}
|
2838
|
+
// Check Google specifications (also supports thinking)
|
2839
|
+
if (specification.serviceType === Types.ModelServiceTypes.Google) {
|
2840
|
+
const google = specification.google;
|
2841
|
+
if (google?.enableThinking) {
|
2842
|
+
return {
|
2843
|
+
type: "enabled",
|
2844
|
+
budget_tokens: google.thinkingTokenLimit || 10000,
|
2845
|
+
};
|
2846
|
+
}
|
2847
|
+
}
|
2848
|
+
return undefined;
|
2647
2849
|
}
|
2648
2850
|
/**
|
2649
2851
|
* Stream with Google client
|
2650
2852
|
*/
|
2651
|
-
async streamWithGoogle(specification, messages, systemPrompt, tools, uiAdapter, onComplete) {
|
2853
|
+
async streamWithGoogle(specification, messages, systemPrompt, tools, uiAdapter, onComplete, abortSignal) {
|
2652
2854
|
// Check if we have either the Google module or a provided client
|
2653
2855
|
if (!GoogleGenerativeAI && !this.googleClient) {
|
2654
2856
|
throw new Error("Google GenerativeAI client not available");
|
@@ -2663,12 +2865,12 @@ class Graphlit {
|
|
2663
2865
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2664
2866
|
console.log(`🚀 [Graphlit SDK] Routing to Google streaming provider | Spec: ${specification.name} (${specification.id}) | Messages: ${messages.length} | Tools: ${tools?.length || 0} | SystemPrompt: ${systemPrompt ? "Yes" : "No"}`);
|
2665
2867
|
}
|
2666
|
-
await streamWithGoogle(specification, messages, systemPrompt, tools, googleClient, (event) => uiAdapter.handleEvent(event), onComplete);
|
2868
|
+
await streamWithGoogle(specification, messages, systemPrompt, tools, googleClient, (event) => uiAdapter.handleEvent(event), onComplete, abortSignal);
|
2667
2869
|
}
|
2668
2870
|
/**
|
2669
2871
|
* Stream with Groq client (OpenAI-compatible)
|
2670
2872
|
*/
|
2671
|
-
async streamWithGroq(specification, messages, tools, uiAdapter, onComplete) {
|
2873
|
+
async streamWithGroq(specification, messages, tools, uiAdapter, onComplete, abortSignal) {
|
2672
2874
|
// Check if we have either the Groq module or a provided client
|
2673
2875
|
if (!Groq && !this.groqClient) {
|
2674
2876
|
throw new Error("Groq client not available");
|
@@ -2683,12 +2885,12 @@ class Graphlit {
|
|
2683
2885
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2684
2886
|
console.log(`🚀 [Graphlit SDK] Routing to Groq streaming provider | Spec: ${specification.name} (${specification.id}) | Messages: ${messages.length} | Tools: ${tools?.length || 0}`);
|
2685
2887
|
}
|
2686
|
-
await streamWithGroq(specification, messages, tools, groqClient, (event) => uiAdapter.handleEvent(event), onComplete);
|
2888
|
+
await streamWithGroq(specification, messages, tools, groqClient, (event) => uiAdapter.handleEvent(event), onComplete, abortSignal);
|
2687
2889
|
}
|
2688
2890
|
/**
|
2689
2891
|
* Stream with Cerebras client (OpenAI-compatible)
|
2690
2892
|
*/
|
2691
|
-
async streamWithCerebras(specification, messages, tools, uiAdapter, onComplete) {
|
2893
|
+
async streamWithCerebras(specification, messages, tools, uiAdapter, onComplete, abortSignal) {
|
2692
2894
|
// Check if we have either the OpenAI module or a provided client
|
2693
2895
|
if (!OpenAI && !this.cerebrasClient) {
|
2694
2896
|
throw new Error("Cerebras client not available");
|
@@ -2706,32 +2908,34 @@ class Graphlit {
|
|
2706
2908
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2707
2909
|
console.log(`🚀 [Graphlit SDK] Routing to Cerebras streaming provider | Spec: ${specification.name} (${specification.id}) | Messages: ${messages.length} | Tools: ${tools?.length || 0}`);
|
2708
2910
|
}
|
2709
|
-
await streamWithCerebras(specification, messages, tools, cerebrasClient, (event) => uiAdapter.handleEvent(event), onComplete);
|
2911
|
+
await streamWithCerebras(specification, messages, tools, cerebrasClient, (event) => uiAdapter.handleEvent(event), onComplete, abortSignal);
|
2710
2912
|
}
|
2711
2913
|
/**
|
2712
2914
|
* Stream with Cohere client
|
2713
2915
|
*/
|
2714
|
-
async streamWithCohere(specification, messages, tools, uiAdapter, onComplete) {
|
2916
|
+
async streamWithCohere(specification, messages, tools, uiAdapter, onComplete, abortSignal) {
|
2715
2917
|
// Check if we have either the Cohere module or a provided client
|
2716
|
-
if (!CohereClient && !this.cohereClient) {
|
2918
|
+
if (!CohereClient && !CohereClientV2 && !this.cohereClient) {
|
2717
2919
|
throw new Error("Cohere client not available");
|
2718
2920
|
}
|
2719
|
-
// Use provided client or create a new one
|
2921
|
+
// Use provided client or create a new one - prefer v2
|
2720
2922
|
const cohereClient = this.cohereClient ||
|
2721
|
-
(
|
2722
|
-
? new
|
2723
|
-
:
|
2724
|
-
|
2725
|
-
|
2923
|
+
(CohereClientV2
|
2924
|
+
? new CohereClientV2({ token: process.env.COHERE_API_KEY || "" })
|
2925
|
+
: CohereClient
|
2926
|
+
? new CohereClient({ token: process.env.COHERE_API_KEY || "" })
|
2927
|
+
: (() => {
|
2928
|
+
throw new Error("Cohere module not available");
|
2929
|
+
})());
|
2726
2930
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2727
2931
|
console.log(`🚀 [Graphlit SDK] Routing to Cohere streaming provider | Spec: ${specification.name} (${specification.id}) | Messages: ${messages.length} | Tools: ${tools?.length || 0}`);
|
2728
2932
|
}
|
2729
|
-
await streamWithCohere(specification, messages, tools, cohereClient, (event) => uiAdapter.handleEvent(event), onComplete);
|
2933
|
+
await streamWithCohere(specification, messages, tools, cohereClient, (event) => uiAdapter.handleEvent(event), onComplete, abortSignal);
|
2730
2934
|
}
|
2731
2935
|
/**
|
2732
2936
|
* Stream with Mistral client
|
2733
2937
|
*/
|
2734
|
-
async streamWithMistral(specification, messages, tools, uiAdapter, onComplete) {
|
2938
|
+
async streamWithMistral(specification, messages, tools, uiAdapter, onComplete, abortSignal) {
|
2735
2939
|
// Check if we have either the Mistral module or a provided client
|
2736
2940
|
if (!Mistral && !this.mistralClient) {
|
2737
2941
|
throw new Error("Mistral client not available");
|
@@ -2739,19 +2943,25 @@ class Graphlit {
|
|
2739
2943
|
// Use provided client or create a new one
|
2740
2944
|
const mistralClient = this.mistralClient ||
|
2741
2945
|
(Mistral
|
2742
|
-
?
|
2946
|
+
? (() => {
|
2947
|
+
const apiKey = process.env.MISTRAL_API_KEY;
|
2948
|
+
if (!apiKey) {
|
2949
|
+
throw new Error("MISTRAL_API_KEY environment variable is required for Mistral streaming");
|
2950
|
+
}
|
2951
|
+
return new Mistral({ apiKey });
|
2952
|
+
})()
|
2743
2953
|
: (() => {
|
2744
2954
|
throw new Error("Mistral module not available");
|
2745
2955
|
})());
|
2746
2956
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2747
2957
|
console.log(`🚀 [Graphlit SDK] Routing to Mistral streaming provider | Spec: ${specification.name} (${specification.id}) | Messages: ${messages.length} | Tools: ${tools?.length || 0}`);
|
2748
2958
|
}
|
2749
|
-
await streamWithMistral(specification, messages, tools, mistralClient, (event) => uiAdapter.handleEvent(event), onComplete);
|
2959
|
+
await streamWithMistral(specification, messages, tools, mistralClient, (event) => uiAdapter.handleEvent(event), onComplete, abortSignal);
|
2750
2960
|
}
|
2751
2961
|
/**
|
2752
2962
|
* Stream with Bedrock client
|
2753
2963
|
*/
|
2754
|
-
async streamWithBedrock(specification, messages, systemPrompt, tools, uiAdapter, onComplete) {
|
2964
|
+
async streamWithBedrock(specification, messages, systemPrompt, tools, uiAdapter, onComplete, abortSignal) {
|
2755
2965
|
// Check if we have either the Bedrock module or a provided client
|
2756
2966
|
if (!BedrockRuntimeClient && !this.bedrockClient) {
|
2757
2967
|
throw new Error("Bedrock client not available");
|
@@ -2768,12 +2978,12 @@ class Graphlit {
|
|
2768
2978
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2769
2979
|
console.log(`🚀 [Graphlit SDK] Routing to Bedrock streaming provider | Spec: ${specification.name} (${specification.id}) | Messages: ${messages.length} | Tools: ${tools?.length || 0} | SystemPrompt: ${systemPrompt ? "Yes" : "No"}`);
|
2770
2980
|
}
|
2771
|
-
await streamWithBedrock(specification, messages, systemPrompt, tools, bedrockClient, (event) => uiAdapter.handleEvent(event), onComplete);
|
2981
|
+
await streamWithBedrock(specification, messages, systemPrompt, tools, bedrockClient, (event) => uiAdapter.handleEvent(event), onComplete, abortSignal);
|
2772
2982
|
}
|
2773
2983
|
/**
|
2774
2984
|
* Stream with Deepseek client
|
2775
2985
|
*/
|
2776
|
-
async streamWithDeepseek(specification, messages, tools, uiAdapter, onComplete) {
|
2986
|
+
async streamWithDeepseek(specification, messages, tools, uiAdapter, onComplete, abortSignal) {
|
2777
2987
|
// Check if we have either the OpenAI module or a provided Deepseek client
|
2778
2988
|
if (!OpenAI && !this.deepseekClient) {
|
2779
2989
|
throw new Error("Deepseek client not available (requires OpenAI SDK)");
|
@@ -2792,7 +3002,7 @@ class Graphlit {
|
|
2792
3002
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
2793
3003
|
console.log(`🚀 [Graphlit SDK] Routing to Deepseek streaming provider | Spec: ${specification.name} (${specification.id}) | Messages: ${messages.length} | Tools: ${tools?.length || 0}`);
|
2794
3004
|
}
|
2795
|
-
await streamWithDeepseek(specification, messages, tools, deepseekClient, (event) => uiAdapter.handleEvent(event), onComplete);
|
3005
|
+
await streamWithDeepseek(specification, messages, tools, deepseekClient, (event) => uiAdapter.handleEvent(event), onComplete, abortSignal);
|
2796
3006
|
}
|
2797
3007
|
// Helper method to execute tools for promptAgent
|
2798
3008
|
async executeToolsForPromptAgent(toolCalls, toolHandlers, allToolCalls, signal) {
|
@@ -27,6 +27,12 @@ export declare const GetCollection: import("graphql").DocumentNode;
|
|
27
27
|
export declare const QueryCollections: import("graphql").DocumentNode;
|
28
28
|
export declare const RemoveContentsFromCollection: import("graphql").DocumentNode;
|
29
29
|
export declare const UpdateCollection: import("graphql").DocumentNode;
|
30
|
+
export declare const CountConnectors: import("graphql").DocumentNode;
|
31
|
+
export declare const CreateConnector: import("graphql").DocumentNode;
|
32
|
+
export declare const DeleteConnector: import("graphql").DocumentNode;
|
33
|
+
export declare const GetConnector: import("graphql").DocumentNode;
|
34
|
+
export declare const QueryConnectors: import("graphql").DocumentNode;
|
35
|
+
export declare const UpdateConnector: import("graphql").DocumentNode;
|
30
36
|
export declare const CountContents: import("graphql").DocumentNode;
|
31
37
|
export declare const DeleteAllContents: import("graphql").DocumentNode;
|
32
38
|
export declare const DeleteContent: import("graphql").DocumentNode;
|
@@ -293,6 +299,16 @@ export declare const GetUser: import("graphql").DocumentNode;
|
|
293
299
|
export declare const GetUserByIdentifier: import("graphql").DocumentNode;
|
294
300
|
export declare const QueryUsers: import("graphql").DocumentNode;
|
295
301
|
export declare const UpdateUser: import("graphql").DocumentNode;
|
302
|
+
export declare const CountViews: import("graphql").DocumentNode;
|
303
|
+
export declare const CreateView: import("graphql").DocumentNode;
|
304
|
+
export declare const DeleteAllViews: import("graphql").DocumentNode;
|
305
|
+
export declare const DeleteView: import("graphql").DocumentNode;
|
306
|
+
export declare const DeleteViews: import("graphql").DocumentNode;
|
307
|
+
export declare const GetView: import("graphql").DocumentNode;
|
308
|
+
export declare const QueryViews: import("graphql").DocumentNode;
|
309
|
+
export declare const UpdateView: import("graphql").DocumentNode;
|
310
|
+
export declare const UpsertView: import("graphql").DocumentNode;
|
311
|
+
export declare const ViewExists: import("graphql").DocumentNode;
|
296
312
|
export declare const CountWorkflows: import("graphql").DocumentNode;
|
297
313
|
export declare const CreateWorkflow: import("graphql").DocumentNode;
|
298
314
|
export declare const DeleteAllWorkflows: import("graphql").DocumentNode;
|