@yourgpt/llm-sdk 2.1.5 → 2.1.6

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.
Files changed (41) hide show
  1. package/dist/adapters/index.d.mts +11 -37
  2. package/dist/adapters/index.d.ts +11 -37
  3. package/dist/adapters/index.js +41 -192
  4. package/dist/adapters/index.mjs +42 -192
  5. package/dist/{base-5n-UuPfS.d.mts → base-D-U61JaB.d.mts} +22 -2
  6. package/dist/{base-Di31iy_8.d.ts → base-iGi9Va6Z.d.ts} +22 -2
  7. package/dist/fallback/index.d.mts +3 -3
  8. package/dist/fallback/index.d.ts +3 -3
  9. package/dist/index.d.mts +5 -5
  10. package/dist/index.d.ts +5 -5
  11. package/dist/index.js +96 -76
  12. package/dist/index.mjs +96 -76
  13. package/dist/providers/anthropic/index.d.mts +2 -2
  14. package/dist/providers/anthropic/index.d.ts +2 -2
  15. package/dist/providers/azure/index.d.mts +2 -2
  16. package/dist/providers/azure/index.d.ts +2 -2
  17. package/dist/providers/azure/index.js +4 -2
  18. package/dist/providers/azure/index.mjs +4 -2
  19. package/dist/providers/google/index.d.mts +2 -2
  20. package/dist/providers/google/index.d.ts +2 -2
  21. package/dist/providers/google/index.js +527 -339
  22. package/dist/providers/google/index.mjs +527 -339
  23. package/dist/providers/ollama/index.d.mts +3 -3
  24. package/dist/providers/ollama/index.d.ts +3 -3
  25. package/dist/providers/openai/index.d.mts +2 -2
  26. package/dist/providers/openai/index.d.ts +2 -2
  27. package/dist/providers/openai/index.js +34 -11
  28. package/dist/providers/openai/index.mjs +34 -11
  29. package/dist/providers/openrouter/index.d.mts +2 -2
  30. package/dist/providers/openrouter/index.d.ts +2 -2
  31. package/dist/providers/openrouter/index.js +34 -11
  32. package/dist/providers/openrouter/index.mjs +34 -11
  33. package/dist/providers/xai/index.d.mts +2 -2
  34. package/dist/providers/xai/index.d.ts +2 -2
  35. package/dist/providers/xai/index.js +355 -46
  36. package/dist/providers/xai/index.mjs +355 -46
  37. package/dist/{types-CNL8ZRne.d.ts → types-38yolWJn.d.ts} +1 -1
  38. package/dist/{types-C0vLXzuw.d.ts → types-BctsnC3g.d.ts} +1 -1
  39. package/dist/{types-BQl1suAv.d.mts → types-D4YfrQJR.d.mts} +1 -1
  40. package/dist/{types-VDgiUvH2.d.mts → types-DRqxMIjF.d.mts} +1 -1
  41. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2165,6 +2165,8 @@ var Runtime = class {
2165
2165
  let accumulatedText = "";
2166
2166
  const toolCalls = [];
2167
2167
  let currentToolCall = null;
2168
+ const serverToolResults = [];
2169
+ const toolContextData = "toolContext" in this.config ? this.config.toolContext : void 0;
2168
2170
  let adapterUsage;
2169
2171
  const completionRequest = {
2170
2172
  messages: [],
@@ -2183,6 +2185,8 @@ var Runtime = class {
2183
2185
  for await (const event of stream) {
2184
2186
  switch (event.type) {
2185
2187
  case "message:start":
2188
+ yield event;
2189
+ break;
2186
2190
  case "message:end":
2187
2191
  yield event;
2188
2192
  break;
@@ -2191,7 +2195,12 @@ var Runtime = class {
2191
2195
  yield event;
2192
2196
  break;
2193
2197
  case "action:start":
2194
- currentToolCall = { id: event.id, name: event.name, args: "" };
2198
+ currentToolCall = {
2199
+ id: event.id,
2200
+ name: event.name,
2201
+ args: "",
2202
+ ...event.extra_content ? { extra_content: event.extra_content } : {}
2203
+ };
2195
2204
  if (debug) {
2196
2205
  console.log(`[Copilot SDK] Tool call started: ${event.name}`);
2197
2206
  }
@@ -2210,7 +2219,8 @@ var Runtime = class {
2210
2219
  toolCalls.push({
2211
2220
  id: currentToolCall.id,
2212
2221
  name: currentToolCall.name,
2213
- args: parsedArgs
2222
+ args: parsedArgs,
2223
+ ...currentToolCall.extra_content ? { extra_content: currentToolCall.extra_content } : {}
2214
2224
  });
2215
2225
  } catch (e) {
2216
2226
  console.error(
@@ -2221,13 +2231,71 @@ var Runtime = class {
2221
2231
  toolCalls.push({
2222
2232
  id: currentToolCall.id,
2223
2233
  name: currentToolCall.name,
2224
- args: {}
2234
+ args: {},
2235
+ ...currentToolCall.extra_content ? { extra_content: currentToolCall.extra_content } : {}
2225
2236
  });
2226
2237
  }
2227
2238
  currentToolCall = null;
2228
2239
  }
2229
2240
  yield event;
2230
2241
  break;
2242
+ case "action:end": {
2243
+ const toolName = event.name;
2244
+ const tool2 = toolName ? selectedToolMap.get(toolName) : void 0;
2245
+ if (tool2?.location === "server" && tool2.handler) {
2246
+ if (debug) {
2247
+ console.log(
2248
+ `[Copilot SDK] Executing server-side tool: ${toolName}`
2249
+ );
2250
+ }
2251
+ const tc = toolCalls.find((t) => t.id === event.id);
2252
+ const args = tc?.args ?? {};
2253
+ const toolContext = buildToolContext(
2254
+ event.id,
2255
+ signal,
2256
+ request.threadId,
2257
+ _httpRequest,
2258
+ toolContextData
2259
+ );
2260
+ try {
2261
+ const result = await tool2.handler(args, toolContext);
2262
+ serverToolResults.push({
2263
+ id: event.id,
2264
+ name: toolName,
2265
+ args,
2266
+ result,
2267
+ tool: tool2
2268
+ });
2269
+ yield {
2270
+ type: "action:end",
2271
+ id: event.id,
2272
+ name: toolName,
2273
+ result
2274
+ };
2275
+ } catch (error) {
2276
+ const errorResult = {
2277
+ success: false,
2278
+ error: error instanceof Error ? error.message : "Tool execution failed"
2279
+ };
2280
+ serverToolResults.push({
2281
+ id: event.id,
2282
+ name: toolName,
2283
+ args,
2284
+ result: errorResult,
2285
+ tool: tool2
2286
+ });
2287
+ yield {
2288
+ type: "action:end",
2289
+ id: event.id,
2290
+ name: toolName,
2291
+ error: error instanceof Error ? error.message : "Tool execution failed"
2292
+ };
2293
+ }
2294
+ } else {
2295
+ yield event;
2296
+ }
2297
+ break;
2298
+ }
2231
2299
  case "citation":
2232
2300
  yield event;
2233
2301
  break;
@@ -2251,67 +2319,10 @@ var Runtime = class {
2251
2319
  toolCalls.map((t) => t.name)
2252
2320
  );
2253
2321
  }
2254
- const serverToolCalls = [];
2255
- const clientToolCalls = [];
2256
- for (const tc of toolCalls) {
2257
- const tool2 = selectedToolMap.get(tc.name);
2258
- if (tool2?.location === "server" && tool2.handler) {
2259
- serverToolCalls.push(tc);
2260
- } else {
2261
- clientToolCalls.push(tc);
2262
- }
2263
- }
2264
- const serverToolResults = [];
2265
- const toolContextData = "toolContext" in this.config ? this.config.toolContext : void 0;
2266
- for (const tc of serverToolCalls) {
2267
- const tool2 = selectedToolMap.get(tc.name);
2268
- if (tool2?.handler) {
2269
- if (debug) {
2270
- console.log(`[Copilot SDK] Executing server-side tool: ${tc.name}`);
2271
- }
2272
- const toolContext = buildToolContext(
2273
- tc.id,
2274
- signal,
2275
- request.threadId,
2276
- _httpRequest,
2277
- toolContextData
2278
- );
2279
- try {
2280
- const result = await tool2.handler(tc.args, toolContext);
2281
- serverToolResults.push({
2282
- id: tc.id,
2283
- name: tc.name,
2284
- args: tc.args,
2285
- result,
2286
- tool: tool2
2287
- });
2288
- yield {
2289
- type: "action:end",
2290
- id: tc.id,
2291
- name: tc.name,
2292
- result
2293
- };
2294
- } catch (error) {
2295
- const errorResult = {
2296
- success: false,
2297
- error: error instanceof Error ? error.message : "Tool execution failed"
2298
- };
2299
- serverToolResults.push({
2300
- id: tc.id,
2301
- name: tc.name,
2302
- args: tc.args,
2303
- result: errorResult,
2304
- tool: tool2
2305
- });
2306
- yield {
2307
- type: "action:end",
2308
- id: tc.id,
2309
- name: tc.name,
2310
- error: error instanceof Error ? error.message : "Tool execution failed"
2311
- };
2312
- }
2313
- }
2314
- }
2322
+ const serverToolIds = new Set(serverToolResults.map((r) => r.id));
2323
+ const clientToolCalls = toolCalls.filter(
2324
+ (tc) => !serverToolIds.has(tc.id)
2325
+ );
2315
2326
  if (serverToolResults.length > 0) {
2316
2327
  if (debug) {
2317
2328
  console.log(
@@ -2321,14 +2332,18 @@ var Runtime = class {
2321
2332
  const assistantWithToolCalls = {
2322
2333
  role: "assistant",
2323
2334
  content: accumulatedText || null,
2324
- tool_calls: serverToolCalls.map((tc) => ({
2325
- id: tc.id,
2326
- type: "function",
2327
- function: {
2328
- name: tc.name,
2329
- arguments: JSON.stringify(tc.args)
2330
- }
2331
- }))
2335
+ tool_calls: serverToolResults.map((tr) => {
2336
+ const tc = toolCalls.find((t) => t.id === tr.id);
2337
+ return {
2338
+ id: tr.id,
2339
+ type: "function",
2340
+ function: {
2341
+ name: tr.name,
2342
+ arguments: JSON.stringify(tr.args)
2343
+ },
2344
+ ...tc?.extra_content ? { extra_content: tc.extra_content } : {}
2345
+ };
2346
+ })
2332
2347
  };
2333
2348
  const toolResultMessages = serverToolResults.map(
2334
2349
  (tr) => {
@@ -2359,7 +2374,6 @@ var Runtime = class {
2359
2374
  result: result.result
2360
2375
  }))
2361
2376
  );
2362
- yield { type: "message:end" };
2363
2377
  for await (const event of this.processChatWithLoop(
2364
2378
  nextRequest,
2365
2379
  signal,
@@ -2383,7 +2397,8 @@ var Runtime = class {
2383
2397
  function: {
2384
2398
  name: tc.name,
2385
2399
  arguments: JSON.stringify(tc.args)
2386
- }
2400
+ },
2401
+ ...tc.extra_content ? { extra_content: tc.extra_content } : {}
2387
2402
  }))
2388
2403
  };
2389
2404
  newMessages.push(assistantMessage);
@@ -2602,7 +2617,8 @@ var Runtime = class {
2602
2617
  function: {
2603
2618
  name: tc.name,
2604
2619
  arguments: JSON.stringify(tc.args)
2605
- }
2620
+ },
2621
+ ...tc.extra_content ? { extra_content: tc.extra_content } : {}
2606
2622
  }))
2607
2623
  };
2608
2624
  const toolResultMessages = serverToolResults.map((tr) => {
@@ -2644,7 +2660,8 @@ var Runtime = class {
2644
2660
  function: {
2645
2661
  name: tc.name,
2646
2662
  arguments: JSON.stringify(tc.args)
2647
- }
2663
+ },
2664
+ ...tc.extra_content ? { extra_content: tc.extra_content } : {}
2648
2665
  }))
2649
2666
  };
2650
2667
  newMessages.push(assistantMessage);
@@ -2820,6 +2837,9 @@ var Runtime = class {
2820
2837
  storageHealthy = false;
2821
2838
  }
2822
2839
  }
2840
+ if (resolvedThreadId) {
2841
+ yield { type: "thread:created", threadId: resolvedThreadId };
2842
+ }
2823
2843
  if (resolvedThreadId && storageHealthy) {
2824
2844
  try {
2825
2845
  const inputMsgs = extractInputMessages(request.messages);
package/dist/index.mjs CHANGED
@@ -2163,6 +2163,8 @@ var Runtime = class {
2163
2163
  let accumulatedText = "";
2164
2164
  const toolCalls = [];
2165
2165
  let currentToolCall = null;
2166
+ const serverToolResults = [];
2167
+ const toolContextData = "toolContext" in this.config ? this.config.toolContext : void 0;
2166
2168
  let adapterUsage;
2167
2169
  const completionRequest = {
2168
2170
  messages: [],
@@ -2181,6 +2183,8 @@ var Runtime = class {
2181
2183
  for await (const event of stream) {
2182
2184
  switch (event.type) {
2183
2185
  case "message:start":
2186
+ yield event;
2187
+ break;
2184
2188
  case "message:end":
2185
2189
  yield event;
2186
2190
  break;
@@ -2189,7 +2193,12 @@ var Runtime = class {
2189
2193
  yield event;
2190
2194
  break;
2191
2195
  case "action:start":
2192
- currentToolCall = { id: event.id, name: event.name, args: "" };
2196
+ currentToolCall = {
2197
+ id: event.id,
2198
+ name: event.name,
2199
+ args: "",
2200
+ ...event.extra_content ? { extra_content: event.extra_content } : {}
2201
+ };
2193
2202
  if (debug) {
2194
2203
  console.log(`[Copilot SDK] Tool call started: ${event.name}`);
2195
2204
  }
@@ -2208,7 +2217,8 @@ var Runtime = class {
2208
2217
  toolCalls.push({
2209
2218
  id: currentToolCall.id,
2210
2219
  name: currentToolCall.name,
2211
- args: parsedArgs
2220
+ args: parsedArgs,
2221
+ ...currentToolCall.extra_content ? { extra_content: currentToolCall.extra_content } : {}
2212
2222
  });
2213
2223
  } catch (e) {
2214
2224
  console.error(
@@ -2219,13 +2229,71 @@ var Runtime = class {
2219
2229
  toolCalls.push({
2220
2230
  id: currentToolCall.id,
2221
2231
  name: currentToolCall.name,
2222
- args: {}
2232
+ args: {},
2233
+ ...currentToolCall.extra_content ? { extra_content: currentToolCall.extra_content } : {}
2223
2234
  });
2224
2235
  }
2225
2236
  currentToolCall = null;
2226
2237
  }
2227
2238
  yield event;
2228
2239
  break;
2240
+ case "action:end": {
2241
+ const toolName = event.name;
2242
+ const tool2 = toolName ? selectedToolMap.get(toolName) : void 0;
2243
+ if (tool2?.location === "server" && tool2.handler) {
2244
+ if (debug) {
2245
+ console.log(
2246
+ `[Copilot SDK] Executing server-side tool: ${toolName}`
2247
+ );
2248
+ }
2249
+ const tc = toolCalls.find((t) => t.id === event.id);
2250
+ const args = tc?.args ?? {};
2251
+ const toolContext = buildToolContext(
2252
+ event.id,
2253
+ signal,
2254
+ request.threadId,
2255
+ _httpRequest,
2256
+ toolContextData
2257
+ );
2258
+ try {
2259
+ const result = await tool2.handler(args, toolContext);
2260
+ serverToolResults.push({
2261
+ id: event.id,
2262
+ name: toolName,
2263
+ args,
2264
+ result,
2265
+ tool: tool2
2266
+ });
2267
+ yield {
2268
+ type: "action:end",
2269
+ id: event.id,
2270
+ name: toolName,
2271
+ result
2272
+ };
2273
+ } catch (error) {
2274
+ const errorResult = {
2275
+ success: false,
2276
+ error: error instanceof Error ? error.message : "Tool execution failed"
2277
+ };
2278
+ serverToolResults.push({
2279
+ id: event.id,
2280
+ name: toolName,
2281
+ args,
2282
+ result: errorResult,
2283
+ tool: tool2
2284
+ });
2285
+ yield {
2286
+ type: "action:end",
2287
+ id: event.id,
2288
+ name: toolName,
2289
+ error: error instanceof Error ? error.message : "Tool execution failed"
2290
+ };
2291
+ }
2292
+ } else {
2293
+ yield event;
2294
+ }
2295
+ break;
2296
+ }
2229
2297
  case "citation":
2230
2298
  yield event;
2231
2299
  break;
@@ -2249,67 +2317,10 @@ var Runtime = class {
2249
2317
  toolCalls.map((t) => t.name)
2250
2318
  );
2251
2319
  }
2252
- const serverToolCalls = [];
2253
- const clientToolCalls = [];
2254
- for (const tc of toolCalls) {
2255
- const tool2 = selectedToolMap.get(tc.name);
2256
- if (tool2?.location === "server" && tool2.handler) {
2257
- serverToolCalls.push(tc);
2258
- } else {
2259
- clientToolCalls.push(tc);
2260
- }
2261
- }
2262
- const serverToolResults = [];
2263
- const toolContextData = "toolContext" in this.config ? this.config.toolContext : void 0;
2264
- for (const tc of serverToolCalls) {
2265
- const tool2 = selectedToolMap.get(tc.name);
2266
- if (tool2?.handler) {
2267
- if (debug) {
2268
- console.log(`[Copilot SDK] Executing server-side tool: ${tc.name}`);
2269
- }
2270
- const toolContext = buildToolContext(
2271
- tc.id,
2272
- signal,
2273
- request.threadId,
2274
- _httpRequest,
2275
- toolContextData
2276
- );
2277
- try {
2278
- const result = await tool2.handler(tc.args, toolContext);
2279
- serverToolResults.push({
2280
- id: tc.id,
2281
- name: tc.name,
2282
- args: tc.args,
2283
- result,
2284
- tool: tool2
2285
- });
2286
- yield {
2287
- type: "action:end",
2288
- id: tc.id,
2289
- name: tc.name,
2290
- result
2291
- };
2292
- } catch (error) {
2293
- const errorResult = {
2294
- success: false,
2295
- error: error instanceof Error ? error.message : "Tool execution failed"
2296
- };
2297
- serverToolResults.push({
2298
- id: tc.id,
2299
- name: tc.name,
2300
- args: tc.args,
2301
- result: errorResult,
2302
- tool: tool2
2303
- });
2304
- yield {
2305
- type: "action:end",
2306
- id: tc.id,
2307
- name: tc.name,
2308
- error: error instanceof Error ? error.message : "Tool execution failed"
2309
- };
2310
- }
2311
- }
2312
- }
2320
+ const serverToolIds = new Set(serverToolResults.map((r) => r.id));
2321
+ const clientToolCalls = toolCalls.filter(
2322
+ (tc) => !serverToolIds.has(tc.id)
2323
+ );
2313
2324
  if (serverToolResults.length > 0) {
2314
2325
  if (debug) {
2315
2326
  console.log(
@@ -2319,14 +2330,18 @@ var Runtime = class {
2319
2330
  const assistantWithToolCalls = {
2320
2331
  role: "assistant",
2321
2332
  content: accumulatedText || null,
2322
- tool_calls: serverToolCalls.map((tc) => ({
2323
- id: tc.id,
2324
- type: "function",
2325
- function: {
2326
- name: tc.name,
2327
- arguments: JSON.stringify(tc.args)
2328
- }
2329
- }))
2333
+ tool_calls: serverToolResults.map((tr) => {
2334
+ const tc = toolCalls.find((t) => t.id === tr.id);
2335
+ return {
2336
+ id: tr.id,
2337
+ type: "function",
2338
+ function: {
2339
+ name: tr.name,
2340
+ arguments: JSON.stringify(tr.args)
2341
+ },
2342
+ ...tc?.extra_content ? { extra_content: tc.extra_content } : {}
2343
+ };
2344
+ })
2330
2345
  };
2331
2346
  const toolResultMessages = serverToolResults.map(
2332
2347
  (tr) => {
@@ -2357,7 +2372,6 @@ var Runtime = class {
2357
2372
  result: result.result
2358
2373
  }))
2359
2374
  );
2360
- yield { type: "message:end" };
2361
2375
  for await (const event of this.processChatWithLoop(
2362
2376
  nextRequest,
2363
2377
  signal,
@@ -2381,7 +2395,8 @@ var Runtime = class {
2381
2395
  function: {
2382
2396
  name: tc.name,
2383
2397
  arguments: JSON.stringify(tc.args)
2384
- }
2398
+ },
2399
+ ...tc.extra_content ? { extra_content: tc.extra_content } : {}
2385
2400
  }))
2386
2401
  };
2387
2402
  newMessages.push(assistantMessage);
@@ -2600,7 +2615,8 @@ var Runtime = class {
2600
2615
  function: {
2601
2616
  name: tc.name,
2602
2617
  arguments: JSON.stringify(tc.args)
2603
- }
2618
+ },
2619
+ ...tc.extra_content ? { extra_content: tc.extra_content } : {}
2604
2620
  }))
2605
2621
  };
2606
2622
  const toolResultMessages = serverToolResults.map((tr) => {
@@ -2642,7 +2658,8 @@ var Runtime = class {
2642
2658
  function: {
2643
2659
  name: tc.name,
2644
2660
  arguments: JSON.stringify(tc.args)
2645
- }
2661
+ },
2662
+ ...tc.extra_content ? { extra_content: tc.extra_content } : {}
2646
2663
  }))
2647
2664
  };
2648
2665
  newMessages.push(assistantMessage);
@@ -2818,6 +2835,9 @@ var Runtime = class {
2818
2835
  storageHealthy = false;
2819
2836
  }
2820
2837
  }
2838
+ if (resolvedThreadId) {
2839
+ yield { type: "thread:created", threadId: resolvedThreadId };
2840
+ }
2821
2841
  if (resolvedThreadId && storageHealthy) {
2822
2842
  try {
2823
2843
  const inputMsgs = extractInputMessages(request.messages);
@@ -1,7 +1,7 @@
1
1
  import { L as LanguageModel } from '../../types-CR8mi9I0.mjs';
2
- import { a as AnthropicProviderConfig, A as AIProvider } from '../../types-VDgiUvH2.mjs';
2
+ import { a as AnthropicProviderConfig, A as AIProvider } from '../../types-DRqxMIjF.mjs';
3
3
  import 'zod';
4
- import '../../base-5n-UuPfS.mjs';
4
+ import '../../base-D-U61JaB.mjs';
5
5
 
6
6
  /**
7
7
  * Anthropic Provider - Modern Pattern
@@ -1,7 +1,7 @@
1
1
  import { L as LanguageModel } from '../../types-CR8mi9I0.js';
2
- import { a as AnthropicProviderConfig, A as AIProvider } from '../../types-C0vLXzuw.js';
2
+ import { a as AnthropicProviderConfig, A as AIProvider } from '../../types-BctsnC3g.js';
3
3
  import 'zod';
4
- import '../../base-Di31iy_8.js';
4
+ import '../../base-iGi9Va6Z.js';
5
5
 
6
6
  /**
7
7
  * Anthropic Provider - Modern Pattern
@@ -1,5 +1,5 @@
1
- import { b as AzureProviderConfig, A as AIProvider } from '../../types-VDgiUvH2.mjs';
2
- import '../../base-5n-UuPfS.mjs';
1
+ import { b as AzureProviderConfig, A as AIProvider } from '../../types-DRqxMIjF.mjs';
2
+ import '../../base-D-U61JaB.mjs';
3
3
  import '../../types-CR8mi9I0.mjs';
4
4
  import 'zod';
5
5
 
@@ -1,5 +1,5 @@
1
- import { b as AzureProviderConfig, A as AIProvider } from '../../types-C0vLXzuw.js';
2
- import '../../base-Di31iy_8.js';
1
+ import { b as AzureProviderConfig, A as AIProvider } from '../../types-BctsnC3g.js';
2
+ import '../../base-iGi9Va6Z.js';
3
3
  import '../../types-CR8mi9I0.js';
4
4
  import 'zod';
5
5
 
@@ -151,11 +151,13 @@ function formatMessagesForOpenAI(messages, systemPrompt) {
151
151
  content: messageToOpenAIContent(msg)
152
152
  });
153
153
  } else if (msg.role === "assistant") {
154
+ const hasToolCalls = msg.tool_calls && msg.tool_calls.length > 0;
154
155
  const assistantMsg = {
155
156
  role: "assistant",
156
- content: msg.content
157
+ // Gemini/xAI (OpenAI-compatible) reject content: "" on assistant messages with tool_calls
158
+ content: hasToolCalls ? msg.content || null : msg.content
157
159
  };
158
- if (msg.tool_calls && msg.tool_calls.length > 0) {
160
+ if (hasToolCalls) {
159
161
  assistantMsg.tool_calls = msg.tool_calls;
160
162
  }
161
163
  formatted.push(assistantMsg);
@@ -149,11 +149,13 @@ function formatMessagesForOpenAI(messages, systemPrompt) {
149
149
  content: messageToOpenAIContent(msg)
150
150
  });
151
151
  } else if (msg.role === "assistant") {
152
+ const hasToolCalls = msg.tool_calls && msg.tool_calls.length > 0;
152
153
  const assistantMsg = {
153
154
  role: "assistant",
154
- content: msg.content
155
+ // Gemini/xAI (OpenAI-compatible) reject content: "" on assistant messages with tool_calls
156
+ content: hasToolCalls ? msg.content || null : msg.content
155
157
  };
156
- if (msg.tool_calls && msg.tool_calls.length > 0) {
158
+ if (hasToolCalls) {
157
159
  assistantMsg.tool_calls = msg.tool_calls;
158
160
  }
159
161
  formatted.push(assistantMsg);
@@ -1,7 +1,7 @@
1
1
  import { L as LanguageModel } from '../../types-CR8mi9I0.mjs';
2
- import { G as GoogleProviderConfig, A as AIProvider } from '../../types-VDgiUvH2.mjs';
2
+ import { G as GoogleProviderConfig, A as AIProvider } from '../../types-DRqxMIjF.mjs';
3
3
  import 'zod';
4
- import '../../base-5n-UuPfS.mjs';
4
+ import '../../base-D-U61JaB.mjs';
5
5
 
6
6
  /**
7
7
  * Google Provider - OpenAI-Compatible
@@ -1,7 +1,7 @@
1
1
  import { L as LanguageModel } from '../../types-CR8mi9I0.js';
2
- import { G as GoogleProviderConfig, A as AIProvider } from '../../types-C0vLXzuw.js';
2
+ import { G as GoogleProviderConfig, A as AIProvider } from '../../types-BctsnC3g.js';
3
3
  import 'zod';
4
- import '../../base-Di31iy_8.js';
4
+ import '../../base-iGi9Va6Z.js';
5
5
 
6
6
  /**
7
7
  * Google Provider - OpenAI-Compatible