@jambonz/llm 0.6.1 → 0.6.3

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);
@@ -1134,6 +1135,116 @@ var xaiFactory = {
1134
1135
  manifest: xaiManifest,
1135
1136
  create: () => new XaiAdapter()
1136
1137
  };
1138
+ var BEDROCK_MANTLE_DEFAULT_BASE_URL = "https://bedrock-mantle.us-east-1.api.aws/v1";
1139
+ var bedrockMantleManifest = {
1140
+ vendor: "bedrock-mantle",
1141
+ displayName: "AWS Bedrock (OpenAI-compatible)",
1142
+ authKinds: [
1143
+ {
1144
+ kind: "apiKey",
1145
+ displayName: "API Key",
1146
+ fields: [
1147
+ {
1148
+ name: "apiKey",
1149
+ label: "Bedrock API Key",
1150
+ type: "password",
1151
+ required: true,
1152
+ help: "Generate a long-term Bedrock API key in the AWS console (Amazon Bedrock \u2192 API keys)."
1153
+ },
1154
+ {
1155
+ name: "baseURL",
1156
+ label: "Base URL",
1157
+ type: "url",
1158
+ required: false,
1159
+ default: BEDROCK_MANTLE_DEFAULT_BASE_URL,
1160
+ help: "Change the region to match your key. xAI models are served only on the /openai/v1 path."
1161
+ }
1162
+ ]
1163
+ }
1164
+ ],
1165
+ /* A convenience seed, NOT the source of truth: the live `/v1/models`
1166
+ * endpoint is authoritative and grows continuously, which is why
1167
+ * `supportsModelListing` is true. Any model the endpoint lists can be used
1168
+ * by id without appearing here.
1169
+ *
1170
+ * AWS publishes no context-window metadata (neither `/v1/models` nor
1171
+ * `GetFoundationModel` returns it), so these limits are carried over from
1172
+ * the native-vendor manifests above for the same underlying models. Vision
1173
+ * follows Bedrock's `inputModalities`. */
1174
+ knownModels: [
1175
+ {
1176
+ id: "zai.glm-5",
1177
+ displayName: "GLM 5",
1178
+ capabilities: {
1179
+ streaming: true,
1180
+ tools: true,
1181
+ vision: false,
1182
+ systemPrompt: true,
1183
+ maxContextTokens: 202800
1184
+ }
1185
+ },
1186
+ {
1187
+ id: "zai.glm-4.7",
1188
+ displayName: "GLM 4.7",
1189
+ capabilities: {
1190
+ streaming: true,
1191
+ tools: true,
1192
+ vision: false,
1193
+ systemPrompt: true,
1194
+ maxContextTokens: 2e5
1195
+ }
1196
+ },
1197
+ {
1198
+ id: "moonshotai.kimi-k2.5",
1199
+ displayName: "Kimi K2.5",
1200
+ capabilities: {
1201
+ streaming: true,
1202
+ tools: true,
1203
+ vision: true,
1204
+ systemPrompt: true,
1205
+ maxContextTokens: 262144
1206
+ }
1207
+ },
1208
+ {
1209
+ id: "xai.grok-4.3",
1210
+ displayName: "Grok 4.3",
1211
+ capabilities: {
1212
+ streaming: true,
1213
+ tools: true,
1214
+ vision: true,
1215
+ systemPrompt: true,
1216
+ maxContextTokens: 1e6
1217
+ }
1218
+ }
1219
+ ],
1220
+ supportsModelListing: true,
1221
+ docsUrl: "https://docs.aws.amazon.com/bedrock/latest/userguide/inference-chat-completions.html"
1222
+ };
1223
+ var BedrockMantleAdapter = class extends OpenAIAdapter {
1224
+ vendor = bedrockMantleManifest.vendor;
1225
+ init(auth, client) {
1226
+ super.init(
1227
+ {
1228
+ ...auth,
1229
+ baseURL: auth.baseURL ?? BEDROCK_MANTLE_DEFAULT_BASE_URL
1230
+ },
1231
+ client
1232
+ );
1233
+ }
1234
+ knownModels() {
1235
+ return bedrockMantleManifest.knownModels;
1236
+ }
1237
+ // Mantle fronts many third-party runtimes with differing param strictness,
1238
+ // and prompt_cache_key is unverified against all of them — do not forward.
1239
+ forwardCacheKey() {
1240
+ return false;
1241
+ }
1242
+ };
1243
+ var bedrockMantleFactory = {
1244
+ vendor: bedrockMantleManifest.vendor,
1245
+ manifest: bedrockMantleManifest,
1246
+ create: () => new BedrockMantleAdapter()
1247
+ };
1137
1248
 
1138
1249
  // src/adapters/anthropic/adapter.ts
1139
1250
  var import_sdk = __toESM(require("@anthropic-ai/sdk"), 1);
@@ -1429,21 +1540,25 @@ var AnthropicAdapter = class {
1429
1540
  }
1430
1541
  yield endEvent;
1431
1542
  }
1432
- appendAssistantToolCall(history, toolCalls) {
1543
+ appendAssistantToolCall(history, toolCalls, assistantText) {
1544
+ const text = assistantText?.trim() ? assistantText : null;
1433
1545
  const wireMessage = {
1434
1546
  role: "assistant",
1435
- content: toolCalls.map((tc) => ({
1436
- type: "tool_use",
1437
- id: tc.id,
1438
- name: tc.name,
1439
- input: tc.arguments ?? {}
1440
- }))
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
+ ]
1441
1556
  };
1442
1557
  return [
1443
1558
  ...history,
1444
1559
  {
1445
1560
  role: "assistant",
1446
- content: "",
1561
+ content: text ?? "",
1447
1562
  vendorRaw: wireMessage
1448
1563
  }
1449
1564
  ];
@@ -1695,21 +1810,25 @@ async function* streamFromGemini(client, req) {
1695
1810
  };
1696
1811
  yield endEvent;
1697
1812
  }
1698
- function appendGeminiAssistantToolCall(history, toolCalls) {
1813
+ function appendGeminiAssistantToolCall(history, toolCalls, assistantText) {
1814
+ const text = assistantText?.trim() ? assistantText : null;
1699
1815
  const wireMessage = {
1700
1816
  role: "model",
1701
- parts: toolCalls.map((tc) => ({
1702
- functionCall: {
1703
- name: parseToolName(tc.id),
1704
- args: tc.arguments ?? {}
1705
- }
1706
- }))
1817
+ parts: [
1818
+ ...text ? [{ text }] : [],
1819
+ ...toolCalls.map((tc) => ({
1820
+ functionCall: {
1821
+ name: parseToolName(tc.id),
1822
+ args: tc.arguments ?? {}
1823
+ }
1824
+ }))
1825
+ ]
1707
1826
  };
1708
1827
  return [
1709
1828
  ...history,
1710
1829
  {
1711
1830
  role: "assistant",
1712
- content: "",
1831
+ content: text ?? "",
1713
1832
  vendorRaw: wireMessage
1714
1833
  }
1715
1834
  ];
@@ -1969,8 +2088,8 @@ var GoogleAdapter = class {
1969
2088
  stream(req) {
1970
2089
  return streamFromGemini(this.ensureClient(), req);
1971
2090
  }
1972
- appendAssistantToolCall(history, toolCalls) {
1973
- return appendGeminiAssistantToolCall(history, toolCalls);
2091
+ appendAssistantToolCall(history, toolCalls, assistantText) {
2092
+ return appendGeminiAssistantToolCall(history, toolCalls, assistantText);
1974
2093
  }
1975
2094
  appendToolResult(history, toolCallId, result) {
1976
2095
  return appendGeminiToolResult(history, toolCallId, result);
@@ -2175,8 +2294,8 @@ var VertexGeminiAdapter = class {
2175
2294
  stream(req) {
2176
2295
  return streamFromGemini(this.ensureClient(), req);
2177
2296
  }
2178
- appendAssistantToolCall(history, toolCalls) {
2179
- return appendGeminiAssistantToolCall(history, toolCalls);
2297
+ appendAssistantToolCall(history, toolCalls, assistantText) {
2298
+ return appendGeminiAssistantToolCall(history, toolCalls, assistantText);
2180
2299
  }
2181
2300
  appendToolResult(history, toolCallId, result) {
2182
2301
  return appendGeminiToolResult(history, toolCallId, result);
@@ -2373,8 +2492,8 @@ var VertexOpenAIAdapter = class {
2373
2492
  vendorMetadataExtractor: VERTEX_OPENAI_METADATA_EXTRACTOR
2374
2493
  });
2375
2494
  }
2376
- appendAssistantToolCall(history, toolCalls) {
2377
- return appendOpenAIAssistantToolCall(history, toolCalls);
2495
+ appendAssistantToolCall(history, toolCalls, assistantText) {
2496
+ return appendOpenAIAssistantToolCall(history, toolCalls, assistantText);
2378
2497
  }
2379
2498
  appendToolResult(history, toolCallId, result) {
2380
2499
  return appendOpenAIToolResult(history, toolCallId, result);
@@ -2860,22 +2979,26 @@ var BedrockAdapter = class {
2860
2979
  }
2861
2980
  yield endEvent;
2862
2981
  }
2863
- appendAssistantToolCall(history, toolCalls) {
2982
+ appendAssistantToolCall(history, toolCalls, assistantText) {
2983
+ const text = assistantText?.trim() ? assistantText : null;
2864
2984
  const wireMessage = {
2865
2985
  role: "assistant",
2866
- content: toolCalls.map((tc) => ({
2867
- toolUse: {
2868
- toolUseId: tc.id,
2869
- name: tc.name,
2870
- input: tc.arguments ?? {}
2871
- }
2872
- }))
2986
+ content: [
2987
+ ...text ? [{ text }] : [],
2988
+ ...toolCalls.map((tc) => ({
2989
+ toolUse: {
2990
+ toolUseId: tc.id,
2991
+ name: tc.name,
2992
+ input: tc.arguments ?? {}
2993
+ }
2994
+ }))
2995
+ ]
2873
2996
  };
2874
2997
  return [
2875
2998
  ...history,
2876
2999
  {
2877
3000
  role: "assistant",
2878
- content: "",
3001
+ content: text ?? "",
2879
3002
  vendorRaw: wireMessage
2880
3003
  }
2881
3004
  ];
@@ -3165,8 +3288,8 @@ var AzureOpenAIAdapter = class {
3165
3288
  vendorMetadataExtractor: AZURE_OPENAI_METADATA_EXTRACTOR
3166
3289
  });
3167
3290
  }
3168
- appendAssistantToolCall(history, toolCalls) {
3169
- return appendOpenAIAssistantToolCall(history, toolCalls);
3291
+ appendAssistantToolCall(history, toolCalls, assistantText) {
3292
+ return appendOpenAIAssistantToolCall(history, toolCalls, assistantText);
3170
3293
  }
3171
3294
  appendToolResult(history, toolCallId, result) {
3172
3295
  return appendOpenAIToolResult(history, toolCallId, result);
@@ -3454,6 +3577,7 @@ registerAdapter(basetenFactory);
3454
3577
  registerAdapter(moonshotFactory);
3455
3578
  registerAdapter(zaiFactory);
3456
3579
  registerAdapter(xaiFactory);
3580
+ registerAdapter(bedrockMantleFactory);
3457
3581
  registerAdapter(anthropicFactory);
3458
3582
  registerAdapter(googleFactory);
3459
3583
  registerAdapter(vertexGeminiFactory);
@@ -3473,6 +3597,7 @@ function normalizeAuth(vendor, raw) {
3473
3597
  case "moonshot":
3474
3598
  case "zai":
3475
3599
  case "xai":
3600
+ case "bedrock-mantle":
3476
3601
  return requireApiKey(vendor, raw);
3477
3602
  case "deepseek":
3478
3603
  return {