@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.d.cts CHANGED
@@ -31,9 +31,9 @@ interface RawCredential {
31
31
  /**
32
32
  * Convert a vendor + raw credential into an `AuthSpec` discriminated union member.
33
33
  *
34
- * Supported vendors: openai, deepseek, baseten, anthropic, google, vertex (alias for
35
- * vertex-gemini + vertex-openai — both accept the same auth shape), vertex-gemini,
36
- * vertex-openai, bedrock, azure-openai, groq, huggingface.
34
+ * Supported vendors: openai, deepseek, baseten, moonshot, zai, anthropic, google,
35
+ * vertex (alias for vertex-gemini + vertex-openai — both accept the same auth shape),
36
+ * vertex-gemini, vertex-openai, bedrock, azure-openai, groq, huggingface.
37
37
  *
38
38
  * Throws with a clear message if the raw credential is missing required fields.
39
39
  */
package/dist/index.d.ts CHANGED
@@ -31,9 +31,9 @@ interface RawCredential {
31
31
  /**
32
32
  * Convert a vendor + raw credential into an `AuthSpec` discriminated union member.
33
33
  *
34
- * Supported vendors: openai, deepseek, baseten, anthropic, google, vertex (alias for
35
- * vertex-gemini + vertex-openai — both accept the same auth shape), vertex-gemini,
36
- * vertex-openai, bedrock, azure-openai, groq, huggingface.
34
+ * Supported vendors: openai, deepseek, baseten, moonshot, zai, anthropic, google,
35
+ * vertex (alias for vertex-gemini + vertex-openai — both accept the same auth shape),
36
+ * vertex-gemini, vertex-openai, bedrock, azure-openai, groq, huggingface.
37
37
  *
38
38
  * Throws with a clear message if the raw credential is missing required fields.
39
39
  */
package/dist/index.js CHANGED
@@ -114,12 +114,18 @@ async function* streamFromOpenAI(client, req, options) {
114
114
  let usage;
115
115
  let finalFinishReason = null;
116
116
  let finalRawReason;
117
+ let sawContent = false;
117
118
  try {
118
119
  for await (const chunk of stream) {
119
120
  if (req.signal?.aborted) {
120
121
  yield { type: "end", finishReason: "aborted" };
121
122
  return;
122
123
  }
124
+ const chunkError = chunk.error;
125
+ if (chunkError) {
126
+ const message = chunkError && typeof chunkError === "object" && "message" in chunkError ? String(chunkError.message) : JSON.stringify(chunkError);
127
+ throw new Error(`OpenAI-compatible stream returned an error: ${message}`);
128
+ }
123
129
  if (chunk.usage) {
124
130
  usage = {
125
131
  ...chunk.usage.prompt_tokens !== void 0 ? { inputTokens: chunk.usage.prompt_tokens } : {},
@@ -133,6 +139,7 @@ async function* streamFromOpenAI(client, req, options) {
133
139
  const finishReason = choice.finish_reason;
134
140
  if (delta?.content) {
135
141
  if (t2 === void 0) t2 = process.hrtime.bigint();
142
+ sawContent = true;
136
143
  yield { type: "token", text: delta.content };
137
144
  }
138
145
  if (delta?.tool_calls) {
@@ -190,6 +197,12 @@ async function* streamFromOpenAI(client, req, options) {
190
197
  }
191
198
  throw err;
192
199
  }
200
+ const producedNothing = finalFinishReason === null && !sawContent && toolCallsEmitted.size === 0 && startedIds.size === 0 && usage === void 0;
201
+ if (producedNothing) {
202
+ throw new Error(
203
+ "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."
204
+ );
205
+ }
193
206
  const endEvent = {
194
207
  type: "end",
195
208
  finishReason: finalFinishReason ?? "stop",
@@ -785,6 +798,152 @@ var basetenFactory = {
785
798
  manifest: basetenManifest,
786
799
  create: () => new BasetenAdapter()
787
800
  };
801
+ var moonshotManifest = {
802
+ vendor: "moonshot",
803
+ displayName: "Moonshot (Kimi)",
804
+ authKinds: [
805
+ {
806
+ kind: "apiKey",
807
+ displayName: "API Key",
808
+ fields: [
809
+ {
810
+ name: "apiKey",
811
+ label: "API Key",
812
+ type: "password",
813
+ required: true,
814
+ help: "Get an API key from https://platform.moonshot.ai/console/api-keys"
815
+ },
816
+ {
817
+ name: "baseURL",
818
+ label: "Base URL",
819
+ type: "url",
820
+ required: false,
821
+ default: "https://api.moonshot.ai/v1",
822
+ help: "Defaults to the global endpoint. Set to https://api.moonshot.cn/v1 for the China endpoint."
823
+ }
824
+ ]
825
+ }
826
+ ],
827
+ knownModels: [
828
+ {
829
+ id: "kimi-k2.6",
830
+ displayName: "Kimi K2.6",
831
+ capabilities: {
832
+ streaming: true,
833
+ tools: true,
834
+ vision: true,
835
+ systemPrompt: true,
836
+ maxContextTokens: 262144
837
+ }
838
+ },
839
+ {
840
+ id: "kimi-k2.5",
841
+ displayName: "Kimi K2.5",
842
+ capabilities: {
843
+ streaming: true,
844
+ tools: true,
845
+ vision: true,
846
+ systemPrompt: true,
847
+ maxContextTokens: 262144
848
+ }
849
+ }
850
+ ],
851
+ supportsModelListing: true,
852
+ docsUrl: "https://platform.moonshot.ai/docs"
853
+ };
854
+ var MoonshotAdapter = class extends OpenAIAdapter {
855
+ vendor = moonshotManifest.vendor;
856
+ init(auth, client) {
857
+ super.init(
858
+ {
859
+ ...auth,
860
+ baseURL: auth.baseURL ?? "https://api.moonshot.ai/v1"
861
+ },
862
+ client
863
+ );
864
+ }
865
+ knownModels() {
866
+ return moonshotManifest.knownModels;
867
+ }
868
+ };
869
+ var moonshotFactory = {
870
+ vendor: moonshotManifest.vendor,
871
+ manifest: moonshotManifest,
872
+ create: () => new MoonshotAdapter()
873
+ };
874
+ var zaiManifest = {
875
+ vendor: "zai",
876
+ displayName: "Z.ai (GLM)",
877
+ authKinds: [
878
+ {
879
+ kind: "apiKey",
880
+ displayName: "API Key",
881
+ fields: [
882
+ {
883
+ name: "apiKey",
884
+ label: "API Key",
885
+ type: "password",
886
+ required: true,
887
+ help: "Get an API key from https://z.ai/manage-apikey/apikey-list"
888
+ },
889
+ {
890
+ name: "baseURL",
891
+ label: "Base URL",
892
+ type: "url",
893
+ required: false,
894
+ default: "https://api.z.ai/api/paas/v4",
895
+ help: "Defaults to the general API. Coding-Plan keys must use https://api.z.ai/api/coding/paas/v4."
896
+ }
897
+ ]
898
+ }
899
+ ],
900
+ knownModels: [
901
+ {
902
+ id: "glm-5.2",
903
+ displayName: "GLM-5.2",
904
+ capabilities: {
905
+ streaming: true,
906
+ tools: true,
907
+ vision: false,
908
+ systemPrompt: true,
909
+ maxContextTokens: 1e6
910
+ }
911
+ },
912
+ {
913
+ id: "glm-4.7",
914
+ displayName: "GLM-4.7",
915
+ capabilities: {
916
+ streaming: true,
917
+ tools: true,
918
+ vision: false,
919
+ systemPrompt: true,
920
+ maxContextTokens: 2e5
921
+ }
922
+ }
923
+ ],
924
+ supportsModelListing: false,
925
+ docsUrl: "https://docs.z.ai/"
926
+ };
927
+ var ZaiAdapter = class extends OpenAIAdapter {
928
+ vendor = zaiManifest.vendor;
929
+ init(auth, client) {
930
+ super.init(
931
+ {
932
+ ...auth,
933
+ baseURL: auth.baseURL ?? "https://api.z.ai/api/paas/v4"
934
+ },
935
+ client
936
+ );
937
+ }
938
+ knownModels() {
939
+ return zaiManifest.knownModels;
940
+ }
941
+ };
942
+ var zaiFactory = {
943
+ vendor: zaiManifest.vendor,
944
+ manifest: zaiManifest,
945
+ create: () => new ZaiAdapter()
946
+ };
788
947
 
789
948
  // src/adapters/anthropic/adapter.ts
790
949
  import Anthropic from "@anthropic-ai/sdk";
@@ -2964,6 +3123,8 @@ var huggingfaceFactory = {
2964
3123
  registerAdapter(openAIFactory);
2965
3124
  registerAdapter(deepseekFactory);
2966
3125
  registerAdapter(basetenFactory);
3126
+ registerAdapter(moonshotFactory);
3127
+ registerAdapter(zaiFactory);
2967
3128
  registerAdapter(anthropicFactory);
2968
3129
  registerAdapter(googleFactory);
2969
3130
  registerAdapter(vertexGeminiFactory);
@@ -2980,6 +3141,8 @@ function normalizeAuth(vendor, raw) {
2980
3141
  case "anthropic":
2981
3142
  case "groq":
2982
3143
  case "huggingface":
3144
+ case "moonshot":
3145
+ case "zai":
2983
3146
  return requireApiKey(vendor, raw);
2984
3147
  case "deepseek":
2985
3148
  return {