@jambonz/llm 0.5.3 → 0.5.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.
@@ -146,12 +146,18 @@ async function* streamFromOpenAI(client, req, options) {
146
146
  let usage;
147
147
  let finalFinishReason = null;
148
148
  let finalRawReason;
149
+ let sawContent = false;
149
150
  try {
150
151
  for await (const chunk of stream) {
151
152
  if (req.signal?.aborted) {
152
153
  yield { type: "end", finishReason: "aborted" };
153
154
  return;
154
155
  }
156
+ const chunkError = chunk.error;
157
+ if (chunkError) {
158
+ const message = chunkError && typeof chunkError === "object" && "message" in chunkError ? String(chunkError.message) : JSON.stringify(chunkError);
159
+ throw new Error(`OpenAI-compatible stream returned an error: ${message}`);
160
+ }
155
161
  if (chunk.usage) {
156
162
  usage = {
157
163
  ...chunk.usage.prompt_tokens !== void 0 ? { inputTokens: chunk.usage.prompt_tokens } : {},
@@ -165,6 +171,7 @@ async function* streamFromOpenAI(client, req, options) {
165
171
  const finishReason = choice.finish_reason;
166
172
  if (delta?.content) {
167
173
  if (t2 === void 0) t2 = process.hrtime.bigint();
174
+ sawContent = true;
168
175
  yield { type: "token", text: delta.content };
169
176
  }
170
177
  if (delta?.tool_calls) {
@@ -222,6 +229,12 @@ async function* streamFromOpenAI(client, req, options) {
222
229
  }
223
230
  throw err;
224
231
  }
232
+ const producedNothing = finalFinishReason === null && !sawContent && toolCallsEmitted.size === 0 && startedIds.size === 0 && usage === void 0;
233
+ if (producedNothing) {
234
+ throw new Error(
235
+ "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."
236
+ );
237
+ }
225
238
  const endEvent = {
226
239
  type: "end",
227
240
  finishReason: finalFinishReason ?? "stop",
@@ -817,6 +830,152 @@ var basetenFactory = {
817
830
  manifest: basetenManifest,
818
831
  create: () => new BasetenAdapter()
819
832
  };
833
+ var moonshotManifest = {
834
+ vendor: "moonshot",
835
+ displayName: "Moonshot (Kimi)",
836
+ authKinds: [
837
+ {
838
+ kind: "apiKey",
839
+ displayName: "API Key",
840
+ fields: [
841
+ {
842
+ name: "apiKey",
843
+ label: "API Key",
844
+ type: "password",
845
+ required: true,
846
+ help: "Get an API key from https://platform.moonshot.ai/console/api-keys"
847
+ },
848
+ {
849
+ name: "baseURL",
850
+ label: "Base URL",
851
+ type: "url",
852
+ required: false,
853
+ default: "https://api.moonshot.ai/v1",
854
+ help: "Defaults to the global endpoint. Set to https://api.moonshot.cn/v1 for the China endpoint."
855
+ }
856
+ ]
857
+ }
858
+ ],
859
+ knownModels: [
860
+ {
861
+ id: "kimi-k2.6",
862
+ displayName: "Kimi K2.6",
863
+ capabilities: {
864
+ streaming: true,
865
+ tools: true,
866
+ vision: true,
867
+ systemPrompt: true,
868
+ maxContextTokens: 262144
869
+ }
870
+ },
871
+ {
872
+ id: "kimi-k2.5",
873
+ displayName: "Kimi K2.5",
874
+ capabilities: {
875
+ streaming: true,
876
+ tools: true,
877
+ vision: true,
878
+ systemPrompt: true,
879
+ maxContextTokens: 262144
880
+ }
881
+ }
882
+ ],
883
+ supportsModelListing: true,
884
+ docsUrl: "https://platform.moonshot.ai/docs"
885
+ };
886
+ var MoonshotAdapter = class extends OpenAIAdapter {
887
+ vendor = moonshotManifest.vendor;
888
+ init(auth, client) {
889
+ super.init(
890
+ {
891
+ ...auth,
892
+ baseURL: auth.baseURL ?? "https://api.moonshot.ai/v1"
893
+ },
894
+ client
895
+ );
896
+ }
897
+ knownModels() {
898
+ return moonshotManifest.knownModels;
899
+ }
900
+ };
901
+ var moonshotFactory = {
902
+ vendor: moonshotManifest.vendor,
903
+ manifest: moonshotManifest,
904
+ create: () => new MoonshotAdapter()
905
+ };
906
+ var zaiManifest = {
907
+ vendor: "zai",
908
+ displayName: "Z.ai (GLM)",
909
+ authKinds: [
910
+ {
911
+ kind: "apiKey",
912
+ displayName: "API Key",
913
+ fields: [
914
+ {
915
+ name: "apiKey",
916
+ label: "API Key",
917
+ type: "password",
918
+ required: true,
919
+ help: "Get an API key from https://z.ai/manage-apikey/apikey-list"
920
+ },
921
+ {
922
+ name: "baseURL",
923
+ label: "Base URL",
924
+ type: "url",
925
+ required: false,
926
+ default: "https://api.z.ai/api/paas/v4",
927
+ help: "Defaults to the general API. Coding-Plan keys must use https://api.z.ai/api/coding/paas/v4."
928
+ }
929
+ ]
930
+ }
931
+ ],
932
+ knownModels: [
933
+ {
934
+ id: "glm-5.2",
935
+ displayName: "GLM-5.2",
936
+ capabilities: {
937
+ streaming: true,
938
+ tools: true,
939
+ vision: false,
940
+ systemPrompt: true,
941
+ maxContextTokens: 1e6
942
+ }
943
+ },
944
+ {
945
+ id: "glm-4.7",
946
+ displayName: "GLM-4.7",
947
+ capabilities: {
948
+ streaming: true,
949
+ tools: true,
950
+ vision: false,
951
+ systemPrompt: true,
952
+ maxContextTokens: 2e5
953
+ }
954
+ }
955
+ ],
956
+ supportsModelListing: false,
957
+ docsUrl: "https://docs.z.ai/"
958
+ };
959
+ var ZaiAdapter = class extends OpenAIAdapter {
960
+ vendor = zaiManifest.vendor;
961
+ init(auth, client) {
962
+ super.init(
963
+ {
964
+ ...auth,
965
+ baseURL: auth.baseURL ?? "https://api.z.ai/api/paas/v4"
966
+ },
967
+ client
968
+ );
969
+ }
970
+ knownModels() {
971
+ return zaiManifest.knownModels;
972
+ }
973
+ };
974
+ var zaiFactory = {
975
+ vendor: zaiManifest.vendor,
976
+ manifest: zaiManifest,
977
+ create: () => new ZaiAdapter()
978
+ };
820
979
 
821
980
  // src/adapters/anthropic/adapter.ts
822
981
  var import_sdk = __toESM(require("@anthropic-ai/sdk"), 1);
@@ -2990,6 +3149,8 @@ var huggingfaceFactory = {
2990
3149
  registerAdapter(openAIFactory);
2991
3150
  registerAdapter(deepseekFactory);
2992
3151
  registerAdapter(basetenFactory);
3152
+ registerAdapter(moonshotFactory);
3153
+ registerAdapter(zaiFactory);
2993
3154
  registerAdapter(anthropicFactory);
2994
3155
  registerAdapter(googleFactory);
2995
3156
  registerAdapter(vertexGeminiFactory);