@jambonz/llm 0.6.2 → 0.6.4

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.cjs CHANGED
@@ -284,10 +284,11 @@ async function* streamFromOpenAI(client, req, options) {
284
284
  }
285
285
  yield endEvent;
286
286
  }
287
- function appendOpenAIAssistantToolCall(history, toolCalls) {
287
+ function appendOpenAIAssistantToolCall(history, toolCalls, assistantText) {
288
+ const text = assistantText?.trim() ? assistantText : null;
288
289
  const wireMessage = {
289
290
  role: "assistant",
290
- content: null,
291
+ content: text,
291
292
  tool_calls: toolCalls.map((tc) => ({
292
293
  id: tc.id,
293
294
  type: "function",
@@ -301,7 +302,7 @@ function appendOpenAIAssistantToolCall(history, toolCalls) {
301
302
  ...history,
302
303
  {
303
304
  role: "assistant",
304
- content: "",
305
+ content: text ?? "",
305
306
  vendorRaw: wireMessage
306
307
  }
307
308
  ];
@@ -572,8 +573,8 @@ var OpenAIAdapter = class {
572
573
  includeCacheKey: this.forwardCacheKey()
573
574
  });
574
575
  }
575
- appendAssistantToolCall(history, toolCalls) {
576
- return appendOpenAIAssistantToolCall(history, toolCalls);
576
+ appendAssistantToolCall(history, toolCalls, assistantText) {
577
+ return appendOpenAIAssistantToolCall(history, toolCalls, assistantText);
577
578
  }
578
579
  appendToolResult(history, toolCallId, result) {
579
580
  return appendOpenAIToolResult(history, toolCallId, result);
@@ -1539,21 +1540,25 @@ var AnthropicAdapter = class {
1539
1540
  }
1540
1541
  yield endEvent;
1541
1542
  }
1542
- appendAssistantToolCall(history, toolCalls) {
1543
+ appendAssistantToolCall(history, toolCalls, assistantText) {
1544
+ const text = assistantText?.trim() ? assistantText : null;
1543
1545
  const wireMessage = {
1544
1546
  role: "assistant",
1545
- content: toolCalls.map((tc) => ({
1546
- type: "tool_use",
1547
- id: tc.id,
1548
- name: tc.name,
1549
- input: tc.arguments ?? {}
1550
- }))
1547
+ content: [
1548
+ ...text ? [{ type: "text", text }] : [],
1549
+ ...toolCalls.map((tc) => ({
1550
+ type: "tool_use",
1551
+ id: tc.id,
1552
+ name: tc.name,
1553
+ input: tc.arguments ?? {}
1554
+ }))
1555
+ ]
1551
1556
  };
1552
1557
  return [
1553
1558
  ...history,
1554
1559
  {
1555
1560
  role: "assistant",
1556
- content: "",
1561
+ content: text ?? "",
1557
1562
  vendorRaw: wireMessage
1558
1563
  }
1559
1564
  ];
@@ -1805,21 +1810,25 @@ async function* streamFromGemini(client, req) {
1805
1810
  };
1806
1811
  yield endEvent;
1807
1812
  }
1808
- function appendGeminiAssistantToolCall(history, toolCalls) {
1813
+ function appendGeminiAssistantToolCall(history, toolCalls, assistantText) {
1814
+ const text = assistantText?.trim() ? assistantText : null;
1809
1815
  const wireMessage = {
1810
1816
  role: "model",
1811
- parts: toolCalls.map((tc) => ({
1812
- functionCall: {
1813
- name: parseToolName(tc.id),
1814
- args: tc.arguments ?? {}
1815
- }
1816
- }))
1817
+ parts: [
1818
+ ...text ? [{ text }] : [],
1819
+ ...toolCalls.map((tc) => ({
1820
+ functionCall: {
1821
+ name: parseToolName(tc.id),
1822
+ args: tc.arguments ?? {}
1823
+ }
1824
+ }))
1825
+ ]
1817
1826
  };
1818
1827
  return [
1819
1828
  ...history,
1820
1829
  {
1821
1830
  role: "assistant",
1822
- content: "",
1831
+ content: text ?? "",
1823
1832
  vendorRaw: wireMessage
1824
1833
  }
1825
1834
  ];
@@ -2079,8 +2088,8 @@ var GoogleAdapter = class {
2079
2088
  stream(req) {
2080
2089
  return streamFromGemini(this.ensureClient(), req);
2081
2090
  }
2082
- appendAssistantToolCall(history, toolCalls) {
2083
- return appendGeminiAssistantToolCall(history, toolCalls);
2091
+ appendAssistantToolCall(history, toolCalls, assistantText) {
2092
+ return appendGeminiAssistantToolCall(history, toolCalls, assistantText);
2084
2093
  }
2085
2094
  appendToolResult(history, toolCallId, result) {
2086
2095
  return appendGeminiToolResult(history, toolCallId, result);
@@ -2285,8 +2294,8 @@ var VertexGeminiAdapter = class {
2285
2294
  stream(req) {
2286
2295
  return streamFromGemini(this.ensureClient(), req);
2287
2296
  }
2288
- appendAssistantToolCall(history, toolCalls) {
2289
- return appendGeminiAssistantToolCall(history, toolCalls);
2297
+ appendAssistantToolCall(history, toolCalls, assistantText) {
2298
+ return appendGeminiAssistantToolCall(history, toolCalls, assistantText);
2290
2299
  }
2291
2300
  appendToolResult(history, toolCallId, result) {
2292
2301
  return appendGeminiToolResult(history, toolCallId, result);
@@ -2483,8 +2492,8 @@ var VertexOpenAIAdapter = class {
2483
2492
  vendorMetadataExtractor: VERTEX_OPENAI_METADATA_EXTRACTOR
2484
2493
  });
2485
2494
  }
2486
- appendAssistantToolCall(history, toolCalls) {
2487
- return appendOpenAIAssistantToolCall(history, toolCalls);
2495
+ appendAssistantToolCall(history, toolCalls, assistantText) {
2496
+ return appendOpenAIAssistantToolCall(history, toolCalls, assistantText);
2488
2497
  }
2489
2498
  appendToolResult(history, toolCallId, result) {
2490
2499
  return appendOpenAIToolResult(history, toolCallId, result);
@@ -2829,11 +2838,12 @@ var BedrockAdapter = class {
2829
2838
  if (Object.keys(inferenceConfig).length > 0) {
2830
2839
  commandInput.inferenceConfig = inferenceConfig;
2831
2840
  }
2832
- if (req.cacheKey) {
2841
+ const caching = req.cacheKey ? cachePointSupport(req.model) : void 0;
2842
+ if (caching) {
2833
2843
  if (commandInput.system) {
2834
2844
  commandInput.system.push({ cachePoint: { type: "default" } });
2835
2845
  }
2836
- if (tools) {
2846
+ if (tools && caching.tools) {
2837
2847
  tools.tools.push({ cachePoint: { type: "default" } });
2838
2848
  }
2839
2849
  markLastMessageForCaching2(messages);
@@ -2970,22 +2980,26 @@ var BedrockAdapter = class {
2970
2980
  }
2971
2981
  yield endEvent;
2972
2982
  }
2973
- appendAssistantToolCall(history, toolCalls) {
2983
+ appendAssistantToolCall(history, toolCalls, assistantText) {
2984
+ const text = assistantText?.trim() ? assistantText : null;
2974
2985
  const wireMessage = {
2975
2986
  role: "assistant",
2976
- content: toolCalls.map((tc) => ({
2977
- toolUse: {
2978
- toolUseId: tc.id,
2979
- name: tc.name,
2980
- input: tc.arguments ?? {}
2981
- }
2982
- }))
2987
+ content: [
2988
+ ...text ? [{ text }] : [],
2989
+ ...toolCalls.map((tc) => ({
2990
+ toolUse: {
2991
+ toolUseId: tc.id,
2992
+ name: tc.name,
2993
+ input: tc.arguments ?? {}
2994
+ }
2995
+ }))
2996
+ ]
2983
2997
  };
2984
2998
  return [
2985
2999
  ...history,
2986
3000
  {
2987
3001
  role: "assistant",
2988
- content: "",
3002
+ content: text ?? "",
2989
3003
  vendorRaw: wireMessage
2990
3004
  }
2991
3005
  ];
@@ -3053,6 +3067,11 @@ function buildWireMessages3(req) {
3053
3067
  }
3054
3068
  return out;
3055
3069
  }
3070
+ function cachePointSupport(model) {
3071
+ if (model.includes("anthropic.claude")) return { tools: true };
3072
+ if (model.includes("amazon.nova")) return { tools: false };
3073
+ return void 0;
3074
+ }
3056
3075
  function markLastMessageForCaching2(messages) {
3057
3076
  if (messages.length === 0) return;
3058
3077
  const last = messages[messages.length - 1];
@@ -3275,8 +3294,8 @@ var AzureOpenAIAdapter = class {
3275
3294
  vendorMetadataExtractor: AZURE_OPENAI_METADATA_EXTRACTOR
3276
3295
  });
3277
3296
  }
3278
- appendAssistantToolCall(history, toolCalls) {
3279
- return appendOpenAIAssistantToolCall(history, toolCalls);
3297
+ appendAssistantToolCall(history, toolCalls, assistantText) {
3298
+ return appendOpenAIAssistantToolCall(history, toolCalls, assistantText);
3280
3299
  }
3281
3300
  appendToolResult(history, toolCallId, result) {
3282
3301
  return appendOpenAIToolResult(history, toolCallId, result);