@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.
@@ -555,7 +555,8 @@ var OpenAIAdapter = class {
555
555
  stream(req) {
556
556
  return streamFromOpenAI(this.ensureClient(), req, {
557
557
  knownModels: this.knownModels(),
558
- vendorMetadataExtractor: OPENAI_METADATA_EXTRACTOR
558
+ vendorMetadataExtractor: OPENAI_METADATA_EXTRACTOR,
559
+ includeCacheKey: this.forwardCacheKey()
559
560
  });
560
561
  }
561
562
  appendAssistantToolCall(history, toolCalls) {
@@ -576,6 +577,20 @@ var OpenAIAdapter = class {
576
577
  knownModels() {
577
578
  return openAIManifest.knownModels;
578
579
  }
580
+ /**
581
+ * Whether to forward `req.cacheKey` as OpenAI's `prompt_cache_key` request
582
+ * param. Default true — verified accepted by OpenAI, Azure OpenAI,
583
+ * Vertex-OpenAI, and Baseten. OpenAI-compatible vendors whose param
584
+ * handling is strict or unverified (DeepSeek, Moonshot, Zai, xAI — and
585
+ * Groq via its own stream override) override to false: a strict backend
586
+ * rejects the whole request on an unknown body param, which is far worse
587
+ * than forgoing a cache-routing hint. Flip a vendor to true only after
588
+ * verifying its endpoint (including any proxy in front of it, e.g.
589
+ * Bedrock Mantle) tolerates the param.
590
+ */
591
+ forwardCacheKey() {
592
+ return true;
593
+ }
579
594
  async testCredential() {
580
595
  await this.ensureClient().models.list();
581
596
  }
@@ -688,6 +703,11 @@ var DeepSeekAdapter = class extends OpenAIAdapter {
688
703
  knownModels() {
689
704
  return deepseekManifest.knownModels;
690
705
  }
706
+ // DeepSeek caches automatically server-side; prompt_cache_key is
707
+ // unverified against its param handling — do not forward.
708
+ forwardCacheKey() {
709
+ return false;
710
+ }
691
711
  };
692
712
  var deepseekFactory = {
693
713
  vendor: deepseekManifest.vendor,
@@ -911,6 +931,12 @@ var MoonshotAdapter = class extends OpenAIAdapter {
911
931
  knownModels() {
912
932
  return moonshotManifest.knownModels;
913
933
  }
934
+ // Moonshot's param handling is strict (e.g. it rejects unknown template
935
+ // kwargs) and prompt_cache_key is unverified against both the native
936
+ // endpoint and Bedrock Mantle deployments — do not forward.
937
+ forwardCacheKey() {
938
+ return false;
939
+ }
914
940
  };
915
941
  var moonshotFactory = {
916
942
  vendor: moonshotManifest.vendor,
@@ -984,6 +1010,11 @@ var ZaiAdapter = class extends OpenAIAdapter {
984
1010
  knownModels() {
985
1011
  return zaiManifest.knownModels;
986
1012
  }
1013
+ // prompt_cache_key is unverified against Zai's OpenAI-compat endpoint —
1014
+ // do not forward.
1015
+ forwardCacheKey() {
1016
+ return false;
1017
+ }
987
1018
  };
988
1019
  var zaiFactory = {
989
1020
  vendor: zaiManifest.vendor,
@@ -1079,12 +1110,127 @@ var XaiAdapter = class extends OpenAIAdapter {
1079
1110
  knownModels() {
1080
1111
  return xaiManifest.knownModels;
1081
1112
  }
1113
+ // xAI caches automatically server-side; prompt_cache_key is unverified
1114
+ // against its param handling — do not forward.
1115
+ forwardCacheKey() {
1116
+ return false;
1117
+ }
1082
1118
  };
1083
1119
  var xaiFactory = {
1084
1120
  vendor: xaiManifest.vendor,
1085
1121
  manifest: xaiManifest,
1086
1122
  create: () => new XaiAdapter()
1087
1123
  };
1124
+ var BEDROCK_MANTLE_DEFAULT_BASE_URL = "https://bedrock-mantle.us-east-1.api.aws/v1";
1125
+ var bedrockMantleManifest = {
1126
+ vendor: "bedrock-mantle",
1127
+ displayName: "AWS Bedrock (OpenAI-compatible)",
1128
+ authKinds: [
1129
+ {
1130
+ kind: "apiKey",
1131
+ displayName: "API Key",
1132
+ fields: [
1133
+ {
1134
+ name: "apiKey",
1135
+ label: "Bedrock API Key",
1136
+ type: "password",
1137
+ required: true,
1138
+ help: "Generate a long-term Bedrock API key in the AWS console (Amazon Bedrock \u2192 API keys)."
1139
+ },
1140
+ {
1141
+ name: "baseURL",
1142
+ label: "Base URL",
1143
+ type: "url",
1144
+ required: false,
1145
+ default: BEDROCK_MANTLE_DEFAULT_BASE_URL,
1146
+ help: "Change the region to match your key. xAI models are served only on the /openai/v1 path."
1147
+ }
1148
+ ]
1149
+ }
1150
+ ],
1151
+ /* A convenience seed, NOT the source of truth: the live `/v1/models`
1152
+ * endpoint is authoritative and grows continuously, which is why
1153
+ * `supportsModelListing` is true. Any model the endpoint lists can be used
1154
+ * by id without appearing here.
1155
+ *
1156
+ * AWS publishes no context-window metadata (neither `/v1/models` nor
1157
+ * `GetFoundationModel` returns it), so these limits are carried over from
1158
+ * the native-vendor manifests above for the same underlying models. Vision
1159
+ * follows Bedrock's `inputModalities`. */
1160
+ knownModels: [
1161
+ {
1162
+ id: "zai.glm-5",
1163
+ displayName: "GLM 5",
1164
+ capabilities: {
1165
+ streaming: true,
1166
+ tools: true,
1167
+ vision: false,
1168
+ systemPrompt: true,
1169
+ maxContextTokens: 202800
1170
+ }
1171
+ },
1172
+ {
1173
+ id: "zai.glm-4.7",
1174
+ displayName: "GLM 4.7",
1175
+ capabilities: {
1176
+ streaming: true,
1177
+ tools: true,
1178
+ vision: false,
1179
+ systemPrompt: true,
1180
+ maxContextTokens: 2e5
1181
+ }
1182
+ },
1183
+ {
1184
+ id: "moonshotai.kimi-k2.5",
1185
+ displayName: "Kimi K2.5",
1186
+ capabilities: {
1187
+ streaming: true,
1188
+ tools: true,
1189
+ vision: true,
1190
+ systemPrompt: true,
1191
+ maxContextTokens: 262144
1192
+ }
1193
+ },
1194
+ {
1195
+ id: "xai.grok-4.3",
1196
+ displayName: "Grok 4.3",
1197
+ capabilities: {
1198
+ streaming: true,
1199
+ tools: true,
1200
+ vision: true,
1201
+ systemPrompt: true,
1202
+ maxContextTokens: 1e6
1203
+ }
1204
+ }
1205
+ ],
1206
+ supportsModelListing: true,
1207
+ docsUrl: "https://docs.aws.amazon.com/bedrock/latest/userguide/inference-chat-completions.html"
1208
+ };
1209
+ var BedrockMantleAdapter = class extends OpenAIAdapter {
1210
+ vendor = bedrockMantleManifest.vendor;
1211
+ init(auth, client) {
1212
+ super.init(
1213
+ {
1214
+ ...auth,
1215
+ baseURL: auth.baseURL ?? BEDROCK_MANTLE_DEFAULT_BASE_URL
1216
+ },
1217
+ client
1218
+ );
1219
+ }
1220
+ knownModels() {
1221
+ return bedrockMantleManifest.knownModels;
1222
+ }
1223
+ // Mantle fronts many third-party runtimes with differing param strictness,
1224
+ // and prompt_cache_key is unverified against all of them — do not forward.
1225
+ forwardCacheKey() {
1226
+ return false;
1227
+ }
1228
+ };
1229
+ var bedrockMantleFactory = {
1230
+ vendor: bedrockMantleManifest.vendor,
1231
+ manifest: bedrockMantleManifest,
1232
+ create: () => new BedrockMantleAdapter()
1233
+ };
1088
1234
 
1089
1235
  // src/adapters/anthropic/adapter.ts
1090
1236
  var import_sdk = __toESM(require("@anthropic-ai/sdk"), 1);
@@ -3383,7 +3529,10 @@ var HuggingfaceAdapter = class extends OpenAIAdapter {
3383
3529
  stream(req) {
3384
3530
  return streamFromOpenAI(this.ensureClient(), req, {
3385
3531
  knownModels: huggingfaceManifest.knownModels,
3386
- vendorMetadataExtractor: HUGGINGFACE_METADATA_EXTRACTOR
3532
+ vendorMetadataExtractor: HUGGINGFACE_METADATA_EXTRACTOR,
3533
+ // The HF router fronts many third-party inference providers;
3534
+ // prompt_cache_key is unverified against them — do not forward.
3535
+ includeCacheKey: false
3387
3536
  });
3388
3537
  }
3389
3538
  };
@@ -3402,6 +3551,7 @@ registerAdapter(basetenFactory);
3402
3551
  registerAdapter(moonshotFactory);
3403
3552
  registerAdapter(zaiFactory);
3404
3553
  registerAdapter(xaiFactory);
3554
+ registerAdapter(bedrockMantleFactory);
3405
3555
  registerAdapter(anthropicFactory);
3406
3556
  registerAdapter(googleFactory);
3407
3557
  registerAdapter(vertexGeminiFactory);