@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.
@@ -107,12 +107,18 @@ async function* streamFromOpenAI(client, req, options) {
107
107
  let usage;
108
108
  let finalFinishReason = null;
109
109
  let finalRawReason;
110
+ let sawContent = false;
110
111
  try {
111
112
  for await (const chunk of stream) {
112
113
  if (req.signal?.aborted) {
113
114
  yield { type: "end", finishReason: "aborted" };
114
115
  return;
115
116
  }
117
+ const chunkError = chunk.error;
118
+ if (chunkError) {
119
+ const message = chunkError && typeof chunkError === "object" && "message" in chunkError ? String(chunkError.message) : JSON.stringify(chunkError);
120
+ throw new Error(`OpenAI-compatible stream returned an error: ${message}`);
121
+ }
116
122
  if (chunk.usage) {
117
123
  usage = {
118
124
  ...chunk.usage.prompt_tokens !== void 0 ? { inputTokens: chunk.usage.prompt_tokens } : {},
@@ -126,6 +132,7 @@ async function* streamFromOpenAI(client, req, options) {
126
132
  const finishReason = choice.finish_reason;
127
133
  if (delta?.content) {
128
134
  if (t2 === void 0) t2 = process.hrtime.bigint();
135
+ sawContent = true;
129
136
  yield { type: "token", text: delta.content };
130
137
  }
131
138
  if (delta?.tool_calls) {
@@ -183,6 +190,12 @@ async function* streamFromOpenAI(client, req, options) {
183
190
  }
184
191
  throw err;
185
192
  }
193
+ const producedNothing = finalFinishReason === null && !sawContent && toolCallsEmitted.size === 0 && startedIds.size === 0 && usage === void 0;
194
+ if (producedNothing) {
195
+ throw new Error(
196
+ "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."
197
+ );
198
+ }
186
199
  const endEvent = {
187
200
  type: "end",
188
201
  finishReason: finalFinishReason ?? "stop",
@@ -778,6 +791,152 @@ var basetenFactory = {
778
791
  manifest: basetenManifest,
779
792
  create: () => new BasetenAdapter()
780
793
  };
794
+ var moonshotManifest = {
795
+ vendor: "moonshot",
796
+ displayName: "Moonshot (Kimi)",
797
+ authKinds: [
798
+ {
799
+ kind: "apiKey",
800
+ displayName: "API Key",
801
+ fields: [
802
+ {
803
+ name: "apiKey",
804
+ label: "API Key",
805
+ type: "password",
806
+ required: true,
807
+ help: "Get an API key from https://platform.moonshot.ai/console/api-keys"
808
+ },
809
+ {
810
+ name: "baseURL",
811
+ label: "Base URL",
812
+ type: "url",
813
+ required: false,
814
+ default: "https://api.moonshot.ai/v1",
815
+ help: "Defaults to the global endpoint. Set to https://api.moonshot.cn/v1 for the China endpoint."
816
+ }
817
+ ]
818
+ }
819
+ ],
820
+ knownModels: [
821
+ {
822
+ id: "kimi-k2.6",
823
+ displayName: "Kimi K2.6",
824
+ capabilities: {
825
+ streaming: true,
826
+ tools: true,
827
+ vision: true,
828
+ systemPrompt: true,
829
+ maxContextTokens: 262144
830
+ }
831
+ },
832
+ {
833
+ id: "kimi-k2.5",
834
+ displayName: "Kimi K2.5",
835
+ capabilities: {
836
+ streaming: true,
837
+ tools: true,
838
+ vision: true,
839
+ systemPrompt: true,
840
+ maxContextTokens: 262144
841
+ }
842
+ }
843
+ ],
844
+ supportsModelListing: true,
845
+ docsUrl: "https://platform.moonshot.ai/docs"
846
+ };
847
+ var MoonshotAdapter = class extends OpenAIAdapter {
848
+ vendor = moonshotManifest.vendor;
849
+ init(auth, client) {
850
+ super.init(
851
+ {
852
+ ...auth,
853
+ baseURL: auth.baseURL ?? "https://api.moonshot.ai/v1"
854
+ },
855
+ client
856
+ );
857
+ }
858
+ knownModels() {
859
+ return moonshotManifest.knownModels;
860
+ }
861
+ };
862
+ var moonshotFactory = {
863
+ vendor: moonshotManifest.vendor,
864
+ manifest: moonshotManifest,
865
+ create: () => new MoonshotAdapter()
866
+ };
867
+ var zaiManifest = {
868
+ vendor: "zai",
869
+ displayName: "Z.ai (GLM)",
870
+ authKinds: [
871
+ {
872
+ kind: "apiKey",
873
+ displayName: "API Key",
874
+ fields: [
875
+ {
876
+ name: "apiKey",
877
+ label: "API Key",
878
+ type: "password",
879
+ required: true,
880
+ help: "Get an API key from https://z.ai/manage-apikey/apikey-list"
881
+ },
882
+ {
883
+ name: "baseURL",
884
+ label: "Base URL",
885
+ type: "url",
886
+ required: false,
887
+ default: "https://api.z.ai/api/paas/v4",
888
+ help: "Defaults to the general API. Coding-Plan keys must use https://api.z.ai/api/coding/paas/v4."
889
+ }
890
+ ]
891
+ }
892
+ ],
893
+ knownModels: [
894
+ {
895
+ id: "glm-5.2",
896
+ displayName: "GLM-5.2",
897
+ capabilities: {
898
+ streaming: true,
899
+ tools: true,
900
+ vision: false,
901
+ systemPrompt: true,
902
+ maxContextTokens: 1e6
903
+ }
904
+ },
905
+ {
906
+ id: "glm-4.7",
907
+ displayName: "GLM-4.7",
908
+ capabilities: {
909
+ streaming: true,
910
+ tools: true,
911
+ vision: false,
912
+ systemPrompt: true,
913
+ maxContextTokens: 2e5
914
+ }
915
+ }
916
+ ],
917
+ supportsModelListing: false,
918
+ docsUrl: "https://docs.z.ai/"
919
+ };
920
+ var ZaiAdapter = class extends OpenAIAdapter {
921
+ vendor = zaiManifest.vendor;
922
+ init(auth, client) {
923
+ super.init(
924
+ {
925
+ ...auth,
926
+ baseURL: auth.baseURL ?? "https://api.z.ai/api/paas/v4"
927
+ },
928
+ client
929
+ );
930
+ }
931
+ knownModels() {
932
+ return zaiManifest.knownModels;
933
+ }
934
+ };
935
+ var zaiFactory = {
936
+ vendor: zaiManifest.vendor,
937
+ manifest: zaiManifest,
938
+ create: () => new ZaiAdapter()
939
+ };
781
940
 
782
941
  // src/adapters/anthropic/adapter.ts
783
942
  import Anthropic from "@anthropic-ai/sdk";
@@ -2957,6 +3116,8 @@ var huggingfaceFactory = {
2957
3116
  registerAdapter(openAIFactory);
2958
3117
  registerAdapter(deepseekFactory);
2959
3118
  registerAdapter(basetenFactory);
3119
+ registerAdapter(moonshotFactory);
3120
+ registerAdapter(zaiFactory);
2960
3121
  registerAdapter(anthropicFactory);
2961
3122
  registerAdapter(googleFactory);
2962
3123
  registerAdapter(vertexGeminiFactory);