lemura 1.4.0 → 1.4.2

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/index.mjs CHANGED
@@ -206,10 +206,36 @@ var OpenAICompatibleAdapter = class {
206
206
  if (r === "content_filter" || r === "error") return "error";
207
207
  return "stop";
208
208
  }
209
+ toOpenAIMessages(messages) {
210
+ return messages.map((msg) => {
211
+ if (msg.role === "assistant" && msg.toolCalls?.length) {
212
+ return {
213
+ role: "assistant",
214
+ content: msg.content || null,
215
+ tool_calls: msg.toolCalls.map((tc) => ({
216
+ id: tc.id,
217
+ type: "function",
218
+ function: {
219
+ name: tc.name,
220
+ arguments: typeof tc.arguments === "string" ? tc.arguments : JSON.stringify(tc.arguments)
221
+ }
222
+ }))
223
+ };
224
+ }
225
+ if (msg.role === "tool") {
226
+ return {
227
+ role: "tool",
228
+ tool_call_id: msg.name,
229
+ content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
230
+ };
231
+ }
232
+ return msg;
233
+ });
234
+ }
209
235
  buildPayload(request) {
210
236
  const payload = {
211
237
  model: request.model || this.defaultModel,
212
- messages: request.messages
238
+ messages: this.toOpenAIMessages(request.messages)
213
239
  };
214
240
  if (request.maxTokens !== void 0) payload.max_tokens = request.maxTokens;
215
241
  if (request.temperature !== void 0) payload.temperature = request.temperature;
@@ -2278,7 +2304,11 @@ var MCPClient = class {
2278
2304
  try {
2279
2305
  const res = await fetch(url, {
2280
2306
  method: "POST",
2281
- headers: { "Content-Type": "application/json", "Accept": "application/json" },
2307
+ headers: {
2308
+ "Content-Type": "application/json",
2309
+ "Accept": "application/json",
2310
+ ...this.config.headers
2311
+ },
2282
2312
  body: JSON.stringify(request),
2283
2313
  signal: controller.signal
2284
2314
  });
@@ -2337,7 +2367,10 @@ var MCPClient = class {
2337
2367
  } else if (this.config.transport !== "stdio") {
2338
2368
  fetch(this.config.url, {
2339
2369
  method: "POST",
2340
- headers: { "Content-Type": "application/json" },
2370
+ headers: {
2371
+ "Content-Type": "application/json",
2372
+ ...this.config.headers
2373
+ },
2341
2374
  body: initializedNotif
2342
2375
  }).catch(() => {
2343
2376
  });