graphlit-client 1.0.20250615001 → 1.0.20250615002
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/model-mapping.js
CHANGED
@@ -106,8 +106,8 @@ const COHERE_MODEL_MAP = {
|
|
106
106
|
[Types.CohereModels.CommandR_202403]: "command-r-03-2024",
|
107
107
|
[Types.CohereModels.CommandR_202408]: "command-r-08-2024",
|
108
108
|
[Types.CohereModels.CommandR7B_202412]: "command-r7b-12-2024",
|
109
|
-
[Types.CohereModels.CommandA]: "command-
|
110
|
-
[Types.CohereModels.CommandA_202503]: "command-
|
109
|
+
[Types.CohereModels.CommandA]: "command-a-03-2025",
|
110
|
+
[Types.CohereModels.CommandA_202503]: "command-a-03-2025",
|
111
111
|
};
|
112
112
|
// Mistral model mappings
|
113
113
|
const MISTRAL_MODEL_MAP = {
|
@@ -81,8 +81,23 @@ export declare function formatMessagesForGoogle(messages: ConversationMessage[])
|
|
81
81
|
* Cohere message format
|
82
82
|
*/
|
83
83
|
export interface CohereMessage {
|
84
|
-
role: "
|
85
|
-
|
84
|
+
role: "user" | "assistant" | "system" | "tool";
|
85
|
+
content: string;
|
86
|
+
tool_calls?: Array<{
|
87
|
+
id: string;
|
88
|
+
name: string;
|
89
|
+
parameters: Record<string, any>;
|
90
|
+
}>;
|
91
|
+
tool_results?: Array<{
|
92
|
+
call: {
|
93
|
+
id: string;
|
94
|
+
name: string;
|
95
|
+
parameters: Record<string, any>;
|
96
|
+
};
|
97
|
+
outputs: Array<{
|
98
|
+
text: string;
|
99
|
+
}>;
|
100
|
+
}>;
|
86
101
|
}
|
87
102
|
/**
|
88
103
|
* Format GraphQL conversation messages for Cohere SDK
|
@@ -273,26 +273,59 @@ export function formatMessagesForGoogle(messages) {
|
|
273
273
|
export function formatMessagesForCohere(messages) {
|
274
274
|
const formattedMessages = [];
|
275
275
|
for (const message of messages) {
|
276
|
-
if (!message.role
|
276
|
+
if (!message.role)
|
277
277
|
continue;
|
278
|
-
|
278
|
+
// Allow messages with tool calls even if they have no text content
|
279
|
+
const hasContent = message.message?.trim();
|
280
|
+
const hasToolCalls = message.toolCalls && message.toolCalls.length > 0;
|
281
|
+
if (!hasContent && !hasToolCalls)
|
282
|
+
continue;
|
283
|
+
const trimmedMessage = message.message?.trim() || "";
|
279
284
|
switch (message.role) {
|
280
285
|
case ConversationRoleTypes.System:
|
281
286
|
formattedMessages.push({
|
282
|
-
role: "
|
283
|
-
|
287
|
+
role: "system",
|
288
|
+
content: trimmedMessage,
|
284
289
|
});
|
285
290
|
break;
|
286
291
|
case ConversationRoleTypes.Assistant:
|
292
|
+
const assistantMessage = {
|
293
|
+
role: "assistant",
|
294
|
+
content: trimmedMessage,
|
295
|
+
};
|
296
|
+
// Add tool calls if present
|
297
|
+
if (message.toolCalls && message.toolCalls.length > 0) {
|
298
|
+
assistantMessage.tool_calls = message.toolCalls
|
299
|
+
.filter((tc) => tc !== null)
|
300
|
+
.map((toolCall) => ({
|
301
|
+
id: toolCall.id,
|
302
|
+
name: toolCall.name,
|
303
|
+
parameters: toolCall.arguments ? JSON.parse(toolCall.arguments) : {},
|
304
|
+
}));
|
305
|
+
}
|
306
|
+
formattedMessages.push(assistantMessage);
|
307
|
+
break;
|
308
|
+
case ConversationRoleTypes.Tool:
|
309
|
+
// Cohere expects tool results as tool messages
|
287
310
|
formattedMessages.push({
|
288
|
-
role: "
|
289
|
-
|
311
|
+
role: "tool",
|
312
|
+
content: trimmedMessage,
|
313
|
+
tool_results: [{
|
314
|
+
call: {
|
315
|
+
id: message.toolCallId || "",
|
316
|
+
name: "", // Would need to be tracked from the tool call
|
317
|
+
parameters: {},
|
318
|
+
},
|
319
|
+
outputs: [{
|
320
|
+
text: trimmedMessage,
|
321
|
+
}],
|
322
|
+
}],
|
290
323
|
});
|
291
324
|
break;
|
292
325
|
default: // User messages
|
293
326
|
formattedMessages.push({
|
294
|
-
role: "
|
295
|
-
|
327
|
+
role: "user",
|
328
|
+
content: trimmedMessage,
|
296
329
|
});
|
297
330
|
break;
|
298
331
|
}
|
@@ -27,6 +27,15 @@ function cleanSchemaForGoogle(schema) {
|
|
27
27
|
if (key === "$schema" || key === "additionalProperties") {
|
28
28
|
continue;
|
29
29
|
}
|
30
|
+
// Handle format field for string types - Google only supports 'enum' and 'date-time'
|
31
|
+
if (key === "format" && typeof value === "string") {
|
32
|
+
// Only keep supported formats
|
33
|
+
if (value === "enum" || value === "date-time") {
|
34
|
+
cleaned[key] = value;
|
35
|
+
}
|
36
|
+
// Skip unsupported formats like "date", "time", "email", etc.
|
37
|
+
continue;
|
38
|
+
}
|
30
39
|
// Recursively clean nested objects
|
31
40
|
cleaned[key] = cleanSchemaForGoogle(value);
|
32
41
|
}
|
@@ -1215,15 +1224,21 @@ onEvent, onComplete) {
|
|
1215
1224
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
1216
1225
|
console.log(`🤖 [Cohere] Model Config: Service=Cohere | Model=${modelName} | Temperature=${specification.cohere?.temperature} | Tools=${tools?.length || 0} | Spec="${specification.name}"`);
|
1217
1226
|
}
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1227
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
1228
|
+
console.log(`🔍 [Cohere] Messages array length: ${messages.length}`);
|
1229
|
+
console.log(`🔍 [Cohere] All messages:`, JSON.stringify(messages, null, 2));
|
1230
|
+
}
|
1231
|
+
if (messages.length === 0) {
|
1232
|
+
throw new Error("No messages found for Cohere streaming");
|
1233
|
+
}
|
1221
1234
|
const streamConfig = {
|
1222
1235
|
model: modelName,
|
1223
|
-
|
1224
|
-
chatHistory: chatHistory,
|
1225
|
-
temperature: specification.cohere?.temperature,
|
1236
|
+
messages: messages, // All messages in chronological order
|
1226
1237
|
};
|
1238
|
+
// Only add temperature if it's defined
|
1239
|
+
if (specification.cohere?.temperature !== undefined) {
|
1240
|
+
streamConfig.temperature = specification.cohere.temperature;
|
1241
|
+
}
|
1227
1242
|
// Add tools if provided
|
1228
1243
|
if (tools && tools.length > 0) {
|
1229
1244
|
streamConfig.tools = tools.map((tool) => {
|
@@ -1231,41 +1246,71 @@ onEvent, onComplete) {
|
|
1231
1246
|
return {
|
1232
1247
|
name: tool.name,
|
1233
1248
|
description: tool.description,
|
1234
|
-
|
1249
|
+
parameter_definitions: {},
|
1235
1250
|
};
|
1236
1251
|
}
|
1237
1252
|
// Parse the JSON schema
|
1238
1253
|
const schema = JSON.parse(tool.schema);
|
1239
1254
|
// Convert JSON Schema to Cohere's expected format
|
1240
|
-
const
|
1255
|
+
const parameter_definitions = {};
|
1241
1256
|
if (schema.properties) {
|
1242
1257
|
for (const [key, value] of Object.entries(schema.properties)) {
|
1243
1258
|
const prop = value;
|
1244
|
-
|
1259
|
+
const paramDef = {
|
1245
1260
|
type: prop.type || "string",
|
1246
1261
|
description: prop.description || "",
|
1247
1262
|
required: schema.required?.includes(key) || false,
|
1248
1263
|
};
|
1249
1264
|
// Add additional properties that Cohere might expect
|
1250
1265
|
if (prop.enum) {
|
1251
|
-
|
1266
|
+
paramDef.options = prop.enum;
|
1252
1267
|
}
|
1253
1268
|
if (prop.default !== undefined) {
|
1254
|
-
|
1269
|
+
paramDef.default = prop.default;
|
1255
1270
|
}
|
1256
1271
|
if (prop.items) {
|
1257
|
-
|
1272
|
+
paramDef.items = prop.items;
|
1258
1273
|
}
|
1274
|
+
parameter_definitions[key] = paramDef;
|
1259
1275
|
}
|
1260
1276
|
}
|
1261
1277
|
return {
|
1262
1278
|
name: tool.name,
|
1263
1279
|
description: tool.description,
|
1264
|
-
|
1280
|
+
parameter_definitions, // Use snake_case as expected by Cohere API
|
1265
1281
|
};
|
1266
1282
|
});
|
1267
1283
|
}
|
1268
|
-
|
1284
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
1285
|
+
console.log(`🔍 [Cohere] Final stream config:`, JSON.stringify(streamConfig, null, 2));
|
1286
|
+
console.log(`🔍 [Cohere] Cohere client methods available:`, Object.getOwnPropertyNames(cohereClient));
|
1287
|
+
console.log(`🔍 [Cohere] Has chatStream method:`, typeof cohereClient.chatStream === 'function');
|
1288
|
+
console.log(`🔍 [Cohere] Has chat property:`, !!cohereClient.chat);
|
1289
|
+
if (cohereClient.chat) {
|
1290
|
+
console.log(`🔍 [Cohere] Chat methods:`, Object.getOwnPropertyNames(cohereClient.chat));
|
1291
|
+
}
|
1292
|
+
console.log(`⏱️ [Cohere] Starting stream request at: ${new Date().toISOString()}`);
|
1293
|
+
}
|
1294
|
+
let stream;
|
1295
|
+
try {
|
1296
|
+
stream = await cohereClient.chatStream(streamConfig);
|
1297
|
+
}
|
1298
|
+
catch (streamError) {
|
1299
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
1300
|
+
console.error(`❌ [Cohere] Stream creation failed:`, streamError);
|
1301
|
+
if (streamError.response) {
|
1302
|
+
console.error(`❌ [Cohere] Stream response status: ${streamError.response.status}`);
|
1303
|
+
console.error(`❌ [Cohere] Stream response data:`, streamError.response.data);
|
1304
|
+
}
|
1305
|
+
if (streamError.status) {
|
1306
|
+
console.error(`❌ [Cohere] Direct status: ${streamError.status}`);
|
1307
|
+
}
|
1308
|
+
if (streamError.body) {
|
1309
|
+
console.error(`❌ [Cohere] Response body:`, streamError.body);
|
1310
|
+
}
|
1311
|
+
}
|
1312
|
+
throw streamError;
|
1313
|
+
}
|
1269
1314
|
for await (const chunk of stream) {
|
1270
1315
|
if (chunk.eventType === "text-generation") {
|
1271
1316
|
const text = chunk.text;
|
@@ -1313,6 +1358,18 @@ onEvent, onComplete) {
|
|
1313
1358
|
onComplete(fullMessage, toolCalls);
|
1314
1359
|
}
|
1315
1360
|
catch (error) {
|
1361
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
1362
|
+
console.error(`❌ [Cohere] Stream error:`, error);
|
1363
|
+
if (error instanceof Error) {
|
1364
|
+
console.error(`❌ [Cohere] Error message: ${error.message}`);
|
1365
|
+
console.error(`❌ [Cohere] Error stack: ${error.stack}`);
|
1366
|
+
}
|
1367
|
+
// Log additional error details if available
|
1368
|
+
if (error.response) {
|
1369
|
+
console.error(`❌ [Cohere] Response status: ${error.response.status}`);
|
1370
|
+
console.error(`❌ [Cohere] Response data:`, error.response.data);
|
1371
|
+
}
|
1372
|
+
}
|
1316
1373
|
throw error;
|
1317
1374
|
}
|
1318
1375
|
}
|