@jambonz/llm 0.6.0 → 0.6.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.cjs CHANGED
@@ -568,7 +568,8 @@ var OpenAIAdapter = class {
568
568
  stream(req) {
569
569
  return streamFromOpenAI(this.ensureClient(), req, {
570
570
  knownModels: this.knownModels(),
571
- vendorMetadataExtractor: OPENAI_METADATA_EXTRACTOR
571
+ vendorMetadataExtractor: OPENAI_METADATA_EXTRACTOR,
572
+ includeCacheKey: this.forwardCacheKey()
572
573
  });
573
574
  }
574
575
  appendAssistantToolCall(history, toolCalls) {
@@ -589,6 +590,20 @@ var OpenAIAdapter = class {
589
590
  knownModels() {
590
591
  return openAIManifest.knownModels;
591
592
  }
593
+ /**
594
+ * Whether to forward `req.cacheKey` as OpenAI's `prompt_cache_key` request
595
+ * param. Default true — verified accepted by OpenAI, Azure OpenAI,
596
+ * Vertex-OpenAI, and Baseten. OpenAI-compatible vendors whose param
597
+ * handling is strict or unverified (DeepSeek, Moonshot, Zai, xAI — and
598
+ * Groq via its own stream override) override to false: a strict backend
599
+ * rejects the whole request on an unknown body param, which is far worse
600
+ * than forgoing a cache-routing hint. Flip a vendor to true only after
601
+ * verifying its endpoint (including any proxy in front of it, e.g.
602
+ * Bedrock Mantle) tolerates the param.
603
+ */
604
+ forwardCacheKey() {
605
+ return true;
606
+ }
592
607
  async testCredential() {
593
608
  await this.ensureClient().models.list();
594
609
  }
@@ -701,6 +716,11 @@ var DeepSeekAdapter = class extends OpenAIAdapter {
701
716
  knownModels() {
702
717
  return deepseekManifest.knownModels;
703
718
  }
719
+ // DeepSeek caches automatically server-side; prompt_cache_key is
720
+ // unverified against its param handling — do not forward.
721
+ forwardCacheKey() {
722
+ return false;
723
+ }
704
724
  };
705
725
  var deepseekFactory = {
706
726
  vendor: deepseekManifest.vendor,
@@ -924,6 +944,12 @@ var MoonshotAdapter = class extends OpenAIAdapter {
924
944
  knownModels() {
925
945
  return moonshotManifest.knownModels;
926
946
  }
947
+ // Moonshot's param handling is strict (e.g. it rejects unknown template
948
+ // kwargs) and prompt_cache_key is unverified against both the native
949
+ // endpoint and Bedrock Mantle deployments — do not forward.
950
+ forwardCacheKey() {
951
+ return false;
952
+ }
927
953
  };
928
954
  var moonshotFactory = {
929
955
  vendor: moonshotManifest.vendor,
@@ -997,6 +1023,11 @@ var ZaiAdapter = class extends OpenAIAdapter {
997
1023
  knownModels() {
998
1024
  return zaiManifest.knownModels;
999
1025
  }
1026
+ // prompt_cache_key is unverified against Zai's OpenAI-compat endpoint —
1027
+ // do not forward.
1028
+ forwardCacheKey() {
1029
+ return false;
1030
+ }
1000
1031
  };
1001
1032
  var zaiFactory = {
1002
1033
  vendor: zaiManifest.vendor,
@@ -1092,12 +1123,127 @@ var XaiAdapter = class extends OpenAIAdapter {
1092
1123
  knownModels() {
1093
1124
  return xaiManifest.knownModels;
1094
1125
  }
1126
+ // xAI caches automatically server-side; prompt_cache_key is unverified
1127
+ // against its param handling — do not forward.
1128
+ forwardCacheKey() {
1129
+ return false;
1130
+ }
1095
1131
  };
1096
1132
  var xaiFactory = {
1097
1133
  vendor: xaiManifest.vendor,
1098
1134
  manifest: xaiManifest,
1099
1135
  create: () => new XaiAdapter()
1100
1136
  };
1137
+ var BEDROCK_MANTLE_DEFAULT_BASE_URL = "https://bedrock-mantle.us-east-1.api.aws/v1";
1138
+ var bedrockMantleManifest = {
1139
+ vendor: "bedrock-mantle",
1140
+ displayName: "AWS Bedrock (OpenAI-compatible)",
1141
+ authKinds: [
1142
+ {
1143
+ kind: "apiKey",
1144
+ displayName: "API Key",
1145
+ fields: [
1146
+ {
1147
+ name: "apiKey",
1148
+ label: "Bedrock API Key",
1149
+ type: "password",
1150
+ required: true,
1151
+ help: "Generate a long-term Bedrock API key in the AWS console (Amazon Bedrock \u2192 API keys)."
1152
+ },
1153
+ {
1154
+ name: "baseURL",
1155
+ label: "Base URL",
1156
+ type: "url",
1157
+ required: false,
1158
+ default: BEDROCK_MANTLE_DEFAULT_BASE_URL,
1159
+ help: "Change the region to match your key. xAI models are served only on the /openai/v1 path."
1160
+ }
1161
+ ]
1162
+ }
1163
+ ],
1164
+ /* A convenience seed, NOT the source of truth: the live `/v1/models`
1165
+ * endpoint is authoritative and grows continuously, which is why
1166
+ * `supportsModelListing` is true. Any model the endpoint lists can be used
1167
+ * by id without appearing here.
1168
+ *
1169
+ * AWS publishes no context-window metadata (neither `/v1/models` nor
1170
+ * `GetFoundationModel` returns it), so these limits are carried over from
1171
+ * the native-vendor manifests above for the same underlying models. Vision
1172
+ * follows Bedrock's `inputModalities`. */
1173
+ knownModels: [
1174
+ {
1175
+ id: "zai.glm-5",
1176
+ displayName: "GLM 5",
1177
+ capabilities: {
1178
+ streaming: true,
1179
+ tools: true,
1180
+ vision: false,
1181
+ systemPrompt: true,
1182
+ maxContextTokens: 202800
1183
+ }
1184
+ },
1185
+ {
1186
+ id: "zai.glm-4.7",
1187
+ displayName: "GLM 4.7",
1188
+ capabilities: {
1189
+ streaming: true,
1190
+ tools: true,
1191
+ vision: false,
1192
+ systemPrompt: true,
1193
+ maxContextTokens: 2e5
1194
+ }
1195
+ },
1196
+ {
1197
+ id: "moonshotai.kimi-k2.5",
1198
+ displayName: "Kimi K2.5",
1199
+ capabilities: {
1200
+ streaming: true,
1201
+ tools: true,
1202
+ vision: true,
1203
+ systemPrompt: true,
1204
+ maxContextTokens: 262144
1205
+ }
1206
+ },
1207
+ {
1208
+ id: "xai.grok-4.3",
1209
+ displayName: "Grok 4.3",
1210
+ capabilities: {
1211
+ streaming: true,
1212
+ tools: true,
1213
+ vision: true,
1214
+ systemPrompt: true,
1215
+ maxContextTokens: 1e6
1216
+ }
1217
+ }
1218
+ ],
1219
+ supportsModelListing: true,
1220
+ docsUrl: "https://docs.aws.amazon.com/bedrock/latest/userguide/inference-chat-completions.html"
1221
+ };
1222
+ var BedrockMantleAdapter = class extends OpenAIAdapter {
1223
+ vendor = bedrockMantleManifest.vendor;
1224
+ init(auth, client) {
1225
+ super.init(
1226
+ {
1227
+ ...auth,
1228
+ baseURL: auth.baseURL ?? BEDROCK_MANTLE_DEFAULT_BASE_URL
1229
+ },
1230
+ client
1231
+ );
1232
+ }
1233
+ knownModels() {
1234
+ return bedrockMantleManifest.knownModels;
1235
+ }
1236
+ // Mantle fronts many third-party runtimes with differing param strictness,
1237
+ // and prompt_cache_key is unverified against all of them — do not forward.
1238
+ forwardCacheKey() {
1239
+ return false;
1240
+ }
1241
+ };
1242
+ var bedrockMantleFactory = {
1243
+ vendor: bedrockMantleManifest.vendor,
1244
+ manifest: bedrockMantleManifest,
1245
+ create: () => new BedrockMantleAdapter()
1246
+ };
1101
1247
 
1102
1248
  // src/adapters/anthropic/adapter.ts
1103
1249
  var import_sdk = __toESM(require("@anthropic-ai/sdk"), 1);
@@ -3396,7 +3542,10 @@ var HuggingfaceAdapter = class extends OpenAIAdapter {
3396
3542
  stream(req) {
3397
3543
  return streamFromOpenAI(this.ensureClient(), req, {
3398
3544
  knownModels: huggingfaceManifest.knownModels,
3399
- vendorMetadataExtractor: HUGGINGFACE_METADATA_EXTRACTOR
3545
+ vendorMetadataExtractor: HUGGINGFACE_METADATA_EXTRACTOR,
3546
+ // The HF router fronts many third-party inference providers;
3547
+ // prompt_cache_key is unverified against them — do not forward.
3548
+ includeCacheKey: false
3400
3549
  });
3401
3550
  }
3402
3551
  };
@@ -3415,6 +3564,7 @@ registerAdapter(basetenFactory);
3415
3564
  registerAdapter(moonshotFactory);
3416
3565
  registerAdapter(zaiFactory);
3417
3566
  registerAdapter(xaiFactory);
3567
+ registerAdapter(bedrockMantleFactory);
3418
3568
  registerAdapter(anthropicFactory);
3419
3569
  registerAdapter(googleFactory);
3420
3570
  registerAdapter(vertexGeminiFactory);
@@ -3434,6 +3584,7 @@ function normalizeAuth(vendor, raw) {
3434
3584
  case "moonshot":
3435
3585
  case "zai":
3436
3586
  case "xai":
3587
+ case "bedrock-mantle":
3437
3588
  return requireApiKey(vendor, raw);
3438
3589
  case "deepseek":
3439
3590
  return {