@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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as ServiceAccountJson, A as AuthSpec, a as AuthKindSchema, P as PromptRequest, b as AdapterFactory, c as AdapterManifest, C as CreateLlmArgs, L as LlmAdapter } from './types-Y0o6rN3B.cjs';
2
- export { d as ApiKeyAuth, e as AuthKind, f as AzureOpenAIApiKeyAuth, B as BedrockApiKeyAuth, g as BedrockIamAuth, h as ClientOptions, i as ContentBlock, F as FinishReason, j as FormField, k as FormFieldType, G as GoogleApiKeyAuth, l as GoogleServiceAccountAuth, J as JsonSchema, m as LlmEvent, M as Message, n as ModelCapabilities, o as ModelInfo, R as Role, T as Tool, p as ToolCallEvent, U as Usage, V as VertexServiceAccountAuth } from './types-Y0o6rN3B.cjs';
1
+ import { S as ServiceAccountJson, A as AuthSpec, a as AuthKindSchema, P as PromptRequest, b as AdapterFactory, c as AdapterManifest, C as CreateLlmArgs, L as LlmAdapter } from './types-dbgrfviJ.cjs';
2
+ export { d as ApiKeyAuth, e as AuthKind, f as AzureOpenAIApiKeyAuth, B as BedrockApiKeyAuth, g as BedrockIamAuth, h as ClientOptions, i as ContentBlock, F as FinishReason, j as FormField, k as FormFieldType, G as GoogleApiKeyAuth, l as GoogleServiceAccountAuth, J as JsonSchema, m as LlmEvent, M as Message, n as ModelCapabilities, o as ModelInfo, R as Role, T as Tool, p as ToolCallEvent, U as Usage, V as VertexServiceAccountAuth } from './types-dbgrfviJ.cjs';
3
3
 
4
4
  /**
5
5
  * The loose "DB-shape" input accepted by `normalizeAuth`.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as ServiceAccountJson, A as AuthSpec, a as AuthKindSchema, P as PromptRequest, b as AdapterFactory, c as AdapterManifest, C as CreateLlmArgs, L as LlmAdapter } from './types-Y0o6rN3B.js';
2
- export { d as ApiKeyAuth, e as AuthKind, f as AzureOpenAIApiKeyAuth, B as BedrockApiKeyAuth, g as BedrockIamAuth, h as ClientOptions, i as ContentBlock, F as FinishReason, j as FormField, k as FormFieldType, G as GoogleApiKeyAuth, l as GoogleServiceAccountAuth, J as JsonSchema, m as LlmEvent, M as Message, n as ModelCapabilities, o as ModelInfo, R as Role, T as Tool, p as ToolCallEvent, U as Usage, V as VertexServiceAccountAuth } from './types-Y0o6rN3B.js';
1
+ import { S as ServiceAccountJson, A as AuthSpec, a as AuthKindSchema, P as PromptRequest, b as AdapterFactory, c as AdapterManifest, C as CreateLlmArgs, L as LlmAdapter } from './types-dbgrfviJ.js';
2
+ export { d as ApiKeyAuth, e as AuthKind, f as AzureOpenAIApiKeyAuth, B as BedrockApiKeyAuth, g as BedrockIamAuth, h as ClientOptions, i as ContentBlock, F as FinishReason, j as FormField, k as FormFieldType, G as GoogleApiKeyAuth, l as GoogleServiceAccountAuth, J as JsonSchema, m as LlmEvent, M as Message, n as ModelCapabilities, o as ModelInfo, R as Role, T as Tool, p as ToolCallEvent, U as Usage, V as VertexServiceAccountAuth } from './types-dbgrfviJ.js';
3
3
 
4
4
  /**
5
5
  * The loose "DB-shape" input accepted by `normalizeAuth`.
package/dist/index.js CHANGED
@@ -239,10 +239,11 @@ async function* streamFromOpenAI(client, req, options) {
239
239
  }
240
240
  yield endEvent;
241
241
  }
242
- function appendOpenAIAssistantToolCall(history, toolCalls) {
242
+ function appendOpenAIAssistantToolCall(history, toolCalls, assistantText) {
243
+ const text = assistantText?.trim() ? assistantText : null;
243
244
  const wireMessage = {
244
245
  role: "assistant",
245
- content: null,
246
+ content: text,
246
247
  tool_calls: toolCalls.map((tc) => ({
247
248
  id: tc.id,
248
249
  type: "function",
@@ -256,7 +257,7 @@ function appendOpenAIAssistantToolCall(history, toolCalls) {
256
257
  ...history,
257
258
  {
258
259
  role: "assistant",
259
- content: "",
260
+ content: text ?? "",
260
261
  vendorRaw: wireMessage
261
262
  }
262
263
  ];
@@ -527,8 +528,8 @@ var OpenAIAdapter = class {
527
528
  includeCacheKey: this.forwardCacheKey()
528
529
  });
529
530
  }
530
- appendAssistantToolCall(history, toolCalls) {
531
- return appendOpenAIAssistantToolCall(history, toolCalls);
531
+ appendAssistantToolCall(history, toolCalls, assistantText) {
532
+ return appendOpenAIAssistantToolCall(history, toolCalls, assistantText);
532
533
  }
533
534
  appendToolResult(history, toolCallId, result) {
534
535
  return appendOpenAIToolResult(history, toolCallId, result);
@@ -1494,21 +1495,25 @@ var AnthropicAdapter = class {
1494
1495
  }
1495
1496
  yield endEvent;
1496
1497
  }
1497
- appendAssistantToolCall(history, toolCalls) {
1498
+ appendAssistantToolCall(history, toolCalls, assistantText) {
1499
+ const text = assistantText?.trim() ? assistantText : null;
1498
1500
  const wireMessage = {
1499
1501
  role: "assistant",
1500
- content: toolCalls.map((tc) => ({
1501
- type: "tool_use",
1502
- id: tc.id,
1503
- name: tc.name,
1504
- input: tc.arguments ?? {}
1505
- }))
1502
+ content: [
1503
+ ...text ? [{ type: "text", text }] : [],
1504
+ ...toolCalls.map((tc) => ({
1505
+ type: "tool_use",
1506
+ id: tc.id,
1507
+ name: tc.name,
1508
+ input: tc.arguments ?? {}
1509
+ }))
1510
+ ]
1506
1511
  };
1507
1512
  return [
1508
1513
  ...history,
1509
1514
  {
1510
1515
  role: "assistant",
1511
- content: "",
1516
+ content: text ?? "",
1512
1517
  vendorRaw: wireMessage
1513
1518
  }
1514
1519
  ];
@@ -1760,21 +1765,25 @@ async function* streamFromGemini(client, req) {
1760
1765
  };
1761
1766
  yield endEvent;
1762
1767
  }
1763
- function appendGeminiAssistantToolCall(history, toolCalls) {
1768
+ function appendGeminiAssistantToolCall(history, toolCalls, assistantText) {
1769
+ const text = assistantText?.trim() ? assistantText : null;
1764
1770
  const wireMessage = {
1765
1771
  role: "model",
1766
- parts: toolCalls.map((tc) => ({
1767
- functionCall: {
1768
- name: parseToolName(tc.id),
1769
- args: tc.arguments ?? {}
1770
- }
1771
- }))
1772
+ parts: [
1773
+ ...text ? [{ text }] : [],
1774
+ ...toolCalls.map((tc) => ({
1775
+ functionCall: {
1776
+ name: parseToolName(tc.id),
1777
+ args: tc.arguments ?? {}
1778
+ }
1779
+ }))
1780
+ ]
1772
1781
  };
1773
1782
  return [
1774
1783
  ...history,
1775
1784
  {
1776
1785
  role: "assistant",
1777
- content: "",
1786
+ content: text ?? "",
1778
1787
  vendorRaw: wireMessage
1779
1788
  }
1780
1789
  ];
@@ -2034,8 +2043,8 @@ var GoogleAdapter = class {
2034
2043
  stream(req) {
2035
2044
  return streamFromGemini(this.ensureClient(), req);
2036
2045
  }
2037
- appendAssistantToolCall(history, toolCalls) {
2038
- return appendGeminiAssistantToolCall(history, toolCalls);
2046
+ appendAssistantToolCall(history, toolCalls, assistantText) {
2047
+ return appendGeminiAssistantToolCall(history, toolCalls, assistantText);
2039
2048
  }
2040
2049
  appendToolResult(history, toolCallId, result) {
2041
2050
  return appendGeminiToolResult(history, toolCallId, result);
@@ -2240,8 +2249,8 @@ var VertexGeminiAdapter = class {
2240
2249
  stream(req) {
2241
2250
  return streamFromGemini(this.ensureClient(), req);
2242
2251
  }
2243
- appendAssistantToolCall(history, toolCalls) {
2244
- return appendGeminiAssistantToolCall(history, toolCalls);
2252
+ appendAssistantToolCall(history, toolCalls, assistantText) {
2253
+ return appendGeminiAssistantToolCall(history, toolCalls, assistantText);
2245
2254
  }
2246
2255
  appendToolResult(history, toolCallId, result) {
2247
2256
  return appendGeminiToolResult(history, toolCallId, result);
@@ -2438,8 +2447,8 @@ var VertexOpenAIAdapter = class {
2438
2447
  vendorMetadataExtractor: VERTEX_OPENAI_METADATA_EXTRACTOR
2439
2448
  });
2440
2449
  }
2441
- appendAssistantToolCall(history, toolCalls) {
2442
- return appendOpenAIAssistantToolCall(history, toolCalls);
2450
+ appendAssistantToolCall(history, toolCalls, assistantText) {
2451
+ return appendOpenAIAssistantToolCall(history, toolCalls, assistantText);
2443
2452
  }
2444
2453
  appendToolResult(history, toolCallId, result) {
2445
2454
  return appendOpenAIToolResult(history, toolCallId, result);
@@ -2790,11 +2799,12 @@ var BedrockAdapter = class {
2790
2799
  if (Object.keys(inferenceConfig).length > 0) {
2791
2800
  commandInput.inferenceConfig = inferenceConfig;
2792
2801
  }
2793
- if (req.cacheKey) {
2802
+ const caching = req.cacheKey ? cachePointSupport(req.model) : void 0;
2803
+ if (caching) {
2794
2804
  if (commandInput.system) {
2795
2805
  commandInput.system.push({ cachePoint: { type: "default" } });
2796
2806
  }
2797
- if (tools) {
2807
+ if (tools && caching.tools) {
2798
2808
  tools.tools.push({ cachePoint: { type: "default" } });
2799
2809
  }
2800
2810
  markLastMessageForCaching2(messages);
@@ -2931,22 +2941,26 @@ var BedrockAdapter = class {
2931
2941
  }
2932
2942
  yield endEvent;
2933
2943
  }
2934
- appendAssistantToolCall(history, toolCalls) {
2944
+ appendAssistantToolCall(history, toolCalls, assistantText) {
2945
+ const text = assistantText?.trim() ? assistantText : null;
2935
2946
  const wireMessage = {
2936
2947
  role: "assistant",
2937
- content: toolCalls.map((tc) => ({
2938
- toolUse: {
2939
- toolUseId: tc.id,
2940
- name: tc.name,
2941
- input: tc.arguments ?? {}
2942
- }
2943
- }))
2948
+ content: [
2949
+ ...text ? [{ text }] : [],
2950
+ ...toolCalls.map((tc) => ({
2951
+ toolUse: {
2952
+ toolUseId: tc.id,
2953
+ name: tc.name,
2954
+ input: tc.arguments ?? {}
2955
+ }
2956
+ }))
2957
+ ]
2944
2958
  };
2945
2959
  return [
2946
2960
  ...history,
2947
2961
  {
2948
2962
  role: "assistant",
2949
- content: "",
2963
+ content: text ?? "",
2950
2964
  vendorRaw: wireMessage
2951
2965
  }
2952
2966
  ];
@@ -3014,6 +3028,11 @@ function buildWireMessages3(req) {
3014
3028
  }
3015
3029
  return out;
3016
3030
  }
3031
+ function cachePointSupport(model) {
3032
+ if (model.includes("anthropic.claude")) return { tools: true };
3033
+ if (model.includes("amazon.nova")) return { tools: false };
3034
+ return void 0;
3035
+ }
3017
3036
  function markLastMessageForCaching2(messages) {
3018
3037
  if (messages.length === 0) return;
3019
3038
  const last = messages[messages.length - 1];
@@ -3236,8 +3255,8 @@ var AzureOpenAIAdapter = class {
3236
3255
  vendorMetadataExtractor: AZURE_OPENAI_METADATA_EXTRACTOR
3237
3256
  });
3238
3257
  }
3239
- appendAssistantToolCall(history, toolCalls) {
3240
- return appendOpenAIAssistantToolCall(history, toolCalls);
3258
+ appendAssistantToolCall(history, toolCalls, assistantText) {
3259
+ return appendOpenAIAssistantToolCall(history, toolCalls, assistantText);
3241
3260
  }
3242
3261
  appendToolResult(history, toolCallId, result) {
3243
3262
  return appendOpenAIToolResult(history, toolCallId, result);