@jambonz/llm 0.5.3 → 0.5.5

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
@@ -159,12 +159,18 @@ async function* streamFromOpenAI(client, req, options) {
159
159
  let usage;
160
160
  let finalFinishReason = null;
161
161
  let finalRawReason;
162
+ let sawContent = false;
162
163
  try {
163
164
  for await (const chunk of stream) {
164
165
  if (req.signal?.aborted) {
165
166
  yield { type: "end", finishReason: "aborted" };
166
167
  return;
167
168
  }
169
+ const chunkError = chunk.error;
170
+ if (chunkError) {
171
+ const message = chunkError && typeof chunkError === "object" && "message" in chunkError ? String(chunkError.message) : JSON.stringify(chunkError);
172
+ throw new Error(`OpenAI-compatible stream returned an error: ${message}`);
173
+ }
168
174
  if (chunk.usage) {
169
175
  usage = {
170
176
  ...chunk.usage.prompt_tokens !== void 0 ? { inputTokens: chunk.usage.prompt_tokens } : {},
@@ -178,6 +184,7 @@ async function* streamFromOpenAI(client, req, options) {
178
184
  const finishReason = choice.finish_reason;
179
185
  if (delta?.content) {
180
186
  if (t2 === void 0) t2 = process.hrtime.bigint();
187
+ sawContent = true;
181
188
  yield { type: "token", text: delta.content };
182
189
  }
183
190
  if (delta?.tool_calls) {
@@ -235,6 +242,12 @@ async function* streamFromOpenAI(client, req, options) {
235
242
  }
236
243
  throw err;
237
244
  }
245
+ const producedNothing = finalFinishReason === null && !sawContent && toolCallsEmitted.size === 0 && startedIds.size === 0 && usage === void 0;
246
+ if (producedNothing) {
247
+ throw new Error(
248
+ "OpenAI-compatible stream produced no data (no content, tool calls, usage, or finish reason). This usually means a misconfigured base URL or a vendor error returned in an HTTP 200 body. Verify the base URL and credentials."
249
+ );
250
+ }
238
251
  const endEvent = {
239
252
  type: "end",
240
253
  finishReason: finalFinishReason ?? "stop",
@@ -830,6 +843,152 @@ var basetenFactory = {
830
843
  manifest: basetenManifest,
831
844
  create: () => new BasetenAdapter()
832
845
  };
846
+ var moonshotManifest = {
847
+ vendor: "moonshot",
848
+ displayName: "Moonshot (Kimi)",
849
+ authKinds: [
850
+ {
851
+ kind: "apiKey",
852
+ displayName: "API Key",
853
+ fields: [
854
+ {
855
+ name: "apiKey",
856
+ label: "API Key",
857
+ type: "password",
858
+ required: true,
859
+ help: "Get an API key from https://platform.moonshot.ai/console/api-keys"
860
+ },
861
+ {
862
+ name: "baseURL",
863
+ label: "Base URL",
864
+ type: "url",
865
+ required: false,
866
+ default: "https://api.moonshot.ai/v1",
867
+ help: "Defaults to the global endpoint. Set to https://api.moonshot.cn/v1 for the China endpoint."
868
+ }
869
+ ]
870
+ }
871
+ ],
872
+ knownModels: [
873
+ {
874
+ id: "kimi-k2.6",
875
+ displayName: "Kimi K2.6",
876
+ capabilities: {
877
+ streaming: true,
878
+ tools: true,
879
+ vision: true,
880
+ systemPrompt: true,
881
+ maxContextTokens: 262144
882
+ }
883
+ },
884
+ {
885
+ id: "kimi-k2.5",
886
+ displayName: "Kimi K2.5",
887
+ capabilities: {
888
+ streaming: true,
889
+ tools: true,
890
+ vision: true,
891
+ systemPrompt: true,
892
+ maxContextTokens: 262144
893
+ }
894
+ }
895
+ ],
896
+ supportsModelListing: true,
897
+ docsUrl: "https://platform.moonshot.ai/docs"
898
+ };
899
+ var MoonshotAdapter = class extends OpenAIAdapter {
900
+ vendor = moonshotManifest.vendor;
901
+ init(auth, client) {
902
+ super.init(
903
+ {
904
+ ...auth,
905
+ baseURL: auth.baseURL ?? "https://api.moonshot.ai/v1"
906
+ },
907
+ client
908
+ );
909
+ }
910
+ knownModels() {
911
+ return moonshotManifest.knownModels;
912
+ }
913
+ };
914
+ var moonshotFactory = {
915
+ vendor: moonshotManifest.vendor,
916
+ manifest: moonshotManifest,
917
+ create: () => new MoonshotAdapter()
918
+ };
919
+ var zaiManifest = {
920
+ vendor: "zai",
921
+ displayName: "Z.ai (GLM)",
922
+ authKinds: [
923
+ {
924
+ kind: "apiKey",
925
+ displayName: "API Key",
926
+ fields: [
927
+ {
928
+ name: "apiKey",
929
+ label: "API Key",
930
+ type: "password",
931
+ required: true,
932
+ help: "Get an API key from https://z.ai/manage-apikey/apikey-list"
933
+ },
934
+ {
935
+ name: "baseURL",
936
+ label: "Base URL",
937
+ type: "url",
938
+ required: false,
939
+ default: "https://api.z.ai/api/paas/v4",
940
+ help: "Defaults to the general API. Coding-Plan keys must use https://api.z.ai/api/coding/paas/v4."
941
+ }
942
+ ]
943
+ }
944
+ ],
945
+ knownModels: [
946
+ {
947
+ id: "glm-5.2",
948
+ displayName: "GLM-5.2",
949
+ capabilities: {
950
+ streaming: true,
951
+ tools: true,
952
+ vision: false,
953
+ systemPrompt: true,
954
+ maxContextTokens: 1e6
955
+ }
956
+ },
957
+ {
958
+ id: "glm-4.7",
959
+ displayName: "GLM-4.7",
960
+ capabilities: {
961
+ streaming: true,
962
+ tools: true,
963
+ vision: false,
964
+ systemPrompt: true,
965
+ maxContextTokens: 2e5
966
+ }
967
+ }
968
+ ],
969
+ supportsModelListing: false,
970
+ docsUrl: "https://docs.z.ai/"
971
+ };
972
+ var ZaiAdapter = class extends OpenAIAdapter {
973
+ vendor = zaiManifest.vendor;
974
+ init(auth, client) {
975
+ super.init(
976
+ {
977
+ ...auth,
978
+ baseURL: auth.baseURL ?? "https://api.z.ai/api/paas/v4"
979
+ },
980
+ client
981
+ );
982
+ }
983
+ knownModels() {
984
+ return zaiManifest.knownModels;
985
+ }
986
+ };
987
+ var zaiFactory = {
988
+ vendor: zaiManifest.vendor,
989
+ manifest: zaiManifest,
990
+ create: () => new ZaiAdapter()
991
+ };
833
992
 
834
993
  // src/adapters/anthropic/adapter.ts
835
994
  var import_sdk = __toESM(require("@anthropic-ai/sdk"), 1);
@@ -3003,6 +3162,8 @@ var huggingfaceFactory = {
3003
3162
  registerAdapter(openAIFactory);
3004
3163
  registerAdapter(deepseekFactory);
3005
3164
  registerAdapter(basetenFactory);
3165
+ registerAdapter(moonshotFactory);
3166
+ registerAdapter(zaiFactory);
3006
3167
  registerAdapter(anthropicFactory);
3007
3168
  registerAdapter(googleFactory);
3008
3169
  registerAdapter(vertexGeminiFactory);
@@ -3019,6 +3180,8 @@ function normalizeAuth(vendor, raw) {
3019
3180
  case "anthropic":
3020
3181
  case "groq":
3021
3182
  case "huggingface":
3183
+ case "moonshot":
3184
+ case "zai":
3022
3185
  return requireApiKey(vendor, raw);
3023
3186
  case "deepseek":
3024
3187
  return {